befly-tpl 3.4.12 → 3.4.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SYSTEMD_DEPLOY.md +8 -21
- package/main.ts +4 -0
- package/package.json +13 -4
- package/befly.service +0 -93
package/SYSTEMD_DEPLOY.md
CHANGED
|
@@ -138,19 +138,15 @@ sudo systemctl restart befly
|
|
|
138
138
|
|
|
139
139
|
## 配置说明
|
|
140
140
|
|
|
141
|
-
###
|
|
141
|
+
### 单进程模式
|
|
142
142
|
|
|
143
143
|
```ini
|
|
144
|
-
#
|
|
144
|
+
# Systemd 推荐单进程模式
|
|
145
145
|
ExecStart=/usr/local/bin/bun run befly start
|
|
146
|
-
|
|
147
|
-
# 选项2:自动集群模式(推荐,使用所有CPU核心)
|
|
148
|
-
ExecStart=/usr/local/bin/bun run befly start --cluster max
|
|
149
|
-
|
|
150
|
-
# 选项3:指定进程数(如4个进程)
|
|
151
|
-
ExecStart=/usr/local/bin/bun run befly start --cluster 4
|
|
152
146
|
```
|
|
153
147
|
|
|
148
|
+
**集群部署推荐使用 PM2**:Systemd 适合单进程部署,如需集群模式请使用 PM2(参见项目根目录的 PM2 相关文档)
|
|
149
|
+
|
|
154
150
|
### 用户和权限
|
|
155
151
|
|
|
156
152
|
```bash
|
|
@@ -193,18 +189,9 @@ EnvironmentFile=/var/www/befly/.env.production
|
|
|
193
189
|
|
|
194
190
|
### Nginx 配置示例
|
|
195
191
|
|
|
196
|
-
|
|
197
|
-
upstream befly_cluster {
|
|
198
|
-
# 集群模式下配置多个端口
|
|
199
|
-
server 127.0.0.1:3000;
|
|
200
|
-
server 127.0.0.1:3001;
|
|
201
|
-
server 127.0.0.1:3002;
|
|
202
|
-
server 127.0.0.1:3003;
|
|
203
|
-
|
|
204
|
-
# 负载均衡策略
|
|
205
|
-
least_conn; # 最少连接
|
|
206
|
-
}
|
|
192
|
+
#### 单进程模式
|
|
207
193
|
|
|
194
|
+
```nginx
|
|
208
195
|
server {
|
|
209
196
|
listen 80;
|
|
210
197
|
server_name yourdomain.com;
|
|
@@ -215,7 +202,7 @@ server {
|
|
|
215
202
|
# ssl_certificate_key /path/to/key.pem;
|
|
216
203
|
|
|
217
204
|
location / {
|
|
218
|
-
proxy_pass http://
|
|
205
|
+
proxy_pass http://127.0.0.1:3000;
|
|
219
206
|
proxy_http_version 1.1;
|
|
220
207
|
|
|
221
208
|
# WebSocket 支持
|
|
@@ -306,7 +293,7 @@ sudo systemd-analyze verify /etc/systemd/system/befly.service
|
|
|
306
293
|
|
|
307
294
|
# 测试启动命令
|
|
308
295
|
cd /var/www/befly
|
|
309
|
-
sudo -u www-data bun run befly start
|
|
296
|
+
sudo -u www-data bun run befly start
|
|
310
297
|
```
|
|
311
298
|
|
|
312
299
|
### 权限问题
|
package/main.ts
ADDED
package/package.json
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly-tpl",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.14",
|
|
4
4
|
"description": "Befly 3.0 TypeScript Template",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public",
|
|
8
8
|
"registry": "https://registry.npmjs.org"
|
|
9
9
|
},
|
|
10
|
-
"scripts": {
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev": "bun run --env-file=.env.development main.ts",
|
|
12
|
+
"start": "bun run --env-file=.env.production main.ts",
|
|
13
|
+
"pm2:start": "pm2 start pm2.config.js --env production",
|
|
14
|
+
"pm2:dev": "pm2 start pm2.config.js --env development",
|
|
15
|
+
"sync:dev": "NODE_ENV=development befly sync",
|
|
16
|
+
"sync:prod": "NODE_ENV=production befly sync"
|
|
17
|
+
},
|
|
11
18
|
"files": [
|
|
12
19
|
"apis",
|
|
13
20
|
"tables",
|
|
21
|
+
"main.ts",
|
|
22
|
+
"ecosystem.config.js",
|
|
14
23
|
".env.development",
|
|
15
24
|
".npmrc",
|
|
16
25
|
"befly.service",
|
|
@@ -23,10 +32,10 @@
|
|
|
23
32
|
],
|
|
24
33
|
"type": "module",
|
|
25
34
|
"dependencies": {
|
|
26
|
-
"befly": "^3.4.
|
|
35
|
+
"befly": "^3.4.13"
|
|
27
36
|
},
|
|
28
37
|
"engines": {
|
|
29
38
|
"bun": ">=1.3.0"
|
|
30
39
|
},
|
|
31
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "f37b14e9acad47245d399709829013fda8a0c44e"
|
|
32
41
|
}
|
package/befly.service
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
# Befly Systemd Service 配置文件
|
|
2
|
-
#
|
|
3
|
-
# 使用方法:
|
|
4
|
-
# 1. 复制此文件到 /etc/systemd/system/befly.service
|
|
5
|
-
# sudo cp befly.service /etc/systemd/system/
|
|
6
|
-
#
|
|
7
|
-
# 2. 修改配置中的路径和用户信息
|
|
8
|
-
# sudo nano /etc/systemd/system/befly.service
|
|
9
|
-
#
|
|
10
|
-
# 3. 重载 systemd 配置
|
|
11
|
-
# sudo systemctl daemon-reload
|
|
12
|
-
#
|
|
13
|
-
# 4. 启动服务
|
|
14
|
-
# sudo systemctl start befly
|
|
15
|
-
#
|
|
16
|
-
# 5. 开机自启
|
|
17
|
-
# sudo systemctl enable befly
|
|
18
|
-
#
|
|
19
|
-
# 6. 查看状态
|
|
20
|
-
# sudo systemctl status befly
|
|
21
|
-
#
|
|
22
|
-
# 7. 查看日志
|
|
23
|
-
# sudo journalctl -u befly -f
|
|
24
|
-
#
|
|
25
|
-
# 8. 重启服务
|
|
26
|
-
# sudo systemctl restart befly
|
|
27
|
-
#
|
|
28
|
-
# 9. 停止服务
|
|
29
|
-
# sudo systemctl stop befly
|
|
30
|
-
|
|
31
|
-
[Unit]
|
|
32
|
-
Description=Befly Application Server
|
|
33
|
-
Documentation=https://github.com/chenbimo/befly
|
|
34
|
-
After=network.target
|
|
35
|
-
|
|
36
|
-
[Service]
|
|
37
|
-
Type=simple
|
|
38
|
-
|
|
39
|
-
# 运行用户和组(根据实际情况修改)
|
|
40
|
-
User=www-data
|
|
41
|
-
Group=www-data
|
|
42
|
-
|
|
43
|
-
# 工作目录(修改为实际项目路径)
|
|
44
|
-
WorkingDirectory=/var/www/befly
|
|
45
|
-
|
|
46
|
-
# 环境变量配置
|
|
47
|
-
Environment="NODE_ENV=production"
|
|
48
|
-
Environment="APP_PORT=3000"
|
|
49
|
-
Environment="APP_HOST=0.0.0.0"
|
|
50
|
-
|
|
51
|
-
# 启动命令
|
|
52
|
-
# 单进程模式:
|
|
53
|
-
# ExecStart=/usr/local/bin/bun run befly start
|
|
54
|
-
#
|
|
55
|
-
# 集群模式(推荐,自动使用所有CPU核心):
|
|
56
|
-
ExecStart=/usr/local/bin/bun run befly start --cluster max
|
|
57
|
-
#
|
|
58
|
-
# 集群模式(指定进程数):
|
|
59
|
-
# ExecStart=/usr/local/bin/bun run befly start --cluster 4
|
|
60
|
-
|
|
61
|
-
# 重启策略
|
|
62
|
-
Restart=always # 总是自动重启(崩溃、OOM、异常退出等)
|
|
63
|
-
RestartSec=10 # 重启前等待10秒
|
|
64
|
-
StartLimitInterval=300 # 5分钟内
|
|
65
|
-
StartLimitBurst=5 # 最多重启5次(防止无限重启)
|
|
66
|
-
|
|
67
|
-
# 资源限制
|
|
68
|
-
MemoryMax=4G # 最大内存限制
|
|
69
|
-
MemoryHigh=3G # 内存高水位警告
|
|
70
|
-
LimitNOFILE=65536 # 最大打开文件数
|
|
71
|
-
LimitNPROC=4096 # 最大进程数
|
|
72
|
-
|
|
73
|
-
# CPU 限制(可选)
|
|
74
|
-
# CPUQuota=200% # 最多使用2个CPU核心(200%)
|
|
75
|
-
|
|
76
|
-
# 安全加固(可选,根据需要启用)
|
|
77
|
-
# PrivateTmp=true # 使用私有 /tmp 目录
|
|
78
|
-
# NoNewPrivileges=true # 禁止提升权限
|
|
79
|
-
# ProtectSystem=strict # 保护系统目录只读
|
|
80
|
-
# ProtectHome=true # 保护家目录
|
|
81
|
-
|
|
82
|
-
# 日志配置
|
|
83
|
-
StandardOutput=journal # 标准输出到 systemd journal
|
|
84
|
-
StandardError=journal # 错误输出到 systemd journal
|
|
85
|
-
SyslogIdentifier=befly # 日志标识符
|
|
86
|
-
|
|
87
|
-
# 优雅关闭
|
|
88
|
-
# KillMode=mixed # 混合模式:先 SIGTERM,超时后 SIGKILL
|
|
89
|
-
# KillSignal=SIGTERM # 发送 SIGTERM 信号
|
|
90
|
-
# TimeoutStopSec=30 # 30秒后强制停止
|
|
91
|
-
|
|
92
|
-
[Install]
|
|
93
|
-
WantedBy=multi-user.target # 多用户模式下启动
|