码迷,mamicode.com
首页 > 其他好文 > 详细

keepalived+LVS高可用Director Server

时间:2015-05-08 00:20:38      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:keepalived lvs 高可用

RHEL6.6-x86-64

主要软件:

    keepalived-1.2.16.tar.gz

    ipvsadm-1.26-4.el6.x86_64.rpm


Master Directory Server :192.168.1.5 

Backup Directory Server:192.168.1.8

Real Server 1 :192.168.1.6

Real Server 2 : 192.168.1.7

VIP: 192.168.1.10



编译安装keepalived

# tar xf keepalived-1.2.16.tar.gz
# cd keepalived-1.2.16
# ./configure --prefix=/usr/local/keepalived --sysconfdir=/etc
# make
# make install


编辑keepalived配置文件

vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
   notification_email {
   root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER
    interface eth1
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.10/24 dev eth1 label eth1:0
    }
}
virtual_server 192.168.1.10 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    #persistence_timeout 50
    protocol TCP
    sorry_server 127.0.0.1 80
    real_server 192.168.1.6 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.1.7 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

# yum install ivsadm


192.168.1.8主机中

安装keepalived同192.168.1.5

配置文件中:

    将“state MASTER" 改为 ”state BACKUP"

    将"priority 100"改为比100小的值,这里改为“priority 70".

# yum install ipvsadm



配置Real server


编写Real Server脚本

#/bin/bash
# Author xiaoming
# mail: xiaoming.linux@gmail.com

VIP=192.168.1.10
. /etc/init.d/functions
case "$1" in
    start)
   echo "Start Real Server "
   /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
   route add -host $VIP dev lo:0
   echo 1 > /proc/sys/net/ipv4/conf/eth1/arp_ignore
   echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
   echo 2 > /proc/sys/net/ipv4/conf/eth1/arp_announce
   echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
   ;;
     stop)
    echo "Stop Real Server"
    /sbin/ifconfig lo:0 down
    route del $VIP
    echo 0 > /proc/sys/net/ipv4/conf/eth1/arp_ignore
    echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
    echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
    echo 0 > /proc/sys/net/ipv4/conf/eth1/arp_announce
   ;;
    *)
   echo "Usage: $0 {start|stop}"
   exit 1
esac


分别在Real Server1和Real Server2上执行此脚本


配置完毕,分别在director server上启动keepalived服务,


查看LVS路由表信息

# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.1.10:80 rr
  -> 192.168.1.6:80               Route   1      0          0         
  -> 192.168.1.7:80               Route   1      0          0


本文出自 “在路上” 博客,请务必保留此出处http://mingxiao.blog.51cto.com/8124243/1643895

keepalived+LVS高可用Director Server

标签:keepalived lvs 高可用

原文地址:http://mingxiao.blog.51cto.com/8124243/1643895

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!