freebsd+Heartbeat2+php+postgres实现数据库复制和高可用网站
用2节点实现。采用heartbeat老版本2.x , 采用自己编写的resource agent,没有采用OCFhttp://img.blog.iyunv.com/20140304190412625?1/1.jpg
1 安装freebsd——废话
2 安装apache php (略) postgres,并设置复制,见:
http://blog.iyunv.com/zeeeitch/article/details/5928319
3 设置hosts文件 (第二节点略)
192.168.15.6zh103
192.168.15.9zh104
4 设置ha.cf文件,(第二节点略)
ucast em1 192.168.15.9
node zh104
node zh103
ping 192.168.14.1
logfile /var/log/ha-log
keepalive 2
deadtime 20
warntime 5
initdead 40
udpport 694
auto_failback off
5 authkeys文件:
auth 1
1 crc
6 haresources 文件:
zh104 192.168.14.11/24/em0 mypgsql myapache
7 通过haresources文件,生成xml文件:
rm /var/lib/heartbeat/crm/cib.xml /var/lib/heartbeat/crm/cib.xml.sig /var/lib/heartbeat/crm/cib.xml.last
python2 /usr/local/lib/heartbeat/haresources2cib.py --stdout -c ha.cf haresources > /var/lib/heartbeat/crm/cib.xml;chown hacluster/var/lib/heartbeat/crm/cib.xml
8 apache php启动关闭代理脚本
#!/bin/sh
case $1 in
status)
ps -ax | grep -v grep | grep -q "httpd"
rc=$?
if [ $rc = 0 ]; then
echo "apache is running."
else
echo "apache is stopped."
fi
exit $rc
;;
start)
/usr/local/etc/rc.d/apache22 onestart
exit
;;
stop)
/usr/local/etc/rc.d/apache22 onestop
exit
;;
esac
exit 0
9 主机上postgres启动关闭代理脚本
#!/bin/sh
case $1 in
status)
ps -ax | grep -q postmaster|grep -v grep
rc=$?
if [ $rc = 0 ]; then
echo "postgres is running."
else
echo "postgres is stopped."
fi
exit $rc
;;
start)
/usr/local/etc/rc.d/postgresql onestart
exit
;;
stop)
/usr/local/etc/rc.d/postgresql onestop
exit
;;
esac
exit 0
10 从机上的postgres代理脚本(启动时,hotstandby转为master)
#!/bin/sh
case $1 in
status)
ps -ax | grep -v grep | grep -q "postgres: writer" && psql -Upgsql -c "select pg_is_in_recovery()" postgres | grep -qf
rc=$?
if [ $rc = 0 ]; then
echo "postgres is running."
else
echo "postgres is stopped."
fi
exit $rc
;;
start)
touch /var/run/pg_st2ma_trigger
while true
do
ps -ax | grep -v grep | grep -q "postgres: writer" && psql -Upgsql -c "select pg_is_in_recovery()" postgres | grep -qf
rc=$?
if [ $rc = 0 ]; then
break
fi
sleep 1
done
exit 0
;;
stop)
#/usr/local/etc/rc.d/postgresql onestop
exit 0
;;
esac
exit 0
11 最后rc.conf自启动
heartbeat_enable="YES"
页:
[1]