docs: 增加容器部署文档

This commit is contained in:
RockYang 2023-06-25 11:06:18 +08:00
parent d971e95900
commit 399a16fa28
10 changed files with 126 additions and 23 deletions

View File

@ -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. 运行后端程序
你可以自己编译或者直接下载我打包好的后端程序运行。

View File

@ -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]

View File

@ -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

View File

@ -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"

View File

@ -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 地址
}
}

View File

@ -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:

View File

@ -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"]

2
docker/mysql/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
data/*
logs/*

32
docker/mysql/conf/my.cnf Normal file
View File

@ -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

View File

@ -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