Saltstack批量部署tomcat(多實例)
上一篇講解了如何批量部署nginx,這篇說一說如何批量部署tomcat,其實方式上都差不多,tomcat多了個java必須配置,以及需要多個實例一起部署。方式方法上可能不是最優方案,功能上是都可以實現基本需求的。
環境介紹:
Centos 6.5
tomcat 7.0.68
java 1.7.0_80
實例3個,site.aaa.com|boss.aaa.com|mobile.aaa.com
minion:test
1.修改主入口文件,如何你看不懂其中沒標註的一些行,請參考《Saltstack批量編譯部署nginx(多模塊)》
vim /srv/salt/top.sls
base: ‘test‘: - tomcat.init
2.創建tomcat目錄
mkdir -p /srv/salt/tomcat/files
mkdir -p /srv/salt/soft/
cd /srv/salt/tomcat && tree
3.編輯初始化文件init.sls
vim /srv/salt/tomcat/init.sls
include: - tomcat.install
4.編輯安裝部署文件install.sls
vim /srv/salt/tomcat/install.sls
include: - soft.jdk #包含jdk的安裝 - soft.start-stop #包含啟動停止腳本 tomcta-install: file.managed: - name: /root/apache-tomcat-7.0.68.tar.gz - source: salt://tomcat/files/apache-tomcat-7.0.68.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: mkdir/data/ && cd /root && tar zxf apache-tomcat-7.0.68.tar.gz && mv apache-tomcat-7.0.68 /data/ - unless: test -d /data/apache-tomcat-7.0.68/ tomcat-main-config: #復制自定義的catalina.sh文件 file.managed: - name: /data/apache-tomcat-7.0.68/bin/catalina.sh - source: salt://tomcat/files/catalina.sh tomcat-site-config: #復制自定義的server.xml文件 cmd.run: #創建實例啟動所需的三個文件夾 - name: mkdir -p /data/site.aaa.com/{logs,bin,conf} file.managed: - name: /data/site.aaa.com/conf/server.xml - source: salt://tomcat/files/site/server.xml tomcat-mobile-config: cmd.run: - name: mkdir -p /data/mobile.aaa.com/{logs,bin,conf} file.managed: - name: /data/mobile.aaa.com/conf/server.xml - source: salt://tomcat/files/mobile/server.xml tomcat-boss-config: cmd.run: - name: mkdir -p /data/boss.aaa.com/{logs,bin,conf} file.managed: - name: /data/boss.aaa.com/conf/server.xml - source: salt://tomcat/files/boss/server.xml
4.編輯jdk配置文件
vim /srv/salt/soft/jdk.sls
jdk-installl: file.managed: - name: /root/jdk-7u80-linux-x64.tar.gz - source: salt://tomcat/files/jdk-7u80-linux-x64.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: cd /root/ && tar zxf jdk-7u80-linux-x64.tar.gz && mv jdk1.7.0_80 /usr/local/jdk - unless: test -d /usr/local/jdk - requrie: - file: jdk-install jdk-config: file.append: #在文件最後一行添加文字 - name: /etc/profile - text: - export JAVA_HOME=/usr/local/jdk - export PATH=${PATH}:${JAVA_HOME}/bin - export CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib cmd.run: - name: source /etc/profile #讓添加的文字生效 - require: - file: jdk-config
5.編輯啟動停止腳本文件,這個腳本是我自己寫的倆個啟動和停止的方法,各位可以根據自己的需要改編
vim /srv/salt/soft/start-stop.sls
tomcat-site-start: file.managed: - name: /data/site.aaa.com/bin/start.sh - source: salt://tomcat/files/site/start.sh tomcat-site-stop: file.managed: - name: /data/site.aaa.com/bin/stop.sh - source: salt://tomcat/files/site/stop.sh tomcat-boss-start: file.managed: - name: /data/boss.aaa.com/bin/start.sh - source: salt://tomcat/files/boss/start.sh tomcat-boss-stop: file.managed: - name: /data/boss.aaa.com/bin/stop.sh - source: salt://tomcat/files/boss/stop.sh tomcat-mobile-start: file.managed: - name: /data/mobile.aaa.com/bin/start.sh - source: salt://tomcat/files/mobile/start.sh tomcat-mobile-stop: file.managed: - name: /data/mobile.aaa.com/bin/stop.sh - source: salt://tomcat/files/mobile/stop.sh tomcat-project-chmod: cmd.run: #給腳本相應的執行權限 - name: chmod +x /data/{m,kstore,boss}.aaa.com/bin/*.sh
註:start.sh
CATALINA_HOME="/data/apache-tomcat-7.0.68" CATALINA_BASE="/data/site.aaa.com" export CATALINA_BASE CATALINA_HOME echo "$CATALINA_HOME" echo $PATH $CATALINA_HOME/bin/catalina.sh start
stop.sh
CATALINA_HOME="/data/apache-tomcat-7.0.68" CATALINA_BASE="/data/site.aaa.com" export CATALINA_BASE CATALINA_HOME echo "$CATALINA_HOME" echo $PATH $CATALINA_HOME/bin/catalina.sh stop
6.執行同步推送
salt ‘test‘ state.highstate
觀察是否全部為success,如果有fail,查看具體失敗原因,解決問題後可繼續推送
本文出自 “linux運維技術” 博客,請務必保留此出處http://forall.blog.51cto.com/12356505/1967458
Saltstack批量部署tomcat(多實例)