PGSQL主从+keepalived高可用配置
- host文件添加服务器地址(2台机器都操作)
[root@master ~]
192.168.124.3 master
192.168.124.4 slave
192.168.124.20 vip
- 安装ekppalived软件包(2台机器都操作)
[root@master ~]
- 修改配置文件(主配置文件)
[root@master ~]
[root@master keepalived]
bal_defs {
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id pg
}
vrrp_script chk_pgsql {
script "/etc/keepalived/scripts/pgsql_check.sh"
interval 2
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 61
priority 100
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass hxh
}
track_script {
chk_pgsql
}
virtual_ipaddress {
192.168.124.20/24
}
}
- 修改配置文件(备配置文件)
[root@slave ~]
[root@slave keepalived]
bal_defs {
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id pg
}
vrrp_script chk_pgsql {
script "/etc/keepalived/scripts/pgsql_check.sh"
interval 2
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 61
priority 80
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass hxh
}
track_script {
chk_pgsql
}
virtual_ipaddress {
192.168.124.20/24
}
}
- 创建目录及脚本(2台机器都操作)
[root@master keepalived]
[root@master keepalived]
[<