更新技术实施方案和PRD文档版本历史

This commit is contained in:
2025-09-11 19:55:21 +08:00
parent 5853953f79
commit 9aecda204b
17 changed files with 3058 additions and 8 deletions

View File

@@ -5,18 +5,13 @@ DB_USERNAME=root
DB_PASSWORD=aiotAiot123!
DB_NAME=jiebandata
# Redis配置
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
# JWT配置
JWT_SECRET=niumall_jwt_secret_key_2024
JWT_EXPIRES_IN=24h
# 应用配置
NODE_ENV=development
PORT=3002
NODE_ENV=production
PORT=4330
API_PREFIX=/api
# 日志配置

123
backend/CLEANUP_GUIDE.md Normal file
View File

@@ -0,0 +1,123 @@
# 活牛采购系统 - 后端文件清理指南
## 概述
本指南用于清理后端项目中不需要的文件和依赖以优化生产环境部署。根据系统需求我们将移除与Redis和RabbitMQ相关的文件和配置。
## 需要清理的文件和依赖
### 1. 移除Redis相关依赖
`package.json`文件中我们需要删除Redis相关的依赖
```javascript
// 移除前
"dependencies": {
// ...其他依赖
"redis": "^4.6.7",
// ...其他依赖
}
// 移除后
"dependencies": {
// ...其他依赖不包含redis
}
```
### 2. 移除Redis相关配置
在代码中我们需要删除任何与Redis相关的导入和使用
```bash
# 查找并删除代码中的Redis相关引用
# 在项目根目录下执行
find . -type f -name "*.js" | xargs grep -l "redis" | xargs sed -i '' '/redis/d'
```
### 3. 其他可能需要删除的文件
根据项目实际情况,以下是可能需要删除的文件:
- 测试文件和测试相关配置(如果不需要在生产环境中保留)
- 开发环境专用的配置文件
- 文档文件(如果不需要在生产环境中保留)
- 临时文件和日志文件
## 清理步骤
### 1. 删除Redis依赖
在本地项目目录中执行:
```bash
npm uninstall redis
```
### 2. 查找并清理Redis相关代码
使用以下命令查找所有包含Redis引用的文件
```bash
# Linux/Mac系统
grep -r "redis" . --include="*.js"
# Windows系统PowerShell
Get-ChildItem -Recurse -Include *.js | Select-String -Pattern "redis"
```
找到包含Redis引用的文件后手动编辑这些文件删除Redis相关的代码。
### 3. 删除其他不需要的文件
根据项目需求,删除不需要的文件:
```bash
# 删除测试目录(如果有)
rm -rf tests/
# 删除开发环境专用配置
rm -f .env.development
# 删除临时文件
rm -rf temp/
# 删除不必要的日志文件
rm -f logs/*.log
```
### 4. 更新.env文件
确保.env文件中不包含Redis相关配置
```ini
# 已在之前的步骤中更新,确保没有以下配置
# REDIS_HOST=localhost
# REDIS_PORT=6379
# REDIS_PASSWORD=
```
### 5. 更新models/index.js
确保数据库连接中没有Redis相关配置
```javascript
// 已更新确保没有Redis相关代码
```
### 6. 重新安装依赖
在清理完不必要的文件和依赖后,重新安装项目依赖:
```bash
rm -rf node_modules/
rm -f package-lock.json
npm install --production
```
## 生产环境部署前检查清单
在部署到生产环境前,请确保:
- [ ] Redis相关依赖已删除
- [ ] Redis相关配置已删除
- [ ] 没有使用RabbitMQ相关功能
- [ ] 数据库连接配置正确使用生产环境MySQL
- [ ] 端口配置为4330
- [ ] NODE_ENV设置为production
- [ ] Swagger文档功能在生产环境中保持启用
- [ ] PM2配置正确ecosystem.config.js
- [ ] Nginx配置正确包含SSL配置
## 注意事项
1. 在执行任何删除操作前,请确保已备份重要文件。
2. 清理完成后,请在测试环境中验证系统功能是否正常。
3. 如果在清理过程中遇到问题,请参考项目文档或联系技术支持。

227
backend/README_DEPLOY.md Normal file
View File

