首页 > 代码库 > lvs+keepalived

lvs+keepalived

-------主服务器&从服务器lvs&keepalived------

 

首先安装依赖包

yum -y install openssl-devel  gcc gcc-c++  ipvsadm

 

yum安装lvs

 

yum -y install ipvsadm

 

yum安装keepalived

 

yum -y installkeepalived

 

/etc/init.d/ipvsadmrestart

service keepalivedrestart

主服务器配置文件

修改keepalived配置文件(删除原内容,粘贴后修改IP

vim/etc/keepalived/keepalived.conf

! Configuration File for keepalived

 

global_defs {

  notification_email {

         linuxedu@foxmail.com

         mageedu@126.com

  }

  notification_email_from kanotify@magedu.com

  smtp_connect_timeout 3

  smtp_server 172.18.5.43

  router_id LVS_DEVEL

}

 

vrrp_script chk_schedown {

  script "[[ -f /etc/keepalived/down ]] && exit 1 || exit0"

  interval 2

  weight -2

}

 

vrrp_instance VI_1 {

   interface eth0

   state MASTER

   priority 101                      #(大于从服务器)

   virtual_router_id 87

   garp_master_delay 1

 

   authentication {

        auth_type PASS

        auth_pass 1221

   }

 

   track_interface {

       eth0

   }

 

   virtual_ipaddress {

        10.1.1.182

        }

 

   track_script {

        chk_schedown

   }

}

virtual_server 10.1.1.182 80 {                     # VIP

   delay_loop 6

   lb_algo rr

   lb_kind DR

   persistence_timeout 50

   protocol TCP

 

   real_server 10.1.1.167 80 {                    # web服务IP

        weight 1

        HTTP_GET {

            url {

              path /

              status_code 301

            }

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

}

real_server 10.1.1.16880 {                          # web服务IP

        weight 1

        HTTP_GET {

            url {

              path /

              status_code 301

            }

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

   }

}

==========================================================================================

附服务器配置文件

修改keepalived配置文件(删除原内容,粘贴后修改IP

vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

 

global_defs {

  notification_email {

         linuxedu@foxmail.com

         mageedu@126.com

  }

  notification_email_from kanotify@magedu.com

  smtp_connect_timeout 3

  smtp_server 172.18.5.43

  router_id LVS_DEVEL

}

 

vrrp_script chk_schedown {

  script "[[ -f /etc/keepalived/down ]] && exit 1 || exit0"

  interval 2

  weight -2

}

 

vrrp_instance VI_1 {

   interface eth0

   state BACKUP

   priority 100                      #(大于从服务器)

   virtual_router_id 87

   garp_master_delay 1

 

   authentication {

        auth_type PASS

        auth_pass 1221

   }

 

   track_interface {

       eth0

   }

 

   virtual_ipaddress {

        10.1.1.182

        }

 

   track_script {

        chk_schedown

   }

}

virtual_server 10.1.1.182 80 {                     # VIP

   delay_loop 6

   lb_algo rr

   lb_kind DR

   persistence_timeout 51

   protocol TCP

 

   real_server 10.1.1.168 80 {                    # web服务IP

        weight 1

        HTTP_GET {

            url {

              path /

              status_code 301

            }

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

}

   real_server 10.1.1.167 80 {                          # web服务IP

        weight 1

        HTTP_GET {

            url {

              path /

              status_code 301

            }

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

   }

}

 

===========================================================================================

查询

ipvsadm -Ln

service ipvsadmrestart

service keepalivedrestart 

web服务段配置(web1web2)直接粘贴

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

   修改IP后粘贴

/sbin/ifconfig lo:0 192.168.11.31broadcast 192.168.11.31 netmask 255.255.255.255 up

/sbin/route add -host 192.168.11.31dev lo:0                  

 

 

 

 


本文出自 “12178027” 博客,请务必保留此出处http://12188027.blog.51cto.com/12178027/1870498

lvs+keepalived