springcloud项目部署到Linux多服务启动脚本

  • Post author:
  • Post category:linux


多服务启动

脚本 java.sh

export修改成自己的项目路径和项目别名(前面是别名,后面是微服务项目名)

端口号跟每个微服务的端口号一样,跟yml配置的一样

修改脚本中$符号的脚本变量,跟export的一样

因为项目写的是全路径,例:/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-eureka.jar

所以放在linux的任何地方都可以执行。

启动项目:./java.sh start

停止项目:./java.sh stop

重启项目:./java.sh restart

java.sh如下:

#!/bin/sh
# chkconfig: 2345 10 90  
# description: Start and Stop redis 
export EUREKA=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-eureka.jar
export GATEWAY=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-gateway.jar
export AUTH=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-auth.jar
export USERMANAGER=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-user-manager.jar
export MONITORDATA=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-monitor-data.jar
export ANALYSISDATA=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-monitor-data-analysis.jar
export BASEMANAGER=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-base-manager.jar
export FORECAST=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-forecast.jar
export MULTIMEDIA=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-multimedia.jar
export OPERATION=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-operation.jar
export QUERYDATA=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-query-data.jar
export FILE=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-file.jar
export JOBSCHEDULER=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-job-scheduler.jar
export REPORT=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-report.jar
export SMS=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-sms.jar
export WARNING=/mnt/apps/zrzy/dam-managment-platform/dmp-micro-svc-warning.jar
export RIVERCHIEF=/mnt/apps/zrzy/dam-managment-platform/river-chief.jar 

export EUREKA_port=80
export GATEWAY_port=7002
export AUTH_port=7003
export USERMANAGER_port=7010
export MONITORDATA_port=7004
export ANALYSISDATA_port=7007
export BASEMANAGER_port=7011
export FORECAST_port=7014
export MULTIMEDIA_port=7017
export OPERATION_port=7015
export QUERYDATA_port=7006
export FILE_port=7018
export JOBSCHEDULER_port=7005
export REPORT_port=7013
export SMS_port=7012
export WARNING_port=7009
export RIVERCHIEF_port=8443
 
case "$1" in
 
