lvs+keepalived

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 {

         [email protected]

         [email protected]

  }

  notification_email_from [email protected]

  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 {

         [email protected]

         [email protected]

  }

  notification_email_from [email protected]

  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的主要内容,如果未能解决你的问题,请参考以下文章

LVS DR模式搭建,keepalived + lvs

keepalived + lvs + nginx 主备配置案例

LVS+Keepalived 高可用群集的介绍和搭建步骤

LVS+keepalived做Mysql集群的负载均衡

Linux集群架构

Keepalived LVS+DR合设配置方法以及存在的问题