Chinaunix首页 | 论坛 | 博客
  • 博客访问: 642198
  • 博文数量: 95
  • 博客积分: 2091
  • 博客等级: 大尉
  • 技术积分: 982
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-05 19:34
文章分类

全部博文(95)

文章存档

2017年(1)

2016年(20)

2015年(10)

2014年(6)

2013年(4)

2012年(1)

2011年(9)

2010年(6)

2009年(20)

2008年(17)

2007年(1)

我的朋友

分类: LINUX

2015-12-29 21:21:39

  keepalived官方地址是最新版本为keepalived-1.2.19, 安装步骤如下:

Master: 192.168.10.46
Backup: 192.168.10.47
VIP:192.168.10.60
Realserver1: 192.168.10.40
Realserver2: 192.168.10.401

系统采用CENTOS6.8 最小安装,并需要安装下列包
yum install kernel kernel-devel openssl openssl-devel gcc

1  安装keepalived
    #  wget
    #  tar zxvf keepalived-1.2.19.tar.gz
    #  cd keepalived-1.2.19
    #  ./configure --prefix=/usr sysconfdir=/etc --with-kernel-dir=/usr/src/kernels/2.6.32-573.12.1.el6.x86_64/  // --prefix=/usr执行安装路径 sysconfdir=/etc 指定配置文件路径    --with-kernel-dir 制定内核源码的头文件,配合LVS使用. 编译过程中越少啥包就装啥包
    
#  make
    #  make install 

2 配置Mater
#   vim /etc/keepalived/keepalived.conf


点击(此处)折叠或打开

  1. ! Configuration File for keepalived


    global_defs {
       notification_email {
         acassen
       }
       notification_email_from 14778424@qq.com
       smtp_server smtp.qq.com
       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 {
            192.168.10.60/24 dev eth0 label eth0:1
        }


    virtual_server 192.168.10.60 80 {
        delay_loop 6
        lb_algo rr
        lb_kind NAT
        persistence_timeout 50
        protocol TCP

       real_server 192.168.10.40 80 {
            weight 1
            HTTP_GET {
                url {
                  path /index.html
                  digest 7e90e3bf411e23327000c1e3528fff5f
              }
                connect_port    80
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
        }


        real_server 192.168.10.41 80 {
            weight 1
            HTTP_GET {
                url {
                  path /index.html
                  digest 5d05aaac53885c5325530d0c969f3b24
                }
                connect_port    80
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
        }
    }

    2.2  生成网页digest的方法, 
        # [root@localhost keepalived]# genhash -s 192.168.10.40 -p 80 -u /index.html 
            MD5SUM = 0a5cb9603c17518a90cfbf3faadf77ca
      PS: 这个digest一定要添加,之前我将这行去掉,测试过程中,可以正常在队列中剔除down的realserver,但恢复后始终无法自动添加到队列中


3  配置backup机器

#   vim /etc/keepalived/keepalived.conf

点击(此处)折叠或打开

  1. ! Configuration File for keepalived

  2. global_defs {
  3.    notification_email {
  4.      acassen
  5.    }
  6.    notification_email_from 14778424@qq.com
  7.    smtp_server smtp.qq.com
  8.    smtp_connect_timeout 30
  9.    router_id LVS_DEVEL
  10. }

  11. vrrp_instance VI_1 {
  12.     state BACKUP
  13.     interface eth0
  14.     virtual_router_id 51
  15.     priority 80
  16.     advert_int 1
  17.     authentication {
  18.         auth_type PASS
  19.         auth_pass 1111
  20.     }
  21.     virtual_ipaddress {
  22.         192.168.10.60/24 dev eth0 label eth0:1
  23.     }
  24. virtual_server 192.168.10.60 80 {
  25.     delay_loop 6
  26.     lb_algo rr
  27.     lb_kind DR
  28.     persistence_timeout 50
  29.     protocol TCP

  30.     real_server 192.168.10.40 80 {
  31.         weight 1
  32.         HTTP_GET {
  33.             url {
  34.               path /index.html
  35.               digest 7e90e3bf411e23327000c1e3528fff5f
  36.           }
  37.             connect_port 80
  38.             connect_timeout 3
  39.             nb_get_retry 3
  40.             delay_before_retry 3
  41.         }
  42.     }

  43.     real_server 192.168.10.41 80 {
  44.         weight 1
  45.         HTTP_GET {
  46.             url {
  47.               path /index.html
  48.               digest 5d05aaac53885c5325530d0c969f3b24
  49.             }
  50.             connect_port 80
  51.             connect_timeout 3
  52.             nb_get_retry 3
  53.             delay_before_retry 3
  54.         }
  55.     }
  56. }

4  配置realserver机器

在/etc/init.d/中新增一个文件lvsrs,并执行 lvsrs start

点击(此处)折叠或打开

  1. #!/bin/sh
  2. #
  3. # Startup script for the Keepalived ReadServer
  4. #
  5. # processname: lvsrs
  6. # description: Start and stop Real Server
  7. VIP=192.168.10.60
  8. # Source function library
  9. . /etc/rc.d/init.d/functions

  10. case "$1" in
  11.   start)
  12.         echo " Start LVS of Real Server"
  13.         /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
  14.         echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
  15.         echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
  16.         echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
  17.         echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
  18.         ;;
  19.   stop)
  20.         /sbin/ifconfig lo:0 down
  21.         echo " Stop LVS of Real Server"
  22.         echo "0" > /proc/sys/net/ipv4/conf/lo/arp_ignore
  23.         echo "0" > /proc/sys/net/ipv4/conf/lo/arp_announce
  24.         echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore
  25.         echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce
  26.         ;;
  27.         *)
  28. echo "Usage: $0 {start|stop}"
  29. exit 1
  30. esac

5 测试














阅读(1030) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~