diff --git a/README.md b/README.md index 17ea3fc1..8965f917 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ * 聊天体验跟 ChatGPT 官方版本完全一致。 * 内置了各种预训练好的角色,比如小红书写手,英语翻译大师,苏格拉底,孔子,乔布斯,周报助手等。轻松满足你的各种聊天和应用需求。 -**本项目基于 MIT 协议,免费开放全部源代码,可以作为个人学习使用或者商用。如需商用建议联系作者登记,仅做统计使用,优秀项目我们将在项目首页为您展示。** +**本项目基于 MIT 协议,免费开放全部源代码,可以作为个人学习使用或者商用。如需商用建议联系作者登记,仅做统计使用,优秀项目我们将在项目首页为您展示。 +** ## 功能截图 @@ -66,9 +67,9 @@ ChatGPT 的服务。 3. 创建会话的时候可以选择聊天角色和模型。 4. 新增聊天设置功能,用户可以导入自己的 API KEY 5. 保存聊天记录,支持聊天上下文。 -7. 重构后台管理模块,更友好,扩展性更好的后台管理系统。 -8. 引入 ip2region 组件,记录用户的登录IP和地址。 -9. 支持会话搜索过滤。 +6. 重构后台管理模块,更友好,扩展性更好的后台管理系统。 +7. 引入 ip2region 组件,记录用户的登录IP和地址。 +8. 支持会话搜索过滤。 ## 项目地址 @@ -83,32 +84,40 @@ ChatGPT 的服务。 * [ ] 接入语音和 TTS API,支持语音聊天 * [ ] 开发手机 App 客户端 -## 安装部署 +## Docker 快速部署 -由于本项目采用的是前后端分离的开发方式,所以部署也需要前后端分开部署。我这里以 linux 系统为例,演示一下部署过程: +V3.0.0 版本以后已经支持使用容器部署了,跳过所有的繁琐的环境准备,一条命令就可以轻松部署上线。 ### 1. 导入数据库 +首先我们需要创建一个 MySQL 容器,并导入初始数据库。 + +```shell +cd docker/mysql +# 创建 mysql 容器 +docker-compose up -d +# 导入数据库 +docker exec -i chatgpt-plus-mysql sh -c 'exec mysql -uroot -p12345678' < ../../database/chatgpt_plus.sql +``` + +如果你本地已经安装了 MySQL 服务,那么你只需手动导入数据库即可。 + ```shell -# 下载数据库 -wget wget https://github.com/yangjian102621/chatgpt-plus/releases/download/v3.0.0/chatgpt_plus.sql # 连接数据库 mysql -u username -p password # 导入数据库 -source chatgpt_plus.sql +source database/chatgpt_plus.sql ``` ### 2. 修改配置文档 -先拷贝项目中的 `api/go/config.sample.toml` 配置文档,修改代理地址和管理员密码: +修改配置文档 `docker/conf/config.toml` 配置文档,修改代理地址和管理员密码: ```toml Listen = "0.0.0.0:5678" ProxyURL = ["YOUR_PROXY_URL"] # 替换成你本地代理,如:http://127.0.0.1:7777 -#ProxyURL = "http://127.0.0.1:7777" #ProxyURL = "" 如果你的服务器本身就在墙外,那么你直接留空就好了 -MysqlDns = "mysql_user:mysql_pass@tcp(localhost:3306)/chatgpt_plus?charset=utf8&parseTime=True&loc=Local" - +MysqlDns = "root:12345678@tcp(172.22.11.200:3307)/chatgpt_plus?charset=utf8&parseTime=True&loc=Local" [Session] SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80" Name = "CHAT_SESSION_ID" @@ -124,6 +133,49 @@ MysqlDns = "mysql_user:mysql_pass@tcp(localhost:3306)/chatgpt_plus?charset=utf8& Password = "admin123" # 如果是生产环境的话,这里管理员的密码记得修改 ``` +修改 nginx 配置文档 `docker/conf/nginx/conf.d/chatgpt-plus.conf`,把后端转发的地址改成当前主机的内网 IP 地址。 + +```shell + # 这里配置后端 API 的转发 +location /api/ { + proxy_http_version 1.1; + proxy_connect_timeout 300s; + proxy_read_timeout 300s; + proxy_send_timeout 12s; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_pass http://172.28.173.76:6789; # 这里改成后端服务的内网 IP 地址 +} +``` + +### 3. 启动应用 + +```shell +cd docker +docker-compose up -d +``` + +* 前端访问地址:http://localhost:8080/chat +* 后台管理地址:http://localhost:8080/admin +* 移动端地址:http://localhost:8080/mobile + +## 手动安装部署 + +由于本项目采用的是前后端分离的开发方式,所以部署也需要前后端分开部署。我这里以 linux 系统为例,演示一下部署过程: + +### 1. 导入数据库 + +请参考容器部署的[导入数据](#1-导入数据库)。 + +### 2. 修改配置文档 + +先拷贝项目中的 `api/go/config.sample.toml` 配置文档,修改代理地址和管理员密码: + +如何修改请参考[修改配置文档](#2-修改配置文档) + ### 3. 运行后端程序 你可以自己编译或者直接下载我打包好的后端程序运行。 diff --git a/api/go/config.sample.toml b/api/go/config.sample.toml index cb0ad8cf..b5c425ec 100644 --- a/api/go/config.sample.toml +++ b/api/go/config.sample.toml @@ -1,5 +1,5 @@ Listen = "0.0.0.0:5678" -ProxyURL = ["YOUR_PROXY_URL"] +ProxyURL = "YOUR_PROXY_URL" MysqlDns = "mysql_user:mysql_pass@tcp(localhost:3306)/chatgpt_plus?charset=utf8&parseTime=True&loc=Local" [Session] diff --git a/docker/build.sh b/docker/build.sh index 0bb23d5b..3e8b4ef0 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -25,7 +25,8 @@ docker build -t chatgpt-plus-vue:$version -f dockerfile-vue ../ # add tag for aliyum docker registry goImageId=`docker images |grep chatgpt-plus-go |grep $version |awk '{print $3}'` docker tag $goImageId registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-go:$version - +echo $goImageId vueImageId=`docker images |grep chatgpt-plus-vue |grep $version |awk '{print $3}'` +echo $vueImageId docker tag $vueImageId registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-vue:$version diff --git a/docker/conf/config.toml b/docker/conf/config.toml index 699930a0..049e50eb 100644 --- a/docker/conf/config.toml +++ b/docker/conf/config.toml @@ -1,6 +1,6 @@ Listen = "0.0.0.0:5678" -ProxyURL = "http://192.168.3.200:7777" -MysqlDns = "root:12345678@tcp(192.168.3.200:3306)/chatgpt_plus?charset=utf8mb4&parseTime=True&loc=Local" +ProxyURL = "http://127.0.0.1:7777" +MysqlDns = "root:12345678@tcp(172.28.173.76:3307)/chatgpt_plus?charset=utf8mb4&parseTime=True&loc=Local" [Session] SecretKey = "8k0c67y2or1n7kbmn1w1c86ygqscguoktuf9t524jm64ls585z8uibpdssiy128s" diff --git a/docker/conf/nginx/conf.d/chatgpt-plus.conf b/docker/conf/nginx/conf.d/chatgpt-plus.conf index 2d97a390..f631802d 100644 --- a/docker/conf/nginx/conf.d/chatgpt-plus.conf +++ b/docker/conf/nginx/conf.d/chatgpt-plus.conf @@ -35,7 +35,7 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; - proxy_pass http://192.168.3.200:6789; # 这里改成后端服务的内网 IP 地址 + proxy_pass http://172.28.173.76:6789; # 这里改成后端服务的内网 IP 地址 } } diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index f52efec1..ef0c6cf9 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -5,21 +5,18 @@ services: image: registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-go:v3.0.1 # image: chatgpt-plus-go:v3.0.1 container_name: chatgpt-plus-go - #build: ./ restart: always - # network_mode: host ports: - "6789:5678" volumes: - ./conf/config.toml:/var/www/app/config.toml + # 前端应用 chatgpt-vue: image: registry.cn-hangzhou.aliyuncs.com/geekmaster/chatgpt-plus-vue:v3.0.1 # image: chatgpt-plus-vue:v3.0.1 container_name: chatgpt-plus-vue - #build: ./ restart: always - # network_mode: host ports: - "8080:8080" volumes: diff --git a/docker/dockerfile-api-go b/docker/dockerfile-api-go index f671e712..270f1a82 100644 --- a/docker/dockerfile-api-go +++ b/docker/dockerfile-api-go @@ -12,4 +12,4 @@ RUN apt-get -qq update \ && apt-get -qq install -y --no-install-recommends ca-certificates curl # 容器启动时执行的命令 -CMD ["./chatgpt-v3-amd64-linux"] +CMD ["./chatgpt-v3-amd64-linux", "--debug=false"] diff --git a/docker/mysql/.gitignore b/docker/mysql/.gitignore new file mode 100644 index 00000000..13aa18b2 --- /dev/null +++ b/docker/mysql/.gitignore @@ -0,0 +1,2 @@ +data/* +logs/* diff --git a/docker/mysql/conf/my.cnf b/docker/mysql/conf/my.cnf new file mode 100644 index 00000000..3ba41579 --- /dev/null +++ b/docker/mysql/conf/my.cnf @@ -0,0 +1,32 @@ +# +# The MySQL database server configuration file. +# +# One can use all long options that the program supports. +# Run program with --help to get a list of available options and with +# --print-defaults to see which it would actually understand and use. +# +# For explanations see +# http://dev.mysql.com/doc/mysql/en/server-system-variables.html + +# Here is entries for some specific programs +# The following values assume you have at least 32M ram + +[mysqld] +# +# * Basic Settings +# +#user = mysql +# pid-file = /var/run/mysqld/mysqld.pid +# socket = /var/run/mysqld/mysqld.sock +# port = 3306 +# datadir = /var/lib/mysql + + +# If MySQL is running as a replication slave, this should be +# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir +# tmpdir = /tmp +# +# Instead of skip-networking the default is now to listen only on +# localhost which is more compatible and is not less secure. +bind-address = 0.0.0.0 +mysqlx-bind-address = 0.0.0.0 diff --git a/docker/mysql/docker-compose.yaml b/docker/mysql/docker-compose.yaml new file mode 100644 index 00000000..b2d34785 --- /dev/null +++ b/docker/mysql/docker-compose.yaml @@ -0,0 +1,19 @@ +version: '3' +services: + # 后端 API 程序 + mysql: + image: mysql:8.0.33 + container_name: chatgpt-plus-mysql + command: --default-authentication-plugin=mysql_native_password + restart: always + environment: + - MYSQL_ROOT_PASSWORD=12345678 + ports: + - "3307:3306" + volumes: + - ./conf/my.cnf:/etc/mysql/my.cnf + - ./data:/var/lib/mysql + - ./logs:/var/log/mysql + + +