Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c90fc7e0
authored
Jun 22, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: use NODE_TYPE to determine node type
parent
e975d41c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
10 deletions
+13
-10
README.md
+7
-6
common/constants.go
+1
-1
common/redis.go
+2
-2
docker-compose.yml
+3
-1
No files found.
README.md
View file @
c90fc7e0
...
@@ -152,12 +152,11 @@ sudo service nginx restart
...
@@ -152,12 +152,11 @@ sudo service nginx restart
### 多机部署
### 多机部署
1. 所有服务器
`
SESSION_SECRET
`
设置一样的值。
1. 所有服务器
`
SESSION_SECRET
`
设置一样的值。
2. 必须设置
`
SQL_DSN
`
,使用 MySQL 数据库而非 SQLite,所有服务器连接同一个数据库。
2. 必须设置
`
SQL_DSN
`
,使用 MySQL 数据库而非 SQLite,所有服务器连接同一个数据库。
3. 所有从服务器必须设置
`
SYNC_FREQUENCY
`
,以定期从数据库同步配置。
3. 所有从服务器必须设置
`
NODE_TYPE
`
为
`
slave
`
。
4. 从服务器可以选择设置
`
FRONTEND_BASE_URL
`
,以重定向页面请求到主服务器。
4. 设置
`
SYNC_FREQUENCY
`
后服务器将定期从数据库同步配置。
5. 从服务器上
**
分别
**
装好 Redis,设置好
`
REDIS_CONN_STRING
`
,这样可以做到在缓存未过期的情况下数据库零访问,可以减少延迟。
5. 从服务器可以选择设置
`
FRONTEND_BASE_URL
`
,以重定向页面请求到主服务器。
6. 如果主服务器访问数据库延迟也比较高,则也需要启用 Redis,并设置
`
SYNC_FREQUENCY
`
,以定期从数据库同步配置。
6. 从服务器上
**
分别
**
装好 Redis,设置好
`
REDIS_CONN_STRING
`
,这样可以做到在缓存未过期的情况下数据库零访问,可以减少延迟。
7. 如果主服务器访问数据库延迟也比较高,则也需要启用 Redis,并设置
`
SYNC_FREQUENCY
`
,以定期从数据库同步配置。
注意,设置
`
SYNC_FREQUENCY
`
后会导致从服务器的状态不会实时更新,而是定期同步。
环境变量的具体使用方法详见[此处]
(
#环境变量)。
环境变量的具体使用方法详见[此处]
(
#环境变量)。
...
@@ -249,6 +248,8 @@ graph LR
...
@@ -249,6 +248,8 @@ graph LR
+
例子:
`FRONTEND_BASE_URL=https://openai.justsong.cn`
+
例子:
`FRONTEND_BASE_URL=https://openai.justsong.cn`
5.
`SYNC_FREQUENCY`
:设置之后将定期与数据库同步配置,单位为秒,未设置则不进行同步。
5.
`SYNC_FREQUENCY`
:设置之后将定期与数据库同步配置,单位为秒,未设置则不进行同步。
+
例子:
`SYNC_FREQUENCY=60`
+
例子:
`SYNC_FREQUENCY=60`
6.
`NODE_TYPE`
:设置之后将指定节点类型,可选值为
`master`
和
`slave`
,未设置则默认为
`master`
。
+
例子:
`NODE_TYPE=slave`
### 命令行参数
### 命令行参数
1.
`--port <port_number>`
: 指定服务器监听的端口号,默认为
`3000`
。
1.
`--port <port_number>`
: 指定服务器监听的端口号,默认为
`3000`
。
...
...
common/constants.go
View file @
c90fc7e0
...
@@ -68,7 +68,7 @@ var PreConsumedQuota = 500
...
@@ -68,7 +68,7 @@ var PreConsumedQuota = 500
var
RootUserEmail
=
""
var
RootUserEmail
=
""
var
IsMasterNode
=
os
.
Getenv
(
"
SYNC_FREQUENCY"
)
==
"
"
var
IsMasterNode
=
os
.
Getenv
(
"
NODE_TYPE"
)
!=
"slave
"
const
(
const
(
RoleGuestUser
=
0
RoleGuestUser
=
0
...
...
common/redis.go
View file @
c90fc7e0
...
@@ -17,9 +17,9 @@ func InitRedisClient() (err error) {
...
@@ -17,9 +17,9 @@ func InitRedisClient() (err error) {
SysLog
(
"REDIS_CONN_STRING not set, Redis is not enabled"
)
SysLog
(
"REDIS_CONN_STRING not set, Redis is not enabled"
)
return
nil
return
nil
}
}
if
IsMasterNode
{
if
os
.
Getenv
(
"SYNC_FREQUENCY"
)
==
""
{
SysLog
(
"Redis is disabled on master node"
)
RedisEnabled
=
false
RedisEnabled
=
false
SysLog
(
"SYNC_FREQUENCY not set, Redis is disabled"
)
return
nil
return
nil
}
}
SysLog
(
"Redis is enabled"
)
SysLog
(
"Redis is enabled"
)
...
...
docker-compose.yml
View file @
c90fc7e0
...
@@ -16,8 +16,10 @@ services:
...
@@ -16,8 +16,10 @@ services:
-
REDIS_CONN_STRING=redis://redis
-
REDIS_CONN_STRING=redis://redis
-
SESSION_SECRET=random_string
# 修改为随机字符串
-
SESSION_SECRET=random_string
# 修改为随机字符串
-
TZ=Asia/Shanghai
-
TZ=Asia/Shanghai
# - SYNC_FREQUENCY=60 # 多机部署时从节点取消注释该行
# - NODE_TYPE=slave # 多机部署时从节点取消注释该行
# - SYNC_FREQUENCY=60 # 需要定期从数据库加载数据时取消注释该行
# - FRONTEND_BASE_URL=https://openai.justsong.cn # 多机部署时从节点取消注释该行
# - FRONTEND_BASE_URL=https://openai.justsong.cn # 多机部署时从节点取消注释该行
depends_on
:
depends_on
:
-
redis
-
redis
healthcheck
:
healthcheck
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment