更新时间:2024-04-26 GMT+08:00
分享

实施步骤

  1. Nginx环境配置

    配置conf

    编辑 /usr/local/nginx/conf 下nginx.conf

    添加以下内容:

    upstream ntocc-basic-api {
    server 127.0.0.1:9002;
    }
    upstream ntocc-park-api {
    server 127.0.0.1:9007;
    }
    upstream ntocc-tps-api {
    server 127.0.0.1:9009;
    }
    location ^~ /ntocc-basic-api/ {
    # proxy_pass   http://park-queue-api/park-queue-api/;
    proxy_pass http://ntocc-basic-api;
    add_header backendIP $upstream_addr;
    index  index.html index.htm;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect default;
    }
    location ^~ /ntocc-park-api/ {
    proxy_pass   http://ntocc-park-api;
    add_header backendIP $upstream_addr;
    index  index.html index.htm;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect off;
    }
    location ^~ /ntocc-tps-api/ {
    proxy_pass   http://ntocc-tps-api;
    add_header backendIP $upstream_addr;
    index  index.html index.htm;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect off;
    }

  2. 移动jar包到指定位置

    移动所需jar包ntocc-basic-api.jar, ntocc-tps-api.jar, ntocc-park-api.jar 到/root 目录下

  3. 应用程序启动

    创建目录(mkdir //usr/local/server)

    添加文件park-api.sh、tps-api.sh、basic-api.sh

    文件内容为:

    echo '#######################开始部署##########################'
    path=`pwd` #当前路径
    serverPath=/usr/local/server #指定部署文件名称
    jarName=ntocc-basic-api
    jarFullName=$jarName.jar
    DATE=`date +%F | sed 's/-//g'``date +%T | sed 's/://g'`
    cd $serverPath #进入部署程序目录
    echo '###开始备份老版本jar包###'
    mv $jarFullName ./bak/$jarFullName.$DATE.bak
    echo '###结束备份老版本jar包###'
    echo '###开始复制新版本jar包###'
    mv /root/$jarFullName ./
    echo '###结束复制新版本jar包###'
    echo '###开始kill原程序进程###'
    PID1=`ps -ef |grep $jarName|grep -v grep|grep 9002|awk '{print $2}'`
    kill -9 $PID1
    echo "$PID1已终止..."
    echo '###结束kill原程序进程###'
    echo '###开始启动新版本jar包###'
    sleep 1 #休眠
    nohup java -jar -server -Xms1024m -Xmx2048m -XX:PermSize=512M -XX:MaxPermSize=512m -XX:MaxNewSize=512m $jarFullName --spring.profiles.active=dev --server.port=9002 --server.servlet.context-path=/$jarName 1>basic.out 2>&1 &
    echo '######################部署结束##########################'

    jarName为必须修改的地方:修改为对应的jar包名称

    server.port为必须修改:修改为nginx配置的对应jar包端口

    server.servlet.context-path为必须修改:修改为对应输出文件名称

    创建后,依次启动服务

    sh /usr/local/server/ park-api.sh
    sh /usr/local/server/ tps -api.sh
    sh /usr/local/server/ basic -api.sh

  4. 验证操作是否成功

    查看日志是否出现成功的字眼,出现“Started NtoccBasicApiApplication in 29.958 seconds”表示已经启动成功

    (tail -1000f basic.out)

相关文档