OushuDB配置IP高可用
一、配置 Keepalive 服务
1.master 和 standby 节点安装 keepalived
sudo yum install -y keepalived
2.编辑 hawq_master_keepalived.conf 和 hawq_standby_keepalived.conf 文件, 替换其中的变量:
${hawq_master_ip}: master 节点 ip
${master_ethnet}: 上述 ip 对应的 eth 端口名
${hawq_standby_ip}: standby 节点 ip
${standby_ethnet}: 上述 ip 对应的 eth 端口名
${hawq_port}: hawq 监听的端口,默认为 5432
${virtual_router_id}: 标识符,不与其他 keepalived 实例冲突即可
${lb_ip}: 浮动 ip,上层应用直接与这个 ip 建连,可以指定子网掩码,格式如 "192.168.1.1/16"
3.hawq_master_keepalived.conf
vrrp_script chk_hawq {
script "/etc/keepalived/hawq_check_master.sh"
interval 2
}
vrrp_instance VI_1 {
interface ${master_ethnet}
state MASTER
priority 200
virtual_router_id ${virtual_router_id}
unicast_src_ip ${hawq_master_ip}
unicast_peer {
${hawq_standby_ip}
}
authentication {
auth_type PASS
auth_pass hawq_lbha
}
virtual_ipaddress { #设置vip
${lb_ip}
}
track_script {
chk_hawq
}
notify_master "iptables -F INPUT"
notify_backup "iptables -F INPUT; iptables -I INPUT -p TCP --destination ${hawq_master_ip} --dport 5432 -j DROP; iptables -I INPUT -p TCP --source ${hawq_master_ip} --dport 5432 -j ACCEPT; iptables -I INPUT -p TCP --source ${hawq_standby_ip} --dport 5432 -j ACCEPT"
notify_fault "iptables -F INPUT; iptables -I INPUT -p TCP --destination ${hawq_master_ip} --dport 5432 -j DROP; iptables -I INPUT -p TCP --source ${hawq_master_ip} --dport 5432 -j ACCEPT; iptables -I INPUT -p TCP --source ${hawq_standby_ip} --dport 5432 -j ACCEPT"
}
4.hawq_standby_keepalived.conf
vrrp_script chk_hawq {
script "/etc/keepalived/hawq_check_master.sh"
interval 2
}
vrrp_instance VI_1 {
interface ${standby_ethnet}
state BACKUP
priority 100
virtual_router_id ${virtual_router_id}
unicast_src_ip ${hawq_standby_ip}
unicast_peer {
${hawq_master_ip}
}
authentication {
auth_type PASS
auth_pass hawq_lbha
}
virtual_ipaddress { #设置vip
${lb_ip}
}
track_script {
chk_hawq
}
notify_master "iptables -F INPUT"
notify_backup "iptables -F INPUT; iptables -A INPUT -p TCP --destination ${hawq_standby_ip} --dport 5432 -j DROP; iptables -I INPUT -p TCP --source ${hawq_master_ip} --dport 5432 -j ACCEPT; iptables -I INPUT -p TCP --source ${hawq_standby_ip} --dport 5432 -j ACCEPT"
notify_fault "iptables -F INPUT; iptables -A INPUT -p TCP --destination ${hawq_standby_ip} --dport 5432 -j DROP; iptables -I INPUT -p TCP --source ${hawq_master_ip} --dport 5432 -j ACCEPT; iptables -I INPUT -p TCP --source ${hawq_standby_ip} --dport 5432 -j ACCEPT"
}
5.拷贝文件
拷贝hawq_master_keepalived.conf覆盖master节点下的 /etc/keepalived/keepalived.conf
拷贝hawq_standby_keepalived.conf覆盖standby节点下的 /etc/keepalived/keepalived.conf
6.编辑/etc/keepalived/hawq_check_master.sh
#!/usr/bin/env bash
ps -ef | grep postgres | grep master
7.启动 keepalived 服务
sudo service keepalived start
二、启动主备切换监听程序
1.修改权限(master 和 standby 节点)
chmod 755 /usr/local/hawq/bin/standby_daemon
chmod 755 /usr/local/hawq/bin/hawq_heartbeat_monitor
chmod 755 /usr/local/hawq/bin/hawq_ctl
chown gpadmin:gpadmin /usr/local/hawq/bin/standby_daemon
chown gpadmin:gpadmin /usr/local/hawq/bin/hawq_heartbeat_monitor
chown gpadmin:gpadmin /usr/local/hawq/bin/hawq_ctl
chmod +x /etc/keepalived/hawq_check_master.sh
2.启动监听服务
#Master节点
su - gpadmin
source /usr/local/hawq/greenplum_path.sh;
nohup /usr/local/hawq/bin/standby_daemon 2>&1 >/dev/null &
#Standby节点
su - gpadmin
source /usr/local/hawq/greenplum_path.sh;
nohup /usr/local/hawq/bin/standby_daemon 2>&1 >/dev/null &
nohup /usr/local/hawq/bin/hawq_heartbeat_monitor 2>&1 >/dev/null &