895
38
3319
管理员
签到天数: 1638 天
[LV.Master]伴坛终老
sonar.jdbc.username=sonar sonar.jdbc.password=123456 sonar.jdbc.url=jdbc:mysql://172.31.225.244:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false sonar.web.host=0.0.0.0 sonar.web.port=9000
#!/bin/bash DATE=`date +%Y-%m-%d_%H-%M-%S` GROUP_LIST=$2 function IP_list(){ if [[ ${GROUP_LIST} == "online-group1" ]];then Server_IP="172.31.225.245" echo ${Server_IP} elif [[ ${GROUP_LIST} == "online-group2" ]];then Server_IP="172.31.225.242" ssh root@172.31.225.243 ""echo enable server web_port/172.31.225.245" | socat stdio /var/lib/haproxy/haproxy.sock" ssh root@172.31.225.244 ""echo enable server web_port/172.31.225.242" | socat stdio /var/lib/haproxy/haproxy.sock" echo ${Server_IP} elif [[ ${GROUP_LIST} == "online-all" ]];then Server_IP="172.31.225.245 172.31.225.242" echo ${Server_IP} fi } #function pull_code(){ # rm -rf /home/tomcat/.jenkins/workspace/testweb # cd /home/tomcat/.jenkins/workspace # git clone git@192.168.7.202:testgroup/testweb.git #} function make_zip(){ cd /var/lib/jenkins/workspace/test-demo1 && zip testweb.war.zip ./* } function down_node(){ for node in ${Server_IP};do echo ${node} ssh root@172.31.225.243 ""echo disable server web_port/${node}" | socat stdio /var/lib/haproxy/haproxy.sock" ssh root@172.31.225.244 ""echo disable server web_port/${node}" | socat stdio /var/lib/haproxy/haproxy.sock" echo "${node} 关闭成功!" done } function stop_tomcat(){ for node in ${Server_IP};do ssh tomcat@${node} "/etc/init.d/tomcat stop" echo "${node} 关闭成功!" done } function start_tomcat(){ for node in ${Server_IP};do ssh tomcat@${node} "/etc/init.d/tomcat start" echo "${node} 启动成功!" done } function scp_codefile(){ cd /var/lib/jenkins/workspace/test-demo1 for node in ${Server_IP};do scp testweb.war.zip tomcat@${node}:/apps/tomcat_appdir ssh tomcat@${node} "cd /apps/tomcat_appdir && unzip testweb.war.zip -d /apps/tomcat_webdir/testweb-${DATE} && rm -rf /data/tomcat_webdir/testweb && ln -sv /apps/tomcat_webdir/testweb-${DATE} /data/tomcat_webdir/testweb" done } function web_test(){ #sleep 30 for node in ${Server_IP};do NUM=`curl -s -I -m 10 -o /dev/null -w %{http_code} http://${node}:8080/testweb/index.html` if [[ ${NUM} -eq 200 ]];then echo "${node} 测试通过,即将添加到负载" add_node ${node} else echo "${node} 测试失败,请检查该服务器是否成功启动tomcat" fi done } function add_node(){ node=$1 echo ${node},"----->" if [ ${node} == "192.168.8.100" ];then echo "192.168.8.100部署完毕,请进行代码测试!" else ssh root@172.31.225.243 ""echo enable server web_port/${node}" | socat stdio /var/lib/haproxy/haproxy.sock" ssh root@172.31.225.244 ""echo enable server web_port/${node}" | socat stdio /var/lib/haproxy/haproxy.sock" fi } function rollback_last_version(){ for node in ${Server_IP};do NOW_VERSION=`ssh tomcat@${node} ""/bin/ls -l -rt /data/tomcat_webdir/ | awk -F"->" '{print $2}' | tail -n1 | awk -F"/apps/tomcat_webdir/" '{print $2}'""` NAME=`ssh tomcat@${node} ""/bin/ls -l -rt -d /apps/tomcat_webdir/testweb* | grep -B 1 ${NOW_VERSION} | head -n1 | awk '{print $9}'""` ssh tomcat@${node} "rm -rf /data/tomcat_webdir/testweb && ln -sv ${NAME} /data/tomcat_webdir/testweb" done } main(){ case $1 in deploy) IP_list; #pull_code; make_zip; down_node; stop_tomcat; scp_codefile; start_tomcat; web_test; ;; rollback_last_version) IP_list; echo ${Server_IP} down_node; stop_tomcat; rollback_last_version; start_tomcat; web_test; ;; esac } main $1 $2
#!/bin/bash # ######################################################### # Tomcat init script for "中企动力科技股份有限公司"#### ########################################################### # chkconfig: 2345 96 14 ################################### # description: 2016/11/1. 张士杰########################## # ######################################################### JDK_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64 CATALINA_HOME=/apps/tomcat export JDK_HOME CATALINA_HOME source /etc/profile #PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'` #NUM=`ps -ef | grep -v grep | grep java | awk '{print $2}' | wc -l` #case $1 in start() { echo "正在判断服务状态,请稍等!" echo "请稍等3秒钟" echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1 if netstat -an | grep 8080 | grep LISTEN >/dev/null then echo "Tomcat已经正在运行了!" else echo "Tomcat没有运行,1秒后启动!" echo 1;sleep 1 $CATALINA_HOME/bin/catalina.sh start echo "Tomcat 已经成功启动完成,5秒后判断是否启动成功" echo "5";sleep 1;echo "4";sleep 1 echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1 if netstat -an | grep 8080 | grep LISTEN >/dev/null then PID=`ps -ef | grep tomcat | grep jdk | awk '{print $2}'` NUM=`ps -ef | grep tomcat | grep jdk | awk '{print $2}' | wc -l` echo "Tomcat 已经成功启动${NUM} 个Tomcat进程!,PID为${PID}" else echo "Tomcat启动失败,请重新启动!" echo 1 fi fi } stop() { PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'` NUM=`ps -ef | grep -v "color" | grep tomcat | awk '{print $2}' | wc -l` echo "正在判断服务状态,请稍等3秒钟!" echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1 if netstat -an | grep 8080 | grep LISTEN >/dev/null then echo "Tomcat运行中,1秒后关闭!" echo 1;sleep 1 echo "即将关闭Tomcat服务,请稍等!" $CATALINA_HOME/bin/catalina.sh stop ;echo "已经执行关闭命令,正在检查关闭了多少Tomcat进程,请稍等5秒钟!" sleep 2 echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1 pkill java && pkill tomcat if netstat -an | grep 8080 | grep LISTEN >/dev/null;then PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'` NUM=`ps -ef | grep -v "color" | grep tomcat | awk '{print $2}' | wc -l` kill -9 $PID ;echo "已成功关闭${NUM} 个tomcat进程" else echo "Tomcat 已经关闭完成!" echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1 fi else echo "Tomcat 没有运行" echo 1 fi if netstat -an | grep 8080 | grep LISTEN >/dev/null;then PID=`ps -ef | grep -v grep | grep java | awk '{print $2}'` #NUM=`ps -ef | grep -v "color" | grep tomcat | awk '{print $2}' | wc -l` echo "关闭失败,即将强制删除tomcat进程!" sleep 2 pkill tomcat ;sleep 2 if netstat -an | grep 8080 | grep LISTEN >/dev/null;then echo "强制关闭失败,即将再次强制删除tomcat进程!" pkill java; sleep 2 fi fi } restart() { stop start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|restart|status}" esac
使用道具 举报
发表回复 回帖并转播 回帖后跳转到最后一页