start)
        ## 启动EUREKA
        echo "--------EUREKA 开始启动--------------"
        nohup java -jar -Dspring.profiles.active=prod  $EUREKA >/dev/null 2>&1 &
        EUREKA_pid=`lsof -i:$EUREKA_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$EUREKA_pid" ]
            do
              EUREKA_pid=`lsof -i:$EUREKA_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "EUREKA pid is $EUREKA_pid" 
        echo "--------EUREKA 启动成功--------------"
 
        ## 启动GATEWAY
        echo "--------开始启动GATEWAY---------------"
        nohup java -jar -Dspring.profiles.active=prod $GATEWAY>/dev/null 2>&1 &
        GATEWAY_pid=`lsof -i:$GATEWAY_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$GATEWAY_pid" ]
            do
              GATEWAY_pid=`lsof -i:$GATEWAY_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "GATEWAY pid is $GATEWAY_pid"     
        echo "---------GATEWAY启动成功-----------"
		
		## 启动AUTH
        echo "--------开始启动AUTH---------------"
        nohup java -jar -Dspring.profiles.active=prod $AUTH >/dev/null 2>&1 &
        AUTH_pid=`lsof -i:$AUTH_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$AUTH_pid" ]
            do
              AUTH_pid=`lsof -i:$AUTH_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "AUTH pid is $AUTH_pid"     
        echo "---------AUTH 启动成功-----------"
 
		
		## 启动USERMANAGER
        echo "--------开始启动USERMANAGER---------------"
        nohup java -jar -Dspring.profiles.active=prod $USERMANAGER>/dev/null 2>&1 &
        USERMANAGER_pid=`lsof -i:$USERMANAGER_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$USERMANAGER_pid" ]
            do
              USERMANAGER_pid=`lsof -i:$USERMANAGER_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "USERMANAGER pid is $USERMANAGER_pid"     
        echo "---------USERMANAGER启动成功-----------"
		
		## 启动MONITORDATA
        echo "--------开始启动MONITORDATA---------------"
        nohup java -jar -Dspring.profiles.active=prod $MONITORDATA>/dev/null 2>&1 &
        MONITORDATA_pid=`lsof -i:$MONITORDATA_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$MONITORDATA_pid" ]
            do
              MONITORDATA_pid=`lsof -i:$MONITORDATA_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "MONITORDATA pid is $MONITORDATA_pid"     
        echo "---------MONITORDATA启动成功-----------"
		
		## 启动ANALYSISDATA
        echo "--------开始启动ANALYSISDATA---------------"
        nohup java -jar -Dspring.profiles.active=prod $ANALYSISDATA>/dev/null 2>&1 &
        ANALYSISDATA_pid=`lsof -i:$ANALYSISDATA_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$ANALYSISDATA_pid" ]
            do
              ANALYSISDATA_pid=`lsof -i:$ANALYSISDATA_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "ANALYSISDATA pid is $ANALYSISDATA_pid"     
        echo "---------ANALYSISDATA启动成功-----------"
		
		## 启动BASEMANAGER
        echo "--------开始启动BASEMANAGER---------------"
        nohup java -jar -Dspring.profiles.active=prod $BASEMANAGER >/dev/null 2>&1 &
        BASEMANAGER_pid=`lsof -i:$BASEMANAGER_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$BASEMANAGER_pid" ]
            do
              BASEMANAGER_pid=`lsof -i:$BASEMANAGER_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "BASEMANAGER pid is $BASEMANAGER_pid"     
        echo "--------BASEMANAGER 启动成功-----------"
		
		## 启动FORECAST
        echo "--------开始启动FORECAST---------------"
        nohup java -jar -Dspring.profiles.active=prod $FORECAST >/dev/null 2>&1 &
        FORECAST_pid=`lsof -i:$FORECAST_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$FORECAST_pid" ]
            do
              FORECAST_pid=`lsof -i:$FORECAST_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "FORECAST pid is $FORECAST_pid"     
        echo "---------FORECAST 启动成功-----------"
		
		## 启动MULTIMEDIA
        echo "--------开始启动MULTIMEDIA---------------"
        nohup java -jar -Dspring.profiles.active=prod $MULTIMEDIA>/dev/null 2>&1 &
        MULTIMEDIA_pid=`lsof -i:$MULTIMEDIA_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$MULTIMEDIA_pid" ]
            do
              MULTIMEDIA_pid=`lsof -i:$MULTIMEDIA_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "MULTIMEDIA pid is $MULTIMEDIA_pid"     
        echo "---------MULTIMEDIA 启动成功-----------"
		
		## 启动OPERATION
        echo "--------开始启动OPERATION---------------"
        nohup java -jar -Dspring.profiles.active=prod $OPERATION>/dev/null 2>&1 &
        OPERATION_pid=`lsof -i:$OPERATION_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$OPERATION_pid" ]
            do
              OPERATION_pid=`lsof -i:$OPERATION_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "OPERATION pid is $OPERATION_pid"     
        echo "---------OPERATION 启动成功-----------"
		
		## 启动QUERYDATA
        echo "--------开始启动QUERYDATA---------------"
        nohup java -jar -Dspring.profiles.active=prod $QUERYDATA>/dev/null 2>&1 &
        QUERYDATA_pid=`lsof -i:$QUERYDATA_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$QUERYDATA_pid" ]
            do
              QUERYDATA_pid=`lsof -i:$QUERYDATA_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "QUERYDATA pid is $QUERYDATA_pid"     
        echo "---------QUERYDATA 启动成功-----------"
 
        ## 启动FILE
        echo "--------开始启动FILE---------------"
        nohup java -jar -Dspring.profiles.active=prod $FILE>/dev/null 2>&1 &
        FILE_pid=`lsof -i:$FILE_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$FILE_pid" ]
            do
              FILE_pid=`lsof -i:$v_port|grep "LISTEN"|awk '{print $2}'`
            done
        echo "FILE pid is $FILE_pid"
        echo "---------FILE启动成功-----------"

		## 启动JOBSCHEDULER
        echo "--------开始启动JOBSCHEDULER---------------"
        nohup java -jar -Dspring.profiles.active=prod $JOBSCHEDULER>/dev/null 2>&1 &
        JOBSCHEDULER_pid=`lsof -i:$JOBSCHEDULER_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$JOBSCHEDULER_pid" ]
            do
              JOBSCHEDULER_pid=`lsof -i:$JOBSCHEDULER_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "JOBSCHEDULER pid is $JOBSCHEDULER_pid"     
        echo "---------JOBSCHEDULER 启动成功-----------"

		## 启动REPORT
        echo "--------开始启动REPORT---------------"
        nohup java -jar -Dspring.profiles.active=prod $REPORT>/dev/null 2>&1 &
        REPORT_pid=`lsof -i:$REPORT_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$REPORT_pid" ]
            do
              REPORT_pid=`lsof -i:$REPORT_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "REPORT pid is $REPORT_pid"     
        echo "---------REPORT 启动成功-----------"

		## 启动SMS
        echo "--------开始启动SMS---------------"
        nohup java -jar -Dspring.profiles.active=prod $SMS>/dev/null 2>&1 &
        SMS_pid=`lsof -i:$SMS_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$SMS_pid" ]
            do
              SMS_pid=`lsof -i:$SMS_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "SMS pid is $SMS_pid"     
        echo "---------SMS 启动成功-----------"

		## 启动WARNING
        echo "--------开始启动WARNING---------------"
        nohup java -jar -Dspring.profiles.active=prod $WARNING>/dev/null 2>&1 &
        WARNING_pid=`lsof -i:$WARNING_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$WARNING_pid" ]
            do
              WARNING_pid=`lsof -i:$WARNING_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "WARNING pid is $WARNING_pid"     
        echo "---------WARNING 启动成功-----------"

		## 启动RIVERCHIEF
        echo "--------开始启动RIVERCHIEF---------------"
        nohup java -jar -Dspring.profiles.active=prod $RIVERCHIEF>/dev/null 2>&1 &
        RIVERCHIEF_pid=`lsof -i:$RIVERCHIEF_port|grep "LISTEN"|awk '{print $2}'` 
        until [ -n "$RIVERCHIEF_pid" ]
            do
              RIVERCHIEF_pid=`lsof -i:$RIVERCHIEF_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "RIVERCHIEF pid is $RIVERCHIEF_pid"     
        echo "---------RIVERCHIEF 启动成功-----------"

 
        echo "===startAll success==="
        ;;
 
 stop)
        P_ID=`ps -ef | grep -w $EUREKA | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===EUREKA process not exists or stop success"
        else
            kill -9 $P_ID
            echo "EUREKA killed success"
        fi
		P_ID=`ps -ef | grep -w $GATEWAY | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===GATEWAYprocess not exists or stop success"
        else
            kill -9 $P_ID
            echo "GATEWAY killed success"
        fi
		P_ID=`ps -ef | grep -w $AUTH | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===AUTH process not exists or stop success"
        else
            kill -9 $P_ID
            echo "AUTH killed success"
        fi
 
		P_ID=`ps -ef | grep -w $USERMANAGER | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===USERMANAGER process not exists or stop success"
        else
            kill -9 $P_ID
            echo "USERMANAGER killed success"
        fi
		P_ID=`ps -ef | grep -w $MONITORDATA | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===MONITORDATA process not exists or stop success"
        else
            kill -9 $P_ID
            echo "MONITORDATA killed success"
        fi
		P_ID=`ps -ef | grep -w $ANALYSISDATA | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===ANALYSISDATA process not exists or stop success"
        else
            kill -9 $P_ID
            echo "ANALYSISDATA killed success"
        fi
		P_ID=`ps -ef | grep -w $BASEMANAGER | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===BASEMANAGER process not exists or stop success"
        else
            kill -9 $P_ID
            echo "BASEMANAGER killed success"
        fi
		P_ID=`ps -ef | grep -w $FORECAST | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===FORECAST process not exists or stop success"
        else
            kill -9 $P_ID
            echo "FORECAST killed success"
        fi
		P_ID=`ps -ef | grep -w $MULTIMEDIA | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===MULTIMEDIA process not exists or stop success"
        else
            kill -9 $P_ID
            echo "MULTIMEDIA killed success"
        fi
		P_ID=`ps -ef | grep -w $OPERATION | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===OPERATION process not exists or stop success"
        else
            kill -9 $P_ID
            echo "OPERATION killed success"
        fi
		P_ID=`ps -ef | grep -w $QUERYDATA | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===QUERYDATA process not exists or stop success"
        else
            kill -9 $P_ID
            echo "QUERYDATA killed success"
        fi
        P_ID=`ps -ef | grep -w $FILE | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===FILE process not exists or stop success"
        else
            kill -9 $P_ID
            echo "FILE killed success"
        fi
 	P_ID=`ps -ef | grep -w $JOBSCHEDULER | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===JOBSCHEDULER process not exists or stop success"
        else
            kill -9 $P_ID
            echo "JOBSCHEDULER killed success"
        fi
 	P_ID=`ps -ef | grep -w $REPORT | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===REPORT process not exists or stop success"
        else
            kill -9 $P_ID
            echo "FILE killed success"
        fi
	 P_ID=`ps -ef | grep -w $SMS | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===SMS process not exists or stop success"
        else
            kill -9 $P_ID
            echo "SMS killed success"
        fi
	 P_ID=`ps -ef | grep -w $WARNING | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===WARNING process not exists or stop success"
        else
            kill -9 $P_ID
            echo "WARNING killed success"
        fi
	 P_ID=`ps -ef | grep -w $RIVERCHIEF | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===RIVERCHIEF process not exists or stop success"
        else
            kill -9 $P_ID
            echo "RIVERCHIEF killed success"
        fi
 
        echo "===stopAll success==="
        ;;   
 
restart)
        $0 stop
        sleep 2
        $0 start
        echo "===restartAll success==="
        ;;   
esac	
exit 0

linux开机自动启动

把java.sh拷贝一份到/etc/init.d/下面

cp java.sh  /etc/init.d/java   改名为java

给java文件执行权限   chmod  777 java

把java添加到开机启动    chkconfig –add java

重启linux    reboot



版权声明:本文为weixin_67588007原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。