vip 192.168.0.40
lvs 192.168.0.44
rel-50 192.168.0.50
rel-60 192.168.0.60
一。需要的软件包
1. ipvsadm-1.24-8.1.i386.rpm
2. modcluster-0.8-27.el5.i386.rpm
3. piranha-0.8.4-7.el5.i386.rpm
4. system-config-cluster-1.0.39-1.0.noarch.rpm
5. php-5.1.6-5.el5.i386.rpm
6. php-cli-5.1.6-5.el5.i386.rpm
7. php-common-5.1.6-5.el5.i386.rpm
8. http*
yum install ipvsadm modcluster piranha system-config-cluster php php-cli php-common
在CentOS 5的kernel中已经包含 ipvs 模块。执行命令 modprobe ip_vs 就可以把ip_vs模块加载到内核
# piranha-passwd
按照提示输入管理密码
配置主LVS服务器.
# vi /etc/sysctl.conf找到下面行 //启用数据转发.
net.ipv4.ip_forward = 0将0 改成1,net.ipv4.ip_forward = 1
执行如下命令来应用:sysctl –p 或重启
ifconfig eth0:0 192.168.0.40 netmask 255.255.255.255 broadcast 192.168.0.40 up
可写 /etc/rc.local 避免重启再输入
(永久保存,将ifcfg-eth0复制成ifcfg-eth0:0。修改设备名、IP、掩码和广播地址,去掉网关)
service httpd start
/etc/init.d/piranha-gui start
touch /etc/sysconfig/ipvsadm
service ipvsadm start
/etc/init.d/pulse start
#ipvsadm -A -t 192.168.0.40:80 -s wlc // add virtual service
#ipvsadm -a -t 192.168.0.40:80 -r 192.168.0.50 -i -w 1 // add real server
#ipvsadm -a -t 192.168.0.40:80 -r 192.168.0.60 -i -w 1 // add real server
把以上三句只能写在 /etc/rc.local 最后,也能避免每次重启后都要去输入这几条命令(这些可以在http;//lvs:3636后台增加配置)
6. 进入 192.168.0.50
把下面四句添加在/etc/sysctl.conf文件最后来关闭arp:
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
采用tunneling模式
ifconfig tunl0 76.73.49.230 netmask 255.255.255.255 broadcast 76.73.49.230 up
route add -host 76.73.49.230 dev tunl0
把以上二句写 /etc/rc.local 最后,避免重启再输入。
# echo ' the site is 192.168.0.50' > /var/www/html/index.html
# chkconfig httpd on
# service httpd start
7. 进入 192.168.0.60
把下面四句添加在/etc/sysctl.conf 文件最后来关闭arp:
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
采用tunneling模式
ifconfig tunl0 76.73.49.230 netmask 255.255.255.255 broadcast 76.73.49.230 up
route add -host 76.73.49.230 dev tunl0
把以上二句写 /etc/rc.local 最后,避免重启再输入。
# echo ' the site is 192.168.0.60' > /var/www/html/index.html
# chkconfig httpd on
# service httpd start
可以使用命令ipvsadm -ln查看其状态像这样:
[root@hehe]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.0.13:80 rr
-> 192.168.0.205:80 Route 1 0 0
-> 192.168.0.12:80 Route 1 0 0
显示LVS 目前的连接 如:ipvsadm -L -c
[root@erictest ha.d]# ipvsadm -L -c
IPVS connection entries
pro expire state source virtual destination
TCP 01:58 FIN_WAIT 192.168.0.66:4963 192.168.0.13:http 192.168.0.12:http
TCP 00:25 SYN_RECV 192.168.0.66:4936 192.168.0.13:http 192.168.0.205:http
TCP 00:26 SYN_RECV 192.168.0.66:iad1 192.168.0.13:http 192.168.0.205:http
--timeout 显示tcp tcpfin udp 的timeout 值 如:ipvsadm -L --timeout
--daemon 显示同步守护进程状态
--stats 显示统计信息
--rate 显示速率信息
--sort 对虚拟服务器和真实服务器排序输出
--numeric -n 输出IP 地址和端口的数字形式
同样可以上面参数也有说到。
ipvsadm -L --stats
[root@erictest ha.d]# ipvsadm -L --stats
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Conns InPkts OutPkts InBytes OutBytes
-> RemoteAddress:Port
TCP 192.168.0.13:http 207 1583 0 105538 0
-> 192.168.0.205:http 104 312 0 14976 0
-> 192.168.0.12:http 103
Iptraf是一款Linux环境下,监控网络流量的一款绝佳的免费小软件,特别是安装到防火墙上,与Iptables一起工作,监控流经防火墙的网络异常,效果非常好