@@ -0,0 +1,227 @@
# 活牛采购系统 - 后端部署文档
## 系统概述
本部署文档详细说明如何部署活牛采购智能数字化系统的后端服务包括环境配置、文件上传、服务启动和Nginx配置等。
## 技术栈
- **Node.js**: >= 18.0.0
- **数据库**: MySQL直接使用生产环境数据库
- **Web服务器**: Nginx配置SSL
- **进程管理**: PM2
- **API文档**: Swagger 3.0(生产环境不禁用)
## 服务器配置
- **操作系统**: CentOS
- **服务器地址**: www.jiebanke.com
- **后端域名**: wapi.yunniushi.cn
- **服务器目录**: /data/nodejs/yunniushi/
- **后端端口**: 4330
- **用户名**: root
- **密码**: Aiotjkl$7jk58s&12
## 部署前准备
### 1. 环境安装
在CentOS服务器上安装以下软件
```bash
# 更新系统
sudo yum update -y
# 安装Node.js 18
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
sudo yum install -y nodejs
# 安装PM2全局
sudo npm install -g pm2
# 安装Nginx
sudo yum install -y nginx
# 启动Nginx服务并设置开机自启
sudo systemctl start nginx
sudo systemctl enable nginx
# 安装Git如果需要从代码仓库克隆代码
sudo yum install -y git
```
### 2. 创建服务器目录结构
```bash
# 创建项目根目录
sudo mkdir -p /data/nodejs/yunniushi/
sudo chown -R $USER:$USER /data/nodejs/yunniushi/
# 创建日志目录
mkdir -p /data/nodejs/yunniushi/logs
# 创建SSL证书目录
mkdir -p /etc/nginx/ssl/wapi.yunniushi.cn/
```
### 3. 上传SSL证书
将SSL证书文件上传到服务器上的SSL证书目录
- fullchain.pem -> /etc/nginx/ssl/wapi.yunniushi.cn/fullchain.pem
- privkey.pem -> /etc/nginx/ssl/wapi.yunniushi.cn/privkey.pem
## 文件同步与部署
### 方法一:使用同步脚本(推荐)
在本地项目目录中执行同步脚本,将代码上传到服务器:
```bash
# 给脚本添加执行权限
chmod +x sync_to_server.sh
# 执行同步脚本(脚本已预配置正确的服务器信息)
./sync_to_server.sh
```
### 方法二:手动上传文件
如果不使用同步脚本,可以手动将以下文件上传到服务器的 `/data/nodejs/yunniushi/` 目录:
- app.js
- package.json
- package-lock.json
- .env
- ecosystem.config.js
- config/ 目录
- models/ 目录
- routes/ 目录
- start_server.sh
### SSH连接问题排查
如果遇到SSH连接问题可以使用专门的测试工具进行诊断
```bash
# 给测试脚本添加执行权限
chmod +x test_ssh_connection.sh
# 执行SSH连接测试脚本
./test_ssh_connection.sh
```
此脚本会执行一系列测试,包括:
- DNS解析测试
- 网络连通性测试
- SSH端口开放测试
- 详细的SSH连接测试
- 提供故障排除建议
## 服务启动
### 在服务器上启动服务
1. 登录到服务器:
```bash
ssh root@www.jiebanke.com
# 密码: Aiotjkl$7jk58s&12
```
2. 进入项目目录:
```bash
cd /data/nodejs/yunniushi/
```
3. 执行启动脚本:
```bash
# 给启动脚本添加执行权限
chmod +x start_server.sh
# 启动服务
./start_server.sh
```
### 手动启动(备选方法)
如果启动脚本出现问题,可以手动执行以下命令:
```bash
# 安装依赖
npm install --production
# 启动PM2管理的服务
npm run pm2:start
# 设置PM2开机自启
pm2 startup
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u $USER --hp $HOME
# 保存PM2配置
sudo pm2 save
```
## Nginx配置
### 复制并激活Nginx配置文件
1. 复制Nginx配置文件到Nginx配置目录
```bash
# 在服务器上执行
cp /data/nodejs/yunniushi/nginx.conf /etc/nginx/conf.d/yunniushi_backend.conf
```
2. 测试Nginx配置是否正确
```bash
sudo nginx -t
```
3. 重启Nginx服务
```bash
sudo systemctl restart nginx
```
### 防火墙配置
如果服务器启用了防火墙,需要开放相关端口:
```bash
# 开放HTTPS端口443
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
```
## 服务管理命令
### PM2常用命令
```bash
# 查看服务状态
npm run pm2:start
# 停止服务
npm run pm2:stop
# 重启服务
npm run pm2:restart
# 查看服务日志
pm2 logs niumall-backend
```
### Nginx常用命令
```bash
# 启动Nginx
sudo systemctl start nginx
# 停止Nginx
sudo systemctl stop nginx
# 重启Nginx
sudo systemctl restart nginx
# 查看Nginx状态
sudo systemctl status nginx
# 查看Nginx日志
sudo tail -f /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log
```
## 访问测试
部署完成后,可以通过以下地址访问系统:
- **API文档**: https://wapi.yunniushi.cn/api/docs
- **健康检查**: https://wapi.yunniushi.cn/health
- **API接口**: https://wapi.yunniushi.cn/api/[接口路径]
## 注意事项
1. 确保服务器上的MySQL数据库已经正确配置并且网络连接通畅。
2. 根据实际情况修改.env文件中的数据库连接信息。
3. 确保SSL证书文件路径与nginx.conf中的配置一致。
4. 如果遇到端口冲突,需要修改配置文件中的端口号。
5. 定期备份数据库和重要配置文件。
6. 生产环境中请确保JWT_SECRET和数据库密码等敏感信息安全。

View File

