SaltStack简介:
- SaltStack是基于Python开发的一套C/S架构配置管理工具(服务器端称作Master,客户端称作Minion),它的底层使用ZeroMQ消息队列pub/sub方式通信,使用SSL证书签发的方式进行认证管理。号称世界上最快的消息队列ZeroMQ使得SaltStack能快速在成千上万台机器上进行各种操作。
主要功能:
- Saltstack最主要的两个功能是:配置管理与远程执行
- Saltstack不只是一个配置管理工具,还是一个云计算与数据中心架构编排的利器
- Saltstack已经支持Docker相关模块
- 在友好地支持各大云平台之后,配合Saltstack的Mine实时发现功能可以实现各种云平台业务的自动扩展
工作机制:
- Master和Minion都以守护进程的方式运行
- Master监听配置文件里定义的ret_port(接收minion请求),和publish_port(发布消息)的端口
- 当Minion运行时,它会自动连接到配置文件里定义的Master地址ret_port端口进行连接认证
- 当Master和Minion可以正常通信后,就可以进行各种各样的配置管理工作了
安装部署
1.软件安装
[root@server1 ~]# cd 2018/
[root@server1 2018]# ls
libsodium-1.0.16-1.el7.x86_64.rpm PyYAML-3.11-1.el7.x86_64.rpm
openpgm-5.2.122-2.el7.x86_64.rpm repodata
python2-libcloud-2.0.0-2.el7.noarch.rpm salt-2018.3.3-1.el7.noarch.rpm
python-cherrypy-5.6.0-2.el7.noarch.rpm salt-api-2018.3.3-1.el7.noarch.rpm
python-crypto-2.6.1-2.el7.x86_64.rpm salt-cloud-2018.3.3-1.el7.noarch.rpm
python-futures-3.0.3-1.el7.noarch.rpm salt-master-2018.3.3-1.el7.noarch.rpm
python-msgpack-0.4.6-1.el7.x86_64.rpm salt-minion-2018.3.3-1.el7.noarch.rpm
python-psutil-2.2.1-1.el7.x86_64.rpm salt-ssh-2018.3.3-1.el7.noarch.rpm
python-tornado-4.2.1-1.el7.x86_64.rpm salt-syndic-2018.3.3-1.el7.noarch.rpm
python-zmq-15.3.0-3.el7.x86_64.rpm zeromq-4.1.4-7.el7.x86_64.rpm
[root@server1 2018]# yum install -y *[root@server2 ~]# cd 2018/
[root@server2 2018]# ls
libsodium-1.0.16-1.el7.x86_64.rpm PyYAML-3.11-1.el7.x86_64.rpm
openpgm-5.2.122-2.el7.x86_64.rpm repodata
python2-libcloud-2.0.0-2.el7.noarch.rpm salt-2018.3.3-1.el7.noarch.rpm
python-cherrypy-5.6.0-2.el7.noarch.rpm salt-api-2018.3.3-1.el7.noarch.rpm
python-crypto-2.6.1-2.el7.x86_64.rpm salt-cloud-2018.3.3-1.el7.noarch.rpm
python-futures-3.0.3-1.el7.noarch.rpm salt-master-2018.3.3-1.el7.noarch.rpm
python-msgpack-0.4.6-1.el7.x86_64.rpm salt-minion-2018.3.3-1.el7.noarch.rpm
python-psutil-2.2.1-1.el7.x86_64.rpm salt-ssh-2018.3.3-1.el7.noarch.rpm
python-tornado-4.2.1-1.el7.x86_64.rpm salt-syndic-2018.3.3-1.el7.noarch.rpm
python-zmq-15.3.0-3.el7.x86_64.rpm zeromq-4.1.4-7.el7.x86_64.rpm
[root@server1 2018]# yum install -y *[root@server3 ~]# cd 2018/
[root@server3 2018]# ls
libsodium-1.0.16-1.el7.x86_64.rpm PyYAML-3.11-1.el7.x86_64.rpm
openpgm-5.2.122-2.el7.x86_64.rpm repodata
python2-libcloud-2.0.0-2.el7.noarch.rpm salt-2018.3.3-1.el7.noarch.rpm
python-cherrypy-5.6.0-2.el7.noarch.rpm salt-api-2018.3.3-1.el7.noarch.rpm
python-crypto-2.6.1-2.el7.x86_64.rpm salt-cloud-2018.3.3-1.el7.noarch.rpm
python-futures-3.0.3-1.el7.noarch.rpm salt-master-2018.3.3-1.el7.noarch.rpm
python-msgpack-0.4.6-1.el7.x86_64.rpm salt-minion-2018.3.3-1.el7.noarch.rpm
python-psutil-2.2.1-1.el7.x86_64.rpm salt-ssh-2018.3.3-1.el7.noarch.rpm
python-tornado-4.2.1-1.el7.x86_64.rpm salt-syndic-2018.3.3-1.el7.noarch.rpm
python-zmq-15.3.0-3.el7.x86_64.rpm zeromq-4.1.4-7.el7.x86_64.rpm
[root@server1 2018]# yum install -y *
2.启动服务及主从节点
启动主节点
[root@server1 2018]# cd /etc/salt/
[root@server1 salt]# systemctl start salt-master
启动两个从节点
[root@server2 2018]# cd /etc/salt/
[root@server2 salt]# vim minion ##指定主节点16 master: 172.25.4.1
[root@server2 salt]# systemctl start salt-minion[root@server3 2018]# cd /etc/salt/
[root@server3 salt]# vim minion ##指定主节点16 master: 172.25.4.1
[root@server3 salt]# systemctl start salt-minion
3.添加密钥(查看密钥,并加入)
[root@server1 salt]# salt-key -L ##查看密钥信息
Accepted Keys:
Denied Keys:
Unaccepted Keys:
server2
server3
Rejected Keys:
[root@server1 salt]# salt-key -a server2 ##给server2添加密钥
The following keys are going to be accepted:
Unaccepted Keys:
server2
Proceed? [n/Y] Y
Key for minion server2 accepted.
[root@server1 salt]# salt-key -L ##查看是否添加成功
Accepted Keys:
server2
Denied Keys:
Unaccepted Keys:
server3
Rejected Keys:
[root@server1 salt]# salt-key -A ##给全部节点添加密钥
The following keys are going to be accepted:
Unaccepted Keys:
server3
Proceed? [n/Y] Y
Key for minion server3 accepted.
[root@server1 salt]# salt-key -L ##查看是否成功
Accepted Keys:
server2
server3
Denied Keys:
Unaccepted Keys:
Rejected Keys:
测试:
[root@server1 salt]# salt '*' test.ping ##查看能否ping通所有节点
server3:True
server2:True[root@server1 minions]# salt '*' cmd.run 'df -h' ##查看所有节点挂载情况
server3:Filesystem Size Used Avail Use% Mounted on/dev/mapper/rhel-root 17G 1.3G 16G 8% /devtmpfs 910M 0 910M 0% /devtmpfs 920M 12K 920M 1% /dev/shmtmpfs 920M 17M 904M 2% /runtmpfs 920M 0 920M 0% /sys/fs/cgroup/dev/sda1 1014M 139M 876M 14% /boottmpfs 184M 0 184M 0% /run/user/0
server2:Filesystem Size Used Avail Use% Mounted on/dev/mapper/rhel-root 17G 1.3G 16G 8% /devtmpfs 1.9G 0 1.9G 0% /devtmpfs 1.9G 12K 1.9G 1% /dev/shmtmpfs 1.9G 17M 1.9G 1% /runtmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/sda1 1014M 139M 876M 14% /boottmpfs 380M 0 380M 0% /run/user/0
[root@server1 minions]# salt '*' cmd.run 'hostname' ##查看节点主机名
server3:server3
server2:server2
4.进程查看
[root@server1 salt]# yum install -y lsof
[root@server1 salt]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 638/sshd
tcp 0 0 0.0.0.0:4505 0.0.0.0:* LISTEN 2237/python
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 836/master
tcp 0 0 0.0.0.0:4506 0.0.0.0:* LISTEN 2243/python
tcp6 0 0 :::22 :::* LISTEN 638/sshd
tcp6 0 0 ::1:25 :::* LISTEN 836/master
(2)查看建立的关系
[root@server1 salt]# lsof -i :4505
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
salt-mast 2237 root 15u IPv4 24353 0t0 TCP *:4505 (LISTEN)
salt-mast 2237 root 17u IPv4 27429 0t0 TCP server1:4505->server2:51706 (ESTABLISHED)
salt-mast 2237 root 18u IPv4 27718 0t0 TCP server1:4505->server3:50856 (ESTABLISHED)
(3)查看那python端口情况
[root@server1 salt]# yum install python-setproctitle -y
[root@server1 salt]# systemctl restart salt-master
[root@server1 salt]# ps ax
5.验证密钥关系
(1)server1的公钥和server2的私钥关系
[root@server1 salt]# cd pki/master
[root@server1 master]# md5sum master.pub
d366dca2e7be0dea942a85aa80ca93a4 master.pub
[root@server2 salt]# cd pki/
[root@server2 pki]# ls
master minion
[root@server2 pki]# cd minion/
[root@server2 minion]# ls
minion_master.pub minion.pem minion.pub
[root@server2 minion]# md5sum minion_master.pub
d366dca2e7be0dea942a85aa80ca93a4 minion_master.pub ##公私钥相同
(2)server2的公钥和server1的私钥关系
[root@server2 minion]# md5sum minion.pub
f3d61e3ab4a5f780346e5cd3a5fc45aa minion.pub
[root@server1 master]# cd minions
[root@server1 minions]# md5sum server2
f3d61e3ab4a5f780346e5cd3a5fc45aa server2 ##公私钥相同
(3)server3和server1的密钥关系
[root@server1 minions]# md5sum server3
a241252542e33ed21db13594628ca5a9 server3
[root@server3 salt]# cd pki/minion/
[root@server3 minion]# md5sum minion_master.pub
d366dca2e7be0dea942a85aa80ca93a4 minion_master.pub
[root@server3 minion]# ls
minion_master.pub minion.pem minion.pub
[root@server3 minion]# md5sum minion.pub
a241252542e33ed21db13594628ca5a9 minion.pub
二、了解YAML
-
默认的SLS文件的renderer是YAML renderer。YAML是一个有很多强大特性的标记性语言。Salt使用了一个YAML的小型子集,映射非常常用的数据结构,像列表和字典。YAML renderer的工作是将YAML数据格式的结构编译成为Python数据结构给Salt使用。
尽管YAML语法可能第一眼看上去很简洁但令人畏惧,但是只要记住三个非常简单的规则就可以使用YAML语法写SLS文件了。 -
三个规则:
1.规则一: 缩进
- YAML使用一个固定的缩进风格表示数据层结构关系。Salt需要每个缩进级别
- 由两个空格组成。不要使用tabs。
2.规则二: 冒号
Python的字典当然理所当然是简单的键值对。其他语言的用户应该
知道这个数据类型叫哈希表或者关联数组。字典的keys在YAML中的表现形式是一个以冒号结尾的字符串。Values的
表现形式冒号下面的每一行,用一个空格隔开:my_key: my_value在Python中,上面的将映射为:{'my_key': 'my_value'}另一种选择,一个value可以通过缩进与key联接。my_key:my_value注解上面的语法是有效的YAML,但是在SLS文件罕见,因为通常情况下,一个key
的value不是单一的,而是一个 列表 的values。在Python中,上面的将映射为:{'my_key': 'my_value'}字典可以被嵌套:first_level_dict_key:second_level_dict_key: value_in_second_level_dict在Python中:{'first_level_dict_key': {'second_level_dict_key': 'value_in_second_level_dict'}
}
3.规则三: 短横杠
想要表示列表项,使用一个短横杠加一个空格。多个项使用同样的缩进
级别作为同一列表的一部分。- list_value_one
- list_value_two
- list_value_three列表可以可以作为一个键值对的value。这个在Salt很常见:my_dictionary:- list_value_one- list_value_two- list_value_three在Python中,上面的将映射为:{'my_dictionary': ['list_value_one', 'list_value_two', 'list_value_three']}
三、配置简单的自动化部署(安装httpd)
1.修改master端的配置文件,开启使用sls类型文件
[root@server1 salt]# vim master 674 file_roots:675 base:676 - /srv/salt ##这个目录没有,需要自己创建
[root@server1 salt]# mkdir /srv/salt
[root@server1 salt]# systemctl restart salt-master
2.安装httpd
(1)仅安装httpd的脚本
[root@server1 salt]# mkdir apache
[root@server1 salt]# cd apache/
[root@server1 apache]# ls
[root@server1 apache]# vim install.sls
httpd:pkg.installed
[root@server1 apache]# salt server2 state.sls apache.install ##在默认目录下的apache目录执行install.sls脚本文件
server2:
----------ID: httpdFunction: pkg.installedResult: TrueComment: All specified packages are already installedStarted: 10:22:10.488545Duration: 2375.758 msChanges: Summary for server2
------------
Succeeded: 1
Failed: 0
------------
Total states run: 1
Total run time: 2.376 s
(2)编写安装相关组建和运行脚本
[root@server1 apache]# vim install.sls
httpd-install:pkg.installed:- pkgs:- httpd- php- httpd-toolsservice.running:- name: httpd- enable: true- reload: true
[root@server1 apache]# salt server2 state.sls apache.install
server2:
----------ID: httpd-installFunction: pkg.installedResult: TrueComment: All specified packages are already installedStarted: 10:33:38.079621Duration: 2391.53 msChanges:
----------ID: httpd-installFunction: service.runningName: httpdResult: TrueComment: The service httpd is already runningStarted: 10:33:40.474549Duration: 116.362 msChanges: Summary for server2
------------
Succeeded: 2
Failed: 0
------------
Total states run: 2
Total run time: 2.508 s
(3)安装时指定服务配置文件并运行服务
[root@server1 apache]# vim install.sls
httpd-install:pkg.installed:- pkgs:- httpd- php- httpd-toolsservice.running:- name: httpd- enable: true- reload: true/etc/httpd/conf/http.conf:file.managed:- source: salt://apache/files/httpd.conf- user: root- group: root- mode: 644
[root@server1 apache]# mkdir files
[root@server1 apache]# cd files/
[root@server1 files]# scp server2:/etc/httpd/conf/httpd.conf .
root@server2's password:
httpd.conf 100% 11KB 11.5KB/s 00:00
[root@server1 files]# salt server2 state.sls apache.install
server2:
----------ID: httpd-installFunction: pkg.installedResult: TrueComment: All specified packages are already installedStarted: 10:37:02.801180Duration: 2465.82 msChanges:
----------ID: httpd-installFunction: service.runningName: httpdResult: TrueComment: The service httpd is already runningStarted: 10:37:05.270318Duration: 115.421 msChanges:
----------ID: /etc/httpd/conf/http.confFunction: file.managedResult: TrueComment: File /etc/httpd/conf/http.conf updatedStarted: 10:37:05.397494Duration: 233.42 msChanges: ----------diff:New filemode:0644Summary for server2
------------
Succeeded: 3 (changed=1)
Failed: 0
------------
Total states run: 3
Total run time: 2.815 s
在从节点上查看是否修改了默认配置文件
[root@server3 minion]# yum install -y tree
[root@server3 minion]# cd /var/cache/salt/minion/
[root@server3 minion]# tree .
.
├── accumulator
├── extmods
├── files
│ └── base
│ └── apache
│ ├── files
│ │ └── httpd.conf
│ └── install.sls
├── highstate.cache.p
├── pkg_refresh
├── proc
└── sls.p
(4)将安装脚本和运行脚本分离
[root@server1 apache]# vim install.sls ##仅安装不运行
httpd-install:pkg.installed:- pkgs:- httpd- php- httpd-toolsfile.managed:- name: /etc/httpd/conf/httpd.conf- source: salt://apache/files/httpd.conf- user: root- group: root- mode: 644[root@server1 apache]# vim service.sls
include:- apache.install ##运行时默认先执行安装脚本httpd-service:service.running:- name: httpd- enable: true- reload: true- watch:- file: httpd-install[root@server1 apache]# salt server2 state.sls apache.service ##运行查看
server2:
----------ID: httpd-installFunction: pkg.installedResult: TrueComment: All specified packages are already installedStarted: 11:45:37.211712Duration: 2374.928 msChanges:
----------ID: httpd-installFunction: file.managedName: /etc/httpd/conf/httpd.confResult: TrueComment: File /etc/httpd/conf/httpd.conf is in the correct stateStarted: 11:45:39.595859Duration: 201.049 msChanges:
----------ID: httpd-serviceFunction: service.runningName: httpdResult: TrueComment: The service httpd is already runningStarted: 11:45:39.801734Duration: 117.124 msChanges: Summary for server2
------------
Succeeded: 3
Failed: 0
------------
Total states run: 3
Total run time: 2.693 s
四.配置nginx自动安装脚本
1.配置安装脚本
[root@server1 salt]# mkdir nginx
[root@server1 salt]# cd nginx/
[root@server1 nginx]# mkdir files
[root@server1 nginx]# vim install.sls ##安装脚本
nginx-install:pkg.installed:- pkgs:- pcre-devel- zlib-devel- gcc- makefile.managed:- name: /mnt/nginx-1.15.8.tar.gz- source: salt://nginx/files/nginx-1.15.8.tar.gzcmd.run:- name: cd /mnt && tar zxf nginx-1.15.8.tar.gz && cd nginx-1.15.8 && sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && ./configure --prefix=/usr/local/nginx &> /dev/null && make &> /dev/null && make install &> /dev/null && cd .. && rm -fr nginx-1.15.8- creates: /usr/local/nginx
2.配置执行脚本(分离)
[root@server1 nginx]# vim service.sls ##安装并执行脚本
include:- nginx.install/usr/local/nginx/conf/nginx.conf:file.managed:- source: salt://nginx/files/nginx.confnginx-service:file.managed:- name: /etc/systemd/system/nginx.service- source: salt://nginx/files/nginx.serviceservice.running:- name: nginx- enable: true- reload: true ##默认重启- watch:- file: /usr/local/nginx/conf/nginx.conf
3.files中添加所需组件
[root@server1 nginx]# cd files/
[root@server1 files]# vim nginx.service ##脚本文件
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[root@server1 files]# ls ##其他两个文件在主机上配置发送到本目录下
nginx-1.15.8.tar.gz nginx.conf nginx.service
4.执行脚本
[root@server1 nginx]# salt server3 state.sls nginx.service
server3:
----------ID: nginx-installFunction: pkg.installedResult: TrueComment: 3 targeted packages were installed/updated.The following packages were already installed: makeStarted: 12:24:41.763917Duration: 16877.221 msChanges: ----------cpp:----------new:4.8.5-11.el7old:gcc:----------new:4.8.5-11.el7old:glibc-devel:----------new:2.17-157.el7old:glibc-headers:----------new:2.17-157.el7old:kernel-headers:----------new:3.10.0-514.el7old:libmpc:----------new:1.0.1-3.el7old:mpfr:----------new:3.1.1-4.el7old:pcre-devel:----------new:8.32-15.el7_2.1old:zlib-devel:----------new:1.2.7-17.el7old:
----------ID: nginx-installFunction: file.managedName: /mnt/nginx-1.15.8.tar.gzResult: TrueComment: File /mnt/nginx-1.15.8.tar.gz updatedStarted: 12:24:58.693188Duration: 267.03 msChanges: ----------diff:New filemode:0644
----------ID: nginx-installFunction: cmd.runName: cd /mnt && tar zxf nginx-1.15.8.tar.gz && cd nginx-1.15.8 && sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && ./configure --prefix=/usr/local/nginx &> /dev/null && make &> /dev/null && make install &> /dev/null && cd .. && rm -fr nginx-1.15.8Result: TrueComment: Command "cd /mnt && tar zxf nginx-1.15.8.tar.gz && cd nginx-1.15.8 && sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && ./configure --prefix=/usr/local/nginx &> /dev/null && make &> /dev/null && make install &> /dev/null && cd .. && rm -fr nginx-1.15.8" runStarted: 12:24:58.998533Duration: 18199.284 msChanges: ----------pid:8159retcode:0stderr:stdout:
----------ID: /usr/local/nginx/conf/nginx.confFunction: file.managedResult: TrueComment: File /usr/local/nginx/conf/nginx.conf is in the correct stateStarted: 12:25:17.198062Duration: 465.018 msChanges:
----------ID: nginx-serviceFunction: file.managedName: /etc/systemd/system/nginx.serviceResult: TrueComment: File /etc/systemd/system/nginx.service updatedStarted: 12:25:17.663368Duration: 78.281 msChanges: ----------diff:New filemode:0644
----------ID: nginx-serviceFunction: service.runningName: nginxResult: TrueComment: Service nginx is already enabled, and is runningStarted: 12:26:40.753937Duration: 78.23 msChanges: ----------nginx:TrueSummary for server3
------------
Succeeded: 6 (changed=1)
Failed: 0
------------
Total states run: 6
Total run time: 715.818 ms
5.测试是否生效:
[root@server1 nginx]# curl server3
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>
6.更改nginx配置文件再运行(因为在运行脚本中写了默认重启服务,所以再次执行脚本就生效啦)
[root@server1 nginx]# cd files/[root@server1 files]# vim nginx.conf3 worker_processes auto; ##以主机的cpu片数,自动分配进程[root@server1 files]# cd ..
[root@server1 nginx]# salt server3 state.sls nginx.service
server3:
----------ID: nx-installFunction: pkg.installedResult: TrueComment: All specified packages are already installedStarted: 12:58:26.902799Duration: 3255.187 msChanges:
----------ID: nx-installFunction: file.managedName: /mnt/nginx-1.15.8.tar.gzResult: TrueComment: File /mnt/nginx-1.15.8.tar.gz is in the correct stateStarted: 12:58:30.166477Duration: 185.126 msChanges:
----------ID: nx-installFunction: cmd.runName: cd /mnt && tar zxf nginx-1.15.8.tar.gz && cd nginx-1.15.8 && sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && ./configure --prefix=/usr/local/nginx &> /dev/null && make &> /dev/null && make install &> /dev/null && cd .. && rm -fr nginx-1.15.8Result: TrueComment: /usr/local/nginx existsStarted: 12:58:30.356785Duration: 3.352 msChanges:
----------ID: /usr/local/nginx/conf/nginx.confFunction: file.managedResult: TrueComment: File /usr/local/nginx/conf/nginx.conf updatedStarted: 12:58:30.360843Duration: 108.806 msChanges: ----------diff:--- +++ @@ -1,6 +1,6 @@#user nobody;-worker_processes 1;+worker_processes auto;#error_log logs/error.log;#error_log logs/error.log notice;
----------ID: nginx-serviceFunction: file.managedName: /etc/systemd/system/nginx.serviceResult: TrueComment: File /etc/systemd/system/nginx.service is in the correct stateStarted: 12:58:30.470633Duration: 283.309 msChanges:
----------ID: nginx-serviceFunction: service.runningName: nginxResult: TrueComment: Service reloadedStarted: 12:58:30.911930Duration: 151.5 msChanges: ----------nginx:TrueSummary for server3
------------
Succeeded: 6 (changed=2)
Failed: 0
------------
Total states run: 6
Total run time: 3.987 s
五.自动化部署server2和server3的服务
1.指定节点运行安装指定服务
[root@server1 salt]# vim top.sls
base:'server2':- apache.service'server3':- nginx.service
2.运行sls文件,查看能否生效
[root@server1 salt]# salt '*' state.highstate
server2:
----------ID: httpd-installFunction: pkg.installedResult: TrueComment: All specified packages are already installedStarted: 13:02:47.972426Duration: 2549.071 msChanges:
----------ID: httpd-installFunction: file.managedName: /etc/httpd/conf/httpd.confResult: TrueComment: File /etc/httpd/conf/httpd.conf is in the correct stateStarted: 13:02:50.530064Duration: 122.523 msChanges:
----------ID: httpd-serviceFunction: service.runningName: httpdResult: TrueComment: The service httpd is already runningStarted: 13:02:50.658502Duration: 120.327 msChanges: Summary for server2
------------
Succeeded: 3
Failed: 0
------------
Total states run: 3
Total run time: 2.792 s
server3:
----------ID: nx-installFunction: pkg.installedResult: TrueComment: All specified packages are already installedStarted: 13:02:48.920742Duration: 2759.112 msChanges:
----------ID: nx-installFunction: file.managedName: /mnt/nginx-1.15.8.tar.gzResult: TrueComment: File /mnt/nginx-1.15.8.tar.gz is in the correct stateStarted: 13:02:51.688563Duration: 219.026 msChanges:
----------ID: nx-installFunction: cmd.runName: cd /mnt && tar zxf nginx-1.15.8.tar.gz && cd nginx-1.15.8 && sed -i 's/CFLAGS="$CFLAGS -g"/#CFLAGS="$CFLAGS -g"/g' auto/cc/gcc && ./configure --prefix=/usr/local/nginx &> /dev/null && make &> /dev/null && make install &> /dev/null && cd .. && rm -fr nginx-1.15.8Result: TrueComment: /usr/local/nginx existsStarted: 13:02:51.912767Duration: 3.357 msChanges:
----------ID: /usr/local/nginx/conf/nginx.confFunction: file.managedResult: TrueComment: File /usr/local/nginx/conf/nginx.conf is in the correct stateStarted: 13:02:51.916857Duration: 63.208 msChanges:
----------ID: nginx-serviceFunction: file.managedName: /etc/systemd/system/nginx.serviceResult: TrueComment: File /etc/systemd/system/nginx.service is in the correct stateStarted: 13:02:51.981059Duration: 62.075 msChanges:
----------ID: nginx-serviceFunction: service.runningName: nginxResult: TrueComment: The service nginx is already runningStarted: 13:02:52.048821Duration: 113.759 msChanges: Summary for server3
------------
Succeeded: 6
Failed: 0
------------
Total states run: 6
Total run time: 3.221 s