saltstack(八):saltstack配置管理-安装配置启动tomcat样例
Saltstack配置启动tomcat
判断minion有没有安装jdk和tomcat,没有就分别源码安装,并以普通用户启动。
#有一个认识上的坑,saltstack实际上是基于状态管理,例如说tomcat启动了,那就不会重复启动,不用再代码判断,/etc/profile这种文件追加也一样。
文件目录
准备好 jdk和apache-tomcat 源码tar包
[root@pe-jira web]# pwd /srv/salt/base/web [root@pe-jira web]# tree . ├── apache.sls ├── apache.sls_bak ├── files │ ├── apache-conf.d │ │ ├── autoindex.conf │ │ ├── nagios.conf │ │ ├── php.conf │ │ ├── README │ │ ├── userdir.conf │ │ └── welcome.conf │ ├── apache-tomcat-7.0.62.tar.gz │ ├── httpd.conf │ ├── jdk-8u73-linux-x64.tar.gz │ └── php.ini ├── lnmp.sls └── tomcat.sls 2 directories, 14 files [root@pe-jira web]#
tomcat.sls
jdk-install: file.managed: - name : /home/admin/soft/jdk-8u73-linux-x64.tar.gz - source : salt://web/files/jdk-8u73-linux-x64.tar.gz - user: root - group: root - mode: 755 cmd.run: - name : cd /home/admin/soft/ && tar zxf jdk-8u73-linux-x64.tar.gz && mv jdk1.8.0_73/ jdk && mv jdk /usr/local/jdk - require: #依赖 - file : jdk-install #执行了id为jdk-install的命令才能执行cmd.run - unless : source /etc/profile && java -version jdk-config: file.append: - name : /etc/profile - text: - JAVA_HOME=/usr/local/jdk - PATH=$JAVA_HOME/bin:$PATH - CLASSPATH=$JAVA_HOME/lib:$CLASSPATH - export JAVA_HOME - export PATH - export CLASSPATH cmd.run: - name: source /etc/profile #让添加的文字生效 - require: - file: jdk-install - unless : source /etc/profile && java -version tomcat-install: file.managed: - name: /tmp/apache-tomcat-7.0.62.tar.gz - source : salt://web/files/apache-tomcat-7.0.62.tar.gz - user: admin - group: admin - mode: 755 cmd.run: - name : cd /tmp/ && tar zxf apache-tomcat-7.0.62.tar.gz && mv apache-tomcat-7.0.62 /home/admin/tomcat - user: admin - group: admin - unless: test -d /home/admin/tomcat tomcat-start: cmd.run: - name: source /etc/profile && /bin/bash /home/admin/tomcat/bin/startup.sh - user: admin - group: admin
执行
minion端测试