@@ -4,6 +4,8 @@ const helmet = require('helmet')
const morgan = require('morgan')
const rateLimit = require('express-rate-limit')
const compression = require('compression')
const swaggerJsdoc = require('swagger-jsdoc')
const swaggerUi = require('swagger-ui-express')
require('dotenv').config()
// 数据库连接
@@ -19,6 +21,75 @@ app.use(morgan('combined')) // 日志
app.use(express.json({ limit: '10mb' }))
app.use(express.urlencoded({ extended: true, limit: '10mb' }))
// Swagger 配置
const swaggerOptions = {
definition: {
openapi: '3.0.0',
info: {
title: '活牛采购智能数字化系统 API',
version: '1.0.0',
description: '活牛采购标准化操作流程系统接口文档',
contact: {
name: 'API支持',
email: 'support@niumall.com'
}
},
servers: [
{
url: 'http://localhost:4330/api',
description: '开发环境'
},
{
url: 'https://wapi.yunniushi.cn/api',
description: '生产环境'
}
],
components: {
securitySchemes: {
BearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT'
}
},
schemas: {
ApiResponse: {
type: 'object',
properties: {
success: { type: 'boolean', description: '请求是否成功' },
message: { type: 'string', description: '提示信息' },
data: { type: 'object', description: '响应数据' },
timestamp: { type: 'string', format: 'date-time', description: '时间戳' }
}
},
PaginationParams: {
type: 'object',
properties: {
page: { type: 'integer', description: '当前页码' },
limit: { type: 'integer', description: '每页数量' },
sort: { type: 'string', description: '排序字段' },
order: { type: 'string', enum: ['asc', 'desc'], description: '排序方向' }
}
},
PaginatedResponse: {
type: 'object',
properties: {
items: { type: 'array', description: '数据列表' },
total: { type: 'integer', description: '总记录数' },
page: { type: 'integer', description: '当前页码' },
limit: { type: 'integer', description: '每页数量' },
totalPages: { type: 'integer', description: '总页数' }
}
}
}
}
},
apis: ['./routes/*.js', './models/*.js'] // API路由文件路径
};
const swaggerSpec = swaggerJsdoc(swaggerOptions);
app.use('/api/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// 限流
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 分钟

View File

@@ -0,0 +1,17 @@
module.exports = {
apps: [{
name: 'niumall-backend',
script: 'app.js',
cwd: '/data/nodejs/yunniushi/',
instances: 'max',
exec_mode: 'cluster',
env: {
NODE_ENV: 'production',
PORT: 4330
},
error_file: '/data/nodejs/yunniushi/logs/backend-error.log',
out_file: '/data/nodejs/yunniushi/logs/backend-out.log',
log_file: '/data/nodejs/yunniushi/logs/backend.log',
time: true
}]
}

View File

@@ -0,0 +1,205 @@
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug3: channel_clear_timeouts: clearing
debug3: ssh_connect_direct: entering
debug1: Connecting to 1.13.156.49 [1.13.156.49] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug2: fd 3 setting O_NONBLOCK
debug1: fd 3 clearing O_NONBLOCK
debug1: Connection established.
debug3: timeout: 15000 ms remain after connect
debug1: identity file /Users/aiotagro/.ssh/id_rsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_rsa-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519 type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_xmss type -1
debug1: identity file /Users/aiotagro/.ssh/id_xmss-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_dsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: compat_banner: match: OpenSSH_7.4 pat OpenSSH_7.4* compat 0x04000006
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 1.13.156.49:22 as 'root'
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug3: order_hostkeyalgs: no algorithms matched; accept original
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: sntrup761x25519-sha512,sntrup761x25519-sha512@openssh.com,mlkem768x25519-sha256,curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c,kex-strict-c-v00@openssh.com
debug2: host key algorithms: ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,rsa-sha2-512,rsa-sha2-256
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256
debug2: host key algorithms: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr
debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: aes128-ctr MAC: umac-64-etm@openssh.com compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: umac-64-etm@openssh.com compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:ONgY2i3Y/Gd0HjWKt1/pcN9RLkhpVTIotxT8KOrPrGA
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
Warning: Permanently added '1.13.156.49' (ED25519) to the list of known hosts.
debug3: send packet: type 21
debug2: ssh_set_newkeys: mode 1
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: ssh_set_newkeys: mode 0
debug1: rekey in after 4294967296 blocks
debug2: KEX algorithms: sntrup761x25519-sha512,sntrup761x25519-sha512@openssh.com,mlkem768x25519-sha256,curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c,kex-strict-c-v00@openssh.com
debug2: host key algorithms: ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,rsa-sha2-512,rsa-sha2-256
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug3: kex_input_ext_info: extension server-sig-algs
debug1: kex_ext_info_client_parse: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug3: ssh_get_authentication_socket_path: path '/private/tmp/com.apple.launchd.eXSXPPVBcF/Listeners'
debug1: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: ssh_fetch_identitylist: agent contains no identities
debug1: Will attempt key: /Users/aiotagro/.ssh/id_rsa
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ecdsa
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ed25519
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/aiotagro/.ssh/id_xmss
debug1: Will attempt key: /Users/aiotagro/.ssh/id_dsa
debug2: pubkey_prepare: done
debug1: Trying private key: /Users/aiotagro/.ssh/id_rsa
debug3: no such identity: /Users/aiotagro/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /Users/aiotagro/.ssh/id_ecdsa
debug3: no such identity: /Users/aiotagro/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /Users/aiotagro/.ssh/id_ecdsa_sk
debug3: no such identity: /Users/aiotagro/.ssh/id_ecdsa_sk: No such file or directory
debug1: Trying private key: /Users/aiotagro/.ssh/id_ed25519
debug3: no such identity: /Users/aiotagro/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /Users/aiotagro/.ssh/id_ed25519_sk
debug3: no such identity: /Users/aiotagro/.ssh/id_ed25519_sk: No such file or directory
debug1: Trying private key: /Users/aiotagro/.ssh/id_xmss
debug3: no such identity: /Users/aiotagro/.ssh/id_xmss: No such file or directory
debug1: Trying private key: /Users/aiotagro/.ssh/id_dsa
debug3: no such identity: /Users/aiotagro/.ssh/id_dsa: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
debug3: send packet: type 50
debug2: we sent a password packet, wait for reply
debug3: receive packet: type 52
Authenticated to 1.13.156.49 ([1.13.156.49]:22) using "password".
debug2: fd 5 setting O_NONBLOCK
debug1: channel 0: new session [client-session] (inactive timeout: 0)
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Requesting no-more-sessions@openssh.com
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
debug3: client_repledge: enter
debug3: receive packet: type 80
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug3: receive packet: type 91
debug2: channel_input_open_confirmation: channel 0: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: set_sock_tos: set socket 3 IP_TOS 0x20
debug2: client_session2_setup: id 0
debug1: Sending command: exit
debug2: channel 0: request exec confirm 1
debug3: send packet: type 98
debug3: client_repledge: enter
debug1: pledge: fork
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug2: channel 0: rcvd eow
debug2: chan_shutdown_read: channel 0: (i0 o0 sock -1 wfd 4 efd 6 [write])
debug2: channel 0: input open -> closed
debug3: receive packet: type 96
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: chan_shutdown_write: channel 0: (i3 o1 sock -1 wfd 5 efd 6 [write])
debug2: channel 0: output drain -> closed
debug3: receive packet: type 97
debug2: channel 0: rcvd close
debug3: channel 0: will not send data after close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send_close2
debug2: channel 0: send close for remote id 0
debug3: send packet: type 97
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
#0 client-session (t4 [session] r0 nm0 i3/0 o3/0 e[write]/0 fd -1/-1/6 sock -1 cc -1 nc0 io 0x00/0x00)
debug3: send packet: type 1
Transferred: sent 2048, received 1880 bytes, in 0.1 seconds
Bytes per second: sent 22324.7, received 20493.4
debug1: Exit status 0

426
backend/logs/sync_log.txt Normal file
View File

@@ -0,0 +1,426 @@
2025-09-11 17:54:38 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 17:54:38 - 代码同步失败!
2025-09-11 17:57:49 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 17:57:49 - 代码同步失败!
2025-09-11 18:19:54 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:19:54 - 代码同步失败!
2025-09-11 18:20:45 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:20:45 - 代码同步失败!
2025-09-11 18:22:24 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:22:24 - 代码同步失败!
2025-09-11 18:23:18 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:23:18 - 代码同步失败!
2025-09-11 18:23:19 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:23:19 - 代码同步失败!
2025-09-11 18:23:20 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:23:20 - 代码同步失败!
2025-09-11 18:23:21 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:23:21 - 代码同步失败!
2025-09-11 18:23:22 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:23:22 - 代码同步失败!
2025-09-11 18:23:23 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:23:23 - 代码同步失败!
2025-09-11 18:23:24 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:23:24 - 代码同步失败!
2025-09-11 18:23:25 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:23:25 - 代码同步失败!
2025-09-11 18:24:25 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:24:25 - 代码同步失败!
2025-09-11 18:24:30 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:24:30 - 代码同步失败!
SSH连接测试失败无法继续同步。
SSH连接测试失败无法继续同步。
SSH连接测试失败无法继续同步。
SSH连接测试失败无法继续同步。
SSH连接测试失败无法继续同步。
SSH连接测试失败无法继续同步。
SSH连接测试失败无法继续同步。
2025-09-11 18:56:37 - 开始同步后端代码到服务器 www.jiebanke.com...
2025-09-11 18:56:37 - 代码同步失败!
文件同步失败,请查看日志获取详细信息。
2025-09-11 19:03:02 - 开始同步后端代码到服务器 1.13.156.49...
2025-09-11 19:03:02 - 代码同步失败!
文件同步失败,请查看日志获取详细信息。
2025-09-11 19:03:14 - 开始同步后端代码到服务器 1.13.156.49...
2025-09-11 19:03:14 - 代码同步失败!
文件同步失败,请查看日志获取详细信息。
OpenSSH_9.9p2, LibreSSL 3.3.6
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to 1.13.156.49 [1.13.156.49] port 22.
debug1: fd 3 clearing O_NONBLOCK
debug1: Connection established.
debug1: identity file /Users/aiotagro/.ssh/id_rsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_rsa-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519 type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_xmss type -1
debug1: identity file /Users/aiotagro/.ssh/id_xmss-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_dsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: compat_banner: match: OpenSSH_7.4 pat OpenSSH_7.4* compat 0x04000006
debug1: Authenticating to 1.13.156.49:22 as 'root'
debug1: load_hostkeys: fopen /Users/aiotagro/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: aes128-ctr MAC: umac-64-etm@openssh.com compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: umac-64-etm@openssh.com compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:ONgY2i3Y/Gd0HjWKt1/pcN9RLkhpVTIotxT8KOrPrGA
debug1: load_hostkeys: fopen /Users/aiotagro/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '1.13.156.49' is known and matches the ED25519 host key.
debug1: Found key in /Users/aiotagro/.ssh/known_hosts:4
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 4294967296 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_ext_info_client_parse: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: ssh_fetch_identitylist: agent contains no identities
debug1: Will attempt key: /Users/aiotagro/.ssh/id_rsa
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ecdsa
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ed25519
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/aiotagro/.ssh/id_xmss
debug1: Will attempt key: /Users/aiotagro/.ssh/id_dsa
debug1: Trying private key: /Users/aiotagro/.ssh/id_rsa
debug1: Trying private key: /Users/aiotagro/.ssh/id_ecdsa
debug1: Trying private key: /Users/aiotagro/.ssh/id_ecdsa_sk
debug1: Trying private key: /Users/aiotagro/.ssh/id_ed25519
debug1: Trying private key: /Users/aiotagro/.ssh/id_ed25519_sk
debug1: Trying private key: /Users/aiotagro/.ssh/id_xmss
debug1: Trying private key: /Users/aiotagro/.ssh/id_dsa
debug1: Next authentication method: password
Authenticated to 1.13.156.49 ([1.13.156.49]:22) using "password".
debug1: channel 0: new session [client-session] (inactive timeout: 0)
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: filesystem
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: client_input_hostkeys: searching /Users/aiotagro/.ssh/known_hosts for 1.13.156.49 / (none)
debug1: client_input_hostkeys: searching /Users/aiotagro/.ssh/known_hosts2 for 1.13.156.49 / (none)
debug1: client_input_hostkeys: hostkeys file /Users/aiotagro/.ssh/known_hosts2 does not exist
debug1: client_input_hostkeys: host key found matching a different name/address, skipping UserKnownHostsFile update
debug1: Sending environment.
debug1: channel 0: setting env LANG = "zh_CN.UTF-8"
debug1: Sending command: exit
debug1: pledge: fork
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2100, received 1880 bytes, in 0.1 seconds
Bytes per second: sent 25990.7, received 23267.9
debug1: Exit status 0
2025-09-11 19:08:49 - 开始同步后端代码到服务器 1.13.156.49...
2025-09-11 19:08:49 - 代码同步失败!
文件同步失败,请查看日志获取详细信息。
OpenSSH_9.9p2, LibreSSL 3.3.6
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to 1.13.156.49 [1.13.156.49] port 22.
debug1: fd 3 clearing O_NONBLOCK
debug1: Connection established.
debug1: identity file /Users/aiotagro/.ssh/id_rsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_rsa-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519 type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_xmss type -1
debug1: identity file /Users/aiotagro/.ssh/id_xmss-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_dsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: compat_banner: match: OpenSSH_7.4 pat OpenSSH_7.4* compat 0x04000006
debug1: Authenticating to 1.13.156.49:22 as 'root'
debug1: load_hostkeys: fopen /Users/aiotagro/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: aes128-ctr MAC: umac-64-etm@openssh.com compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: umac-64-etm@openssh.com compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:ONgY2i3Y/Gd0HjWKt1/pcN9RLkhpVTIotxT8KOrPrGA
debug1: load_hostkeys: fopen /Users/aiotagro/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '1.13.156.49' is known and matches the ED25519 host key.
debug1: Found key in /Users/aiotagro/.ssh/known_hosts:4
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 4294967296 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_ext_info_client_parse: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: ssh_fetch_identitylist: agent contains no identities
debug1: Will attempt key: /Users/aiotagro/.ssh/id_rsa
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ecdsa
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ed25519
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/aiotagro/.ssh/id_xmss
debug1: Will attempt key: /Users/aiotagro/.ssh/id_dsa
debug1: Trying private key: /Users/aiotagro/.ssh/id_rsa
debug1: Trying private key: /Users/aiotagro/.ssh/id_ecdsa
debug1: Trying private key: /Users/aiotagro/.ssh/id_ecdsa_sk
debug1: Trying private key: /Users/aiotagro/.ssh/id_ed25519
debug1: Trying private key: /Users/aiotagro/.ssh/id_ed25519_sk
debug1: Trying private key: /Users/aiotagro/.ssh/id_xmss
debug1: Trying private key: /Users/aiotagro/.ssh/id_dsa
debug1: Next authentication method: password
Authenticated to 1.13.156.49 ([1.13.156.49]:22) using "password".
debug1: channel 0: new session [client-session] (inactive timeout: 0)
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: filesystem
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: client_input_hostkeys: searching /Users/aiotagro/.ssh/known_hosts for 1.13.156.49 / (none)
debug1: client_input_hostkeys: searching /Users/aiotagro/.ssh/known_hosts2 for 1.13.156.49 / (none)
debug1: client_input_hostkeys: hostkeys file /Users/aiotagro/.ssh/known_hosts2 does not exist
debug1: client_input_hostkeys: host key found matching a different name/address, skipping UserKnownHostsFile update
debug1: Sending environment.
debug1: channel 0: setting env LANG = "zh_CN.UTF-8"
debug1: Sending command: exit
debug1: pledge: fork
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2100, received 1880 bytes, in 0.1 seconds
Bytes per second: sent 20501.8, received 18354.0
debug1: Exit status 0
2025-09-11 19:12:07 - 开始同步后端代码到服务器 1.13.156.49...
2025-09-11 19:13:10 - 代码同步成功!
2025-09-11 19:13:17 - 正在安装远程依赖...
2025-09-11 19:13:44 - 依赖安装成功!
2025-09-11 19:13:52 - 正在重启远程服务...
OpenSSH_9.9p2, LibreSSL 3.3.6
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to 1.13.156.49 [1.13.156.49] port 22.
debug1: fd 3 clearing O_NONBLOCK
debug1: Connection established.
debug1: identity file /Users/aiotagro/.ssh/id_rsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_rsa-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519 type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_xmss type -1
debug1: identity file /Users/aiotagro/.ssh/id_xmss-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_dsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: compat_banner: match: OpenSSH_7.4 pat OpenSSH_7.4* compat 0x04000006
debug1: Authenticating to 1.13.156.49:22 as 'root'
debug1: load_hostkeys: fopen /Users/aiotagro/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: aes128-ctr MAC: umac-64-etm@openssh.com compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: umac-64-etm@openssh.com compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:ONgY2i3Y/Gd0HjWKt1/pcN9RLkhpVTIotxT8KOrPrGA
debug1: load_hostkeys: fopen /Users/aiotagro/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '1.13.156.49' is known and matches the ED25519 host key.
debug1: Found key in /Users/aiotagro/.ssh/known_hosts:4
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 4294967296 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_ext_info_client_parse: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: ssh_fetch_identitylist: agent contains no identities
debug1: Will attempt key: /Users/aiotagro/.ssh/id_rsa
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ecdsa
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ed25519
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/aiotagro/.ssh/id_xmss
debug1: Will attempt key: /Users/aiotagro/.ssh/id_dsa
debug1: Trying private key: /Users/aiotagro/.ssh/id_rsa
debug1: Trying private key: /Users/aiotagro/.ssh/id_ecdsa
debug1: Trying private key: /Users/aiotagro/.ssh/id_ecdsa_sk
debug1: Trying private key: /Users/aiotagro/.ssh/id_ed25519
debug1: Trying private key: /Users/aiotagro/.ssh/id_ed25519_sk
debug1: Trying private key: /Users/aiotagro/.ssh/id_xmss
debug1: Trying private key: /Users/aiotagro/.ssh/id_dsa
debug1: Next authentication method: password
Authenticated to 1.13.156.49 ([1.13.156.49]:22) using "password".
debug1: channel 0: new session [client-session] (inactive timeout: 0)
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: filesystem
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: client_input_hostkeys: searching /Users/aiotagro/.ssh/known_hosts for 1.13.156.49 / (none)
debug1: client_input_hostkeys: searching /Users/aiotagro/.ssh/known_hosts2 for 1.13.156.49 / (none)
debug1: client_input_hostkeys: hostkeys file /Users/aiotagro/.ssh/known_hosts2 does not exist
debug1: client_input_hostkeys: host key found matching a different name/address, skipping UserKnownHostsFile update
debug1: Sending environment.
debug1: channel 0: setting env LANG = "zh_CN.UTF-8"
debug1: Sending command: exit
debug1: pledge: fork
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2100, received 1880 bytes, in 0.1 seconds
Bytes per second: sent 20348.0, received 18216.3
debug1: Exit status 0
2025-09-11 19:15:42 - 开始同步后端代码到服务器 1.13.156.49...
2025-09-11 19:15:44 - 代码同步成功!
2025-09-11 19:15:47 - 正在安装远程依赖...
2025-09-11 19:15:52 - 依赖安装成功!
2025-09-11 19:15:57 - 正在重启远程服务...
2025-09-11 19:15:57 - 已提示用户手动重启服务。
OpenSSH_9.9p2, LibreSSL 3.3.6
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to 1.13.156.49 [1.13.156.49] port 22.
debug1: fd 3 clearing O_NONBLOCK
debug1: Connection established.
debug1: identity file /Users/aiotagro/.ssh/id_rsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_rsa-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/aiotagro/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519 type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/aiotagro/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_xmss type -1
debug1: identity file /Users/aiotagro/.ssh/id_xmss-cert type -1
debug1: identity file /Users/aiotagro/.ssh/id_dsa type -1
debug1: identity file /Users/aiotagro/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: compat_banner: match: OpenSSH_7.4 pat OpenSSH_7.4* compat 0x04000006
debug1: Authenticating to 1.13.156.49:22 as 'root'
debug1: load_hostkeys: fopen /Users/aiotagro/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: aes128-ctr MAC: umac-64-etm@openssh.com compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: umac-64-etm@openssh.com compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:ONgY2i3Y/Gd0HjWKt1/pcN9RLkhpVTIotxT8KOrPrGA
debug1: load_hostkeys: fopen /Users/aiotagro/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '1.13.156.49' is known and matches the ED25519 host key.
debug1: Found key in /Users/aiotagro/.ssh/known_hosts:4
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 4294967296 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_ext_info_client_parse: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: ssh_fetch_identitylist: agent contains no identities
debug1: Will attempt key: /Users/aiotagro/.ssh/id_rsa
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ecdsa
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ed25519
debug1: Will attempt key: /Users/aiotagro/.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/aiotagro/.ssh/id_xmss
debug1: Will attempt key: /Users/aiotagro/.ssh/id_dsa
debug1: Trying private key: /Users/aiotagro/.ssh/id_rsa
debug1: Trying private key: /Users/aiotagro/.ssh/id_ecdsa
debug1: Trying private key: /Users/aiotagro/.ssh/id_ecdsa_sk
debug1: Trying private key: /Users/aiotagro/.ssh/id_ed25519
debug1: Trying private key: /Users/aiotagro/.ssh/id_ed25519_sk
debug1: Trying private key: /Users/aiotagro/.ssh/id_xmss
debug1: Trying private key: /Users/aiotagro/.ssh/id_dsa
debug1: Next authentication method: password
Authenticated to 1.13.156.49 ([1.13.156.49]:22) using "password".
debug1: channel 0: new session [client-session] (inactive timeout: 0)
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: filesystem
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: client_input_hostkeys: searching /Users/aiotagro/.ssh/known_hosts for 1.13.156.49 / (none)
debug1: client_input_hostkeys: searching /Users/aiotagro/.ssh/known_hosts2 for 1.13.156.49 / (none)
debug1: client_input_hostkeys: hostkeys file /Users/aiotagro/.ssh/known_hosts2 does not exist
debug1: client_input_hostkeys: host key found matching a different name/address, skipping UserKnownHostsFile update
debug1: Sending environment.
debug1: channel 0: setting env LANG = "zh_CN.UTF-8"
debug1: Sending command: exit
debug1: pledge: fork
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2100, received 1880 bytes, in 0.1 seconds
Bytes per second: sent 22521.1, received 20161.7
debug1: Exit status 0
2025-09-11 19:39:29 - 开始同步后端代码到服务器 1.13.156.49...
2025-09-11 19:39:32 - 代码同步成功!
2025-09-11 19:39:37 - 正在安装远程依赖...
2025-09-11 19:39:43 - 依赖安装成功!
2025-09-11 19:39:49 - 正在重启远程服务...
2025-09-11 19:39:49 - 已提示用户手动重启服务。

121
backend/nginx.conf Normal file
View File

@@ -0,0 +1,121 @@
# 活牛采购系统Nginx配置文件
# 此配置文件用于配置Nginx作为反向代理服务器提供HTTPS访问
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# 加载动态模块
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 开启gzip压缩
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
# 虚拟主机配置 - 活牛采购系统后端API
server {
# 监听HTTP端口重定向到HTTPS
listen 80;
server_name wapi.yunniushi.cn;
return 301 https://$server_name$request_uri;
}
server {
# 监听HTTPS端口
listen 443 ssl http2;
server_name wapi.yunniushi.cn;
# SSL证书配置
ssl_certificate /etc/nginx/ssl/wapi.yunniushi.cn/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/wapi.yunniushi.cn/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
# HSTS配置
add_header Strict-Transport-Security "max-age=63072000" always;
# 安全头部配置
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
# 反向代理配置
location / {
# 代理到Node.js后端服务
proxy_pass http://localhost:4330;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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 X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
# 增加代理超时
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
}
# 静态文件服务配置(如果需要)
# location /public {
# alias /data/nodejs/yunniushi/public;
# expires 30d;
# }
# 健康检查端点
location /health {
proxy_pass http://localhost:4330;
proxy_http_version 1.1;
proxy_set_header Host $host;
access_log off;
}
# API文档端点
location /api/docs {
proxy_pass http://localhost:4330;
proxy_http_version 1.1;
proxy_set_header Host $host;
}
# 错误页面配置
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
# 加载其他配置文件
include /etc/nginx/conf.d/*.conf;
}

View File

@@ -46,9 +46,10 @@
"morgan": "^1.10.1",
"multer": "^1.4.5-lts.1",
"mysql2": "^3.6.0",
"redis": "^4.6.7",
"sequelize": "^6.32.1",
"socket.io": "^4.7.2",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.0",
"uuid": "^9.0.0",
"winston": "^3.10.0"
},

91
backend/start_server.sh Executable file
View File

@@ -0,0 +1,91 @@
#!/bin/bash
# 结伴客后端服务器启动脚本
# 适用于CentOS生产环境
# 服务器目录: /data/nodejsjiebanke/
set -e
# 配置参数
APP_NAME="yunniushi-backend"
APP_DIR="/data/nodejs/yunniushi"
PORT="4330"
LOG_DIR="$APP_DIR/logs"
cd "$APP_DIR"
echo "🚀 开始启动 $APP_NAME 服务..."
echo "📋 工作目录: $APP_DIR"
echo "🔌 服务端口: $PORT"
echo "📊 日志目录: $LOG_DIR"
echo ""
# 创建日志目录
if [ ! -d "$LOG_DIR" ]; then
mkdir -p "$LOG_DIR"
echo "✅ 创建日志目录: $LOG_DIR"
fi
# 检查Node.js环境
echo "🔍 检查Node.js环境..."
if ! command -v node &> /dev/null; then
echo "❌ Node.js未安装请先安装Node.js"
exit 1
fi
if ! command -v npm &> /dev/null; then
echo "❌ npm未安装请先安装npm"
exit 1
fi
if ! command -v pm2 &> /dev/null; then
echo "❌ pm2未安装正在安装pm2..."
npm install -g pm2
echo "✅ pm2安装完成"
fi
echo "✅ Node.js版本: $(node -v)"
echo "✅ npm版本: $(npm -v)"
echo "✅ pm2版本: $(pm2 -v)"
# 安装依赖
echo ""
echo "📦 安装项目依赖..."
npm install --production
# 停止现有服务(如果存在)
echo ""
echo "🛑 停止现有服务..."
pm2 delete "$APP_NAME" 2>/dev/null || true
pm2 flush "$APP_NAME" 2>/dev/null || true
# 启动服务
echo ""
echo "🚀 启动服务..."
NODE_ENV=production PORT=$PORT pm2 start ecosystem.config.js --name "$APP_NAME"
# 保存pm2配置
echo ""
echo "💾 保存pm2配置..."
pm2 save
# 设置开机自启
echo ""
echo "🔧 设置开机自启..."
pm2 startup 2>/dev/null || echo "⚠️ 开机自启设置可能需要手动执行: pm2 startup"
# 显示服务状态
echo ""
echo "📊 服务状态:"
pm2 status "$APP_NAME"
echo ""
echo "$APP_NAME 服务启动成功!"
echo "🌐 服务地址: http://localhost:$PORT"
echo "📋 启动时间: $(date)"
echo ""
echo "💡 常用命令:"
echo " 查看日志: pm2 logs $APP_NAME"
echo " 重启服务: pm2 restart $APP_NAME"
echo " 停止服务: pm2 stop $APP_NAME"
echo " 服务状态: pm2 status"

221
backend/sync_to_server.sh Executable file
View File

@@ -0,0 +1,221 @@
#!/bin/bash
# 活牛采购系统后端代码同步脚本
# 此脚本用于将本地后端代码同步到远程服务器
# 设置脚本执行选项:发生错误时退出,命令出错时退出(移除了-u选项因为密码中包含$字符可能导致未绑定变量错误)
set -eo pipefail
# 服务器配置
SERVER=1.13.156.49
SERVER_DIR=/data/nodejs/yunniushi/
SSH_PORT=22
SSH_USER="root"
# 本地目录配置
LOCAL_DIR=$(pwd)
# 日志配置
LOG_FILE=sync_log.txt
LOG_DIR="$LOCAL_DIR/logs"
# 检查必要的工具是否安装
check_dependencies() {
echo "检查必要工具..."
if ! command -v rsync &> /dev/null; then
echo "错误: rsync命令未安装请先安装rsync!"
echo "在Mac上: brew install rsync"
echo "在Ubuntu上: sudo apt-get install rsync"
echo "在CentOS上: sudo yum install rsync"
exit 1
fi
if ! command -v ssh &> /dev/null; then
echo "错误: ssh命令未安装请先安装ssh!"
exit 1
fi
echo "所有必要工具已安装"
}
# 创建日志目录(如果不存在)
create_log_directory() {
if [ ! -d "$LOG_DIR" ]; then
echo "创建日志目录: $LOG_DIR"
mkdir -p "$LOG_DIR"
fi
}
# 显示脚本配置信息
show_config() {
echo "\n===== 同步配置信息 ====="
echo "本地目录: $LOCAL_DIR"
echo "远程服务器: $SERVER"
echo "远程目录: $SERVER_DIR"
echo "SSH端口: $SSH_PORT"
echo "SSH用户: $SSH_USER"
echo "服务器类型: CentOS"
echo "日志文件: $LOG_DIR/$LOG_FILE"
echo "======================\n"
}
# 测试SSH连接
test_ssh_connection() {
echo "测试SSH连接到 $SERVER..."
echo "命令格式: ssh -p $SSH_PORT $SSH_USER@$SERVER"
echo "服务器类型: CentOS用户名: root密码: Aiotjkl$7jk58s&12"
# 尝试使用详细模式连接,显示更多信息
echo "\n正在尝试SSH连接测试详细模式..."
ssh -v -p $SSH_PORT -o ConnectTimeout=10 $SSH_USER@$SERVER 'exit' 2>&1 | tee -a "$LOG_DIR/$LOG_FILE"
# 检查连接结果
if [ $? -eq 0 ]; then
echo "SSH连接成功"
return 0
else
echo "\n错误: SSH连接失败请检查以下可能的原因"
echo "1. 服务器地址是否正确: $SERVER"
echo "2. 服务器是否在线,网络连接是否通畅"
echo "3. SSH端口是否正确: $SSH_PORT"
echo "4. 用户名是否正确: $SSH_USER"
echo "5. 密码是否正确: Aiotjkl$7jk58s&12"
echo "6. 服务器防火墙是否允许SSH连接"
echo "7. 本地网络是否有防火墙限制"
echo "\n排查建议"
echo "- 手动执行以下命令测试连接ssh -p $SSH_PORT $SSH_USER@$SERVER"
echo "- 如果使用密钥认证,请确保密钥已正确配置"
echo "- 如果是首次连接,可能需要手动接受服务器指纹"
echo "- 检查服务器的SSH服务是否正常运行"
return 1
fi
}
# 同步文件到服务器
sync_files() {
echo "$(date +'%Y-%m-%d %H:%M:%S') - 开始同步后端代码到服务器 $SERVER..." | tee -a "$LOG_DIR/$LOG_FILE"
# 排除列表
EXCLUDE_LIST=(
--exclude='node_modules/'
--exclude='.git/'
--exclude='logs/'
--exclude='.env'
--exclude='.DS_Store'
--exclude='CLEANUP_GUIDE.md'
--exclude='README_DEPLOY.md'
)
# 执行rsync同步
rsync -avz --delete \
"${EXCLUDE_LIST[@]}" \
--progress \
-e "ssh -p $SSH_PORT" \
"$LOCAL_DIR/" \
"$SSH_USER@$SERVER:$SERVER_DIR"
# 检查同步结果
if [ $? -eq 0 ]; then
echo "$(date +'%Y-%m-%d %H:%M:%S') - 代码同步成功!" | tee -a "$LOG_DIR/$LOG_FILE"
return 0
else
echo "$(date +'%Y-%m-%d %H:%M:%S') - 代码同步失败!" | tee -a "$LOG_DIR/$LOG_FILE"
return 1
fi
}
# 安装远程依赖
install_dependencies() {
echo "$(date +'%Y-%m-%d %H:%M:%S') - 正在安装远程依赖..." | tee -a "$LOG_DIR/$LOG_FILE"
ssh -p $SSH_PORT "$SSH_USER@$SERVER" "cd $SERVER_DIR && npm install --production"
if [ $? -eq 0 ]; then
echo "$(date +'%Y-%m-%d %H:%M:%S') - 依赖安装成功!" | tee -a "$LOG_DIR/$LOG_FILE"
return 0
else
echo "$(date +'%Y-%m-%d %H:%M:%S') - 依赖安装失败,请手动检查!" | tee -a "$LOG_DIR/$LOG_FILE"
return 1
fi
}
# 重启远程服务
restart_service() {
echo "$(date +'%Y-%m-%d %H:%M:%S') - 正在重启远程服务..." | tee -a "$LOG_DIR/$LOG_FILE"
echo "\n警告在CentOS系统上以root用户直接运行Node.js应用程序可能会遇到权限问题。"
echo "建议在服务器上手动执行以下命令重启服务:"
echo "ssh -p $SSH_PORT $SSH_USER@$SERVER 'cd $SERVER_DIR && npm run pm2:restart'"
echo "如果遇到权限问题,可以尝试:"
echo "1. 使用非root用户运行PM2"
echo "2. 或者执行ssh -p $SSH_PORT $SSH_USER@$SERVER 'cd $SERVER_DIR && pm2 start ecosystem.config.js'"
echo "3. 或者参考PM2的文档配置正确的权限"
# 由于权限问题,我们不再自动执行重启命令,而是让用户手动操作
echo "$(date +'%Y-%m-%d %H:%M:%S') - 已提示用户手动重启服务。" | tee -a "$LOG_DIR/$LOG_FILE"
return 0
}
# 显示完成信息
show_completion_message() {
echo "\n===== 同步完成 ====="
echo "代码已成功同步到服务器 $SERVER"
echo "服务器类型: CentOS"
echo "用户名: $SSH_USER"
echo "\n您可以通过以下方式验证服务状态"
echo "1. 检查服务日志: ssh -p $SSH_PORT $SSH_USER@$SERVER 'pm2 logs niumall-backend'"
echo "2. 访问健康检查: https://wapi.yunniushi.cn/health"
echo "3. 查看API文档: https://wapi.yunniushi.cn/api/docs"
echo "\n如果需要手动重启服务请执行"
echo "ssh -p $SSH_PORT $SSH_USER@$SERVER 'cd $SERVER_DIR && npm run pm2:restart'"
echo "=====================\n"
}
# 主函数
main() {
# 1. 检查依赖
check_dependencies
# 2. 创建日志目录
create_log_directory
# 3. 显示配置信息
show_config
# 4. 询问是否跳过SSH连接测试用于调试
read -p "是否跳过SSH连接测试(y/N): " SKIP_SSH_TEST
if [ "$SKIP_SSH_TEST" != "y" ] && [ "$SKIP_SSH_TEST" != "Y" ]; then
# 测试SSH连接
if ! test_ssh_connection; then
echo "\nSSH连接测试失败"
read -p "是否强制继续同步?(y/N): " FORCE_CONTINUE
if [ "$FORCE_CONTINUE" != "y" ] && [ "$FORCE_CONTINUE" != "Y" ]; then
echo "同步已取消。" | tee -a "$LOG_DIR/$LOG_FILE"
exit 1
fi
echo "强制继续同步..." | tee -a "$LOG_DIR/$LOG_FILE"
fi
fi
# 5. 同步文件
if ! sync_files; then
echo "文件同步失败,请查看日志获取详细信息。" | tee -a "$LOG_DIR/$LOG_FILE"
exit 1
fi
# 6. 询问是否安装依赖
read -p "是否在服务器上安装依赖?(y/n): " INSTALL_DEP
if [ "$INSTALL_DEP" = "y" ] || [ "$INSTALL_DEP" = "Y" ]; then
install_dependencies
fi
# 7. 询问是否重启服务
read -p "是否重启服务器上的服务?(y/n): " RESTART_SVC
if [ "$RESTART_SVC" = "y" ] || [ "$RESTART_SVC" = "Y" ]; then
restart_service
fi
# 8. 显示完成信息
show_completion_message
}
# 执行主函数
main

189
backend/test_ssh_connection.sh Executable file
View File

@@ -0,0 +1,189 @@
#!/bin/bash
# SSH连接测试脚本
# 此脚本用于诊断和测试SSH连接问题
# 设置脚本执行选项
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -eo pipefail # 移除了-u选项因为密码中包含$字符可能导致未绑定变量错误
# 服务器配置
SERVER=1.13.156.49
SSH_PORT=22
SSH_USER="root"
# 日志配置
LOG_DIR="$(pwd)/logs"
LOG_FILE="ssh_test_$(date +'%Y%m%d_%H%M%S').log"
# 创建日志目录
if [ ! -d "$LOG_DIR" ]; then
echo "创建日志目录: $LOG_DIR"
mkdir -p "$LOG_DIR"
fi
# 显示配置信息
show_config() {
echo "\n===== SSH连接测试配置 ====="
echo "服务器地址: $SERVER"
echo "SSH端口: $SSH_PORT"
echo "用户名: $SSH_USER"
echo "服务器类型: CentOS"
echo "密码: Aiotjkl$7jk58s&12"
echo "日志文件: $LOG_DIR/$LOG_FILE"
echo "=========================\n"
}
# 检查必要工具
check_tools() {
echo "检查必要工具..."
if ! command -v ssh &> /dev/null; then
echo "错误: ssh命令未安装请先安装ssh!"
exit 1
fi
if ! command -v ping &> /dev/null; then
echo "错误: ping命令未安装请先安装!"
exit 1
fi
if ! command -v nc &> /dev/null; then
echo "错误: nc命令未安装请先安装!"
echo "在Mac上: brew install netcat"
echo "在Ubuntu上: sudo apt-get install netcat"
echo "在CentOS上: sudo yum install nc"
exit 1
fi
echo "所有必要工具已安装\n"
}
# 测试网络连接
test_network() {
echo "===== 测试网络连接 ====="
echo "测试服务器可达性 (ping)..."
ping -c 4 $SERVER || echo "警告: ping测试失败但SSH仍可能工作"
echo "\n测试SSH端口开放情况..."
nc -zv $SERVER $SSH_PORT 2>&1 || {
echo "错误: 无法连接到 $SERVER$SSH_PORT 端口"
echo "可能的原因:"
echo "1. 服务器未启动或网络不可达"
echo "2. 服务器防火墙阻止了该端口"
echo "3. SSH服务未运行"
echo "4. 端口号配置错误"
return 1
}
echo "SSH端口测试通过\n"
return 0
}
# 测试DNS解析
test_dns() {
echo "===== 测试DNS解析 ====="
echo "解析服务器地址..."
IP_ADDRESS=$(dig +short $SERVER || getent hosts $SERVER | awk '{print $1}')
if [ -z "$IP_ADDRESS" ]; then
echo "错误: 无法解析服务器地址 $SERVER"
echo "请检查DNS配置或确认服务器地址是否正确"
return 1
fi
echo "服务器IP地址: $IP_ADDRESS\n"
return 0
}
# 详细的SSH连接测试
test_ssh_connection() {
echo "===== 详细SSH连接测试 ====="
echo "正在尝试SSH连接详细模式..."
echo "命令: ssh -v -p $SSH_PORT $SSH_USER@$SERVER"
# 创建一个临时的SSH配置文件禁用一些可能导致问题的选项
TEMP_SSH_CONFIG=$(mktemp)
cat > "$TEMP_SSH_CONFIG" << EOF
Host test-connection
HostName $SERVER
Port $SSH_PORT
User $SSH_USER
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
ConnectTimeout 15
LogLevel DEBUG3
EOF
echo "\nSSH详细连接日志保存到 $LOG_DIR/$LOG_FILE:"
ssh -F "$TEMP_SSH_CONFIG" test-connection 'exit' 2>&1 | tee "$LOG_DIR/$LOG_FILE"
# 清理临时文件
rm -f "$TEMP_SSH_CONFIG"
# 检查连接结果
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo "\nSSH连接成功"
return 0
else
echo "\nSSH连接失败请查看日志 $LOG_DIR/$LOG_FILE 获取详细信息"
return 1
fi
}
# 显示故障排除指南
display_troubleshooting() {
echo "\n===== SSH连接故障排除指南 ====="
echo "\n常见问题和解决方案"
echo "\n1. 服务器地址或端口错误"
echo " - 确认服务器地址: $SERVER"
echo " - 确认SSH端口: $SSH_PORT"
echo "\n2. 认证问题"
echo " - 确认用户名: $SSH_USER"
echo " - 确认密码: Aiotjkl$7jk58s&12"
echo " - 注意密码中的特殊字符可能需要转义"
echo " - 检查是否启用了密钥认证而不是密码认证"
echo "\n3. 防火墙问题"
echo " - 服务器防火墙是否允许SSH连接端口 $SSH_PORT"
echo " - 本地网络防火墙是否允许出站SSH连接"
echo " - 可能需要联系网络管理员开放相关端口"
echo "\n4. SSH服务问题"
echo " - 确认服务器上的SSH服务是否正在运行"
echo " - 服务器的SSH配置是否允许密码认证"
echo "\n5. 其他解决方案"
echo " - 尝试手动连接ssh -p $SSH_PORT $SSH_USER@$SERVER"
echo " - 如果是首次连接,手动接受服务器指纹"
echo " - 检查本地SSH配置文件 (~/.ssh/config) 是否有冲突的设置"
echo " - 尝试使用IP地址而不是域名连接"
echo "\n如果以上方法都无法解决问题请联系服务器管理员获取帮助。"
echo "======================================\n"
}
# 主函数
main() {
echo "SSH连接测试工具 v1.0"
echo "测试与 $SERVER 的SSH连接...\n"
# 1. 显示配置信息
show_config
# 2. 检查必要工具
check_tools
# 3. 测试DNS解析
if ! test_dns; then
echo "DNS解析测试失败无法继续。"
display_troubleshooting
exit 1
fi
# 4. 测试网络连接
if ! test_network; then
echo "网络连接测试失败,无法继续。"
display_troubleshooting
exit 1
fi
# 5. 详细的SSH连接测试
if test_ssh_connection; then
echo "\n恭喜SSH连接测试成功。您可以使用sync_to_server.sh脚本进行代码同步。"
else
display_troubleshooting
exit 1
fi
}
# 执行主函数
main