[root@linux-node1 ~]# cd /srv/salt/prod/modules [root@linux-node1 modules]# ls haproxy keepalived memcached pcre pkg user jdk libevent nginx php tomcat [root@linux-node1 modules]# mkdir jdk && mkdir tomcat
modules是我存放功能模块的的目录,每个服务尽量能单独写一个状态文件,具有通用性。
[root@linux-node1 modules]# cd jdk [root@linux-node1 jdk]# mkdir files #存放安装包 [root@linux-node1 jdk]# vim jdk-install.sls #编写安装状态文件 jdk-installl: file.managed: - name: /server/tools/jdk-8u45-linux-x64.tar.gz - source: salt://modules/jdk/files/jdk-8u45-linux-x64.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: cd /server/tools/jdk-8u45-linux-x64.tar.gz && tar zxf jdk-8u45-linux-x64.tar.gz && mv jdk1.8.0_45 /application/jdk && chown -R root:root /application/jdk - unless: test -d /application/jdk - requrie: - file: jdk-install jdk-config: file.append: - name: /etc/profile - text: - export JAVA_HOME=/application/jdk - export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH - export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
上面安装了jdk环境
[root@linux-node1 modules]# cd tomcat [root@linux-node1 tomcat]# mkdir files #存放tomcat的安装包 [root@linux-node1 tomcat]# vim install.sls #编写安装状态文件 include: - modules.jdk.install tomcta-install: file.managed: - name: /server/tools/apache-tomcat-8.0.23.tar.gz - source: salt://modules/tomcat/files/apache-tomcat-8.0.23.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: cd /server/tools/ && tar zxf apache-tomcat-8.0.23.tar.gz && mv apache-tomcat-8.0.23 /application/ && ln -s /application/apache-tomcat-8.0.23 /application/tomcat && chown -R root:root /application/tomcat8 - unless: test -d /application/tomcat tomcat-config: file.append: - name: /etc/profile - text: - export TOMCAT_HOME=/application/tomcat
本文出自 “Sunset” 博客,谢绝转载!
原文地址:http://roles.blog.51cto.com/9623242/1855846