Bladeren bron

chore: update server deployment scripts and configurations

bobyuxinyang 6 uur geleden
bovenliggende
commit
a608da4c4d
12 gewijzigde bestanden met toevoegingen van 125 en 60 verwijderingen
  1. 2 2
      ccdw.xyz.conf
  2. 2 2
      check_nginx.sh
  3. 4 4
      check_node.sh
  4. 3 3
      deploy.sh
  5. 7 7
      explore_nginx.sh
  6. 4 4
      final_check.sh
  7. 13 16
      fix_and_deploy.sh
  8. 6 5
      fix_nginx_final.sh
  9. 2 0
      pnpm-workspace.yaml
  10. 7 7
      retry_https.sh
  11. 11 10
      setup_https_full.sh
  12. 64 0
      setup_server.sh

+ 2 - 2
ccdw.xyz.conf

@@ -2,8 +2,8 @@ server {
     listen 80;
     server_name ccdw.xyz www.ccdw.xyz;
     
-    access_log /www/wwwlogs/ccdw.xyz.log;
-    error_log /www/wwwlogs/ccdw.xyz.error.log;
+    access_log /var/log/nginx/ccdw.xyz.log;
+    error_log /var/log/nginx/ccdw.xyz.error.log;
 
     location / {
         proxy_pass http://127.0.0.1:3001;

+ 2 - 2
check_nginx.sh

@@ -1,7 +1,7 @@
 #!/bin/bash
-SERVER_IP="47.253.147.187"
+SERVER_IP="45.61.60.10"
 SERVER_USER="root"
-SERVER_PASS="5H0FuZ:2s0q)Lx"
+SERVER_PASS="UQb9TgSwC@vwhEM"
 
 # 使用 expect 自动登录并执行检查命令
 /usr/bin/expect <<EOF

+ 4 - 4
check_node.sh

@@ -1,7 +1,7 @@
 #!/bin/bash
-SERVER_IP="47.253.147.187"
+SERVER_IP="45.61.60.10"
 SERVER_USER="root"
-SERVER_PASS="5H0FuZ:2s0q)Lx"
+SERVER_PASS="UQb9TgSwC@vwhEM"
 
 /usr/bin/expect <<EOF
 set timeout 30
@@ -16,8 +16,8 @@ expect "#"
 send "echo '--- CHECKING NODEJS ---'\r"
 send "which node\r"
 send "which npm\r"
-send "ls -F /www/server/nodejs/ 2>/dev/null\r"
-send "find /www/server -name node -type f 2>/dev/null | grep bin/node\r"
+send "node -v\r"
+send "npm -v\r"
 send "echo '--- CHECKING SYSTEM INFO AGAIN ---'\r"
 send "cat /etc/os-release\r"
 send "exit\r"

+ 3 - 3
deploy.sh

@@ -1,10 +1,10 @@
 #!/bin/bash
 
 # 服务器配置信息
-SERVER_IP="47.253.147.187"
+SERVER_IP="45.61.60.10"
 SERVER_USER="root"
-SERVER_PASS="5H0FuZ:2s0q)Lx"
-REMOTE_PARENT_DIR="/www/wwwroot/ccdw-website"
+SERVER_PASS="UQb9TgSwC@vwhEM"
+REMOTE_PARENT_DIR="/var/www/ccdw-website"
 
 # 颜色输出
 GREEN='\033[0;32m'

+ 7 - 7
explore_nginx.sh

@@ -1,7 +1,7 @@
 #!/bin/bash
-SERVER_IP="47.253.147.187"
+SERVER_IP="45.61.60.10"
 SERVER_USER="root"
-SERVER_PASS="5H0FuZ:2s0q)Lx"
+SERVER_PASS="UQb9TgSwC@vwhEM"
 
 /usr/bin/expect <<EOF
 set timeout 30
@@ -13,12 +13,12 @@ expect {
 }
 
 expect "#"
-send "ls -F /www/server/nginx/conf/\r"
-send "ls -F /www/server/nginx/conf/vhost/\r"
-send "ls -F /www/server/panel/vhost/nginx/ 2>/dev/null\r"
+send "ls -F /etc/nginx/\r"
+send "ls -F /etc/nginx/sites-available/\r"
+send "ls -F /etc/nginx/sites-enabled/\r"
 send "echo '--- EXISTING CERTS ---'\r"
-send "find /www/server -name '*.pem' -o -name '*.crt' | head -n 10\r"
-send "cat /www/server/nginx/conf/nginx.conf\r"
+send "find /etc/letsencrypt -name '*.pem' -o -name '*.crt' | head -n 10\r"
+send "cat /etc/nginx/nginx.conf\r"
 send "exit\r"
 expect eof
 EOF

+ 4 - 4
final_check.sh

@@ -1,7 +1,7 @@
 #!/bin/bash
-SERVER_IP="47.253.147.187"
+SERVER_IP="45.61.60.10"
 SERVER_USER="root"
-SERVER_PASS="5H0FuZ:2s0q)Lx"
+SERVER_PASS="UQb9TgSwC@vwhEM"
 
 /usr/bin/expect <<EOF
 set timeout 30
@@ -13,10 +13,10 @@ expect {
 expect "#"
 
 # 确保配置已移动
-send "if test -f /tmp/ccdw_full.conf && test -f /etc/letsencrypt/live/ccdw.xyz/fullchain.pem; then mv /tmp/ccdw_full.conf /www/server/panel/vhost/nginx/ccdw.xyz.conf; fi\r"
+send "if test -f /tmp/ccdw_full.conf && test -f /etc/letsencrypt/live/ccdw.xyz/fullchain.pem; then mv /tmp/ccdw_full.conf /etc/nginx/sites-available/ccdw.xyz.conf && ln -sf /etc/nginx/sites-available/ccdw.xyz.conf /etc/nginx/sites-enabled/ccdw.xyz.conf; fi\r"
 
 # 强制重启 Nginx
-send "/etc/init.d/nginx restart\r"
+send "systemctl restart nginx\r"
 
 # 验证
 send "echo '--- VALIDATION ---'\r"

+ 13 - 16
fix_and_deploy.sh

@@ -1,8 +1,7 @@
 #!/bin/bash
-SERVER_IP="47.253.147.187"
+SERVER_IP="45.61.60.10"
 SERVER_USER="root"
-SERVER_PASS="5H0FuZ:2s0q)Lx"
-NODE_BIN="/www/server/nodejs/v22.16.0/bin"
+SERVER_PASS="UQb9TgSwC@vwhEM"
 
 /usr/bin/expect <<EOF
 set timeout 180
@@ -15,19 +14,17 @@ expect {
 
 expect "#"
 
-# 1. Link Node binaries
-send "echo '--- LINKING NODE BINARIES ---'\r"
-send "ln -sf $NODE_BIN/node /usr/bin/node\r"
-send "ln -sf $NODE_BIN/npm /usr/bin/npm\r"
-send "ln -sf $NODE_BIN/npx /usr/bin/npx\r"
+# 1. Check Node binaries
+send "echo '--- CHECKING NODE BINARIES ---'\r"
+send "which node\r"
+send "which npm\r"
+send "which npx\r"
 
 # 2. Finish backend deployment
 send "echo '--- FINISHING BACKEND DEPLOYMENT ---'\r"
-send "cd /www/wwwroot/ccdw-website/server\r"
+send "cd /var/www/ccdw-website/server\r"
 send "npm install --omit=dev --registry=https://registry.npmmirror.com\r"
 send "npm install -g pm2 --registry=https://registry.npmmirror.com\r"
-# Link PM2
-send "ln -sf $NODE_BIN/pm2 /usr/bin/pm2\r"
 
 # Start App
 send "echo '--- STARTING APP ---'\r"
@@ -37,13 +34,13 @@ send "pm2 save\r"
 
 # 3. Create Nginx Config (HTTP)
 send "echo '--- CREATING NGINX CONFIG ---'\r"
-send "cat > /www/server/panel/vhost/nginx/ccdw.xyz.conf <<ENDCONF
+send "cat > /etc/nginx/sites-available/ccdw.xyz.conf <<ENDCONF
 server {
     listen 80;
     server_name ccdw.xyz www.ccdw.xyz;
     
-    access_log /www/wwwlogs/ccdw.xyz.log;
-    error_log /www/wwwlogs/ccdw.xyz.error.log;
+    access_log /var/log/nginx/ccdw.xyz.log;
+    error_log /var/log/nginx/ccdw.xyz.error.log;
 
     location / {
         proxy_pass http://127.0.0.1:3001;
@@ -58,8 +55,8 @@ ENDCONF\r"
 # 4. Reload Nginx
 send "echo '--- RELOADING NGINX ---'\r"
 send "nginx -t\r"
-# 宝塔环境下 reload 命令
-send "/etc/init.d/nginx reload\r"
+send "ln -sf /etc/nginx/sites-available/ccdw.xyz.conf /etc/nginx/sites-enabled/ccdw.xyz.conf\r"
+send "systemctl reload nginx\r"
 
 # 5. Check URL access
 send "echo '--- CHECKING ACCESS ---'\r"

+ 6 - 5
fix_nginx_final.sh

@@ -1,12 +1,12 @@
 #!/bin/bash
-SERVER_IP="47.253.147.187"
+SERVER_IP="45.61.60.10"
 SERVER_USER="root"
-SERVER_PASS="5H0FuZ:2s0q)Lx"
+SERVER_PASS="UQb9TgSwC@vwhEM"
 
 # 1. Upload Nginx config
 /usr/bin/expect <<EOF
 set timeout 30
-spawn scp -o StrictHostKeyChecking=no ccdw.xyz.conf $SERVER_USER@$SERVER_IP:/www/server/panel/vhost/nginx/ccdw.xyz.conf
+spawn scp -o StrictHostKeyChecking=no ccdw.xyz.conf $SERVER_USER@$SERVER_IP:/etc/nginx/sites-available/ccdw.xyz.conf
 expect {
     "password:" { send "$SERVER_PASS\r" }
     "yes/no" { send "yes\r"; exp_continue }
@@ -29,11 +29,12 @@ expect "#"
 # Reload Nginx
 send "echo '--- RELOADING NGINX STATUS ---'\r"
 send "nginx -t\r"
-send "/etc/init.d/nginx reload\r"
+send "ln -sf /etc/nginx/sites-available/ccdw.xyz.conf /etc/nginx/sites-enabled/ccdw.xyz.conf\r"
+send "systemctl reload nginx\r"
 
 # Check Node App
 send "echo '--- CHECKING NODE APP ---'\r"
-send "cd /www/wwwroot/ccdw-website/server\r"
+send "cd /var/www/ccdw-website/server\r"
 # Force install production deps again just in case
 send "npm install --omit=dev --registry=https://registry.npmmirror.com\r"
 send "pm2 restart ccdw-server\r"

+ 2 - 0
pnpm-workspace.yaml

@@ -0,0 +1,2 @@
+allowBuilds:
+  esbuild: set this to true or false

+ 7 - 7
retry_https.sh

@@ -1,7 +1,7 @@
 #!/bin/bash
-SERVER_IP="47.253.147.187"
+SERVER_IP="45.61.60.10"
 SERVER_USER="root"
-SERVER_PASS="5H0FuZ:2s0q)Lx"
+SERVER_PASS="UQb9TgSwC@vwhEM"
 
 /usr/bin/expect <<EOF
 set timeout 120
@@ -16,22 +16,22 @@ send "ls -l /etc/letsencrypt/live/ccdw.xyz/fullchain.pem\r"
 
 # 使用 test 命令代替 [] 避免 Tcl 解析错误
 send "if test -f /etc/letsencrypt/live/ccdw.xyz/fullchain.pem; then \
-    mv /tmp/ccdw_full.conf /www/server/panel/vhost/nginx/ccdw.xyz.conf; \
+    mv /tmp/ccdw_full.conf /etc/nginx/sites-available/ccdw.xyz.conf && ln -sf /etc/nginx/sites-available/ccdw.xyz.conf /etc/nginx/sites-enabled/ccdw.xyz.conf; \
     echo 'Certificate verified. Applying config...'; \
 else \
     echo 'Certificate NOT found, trying install again...'; \
     apt-get update && apt-get install -y certbot; \
-    /etc/init.d/nginx stop; \
+    systemctl stop nginx; \
     killall nginx; \
     certbot certonly --standalone -d ccdw.xyz -d www.ccdw.xyz --email bob.yuxinyang@gmail.com --agree-tos --non-interactive; \
     if test -f /etc/letsencrypt/live/ccdw.xyz/fullchain.pem; then \
-        mv /tmp/ccdw_full.conf /www/server/panel/vhost/nginx/ccdw.xyz.conf; \
+        mv /tmp/ccdw_full.conf /etc/nginx/sites-available/ccdw.xyz.conf && ln -sf /etc/nginx/sites-available/ccdw.xyz.conf /etc/nginx/sites-enabled/ccdw.xyz.conf; \
     fi; \
 fi\r"
 
 send "echo '--- RESTARTING NGINX ---'\r"
-send "/etc/init.d/nginx start\r"
-send "/etc/init.d/nginx reload\r"
+send "systemctl start nginx\r"
+send "systemctl reload nginx\r"
 send "nginx -t\r"
 
 send "echo '--- VERIFYING ---'\r"

+ 11 - 10
setup_https_full.sh

@@ -1,7 +1,7 @@
 #!/bin/bash
-SERVER_IP="47.253.147.187"
+SERVER_IP="45.61.60.10"
 SERVER_USER="root"
-SERVER_PASS="5H0FuZ:2s0q)Lx"
+SERVER_PASS="UQb9TgSwC@vwhEM"
 
 # 1. 编写完整的 Nginx HTTPS 配置文件 (预备)
 # 注意:证书路径暂时写死为 Let's Encrypt 标准路径
@@ -28,8 +28,8 @@ server {
     ssl_prefer_server_ciphers off;
 
     # 日志
-    access_log /www/wwwlogs/ccdw.xyz.log;
-    error_log /www/wwwlogs/ccdw.xyz.error.log;
+    access_log /var/log/nginx/ccdw.xyz.log;
+    error_log /var/log/nginx/ccdw.xyz.error.log;
 
     # 反向代理到 Node.js (3001)
     location / {
@@ -74,7 +74,7 @@ send "apt-get update && apt-get install -y certbot\r"
 
 send "echo '--- 2. STOPPING NGINX FOR AUTH ---'\r"
 # 停止 Nginx 以释放 80 端口供 Certbot 使用
-send "/etc/init.d/nginx stop\r"
+send "systemctl stop nginx\r"
 # 确保进程已杀掉
 send "killall nginx 2>/dev/null\r"
 
@@ -84,17 +84,18 @@ send "certbot certonly --standalone -d ccdw.xyz -d www.ccdw.xyz --email bob.yuxi
 
 send "echo '--- 4. APPLYING NGINX CONFIG ---'\r"
 # 检查证书是否生成成功
-send "if [ -f /etc/letsencrypt/live/ccdw.xyz/fullchain.pem ]; then \
+send "if test -f /etc/letsencrypt/live/ccdw.xyz/fullchain.pem; then \
     echo 'Certificate verified. Applying config...'; \
-    mv /tmp/ccdw_full.conf /www/server/panel/vhost/nginx/ccdw.xyz.conf; \
+    mv /tmp/ccdw_full.conf /etc/nginx/sites-available/ccdw.xyz.conf; \
+    ln -sf /etc/nginx/sites-available/ccdw.xyz.conf /etc/nginx/sites-enabled/ccdw.xyz.conf; \
 else \
     echo 'ERROR: Certificate generation failed!'; \
-    rm /www/server/panel/vhost/nginx/ccdw.xyz.conf 2>/dev/null; \
+    rm /etc/nginx/sites-available/ccdw.xyz.conf 2>/dev/null; \
+    rm /etc/nginx/sites-enabled/ccdw.xyz.conf 2>/dev/null; \
 fi\r"
 
 send "echo '--- 5. RESTARTING NGINX ---'\r"
-send "/etc/init.d/nginx start\r"
-send "nginx -t\r"
+send "nginx -t && systemctl start nginx\r"
 
 send "echo '--- 6. VERIFYING ---'\r"
 send "netstat -tulpn | grep nginx\r"

+ 64 - 0
setup_server.sh

@@ -0,0 +1,64 @@
+#!/bin/bash
+
+SERVER_IP="45.61.60.10"
+SERVER_USER="root"
+SERVER_PASS="UQb9TgSwC@vwhEM"
+
+GREEN='\033[0;32m'
+NC='\033[0m'
+
+echo -e "${GREEN}=== 开始配置远程服务器环境 ===${NC}"
+
+# 使用 expect 登录远程服务器并执行初始化
+/usr/bin/expect <<EOF
+set timeout 600
+spawn ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP
+
+expect {
+    "password:" { send "$SERVER_PASS\r" }
+    "yes/no" { send "yes\r"; exp_continue }
+}
+
+expect "#"
+
+# 1. 更新系统并安装基础依赖
+send "echo '--- 1. UPDATING PACKAGES & SYSTEM ---'\r"
+expect "#"
+send "apt-get update && apt-get install -y curl gnupg git build-essential nginx certbot python3-certbot-nginx\r"
+expect "#"
+
+# 2. 安装 Node.js 22 LTS (via NodeSource)
+send "echo '--- 2. INSTALLING NODE.JS 22 ---'\r"
+expect "#"
+send "curl -fsSL https://deb.nodesource.com/setup_22.x | bash -\r"
+expect "#"
+send "apt-get install -y nodejs\r"
+expect "#"
+
+# 3. 验证 Node/NPM 并安装 PM2
+send "echo '--- 3. INSTALLING PM2 ---'\r"
+expect "#"
+send "node -v && npm -v\r"
+expect "#"
+send "npm install -g pm2 --registry=https://registry.npmmirror.com\r"
+expect "#"
+
+# 4. 创建部署目录
+send "echo '--- 4. CREATING DEPLOYMENT DIR ---'\r"
+expect "#"
+send "mkdir -p /var/www/ccdw-website\r"
+expect "#"
+send "chown -R root:root /var/www/ccdw-website\r"
+expect "#"
+
+# 5. 验证安装
+send "echo '--- 5. VERIFYING INSTALLATIONS ---'\r"
+expect "#"
+send "command -v node && command -v npm && command -v pm2 && command -v nginx\r"
+expect "#"
+
+send "exit\r"
+expect eof
+EOF
+
+echo -e "${GREEN}=== 服务器环境配置完成! ===${NC}"