首先用我写的squid自动安装shell来安装squidA和squidB. 反向代理的站为test.17u.net和自己的一个站 在实现双机的时候要用这个去做测试是否访问正常。
首先保证squidA和squidB这两台机器的服务都是up的。
安装的包如下:
[root@syss ~]# rpm -qa|grep heartbeat
heartbeat-pils-2.1.3-3.el5.centos
heartbeat-devel-2.1.3-3.el5.centos
heartbeat-gui-2.1.3-3.el5.centos
heartbeat-stonith-2.1.3-3.el5.centos
heartbeat-2.1.3-3.el5.centos
heartbeat-ldirectord-2.1.3-3.el5.centos
[root@sys ~]# rpm -qa|grep heartbeat
heartbeat-2.1.3-3.el5.centos
heartbeat-pils-2.1.3-3.el5.centos
heartbeat-devel-2.1.3-3.el5.centos heartbeat的开发包
heartbeat-ldirectord-2.1.3-3.el5.centos 这个是和LVS一起用的时候。要用到
heartbeat-stonith-2.1.3-3.el5.centos
heartbeat-gui-2.1.3-3.el5.centos 图型的配置界面
两台机器都要安装这些包
然后开始设置
1. 添加主机名到/etc/hosts中(两台都要添加)
192.168.0.90 sys.squid sys
192.168.0.89 syss.squid syss
2.修改heartbeat要启动的必要文件(两台机器上要一样)
Ha.cf(HA的主配置文件) autokeys(认证文件) haresources(资源文件) resource.d (资源脚本放置的地方)
Ha.cf配置文件如下:
debugfile /var/log/ha-debug
logfile /var/log/ha-log
keepalive 2 //设置心跳间隔时间为2两秒
deadtime 30 //在30秒后明确该节点的死亡
warntime 10 //在日志中发出最后心跳”late heartbeat” 前的警告时间设定
initdead 120 //在一些配置中,节点重启后需要花一些时间启动网络。这个时间与”deadtime”不同,要单独对待。 至少是标准死亡时间的两倍。
udpport 694 //设置udp的通信port
baud 19200 //设置速率
serial /dev/ttyS0 //因为用的是rs232 所以设置为串口
auto_failback on //设置如果主结点修复,会自动变成active
node sys.squid //设置HA结点的名字
node syss.squid
ping 192.168.1.4 //设置网关,以确认网络是通的,也可以设置别的
respawn hacluster /usr/lib/heartbeat/ipfail
autokeys 认证文件
auth 1
1 crc
有三种认证方式,个人可以自己选择一种
Chmod 600 autokeys一定要给600的权限
设置haresources (资源文件)
主结点名 VIP 资源名(指资源的启动shell,必要包括start|stop两项)
sys.squid 192.168.0.88 squid
因为是编译的squid 所以自己写了一个squid资源文件shell 放在/etc/ha.d/resource.d
或放到/etc/init.d/ 下。
Squid资源如下:
#!/bin/bash
squiddir="/usr/local/squid"
logger $0 called with $1
case "$1" in
start)
$squiddir/sbin/squid start
;;
stop)
# Stop commands go here
$squiddir/sbin/squid -k shutdown
echo "Please wait 3 seconds"
sleep 3
;;
status)
# Status commands go here
if [ -f /usr/local/squid/var/logs/squid.pid ]
then
echo "The squid now running"
else
echo "The squid may be down,Please check"
fi
;;
Esac
然后启动 heartbeat( 两台上都启动)
Service heartbeat start
然后看一下日志
Tailf –f /var/log/ha-log或tail –f /var/log/ha-debug。可以看到结点是active 还是standby
如果想测试standby是不是可以正常工作,可以把active的服务给down掉,看看standy的日志,会变成active
然后看下应用的连接,全部过来了
root@sys resource.d]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
squid 10084 squidzsj 22u IPv4 470919 TCP 192.168.0.88:http->231.145.63.58.broad.gz.gd.dynamic.163data.com.cn:43017 (ESTABLISHED)
squid 10084 squidzsj 23u IPv4 467226 TCP 192.168.0.88:http->58.24.179.167:18641 (ESTABLISHED)
squid 10084 squidzsj 24u IPv4 26397 TCP *:http (LISTEN)
squid 10084 squidzsj 27u IPv4 472301 TCP 192.168.0.88:http->58.211.21.93:51209 (ESTABLISHED)
squid 10084 squidzsj 28u IPv4 471827 TCP 192.168.0.88:http->125.34.18.168:csd-mgmt-port (ESTABLISHED)
squid 10084 squidzsj 29u IPv4 472423 TCP 192.168.0.88:http->60.7.212.121:rds2 (ESTABLISHED)
squid 10084 squidzsj 30u IPv4 473207 TCP 192.168.0.88:http->58.211.68.82:discp-server (ESTABLISHED)
squid 10084 squidzsj 31u IPv4 471741 TCP 192.168.0.88:http->123.137.77.158:4256 (ESTABLISHED)
squid 10084 squidzsj 32u IPv4 471487 TCP 192.168.0.88:http->58.212.76.234:prodigy-intrnet (ESTABLISHED)
squid 10084 squidzsj 33u IPv4 472773 TCP 192.168.0.88:http->219.237.196.198:35091 (ESTABLISHED)
squid 10084 squidzsj 34u IPv4 473319 TCP 192.168.0.88:http->116.17.9.170:19292 (ESTABLISHED)
squid 10084 squidzsj 35u IPv4 473279 TCP 192.168.0.88:http->218.104.237.230:57618 (ESTABLISHED)
squid 10084 squidzsj 36u IPv4 472291 TCP 192.168.0.88:http->58.45.42.253:21144 (ESTABLISHED)
squid 10084 squidzsj 37u IPv4 469120 TCP 192.168.0.88:http->58.18.185.54:triquest-lm (ESTABLISHED)
squid 10084 squidzsj 38u IPv4 472425 TCP 192.168.0.88:http->8.240.234.221.broad.wh.hb.dynamic.163data.com.cn:20494 (ESTABLISHED)
squid 10084 squidzsj 39u IPv4 473357 TCP sys.squid:55205->192.168.1.110:http (ESTABLISHED)
squid 10084 squidzsj 40u IPv4 473108 TCP 192.168.0.88:http->221.222.236.218:4150 (ESTABLISHED)
squid 10084 squidzsj 41u IPv4 472737 TCP 192.168.0.88:http->121.18.82.38:netml (ESTABLISHED)
squid 10084 squidzsj 42u IPv4 470404 TCP 192.168.0.88:http->222.175.169.61:34210 (ESTABLISHED)
squid 10084 squidzsj 43u IPv4 473372 TCP 192.168.0.88:http->222.92.21.198:h323gatestat (ESTABLISHED)
squid 10084 squidzsj 44u IPv4 471415 TCP 192.168.0.88:http->61.186.162.41:4946 (ESTABLISHED)
squid 10084 squidzsj 45u IPv4 470080 TCP 192.168.0.88:http->202.106.71.190:cisco-wafs (ESTABLISHED)
squid 10084 squidzsj 46u IPv4 471653 TCP 192.168.0.88:http->125.46.75.9:13084 (ESTABLISHED)
OVER