特殊说明,如需从linux远程到另一台linux
ssh -p 331 root@10.45.33.131
1. 创建存放文件的对应文件夹
1.1 创建存放源码的文件夹
mkdir /data/workspaces/code/zyzy-scene
1.2 创建存放编译文件的文件夹
mkdir -p /data/workspaces/deploy/zyzy-scene/zyzy-app-weixin-api
1.3 创建存放脚本的文件夹
cd /data/workspaces/code/zyzy-scene
mkdir /data/workspaces/autodeploy/zyzy-scene
2. 拉取指定分支的代码
git clone -b main-scene-prod http://58.22.7.74:8001/xintong2021/zyzy/code/zyzy-app-weixin-api.git
3. 编写自动化脚本
#!/bin/bash
export build_folder=/data/workspaces/code/zyzy-scene/zyzy-app-weixin-api
export deploy_folder=/data/workspaces/deploy/zyzy-scene/zyzy-app-weixin-api
export jar_name=profession-wx-api-0.1.1-SNAPSHOT.jar
export port=38072
export screenName=zyzy-scene-app-weixin-api
cd $build_folder
echo '拉取GIT最新代码'
#git pull origin main-scene-prod
mvn clean package -f $build_folder
mvn_result=$?
if [[ $mvn_result = '0' ]] ; then
echo '停止服务'
#curl -XPOST http://127.0.0.1:$port/actuator/shutdown
screen -x -R $screenName -p 0 -X stuff "echo -e \003\n"
echo '休眠5秒'
sleep 5s
echo '部署代码'
cp $build_folder/target/$jar_name $deploy_folder/
echo '后台启动服务'
screen -x -R $screenName -p 0 -X stuff "cd $deploy_folder\n"
screen -x -R $screenName -p 0 -X stuff "java -jar $jar_name --spring.profiles.active=scene-prod --server.port=$port\n"
fi
4. 上传脚本及赋予可执行权限
chmod u+x auto_deplloy_zyzy-scene-app-weixin-api.sh
5. 运行脚本
5.1 创建会话
先确认会话列表
screen --ls
再创建会话(如果已存在不会再创建,会直接进入)
screen -R zyzy-scene-app-weixin-api
Ctrl+A+D退出会话
6. telnet 确保已经可以
6.1 安装telnet
# 查询是否安装
rpm -qa telnet-server
# 安装 telnet-server
yum install -y telnet-server
# 安装 telnet
yum install -y telnet
6.2 本机telnet 及 远程telnet
telnet 10.45.33.131 38072
7. Nginx配置
7.1 修改Nginx配置文件
upstream intf-api-80 {
server 10.45.33.68:8070;
server 10.45.33.35:8070;
}
upstream wx-api-80 {
server 10.45.33.104:18071;
server 10.45.33.115:18071;
}
upstream wx-api-now-80 {
server 10.45.33.104:18072;
server 10.45.33.115:18072;
}
server {
#监听443端口
listen 443 ssl;
server_name zyzy.xtweb.com.cn;
#公钥路径
ssl_certificate /usr/local/nginx/ssl/zyzy.xtweb.com.cn.crt;
#私钥路径
ssl_certificate_key /usr/local/nginx/ssl/zyzy.xtweb.com.cn.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
#ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_prefer_server_ciphers on;
# listen 443;
# server_name zyzy.xtweb.com.cn;
# server_name 220.250.1.199;
location / {
root /data/workspaces/deploy/zyzy/zyzy-cms-view/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /web {
alias /data/workspaces/deploy/zyzy/zyzy-mng-web/dist/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /new-wx-api/ {
#proxy_pass http://127.0.0.1:17161;
proxy_pass http://wx-api-80;
proxy_set_header Host $host;
proxy_set_header Remote_Addr $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
}
location /xtrelease/ {
root /data/workspaces/zyzy;
}
location /wx-api-scene/ {
proxy_pass http://10.45.33.115:38072;
proxy_set_header Host $host;
proxy_set_header Remote_Addr $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
}
}
7.2 执行新配置
- nginx启动:
cd /usr/local/nginx/sbin
- 启动
./nginx
- 关闭
./nginx -s stop
- 检查nginx 的配置情况
./nginx -t
- 重新加载配置
./nginx -s reload