一次keepalived安装配置实例

来源:互联网 发布:淘宝上买精密管犯法么 编辑:程序博客网 时间:2024/06/05 23:08
1.源码安装keepalive  tar包
./configure   --with-kernel-dir=/usr/src/kernels/2.6.18-238.19.1.el5-i686/
make
make install

三部曲

预编译后应有如下提示:

Keepalived configuration
------------------------
Keepalived version       : 1.2.2
Compiler                 : gcc
Compiler flags           : -g -O2 -DETHERTYPE_IPV6=0x86dd
Extra Lib                : -lpopt -lssl -lcrypto
Use IPVS Framework       : Yes
IPVS sync daemon support : Yes
IPVS use libnl           : No
Use VRRP Framework       : Yes
Use Debug flags          : No

检查如果Use IPVS Framework :No,则yum安装之。
yum install -y ipvsadm

--with-kernel-dir后接系统kernel内核的目录,确认目录是否存在于/usr/src/kernels

如果make时提示如下错误:

/usr/include/stdint.h:41: error: conflicting types for 'int64_t'
/usr/src/linux/include/linux/types.h:126: error: previous declaration of 'int64_t' was here
/usr/include/stdint.h:56: error: conflicting types for 'uint64_t'
/usr/src/linux/include/linux/types.h:124: error: previous declaration of 'uint64_t' was here
……

此时需要修改源码包中的ip_vs.h头文件
vi keepalived-1.2.2/keepalived/libipvs-2.6/ip_vs.h

#include <sys/types.h>放到#include <linux/types.h>的前面



2.配置keepalived  conf文件
configure时使用默认prefix参数,则目录在:/usr/local/etc/keepalived/keepalived.conf

3.管理文件
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
之后就可以使用service命令来管理keepalived进程了

cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
将配置文件存放到默认读取路径

4.启动keepalived
service keepalived restart
chkconfig keepalived on

检查/var/log/messages 日志文件,查看启动信息。


keepalived.conf文件示例:
master:
#######################################################################
! Configuration File for keepalived

global_defs {
   notification_email {
    xxx@xxx.com
   }
   notification_email_from  xxx@xxx.com
   smtp_server 127.0.0.1 
   smtp_connect_timeout 30
   router_id tracker_id
}


vrrp_instance control_uc {
    state MASTER
    interface eth0
    virtual_router_id 202
    priority 195
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 121212
    }
    virtual_ipaddress {
      10.10.69.252
    }
}





###########################control uc###################

virtual_server 10.10.69.252 9091 {
    delay_loop 3
    lb_algo wrr
    lb_kind DR
    protocol TCP

    sorry_server 10.10.69.125 9091

    real_server 10.10.69.195 9091 {

    weight 195

        TCP_CHECK {  
            connect_timeout 3  
            nb_get_retry 3  
            delay_before_retry 3  
            connect_port 9091
        } 

  }

}

virtual_server 10.10.69.252 9090 {
    delay_loop 3
    lb_algo wrr
    lb_kind DR
    protocol TCP

    sorry_server 10.10.69.125 9090

    real_server 10.10.69.195 9090 {

    weight 195

        TCP_CHECK {  
            connect_timeout 3  
            nb_get_retry 3  
            delay_before_retry 3  
            connect_port 9090
        } 

  }

}
#######################################################################


slave:
#######################################################################
! Configuration File for keepalived

global_defs {
   notification_email {
     xxx@xxx.com
   }
   notification_email_from  xxx@xxx.com
   smtp_server 127.0.0.1 
   smtp_connect_timeout 30
   router_id tracker_id
}


vrrp_instance control_uc {
    state BACKUP
    interface eth0
    virtual_router_id 202
    priority 125
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 121212
    }
    virtual_ipaddress {
      10.10.69.252
    }
}





###########################control uc###################

virtual_server 10.10.69.252 9091 {
    delay_loop 3
    lb_algo wrr
    lb_kind DR
    protocol TCP

    sorry_server 10.10.69.125 9091

    real_server 10.10.69.195 9091 {

    weight 125

        TCP_CHECK {  
            connect_timeout 3  
            nb_get_retry 3  
            delay_before_retry 3  
            connect_port 9091
        } 

  }

}

virtual_server 10.10.69.252 9090 {
    delay_loop 3
    lb_algo wrr
    lb_kind DR
    protocol TCP

    sorry_server 10.10.69.125 9090

    real_server 10.10.69.195 9090 {

    weight 125

        TCP_CHECK {  
            connect_timeout 3  
            nb_get_retry 3  
            delay_before_retry 3  
            connect_port 9090
        } 

  }

}
#######################################################################

















0 0
原创粉丝点击