Automated operation and Maintenance series Saltstack Saltstack principle of batch deployment Apache service
Salstack is composed of master and Minion, Master is the service side, represents a server, Minion is the client, representing multiple servers. Sending a command on master to a qualifying minion,minion executes the corresponding command. Between Master and Minion is communicated through ZEROMQ (Message Queuing).
The listening port on the master side of the Saltstack is the 4505 and 4506,4505 ports are the master and Minion authenticated communication ports, and the 4506 ports are the commands that Master uses to send commands or receive Minion to perform return information.
When the client starts, it actively connects to the master-side registration and then maintains the TCP connection, while master controls the client through this TCP connection.
Saltstack Common Modules
(1)、pkg模块pkg模块的作用是包管理,包括增删更新。(2)、file模块file模块的作用的管理文件操作,包括同步文件、设置文件权限和所属用户组、删除文件等操作。(3)、cmd模块cmd模块的作用是在Minion上执行命令或者脚本。(4)、user模块user模块的作用是管理系统账户操作。(5)、service模块service模块的作用是管理系统服务操作。(6)、cron模块cron模块的作用是管理cron服务操作。
Saltstack Deployment Installation
role |
Host name |
IP Address |
Master |
Master.saltstack.com |
172.16.10.138 |
Minion |
Web01.saltstack.com |
172.16.10.147 |
Minion |
Web02.saltstack.com |
172.16.10.146 |
Steps to install a deployment
- Modify the host name of three servers
Vim/etc/hostname
三台主机分别为:master.saltstack.com //(管理)web01.saltstack.com //(被管理)web02.saltstack.com //(被管理)
- Modifying a host parsing file
Vim/etc/hosts
172.16.10.138 master.saltstack.com172.16.10.147 web01.saltstack.com172.16.10.146 web02.saltstack.com//修改完成后,init 6 重启服务器使配置生效
- When the reboot is complete, first turn off the firewall
systemctl stop firewalld.service //关闭防火墙setenforce 0 //关闭增强性安全功能
yum install -y epel-release //配置安装软件源yum install -y salt-master //管理端安装yum install -y epel-release //配置安装软件源yum install -y salt-minion //被管理端安装
- Management-side configuration (Modify the configuration file on the management side)
Vim/etc/salt/master
修改如下:15行 interface: 172.16.10.138 //监听地址(本地地址)215行 auto_accept: True //避免要运行salt-key来确认证书认证416行 file_roots: base: - /srv/salt //saltstack文件根目录位置,目录需要创建710行组分类:nodegroups: group1: ‘web01.saltstack.com‘ group2: ‘web02.saltstack.com‘552行 pillar_opts: True //开启pillar功能,同步文件功能529行 pillar_roots: base: - /srv/pillar //pillar的主目录,需要创建
- To view changes made to the master configuration file
Cat/etc/salt/master | Grep-v ^$ | Grep-v ^#
- Create the Saltstack file root directory, pillar home directory
mkdir /srv/salt //创建saltstack文件根目录mkdir /srv/pillar //创建pillar的主目录
- Start master server (management side)
systemctl start salt-master.service //开启salt-master服务systemctl enable salt-master.service //设置开机自启动netstat -anpt | egrep ‘4505|4506‘ //检查master的端口是否开启
- Managed Side Configuration
Vim/etc/salt/minion
16行 master: 172.16.10.138 //指定主控端IP78行 id: web01.saltstack.com //指定被控端主机名 id: web02.saltstack.com //第二台被控端主机名
- Open the service of the controlled end
systemctl start salt-minion.service
- The communication status between the host side test and the controlled end
salt ‘*‘ test.ping //*表示所有主机salt ‘*‘ cmd.run ‘df -h‘ //远程执行命令salt-key //查看在 master 上已经被接受过的客户端salt ‘web01.saltstack.com‘ grains.items (静态数据)salt ‘web01.saltstack.com‘ pillar.items (动态数据)
Configuration Management installation Apache
- Create a portal file on the master side
Vim/srv/salt/top.sls
base: ‘*‘: - apache注意:‘*‘,则表示在所有的客户端执行 apache 模块。
- Create a Apache.sls file and write the following:
Vim/srv/salt/apache.sls
apache-service: pkg.installed: - names: // 如果只有一个服务,那么就可以写成 –name: httpd 不用再换一行 - httpd - httpd-devel service.running: - name: httpd - enable: True注意:apache-service 是自定义的 id 名。pkg.installed 为包安装函数,下面是要安装的包的名字。service.running 也是一个函数,来保证指定的服务启动,enable 表示开机启动。
- Restart the control Terminal Service
systemctl restart salt-master.service
- Flush the state Configuration command to install Apache and configure the start-up service for the two managed terminals
- The controlled side checks to verify that the Acaphe service is installed and started
Automated operation and Maintenance series Saltstack batch deployment Apache Service