实验环境
主机 IP 服务 角色
server1 172.25.19.1 haproxy,keepalived master
server2 172.25.19.1 httpd minion
server3 172.25.19.1 nginx minion
server4 172.25.19.1 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]# salt server3 state.sls nginx.service
二、saltstack搭建nginx
-
编辑自动编译安装nginx文件
[root@server1 salt]# mkdir nginx [root@server1 salt]# cd nginx/ [root@server1 nginx]# mkdir files [root@server1 nginx]# cd files/ [root@server1 files]# ls nginx-1.1