LVS+Heartbeat 高可用集群方案操作步骤详解(2)

1) 安装lvs依赖
[root@ha-master ~]# yum install -y libnl* popt*
 
查看是否加载lvs模块
[root@ha-master ~]# modprobe -l |grep ipvs
kernel/net/netfilter/ipvs/ip_vs.ko
kernel/net/netfilter/ipvs/ip_vs_rr.ko
kernel/net/netfilter/ipvs/ip_vs_wrr.ko
kernel/net/netfilter/ipvs/ip_vs_lc.ko
kernel/net/netfilter/ipvs/ip_vs_wlc.ko
kernel/net/netfilter/ipvs/ip_vs_lblc.ko
kernel/net/netfilter/ipvs/ip_vs_lblcr.ko
kernel/net/netfilter/ipvs/ip_vs_dh.ko
kernel/net/netfilter/ipvs/ip_vs_sh.ko
kernel/net/netfilter/ipvs/ip_vs_sed.ko
kernel/net/netfilter/ipvs/ip_vs_nq.ko
kernel/net/netfilter/ipvs/ip_vs_ftp.ko
kernel/net/netfilter/ipvs/ip_vs_pe_sip.ko
 
2) 下载并安装LVS
[root@ha-master ~]# cd /usr/local/src/
[root@ha-master src]# unlink /usr/src/linux
[root@ha-master src]# ln -s /usr/src/kernels/2.6.32-431.5.1.el6.x86_64/ /usr/src/linux
[root@ha-master src]# wget
[root@ha-master src]# tar -zvxf ipvsadm-1.26.tar.gz
[root@ha-master src]# cd ipvsadm-1.26
[root@ha-master ipvsadm-1.26]# make && make install
 
LVS安装完成,查看当前LVS集群
[root@ha-master ipvsadm-1.26]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port          Forward Weight ActiveConn InActConn
 
3) 添加lvs的管理脚本(ipvsadm)
ipvsadm服务的配置文件是/etc/sysconfig/ipvsadm
[root@ha-master ha.d]# vim /etc/sysconfig/ipvsadm
#!/bin/bash
# description: start LVS of DirectorServer
#Written by :NetSeek
GW=172.16.60.1                                  #这个是VIP所在网段的网段地址
 
# website director vip.
WEB_VIP=172.16.60.111 
WEB_RIP1=172.16.60.204
WEB_RIP2=172.16.60.205
 
 
. /etc/rc.d/init.d/functions
 
logger $0 called with $1
 
case "$1" in
 
start)
        # Clear all iptables rules.
        /sbin/iptables -F
        # Reset iptables counters.
        /sbin/iptables -Z
        # Clear all ipvsadm rules/services.
        /sbin/ipvsadm -C
 
 #set lvs vip for dr
        /sbin/ipvsadm --set 30 5 60
        /sbin/ifconfig eth0:0 $WEB_VIP broadcast $WEB_VIP netmask 255.255.255.255 up
        /sbin/route add -host $WEB_VIP dev eth0:0
                /sbin/ipvsadm -A -t $WEB_VIP:80 -s wlc -p 600
                /sbin/ipvsadm -a -t $WEB_VIP:80 -r $WEB_RIP1:80 -g
                /sbin/ipvsadm -a -t $WEB_VIP:80 -r $WEB_RIP2:80 -g
 
        touch /var/lock/subsys/ipvsadm >/dev/null 2>&1
         
        # set Arp
                /sbin/arping -I eth0 -c 5 -s $WEB_VIP $GW >/dev/null 2>&1 
      ;;
stop)
        /sbin/ipvsadm -C
        /sbin/ipvsadm -Z
        ifconfig eth0:0 down
        route del $WEB_VIP  >/dev/null 2>&1
        rm -rf /var/lock/subsys/ipvsadm >/dev/null 2>&1
                /sbin/arping -I eth0 -c 5 -s $WEB_VIP $GW
        echo "ipvsadm stoped"
      ;;
 
status)
 
        if [ ! -e /var/lock/subsys/ipvsadm ];then
                echo "ipvsadm is stoped"
                exit 1
        else
                ipvsadm -ln
                echo "..........ipvsadm is OK."
        fi
      ;;
 
*)
        echo "Usage: $0 {start|stop|status}"
        exit 1
esac
 
exit 0
 
 
===============温馨提示=================
上面配置中的"-p 600"的意思是会话保持时间为600秒,这个应该和ldirectord.cf文件配置一致 (还有lvs策略也要一致, 如这里的lwc)
 
授权脚本执行权限
[root@ha-master ha.d]# chmod 755 /etc/sysconfig/ipvsadm

4) realserver 节点配置

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a3c81ffb78ffb50266c1d4bc239d78e0.html