freebsd+Heartbeat2+php+postgres实现数据库复制和高可用网站

用2节点实现。采用heartbeat老版本2.x , 采用自己编写的resource agent,没有采用OCF


1 安装freebsd——废话


2 安装apache php (略) postgres,并设置复制,见:

http://blog.csdn.net/zeeeitch/article/details/5928319

3 设置hosts文件 (第二节点略)

192.168.15.6  zh103
192.168.15.9  zh104  

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 -q  f
        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 -q  f
      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"
  




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值