实验环境:
server1和server4组成高可用和负载均衡集群;
server2作为后端真实服务器提供httpd服务
server3作为后端真实服务器提供nginx服务
主机 | IP | 服务 | 角色 |
---|---|---|---|
server1 | 172.25.19.1 | haproxy,keepalived | master |
server2 | 172.25.19.2 | httpd | minion |
server3 | 172.25.19.3 | nginx | minion |
server4 | 172.25.19.4 | haproxy,keepalived | minion |
server1/2/3/4都要指定master
[root@server1 ~]# cd /etc/salt/
[root@server1 salt]# vim minion
master: 172.25.19.1
开启服务
[root@server1 salt]# systemctl start salt-master
[root@server1 salt]# systemctl start salt-minion
[root@server2 salt]# systemctl start salt-minion
[root@server3 salt]# systemctl start salt-minion
[root@server4 salt]# systemctl start salt-minion
交换公钥
[root@server1 salt]# salt-key -L
[root@server1 salt]# salt-key -A # 添加显示的所有主机
[root@server1 salt]# salt-key -L
一、saltstack搭建httpd服务
[root@server1 minions]# cd /etc/salt/
[root@server1 salt]# vim master
674 file_roots:
675 base:
676 - /srv/salt ##这个目录没有,需要自己创建
[root@server1 salt]# mkdir /srv/salt
[root@server1 salt]# mkdir httpd
[root@server1 salt]# cd httpd/
[root@server1 httpd]# mkdir files
[root@server1 httpd]# cd files/
[root@server1 files]# pwd
/etc/salt/httpd/files
[root@server1 files]# ls
httpd.conf ##主机copy一个过来
[root@server1 files]# cd ..
[root@server1 httpd]# ls
files install.sls service.sls
[root@server1 httpd]# cat install.sls ##安装httpd
apache-install:
pkg.installed:
- pkgs:
- httpd
[root@server1 httpd]# cat service.sls ##启动httpd
include:
- httpd.install
/etc/httpd/conf/httpd.conf:
file.managed:
- source: salt://httpd/files/httpd.conf
httpd-service:
service.running:
- name: httpd
- enable: False
- reload: True
watch:
- file: /etc/httpd/conf/httpd.conf
[root@server1 httpd]# sal