下午花了点时间了搞了下saltstack,故在这记录下。
先修改salt master端的配置文件将下面的注释放开。修改完重启生效。
file_roots: base: - /srv/salt
然后我们看下目录结构
[root@server01 salt]# pwd /srv/salt [root@server01 salt]# [root@server01 salt]# tree . ├── jdk │ ├── install.sls │ └── jdk-file │ └── jdk-8u73-linux-x64.tar.gz ├── tomcat │ ├── install.sls │ ├── tomcat-file │ │ └── apache-tomcat-8.5.9.tar.gz │ └── useradd.sls └── top.sls 4 directories, 6 files
我贴下具体的配置文件,先是top.sls
[root@server01 salt]# more top.sls base: '*': - jdk.install - tomcat.install
然后是jdk目录下的install.sls
[root@server01 salt]# cat jdk/install.sls jdk-install: file.managed: - name: /usr/local/java/jdk-8u73-linux-x64.tar.gz - source: salt://jdk/jdk-file/jdk-8u73-linux-x64.tar.gz - makedirs: true - user: root - group: root - mode: 755 cmd.run: - name: cd /usr/local/java && tar -zxf jdk-8u73-linux-x64.tar.gz && ln -s jdk1.8.0_73 latest - unless: test -e /usr/local/java/latest - require: - file: jdk-install jdk-env: file.append: - name: /etc/profile - text: - export JAVA_HOME=/usr/local/java/latest - export PATH=$JAVA_HOME/bin:$PATH - require: - file: jdk-install
然后是tomcat目录install.sls
[root@server01 tomcat]# more install.sls include: - jdk.install - tomcat.useradd tomcat-install: file.managed: - name: /opt/apache-tomcat-8.5.9.tar.gz - source: salt://tomcat/tomcat-file/apache-tomcat-8.5.9.tar.gz - makedirs: true cmd.run: - name: cd /opt && tar -zxf apache-tomcat-8.5.9.tar.gz && mv apache-tomcat-8.5.9 tomcatapp && chown -R auser:auser tomcatapp - unless: test -d /opt/tomcatapp - require: - file: tomcat-install
接着是启用tomcat的用户useradd.sls
[root@server01 tomcat]# more useradd.sls auser: user.present: - fullname: auser - shell: /bin/bash - home: /home/auser - password: '$1$auser$BF1Jw7Hcd0uxCP/JEdqCi0' - enforce_password: false
password密码的那条字符串用这种方式生成,这里为测试我设置的是密码也是auser
[auser@client01 ~]$ openssl passwd -1 -salt 'auser' Password: $1$auser$BF1Jw7Hcd0uxCP/JEdqCi0
然后执行** salt '' state.highstate *即可。
Cloudhu 个人随笔|built by django|
沪ICP备16019452号-1