Salt本地管理应用场景
1.在边缘节点服务器非常少没有Salt-master
2.零售店,电影院等弱网络环境没有Salt-master
3.快速部署单个服务没有Salt-master
实现
一,安装minion
[root@linux-node1 ~]# yum install -y salt-minion
二,更改minon配置文件,红色部分为新增加
[root@linux-node1 ~]# cat /etc/salt/minion # defined below by setting it to "local". Setting a local file_client runs the #file_client: remote #默认remote 使用的远程Master模式 file_client: local #新增加一行 使用本地模式 .... # Example: # file_roots: # base: # - /srv/salt/ # dev: # - /srv/salt/dev/services # - /srv/salt/dev/states # prod: # - /srv/salt/prod/services # - /srv/salt/prod/states # file_roots: base: - /srv/salt/base dev: - /srv/salt/dev test: - /srv/salt/test prod: - /srv/salt/prod .....
三,无需启动minion
[root@linux-node1 ~]# systemctl stop salt-minion
四,查看本地状态文件,以安装一个tomcat为列
[root@linux-node1 base]# cat /srv/salt/base/web/tomcat.sls jdk-install: pkg.installed: - name: java-1.8.0-openjdk tomcat-install: file.managed: - name: /usr/local/src/apache-tomcat-8.0.46.tar.gz - source: salt://web/files/apache-tomcat-8.0.46.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: cd /usr/local/src && tar zxf apache-tomcat-8.0.46.tar.gz && mv apache-tomcat-8.0.46 /usr/local/ && ln -s /usr/local/apache-tomcat-8.0.46 /usr/local/tomcat - unless: test -L /usr/local/tomcat && test -d /usr/local/apache-tomcat-8.0.46
五,salt-call测试
[root@linux-node1 ~]# salt-call --local test.ping local: True
六,使用salt-call执行本地状态文件
root@linux-node1 base]# salt-call --local state.sls web.tomcat [INFO ] Loading fresh modules for state activity [INFO ] Fetching file from saltenv 'base', ** done ** 'web/tomcat.sls' [INFO ] Running state [java-1.8.0-openjdk] at time 19:19:34.066323 [INFO ] Executing state pkg.installed for java-1.8.0-openjdk [INFO ] Executing command ['rpm', '-qa', '--queryformat', '%{NAME}_|-%{EPOCH}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-(none) '] in directory '/root' [INFO ] Executing command ['repoquery', '--plugins', '--queryformat', '%{NAME}_|-%{ARCH}', '--pkgnarrow=all', '--all'] in directory '/root' [INFO ] Executing command ['yum', '--quiet', 'clean', 'expire-cache'] in directory '/root' [INFO ] Executing command ['yum', '--quiet', 'check-update'] in directory '/root' [INFO ] Executing command ['yum', '-y', 'install', 'java-1.8.0-openjdk'] in directory '/root' [INFO ] Executing command ['rpm', '-qa', '--queryformat', '%{NAME}_|-%{EPOCH}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-(none) '] in directory '/root' [INFO ] Installed Packages: 'nss-pem' changed from 'absent' to '1.0.3-4.el7' 'nss-tools' changed from '3.21.0-9.el7_2' to '3.28.4-15.el7_4' 'libXi' changed from 'absent' to '1.7.9-1.el7' 'python-javapackages' changed from 'absent' to '3.4.1-11.el7' 'xorg-x11-font-utils' changed from 'absent' to '1:7.5-20.el7' 'libXcomposite' changed from 'absent' to '0.4.4-4.1.el7' 'libICE' changed from 'absent' to '1.0.9-9.el7' 'nss-sysinit' changed from '3.21.0-9.el7_2' to '3.28.4-15.el7_4' 'copy-jdk-configs' changed from 'absent' to '2.2-3.el7' 'tzdata-java' changed from 'absent' to '2017b-1.el7' 'libXrender' changed from 'absent' to '0.9.10-1.el7' 'lksctp-tools' changed from 'absent' to '1.0.17-2.el7' 'xorg-x11-fonts-Type1' changed from 'absent' to '7.5-9.el7' 'libXfont' changed from 'absent' to '1.5.2-1.el7' 'chkconfig' changed from '1.3.61-5.el7_2.1' to '1.7.4-1.el7' 'libfontenc' changed from 'absent' to '1.1.3-3.el7' 'java-1.8.0-openjdk' changed from 'absent' to '1:1.8.0.144-0.b01.el7_4' 'python-lxml' changed from 'absent' to '3.2.1-4.el7' 'javapackages-tools' changed from 'absent' to '3.4.1-11.el7' 'java-1.8.0-openjdk-headless' changed from 'absent' to '1:1.8.0.144-0.b01.el7_4' 'nss' changed from '3.21.0-9.el7_2' to '3.28.4-15.el7_4' 'libXext' changed from 'absent' to '1.3.3-3.el7' 'nspr' changed from '4.11.0-1.el7_2' to '4.13.1-1.0.el7_3' 'nss-util' changed from '3.21.0-2.2.el7_2' to '3.28.4-3.el7' 'giflib' changed from 'absent' to '4.1.6-9.el7' 'libXtst' changed from 'absent' to '1.2.3-1.el7' 'nss-softokn' changed from '3.16.2.3-14.2.el7_2' to '3.28.3-8.el7_4' 'libSM' changed from 'absent' to '1.2.2-2.el7' 'nss-softokn-freebl' changed from '3.16.2.3-14.2.el7_2' to '3.28.3-8.el7_4' 'ttmkfdir' changed from 'absent' to '3.0.9-42.el7' [INFO ] Loading fresh modules for state activity [INFO ] Completed state [java-1.8.0-openjdk] at time 19:24:17.648075 [INFO ] Running state [/usr/local/src/apache-tomcat-8.0.46.tar.gz] at time 19:24:17.654621 [INFO ] Executing state file.managed for /usr/local/src/apache-tomcat-8.0.46.tar.gz [INFO ] Fetching file from saltenv 'base', ** done ** 'web/files/apache-tomcat-8.0.46.tar.gz' [INFO ] File changed: New file [INFO ] Completed state [/usr/local/src/apache-tomcat-8.0.46.tar.gz] at time 19:24:17.811524 [INFO ] Running state [cd /usr/local/src && tar zxf apache-tomcat-8.0.46.tar.gz && mv apache-tomcat-8.0.46 /usr/local/ && ln -s /usr/local/apache-tomcat-8.0.46 /usr/local/tomcat] at time 19:24:17.812426 [INFO ] Executing state cmd.run for cd /usr/local/src && tar zxf apache-tomcat-8.0.46.tar.gz && mv apache-tomcat-8.0.46 /usr/local/ && ln -s /usr/local/apache-tomcat-8.0.46 /usr/local/tomcat [INFO ] Executing command 'test -L /usr/local/tomcat && test -d /usr/local/apache-tomcat-8.0.46' in directory '/root' [INFO ] Executing command 'cd /usr/local/src && tar zxf apache-tomcat-8.0.46.tar.gz && mv apache-tomcat-8.0.46 /usr/local/ && ln -s /usr/local/apache-tomcat-8.0.46 /usr/local/tomcat' in directory '/root' [INFO ] {'pid': 18672, 'retcode': 0, 'stderr': '', 'stdout': ''} [INFO ] Completed state [cd /usr/local/src && tar zxf apache-tomcat-8.0.46.tar.gz && mv apache-tomcat-8.0.46 /usr/local/ && ln -s /usr/local/apache-tomcat-8.0.46 /usr/local/tomcat] at time 19:24:18.311686 local: ---------- ID: jdk-install Function: pkg.installed Name: java-1.8.0-openjdk Result: True Comment: The following packages were installed/updated: java-1.8.0-openjdk Started: 19:19:34.066323 Duration: 283581.752 ms Changes: ---------- chkconfig: ---------- new: 1.7.4-1.el7 old: 1.3.61-5.el7_2.1 copy-jdk-configs: ---------- new: 2.2-3.el7 old: giflib: ---------- new: 4.1.6-9.el7 old: java-1.8.0-openjdk: ---------- new: 1:1.8.0.144-0.b01.el7_4 old: java-1.8.0-openjdk-headless: ---------- new: 1:1.8.0.144-0.b01.el7_4 old: javapackages-tools: ---------- new: 3.4.1-11.el7 old: libICE: ---------- new: 1.0.9-9.el7 old: libSM: ---------- new: 1.2.2-2.el7 old: libXcomposite: ---------- new: 0.4.4-4.1.el7 old: libXext: ---------- new: 1.3.3-3.el7 old: libXfont: ---------- new: 1.5.2-1.el7 old: libXi: ---------- new: 1.7.9-1.el7 old: libXrender: ---------- new: 0.9.10-1.el7 old: libXtst: ---------- new: 1.2.3-1.el7 old: libfontenc: ---------- new: 1.1.3-3.el7 old: lksctp-tools: ---------- new: 1.0.17-2.el7 old: nspr: ---------- new: 4.13.1-1.0.el7_3 old: 4.11.0-1.el7_2 nss: ---------- new: 3.28.4-15.el7_4 old: 3.21.0-9.el7_2 nss-pem: ---------- new: 1.0.3-4.el7 old: nss-softokn: ---------- new: 3.28.3-8.el7_4 old: 3.16.2.3-14.2.el7_2 nss-softokn-freebl: ---------- new: 3.28.3-8.el7_4 old: 3.16.2.3-14.2.el7_2 nss-sysinit: ---------- new: 3.28.4-15.el7_4 old: 3.21.0-9.el7_2 nss-tools: ---------- new: 3.28.4-15.el7_4 old: 3.21.0-9.el7_2 nss-util: ---------- new: 3.28.4-3.el7 old: 3.21.0-2.2.el7_2 python-javapackages: ---------- new: 3.4.1-11.el7 old: python-lxml: ---------- new: 3.2.1-4.el7 old: ttmkfdir: ---------- new: 3.0.9-42.el7 old: tzdata-java: ---------- new: 2017b-1.el7 old: xorg-x11-font-utils: ---------- new: 1:7.5-20.el7 old: xorg-x11-fonts-Type1: ---------- new: 7.5-9.el7 old: ---------- ID: tomcat-install Function: file.managed Name: /usr/local/src/apache-tomcat-8.0.46.tar.gz Result: True Comment: File /usr/local/src/apache-tomcat-8.0.46.tar.gz updated Started: 19:24:17.654621 Duration: 156.903 ms Changes: ---------- diff: New file mode: 0755 ---------- ID: tomcat-install Function: cmd.run Name: cd /usr/local/src && tar zxf apache-tomcat-8.0.46.tar.gz && mv apache-tomcat-8.0.46 /usr/local/ && ln -s /usr/local/apache-tomcat-8.0.46 /usr/local/tomcat Result: True Comment: Command "cd /usr/local/src && tar zxf apache-tomcat-8.0.46.tar.gz && mv apache-tomcat-8.0.46 /usr/local/ && ln -s /usr/local/apache-tomcat-8.0.46 /usr/local/tomcat" run Started: 19:24:17.812426 Duration: 499.26 ms Changes: ---------- pid: 18672 retcode: 0 stderr: stdout: Summary ------------ Succeeded: 3 (changed=3) Failed: 0 ------------ Total states run: 3
总结
1.本地管理模式,无需salt-master
2.本地管理模式,不需要启动minion服务
附 赵班长的 GitHub saltbook-code网址
https://github.com/unixhot/saltbook-code/tree/master