saltstack实现高可用(apache+nginx+keepalived)
作者:互联网
上一篇用server1(salt-master节点)给server2,3分别配置了httpd,nginx服务,现在用server1,继续给2,3配置keepalived
实验过程如下
在salt目录下面建立keepalived目录
将之前apache的推送脚本拷贝一份,然后编辑
写入变量,高可用两个节点的状态,vrid,优先级别均要使用变量
在keepalived目录下面建立files目录
复制一份keepalived的配置文件到这个目录下面,作为模板文件使用
编辑模板文件
编辑文件
[root@server1 keepalived]# vim files/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost ##修改主机名
}
notification_email_from keepalived@localhost ##修改用户名
smtp_server 127.0.0.1 ##本机IP
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
#vrrp_strict ##禁用服务
vrrp_garp_interval 0
vrrp_gna_interval 0
}
##在我们需要获取的参数那使用pillar定义
vrrp_instance VI_1 {
state {{ STATE }} ##状态
interface eth0
virtual_router_id {{ VRID }} ##虚拟ID
priority {{ PRIORITY }} ##优先级
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.25.15.100 ##虚拟地址
}
}
配置pillar参数文件
编辑pillar的top文件
执行文件
[root@server1 keepalived]# salt server4 state.sls keepalived.install
实现使用keepalived实现haproxy的高可用
编辑top文件,使server1(master端)与server4(minion端)都配置好haproxy和keepalived
[root@server1 salt]# vim top.sls
‘server1’:
- haproxy.install
- keepalived.service
‘server4’:
- haproxy.install
- keepalived.service
‘roles:apache’:
- match: grain
- apache.install
‘roles:nginx’:
- match: grain
- nginx.service
给server1上装salt-minion,然后加入server1的master
推:
==测试haproxy高可用 ==
server1、server4:
查看IP:server1有虚拟IP,因为优先级高
查看进程:haproxy和keepalived进程开启
在浏览器中访问172.25.15.100查看轮循
将server1中的keepalived服务关闭,在浏览器中依然能查看轮循
此时在server4上有虚拟IP
再将server1中的keepalived服务打开,在浏览器中依然能查看轮循,此时虚拟IP回到server1上
标签:haproxy,##,keepalived,server1,server4,nginx,vrrp,apache 来源: https://blog.csdn.net/Rapig1/article/details/102710968