NOVOTS KMS 词汇表 Glossary    联系我们 Contact Us
查询 Search  
   
按类别浏览 Browse by Category
NOVOTS KMS .: 操作系统 .: Unix/Linux .: centos6.2,64位系统搭建LVS+Keepalived(DR模式)

centos6.2,64位系统搭建LVS+Keepalived(DR模式)

首先看下我用的系统,系统为centos6.2,64位系统,用getconf LONG_BIT,和uname -a都可以查看 [root@localhost src]# getconf LONG_BIT 64 [root@localhost src]# uname -a Linux localhost 2.6.32-279.19.1.el6.x86_64 #1 SMP Wed Dec 19 07:05:20 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux 然后,分析下搭建这个LVS+Keepalived(DR)需要的关键步骤及注意事项,第一、DR模式主要是靠虚拟IP来实现,那么每台机器都需要建立一个虚拟IP,这个是必需的,第二、要注意的就是popt-static-1.13-7.el6.x86_64.rpm这个包,不装这个包,安装ipvs的时候会报错,第三、就是一些零碎的配置。 [root@localhost src]# wget http://www.keepalived.org/software/keepalived-1.2.2.tar.gz [root@localhost src]# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz [root@localhost src]# wget http://mirror.centos.org/centos/6/os/x86_64/Packages/popt-static-1.13-7.el6.x86_64.rpm 然后,在LVS主跟备份上安装 [root@localhost src]# rpm -ivh popt-static-1.13-7.el6.x86_64.rpm [root@localhost src]# yum -y install kernel-devel make gcc openssl-devel libnl* popt* [root@localhost src]# ln -s /usr/src/kernels/2.6.32-220.13.1.el6.x86_64/ /usr/src/linux [root@localhost src]# tar -zxvf ipvsadm-1.26.tar.gz [root@localhost src]# cd ipvsadm-1.26/ [root@localhost ipvsadm-1.26]# make [root@localhost ipvsadm-1.26]# make install [root@localhost ipvsadm-1.26]# cd .. [root@localhost src]# tar -zxvf keepalived-1.2.2.tar.gz -C /usr/src/ [root@localhost src]# cd keepalived-1.2.2/ [root@localhost keepalived-1.2.2]# ./configure [root@localhost keepalived-1.2.2]# make [root@localhost keepalived-1.2.2]# make install [root@localhost keepalived-1.2.2]# cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/ [root@localhost keepalived-1.2.2]# cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/ [root@localhost keepalived-1.2.2]# mkdir /etc/keepalived [root@localhost keepalived-1.2.2]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/[root@localhost keepalived-1.2.2]# cp /usr/local/sbin/keepalived /usr/sbin/ 在两台LVS上分别配置keepalived, vim /etc/keepalived/keepalived.conf [root@localhost src]# vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { router_id LVS_MASTER #网上资料说这个值也需要修改,具体不详,之前我们线上的主备就一直是一样的 ^ ^还是修改一下吧! } vrrp_instance VI_1 { state MASTER #LVS_Backup上修改成BACKUP interface eth0 virtual_router_id 60 #默认51 主从都修改为60 priority 100 #LVS_Backup上修改成80 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.10.100 } } virtual_server 192.168.10.100 80 { delay_loop 6 lb_algo rr lb_kind DR nat_mask 255.255.255.0 persistence_timeout 50 protocol TCP real_server 192.168.10.3 80 { weight 1 TCP_CHECK { connect_timeout 10 nb_get_retry 3 connect_port 80 } } real_server 192.168.10.4 80 { weight 1 TCP_CHECK { connect_timeout 10 nb_get_retry 3 connect_port 80 } } } 在LVS_Backup上也进行配置,只要把标红的地方改下就OK,然后我们在真实机上配置虚拟IP启动脚本 [root@localhost src]# vim /etc/init.d/realserver.sh #!/bin/bash SNS_VIP=192.168.10.100 . /etc/rc.d/init.d/functions case "$1" in start) ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP /sbin/route add -host $SNS_VIP dev lo:0 echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce sysctl -p >/dev/null 2>&1 echo "RealServer Start OK" ;; stop) ifconfig lo:0 down route del $SNS_VIP >/dev/null 2>&1 echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce echo "RealServer Stoped" ;; *) echo "Usage: $0 {start|stop}" exit 1 esac exit 0 在两台真是机器上面配置apache并启动realserver.sh [root@localhost src]# yum -y install httpd [root@localhost src]# cd /var/www/html/ [root@localhost html]# cat index.html < h1>RealServer 192.168.10.3 [root@localhost html]# /etc/init.d/httpd start [root@localhost src]# /etc/init.d/realserver.sh start 配置完后我们来测试下:分别启动Keepalived [root@localhost src]# chkconfig keepalived on [root@localhost src]# /etc/init.d/keepalived restart [root@localhost src]# ipvsadm IP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.10.100:http rr persistent 50 -> 192.168.10.3:http Route 1 0 0 -> 192.168.10.4:http Route 1 0 0 关闭LVS_MASTER,然后查看LVS_backup日志 [root@localhost src]# tail -f /var/log/messages Mar 21 07:22:28 host2 Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE Mar 21 07:22:29 host2 Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE Mar 21 07:22:29 host2 Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs. Mar 21 07:22:29 host2 Keepalived_healthcheckers: Netlink reflector reports IP 192.168.10.100 added Mar 21 07:22:29 host2 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.10.100 测试访问 [root@localhost html]# curl http://192.168.10.100 < h1>RealServer 192.168.10.4 然后,启动LVS_MASTER查看LVS_BACKUP日志 [root@localhost src]# tail -f /var/log/messages Mar 21 07:26:20 host2 Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert Mar 21 07:26:20 host2 Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE Mar 21 07:26:20 host2 Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs. Mar 21 07:26:20 host2 Keepalived_healthcheckers: Netlink reflector reports IP 192.168.10.100 removed

这篇文章对你多有用?

相关文章

article CentOS6.2下搭建LVS(DR)+Keepalived

  5-1-2012    Views: 1564   
article Nginx+Keepalived+Tomcat之动静分离的web集群
   为小公司提供大概一天持续在100万/

(No rating)  8-21-2013    Views: 1118   

用户评语

添加评语
当前还没有评语.


.: .: .: .: .:
[ 登陆 ]
北京护航科技有限公司 2006

Novots Technologies Limited