Replace the tomcat cluster war package with Shell scripts.

Source: Internet
Author: User

Replace the tomcat cluster war package with Shell scripts.

Run the command to log on to the server without ssh.

The configuration file does not change much to overwrite the previous configuration.

Profile configuration file

Bak =/home/wsm/bak
Webapps =/home/wsm/webapps/WSMMeasure
Arry = 192.168.68.29 192.168.10.147
Newwar = 1.war
Deplypath =/home/wsm/deploy



Scp. sh copy the war and script to the remote service.

Scp. sh

#! /Bin/bash # copy war | deploy. sh | profile # scp 1.war deploy. sh profile root@192.168.68.29:/home/wsm scpdep () {echo 'start Scp... 'scp $1 deploy. sh backup. sh profile $2 @ $3: $4 echo 'end Scp... '} # arry = "192.168.68.29 192.168.10.147" host = 'awk-F' = ''{if ($1 =" arry ") print $2} 'profile 'newwar = 'awk-F' = ''{if ($1 =" newwar ") print $2} 'profile 'for I in $ hostdo echo 'scp root @' $ iscpdep $ newwar root $ I/home/wsmecho 'scp root @... stop 'done


Backup script backup. sh

#! /Bin/bash # dire = "/home/wsm/bak" # Back up webbench function backupWeb () {echo 'backup Start .... ''\ cp-R/home/wsm/webapps/WSMMeasure $ dire 'CD $ direrm-rf $ dirdatemv $ dire/WSMMeasure $ dirdateecho 'backup end'} dirdate = 'date + % Y % m % d 'echo '$ dirdate' dire = 'awk-F' = ''{if ($1 =" bak ") print $2} 'profile 'if [-d "$ dire"]; then echo "bak folder" else mkdir-p $ dire fibackupWeb


Installation script deploy. sh

#! /Bin/bash # dire = "/home/wsm/bak" # Back up webapps # cp war to/home/wsm/webapps/WSMMeasurefunction cpWarApps () {echo 'cpwarapps Start... 'rm-rf/home/wsm/webapps/WSMMeasure/* '\ cp/home/wsm/$1/home/wsm/webapps/WSMMeasure 'CD/home/wsm/webapps /WSMMeasurejar-xvf *. warecho 'cpwarapps End... '} # copy the configuration file function RepConf () {#/home/wsm/webapps/WSMMeasure/WEB-INF/classes # $ dire/$ dirdate/WEB-INF/classesdirdate = 'date + % Y % m % d 'echo 'RepConf Start. .. ''\ cp-R $ dire/$ dirdate/WEB-INF/classes/spring/home/wsm/webapps/WSMMeasure/WEB-INF/classes'' \ cp-R $ dire/$ dirdate /WEB-INF/classes/hbase/home/wsm/webapps/WSMMeasure/WEB-INF/classes ''\ cp-R $ dire/$ dirdate/WEB-INF/classes/dubbo/home/wsm/ webapps/WSMMeasure/WEB-INF/classes ''\ cp $ dire/$ dirdate/WEB-INF/classes/xmpp. properties/home/wsm/webapps/WSMMeasure/WEB-INF/classes ''\ cp $ dire/$ dirdate/WEB-INF/classes/quertz. properties/home/wsm/webapps/WSMMeasure/WEB-INF/classes ''\ cp $ dire/$ dirdate/WEB-INF/classes/file. properties/home/wsm/webapps/WSMMeasure/WEB-INF/classes ''\ cp $ dire/$ dirdate/WEB-INF/classes/const. properties/home/wsm/webapps/WSMMeasure/WEB-INF/classes ''\ cp $ dire/$ dirdate/WEB-INF/classes/jdbc. properties/home/wsm/webapps/WSMMeasure/WEB-INF/classes 'echo 'RepConf End... '<span style = "white-space: pre"> </span>} # Stop tomcatfunction killTomcat () {ps-ef | grep "/home/wsm/bin/tomcat" | grep-v grep | awk '{print $2}' | xargs kill-9 echo "killd tomcat"} function startTomcat () {ps-ef | grep "/home/wsm/bin/tomcat" | grep-v grep | awk '{print $2}' | xargs kill-9cd/home/wsm/ bin. /startup. sh echo "start tomcat end"} dire = 'awk-F' = ''{if ($1 =" bak ") print $2} 'profile 'newwar = 'awk-F' = ''{if ($1 =" newwar ") print $2} 'profile 'backupWebcpWarApps $ newwarRepConfkillTomcatstartTomcat # LocatIP = ifconfig | grep 'inet addr:' | grep-V' 127. 0.0.1 '| cut-d: -f2 | awk '{print $1}' # STATUS_CODE = 'curl-o/dev/null-s-m 13 -- connect-timeout 20-w % {http_code} $ LocatIP: 8080/WSMMeasure/str/report/performancereport'

Remotely execute rangerun. sh

Execute the script scp to the target server through ssh

#! /Bin/bash

# Log on to the remote execution script through ssh # ssh root @ host cd/home/wsm. /deploy. sh # ssh root@192.168.68.29 "cd/home/wsm & ls" rangback () {ssh root @ $1 "cd/home/wsm &&. /backup. sh "} rangdeploy () {ssh root @ $1" cd/home/wsm &&. /deploy. sh "} # arry =" 192.168.68.29 192.168.10.147 "host = 'awk-F' ='' {if ($1 = "arry ") print $2} 'profile 'for I in $ hostdo echo 'ssh root @-Backup start... '$ irangback $ iecho' ssh root @-end of backup... stop '$ iecho' to start installation... '$ irangdeploy $ iecho' End installation... '$ idone
</Pre> <pre code_snippet_id = "507753" snippet_file_name = "blog_20141104_4_9361903" name = "code" class = "java"> rollback script rollback. sh
<Pre name = "code" class = "java"> #! /Bin/bash # Roll Back 1 stop tomcat 2 Delete the backup in webapp content 3bak copy to webapp 4 start tomcat # Stop tomcatfunction killTomcat () {ps-ef | grep "/home/wsm/bin/tomcat" | grep-v grep | awk '{print $2}' | xargs kill-9} function startTomcat () {ps-ef | grep "/home/wsm/bin/tomcat" | grep-v grep | awk '{print $2}' | xargs kill-9cd/home/wsm/ bin. /startup. sh} function rollback () {echo 'start rollback .... '#' \ cp-R/home/wsm/webapps/WSMMeasure $ dire 'rm-rf/home/wsm/webapps/WSMMeasure/* '\ cp-R/home/wsm /bak/$ dirdate/*/home/wsm/webapps/WSMMeasure/'} dirdate = 'date + % Y % m % d' killTomcatrollbackstartTomcat


 







After the war package is deployed to tomcat, is the project that tomcat runs? If you want to change the project's java file, that is, the class, where to change it

As shown above, after the WAR is deployed, it is automatically decompressed as a folder instead of directly running the war package. Generally, the war package does not contain source code. If you want to modify the Java code, you should modify it in the project before packaging, and then package it into a war, uninstall the original application, and redeploy it.

To access the system after deploying the WAR package in tomcat:

1. Have you modified the default tomcat port? None is 8080.
2. Name of your WAR package, such as test
3. Generally, the website has an index. jsp/index.html, that is, you can access it by entering the localhost: 8080/project name.
Then, try: localhost: 8080/your WAR package name.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.