1. 程式人生 > >redhat6.4_LVS_install安裝文件

redhat6.4_LVS_install安裝文件

一、環境準備 redhat6.4 下載安裝包: 實現LVS/DR最重要的兩個東西是ipvs核心模組和ipvsadm工具包,現在的系統已經包含ip_vs模組
1.檢查核心模組,看一下ip_vs 是否被載入
    # lsmod |grep ip_vs
    ip_vs    35009    0
    如果沒有顯示,則說明沒有載入,執行命令 modprobe ip_vs 就可以把ip_vs模組載入到核心
    #modprobe ip_vs   然後再檢視就有了。 2.連結核心,否則會報錯 #lsmod |grep ip_vs #uname -r #ln -s /usr/src/kernels/2.6.32-358.el6.x86_64/  /usr/src/linux
ln -s   /usr/src/kernels/2.6.32-696.1.1.el6.x86_64/ /usr/src/linux 3.安裝依賴 環境準備: yum -y install kernel-devel gcc openssl popt popt-devel libnl libnl-devel  openssl openssl-devel
二、安裝 1.安裝ipvsadmin tar xf ipvsadm-1.26.tar.gz cd ipvsadm-1.26 make  make install      安裝的時候報錯如下,     collect2: ld returned 1 exit status     make: *** [ipvsadm] Error 1     解決方式: 2. 安裝keepalived
cd .. tar xf keepalived-1.2.13.tar.gz  [[email protected]soft]# cd keepalived-1.2.13 ./configure --prefix=/usr/local/keepalived
make && make install  3.配置keepalived  cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/    chkconfig --add keepalived  chkconfig keepalived on  mkdir /etc/keepalived  ln -s /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/  ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/  ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/  4.然後修改配置檔案/etc/keepalived/keepalived.conf

! Configuration File for keepalived global_defs {    notification_email {    }    smtp_server mail.homelink.com.cn    smtp_connect_timeout 30    router_id LVS_DEVEL } vrrp_instance VI_1 {     state MASTER     interface eth0     virtual_router_id 51     priority 100     advert_int 1     authentication {         auth_type PASS         auth_pass 1111     }     virtual_ipaddress {         172.31.1.60     } } virtual_server 172.31.1.60 80 {     delay_loop 3     lb_algo rr      lb_kind DR     persistence_timeout 50     protocol TCP     real_server 172.31.1.61 80 {         weight 1         TCP_CHECK {          connect_timeout 3         nb_get_retry 3         delay_before_retry 3         connect_port 80         }     }     real_server 172.31.1.71 80 {         weight 1         TCP_CHECK {         connect_timeout 3         nb_get_retry 3         delay_before_retry 3         connect_port 80         }     } }

需要注意的配置(主被需要修改) router_id LVS1#設定lvsid,在一個網路內應該是唯一的
state MASTER#設定lvs的狀態,報錯MASTERBACKUP兩種,必須大寫
priority 100#設定優先順序,數值越大,優先順序越高  BACKUP設定50

確認是否為DR,輪尋    

lb_algo rr#負載均衡排程演算法

lb_kind DR#負載均衡轉發規則

5.啟動keepalived /etc/init.d/keepalived start 6.real server 

cat /etc/rc.d/init.d/realserver.sh #!/bin/bash # description: Config realserver lo and apply noarp SNS_VIP=192.168.1.115 /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

7.檢視lvs服務是否正常  ipvsadm -l #注意檢視 #ip addr add172.31.1.60/32dev lo #ip add list  # ip addr del 172.31.1.60/32 dev eth0 如果需要傳送郵件需要開啟/etc/init.d/postfix 
cat /etc/rc.d/init.d/realserver.sh #!/bin/bash # description: Config realserver lo and apply noarp SNS_VIP=192.168.1.115 /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
! Configuration File for keepalived global_defs {    notification_email {    }    smtp_server mail.homelink.com.cn    smtp_connect_timeout 30    router_id LVS_DEVEL } vrrp_instance VI_1 {     state MASTER     interface eth0     virtual_router_id 51     priority 100     advert_int 1     authentication {         auth_type PASS         auth_pass 1111     }     virtual_ipaddress {         172.31.1.60     } } virtual_server 172.31.1.60 80 {     delay_loop 3     lb_algo rr      lb_kind DR     persistence_timeout 50     protocol TCP     real_server 172.31.1.61 80 {         weight 1         TCP_CHECK {          connect_timeout 3         nb_get_retry 3         delay_before_retry 3         connect_port 80         }     }     real_server 172.31.1.71 80 {         weight 1         TCP_CHECK {         connect_timeout 3         nb_get_retry 3         delay_before_retry 3         connect_port 80         }     } }