首页 > 代码库 > keepalived简单快速配置

keepalived简单快速配置

1、官方下载

wget http://www.keepalived.org/software/keepalived-XXXX.tar.gz

2、解压,编译安装

tar zxvf keepalived-XXXX.tar.gz
./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.XXXXXXXX/
make && make install
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
service keepalived start

在使用./configure 时,出现了以下错误:

checking openssl/ssl.h usability... no
checking openssl/ssl.h presence... no
checking for openssl/ssl.h... no
configure: error: 
  !!! OpenSSL is not properly installed on your system. !!!
  !!! Can not include OpenSSL headers files.            !!!

解决方法:安装openssl和openssl-devel包,然后从新编译配置文件

[root@wlm keepalived-1.3.2]# yum install openssl openssl-devel
[root@wlm keepalived-1.3.2]# ./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.XXXXXXXX/
Keepalived configuration
------------------------
Keepalived version       : 1.3.2
Compiler                 : gcc
Preprocessor flags       : 
Compiler flags           : -Wall -Wunused -Wstrict-prototypes -Wextra -g -O2
Linker flags             : 
Extra Lib                : -ldl -lssl -lcrypto 
Use IPVS Framework       : Yes
IPVS use libnl           : No
IPVS syncd attributes    : No
IPVS 64 bit stats        : No
fwmark socket support    : Yes
Use VRRP Framework       : Yes
Use VRRP VMAC            : Yes
Use VRRP authentication  : Yes
With ip rules/routes     : Yes
SNMP vrrp support        : No
SNMP checker support     : No
SNMP RFCv2 support       : No
SNMP RFCv3 support       : No
DBUS support             : No
SHA1 support             : No
Use Debug flags          : No
Stacktrace support       : No
Memory alloc check       : No
libnl version            : None
Use IPv4 devconf         : No
Use libiptc              : No
Use libipset             : No
init type                : systemd
Build genhash            : Yes
Build documentation      : No

3、配置

Master与Backup 的配置文件

Master:

! Configuration File for keepalived
global_defs {
   notification_email {
      15251076067@163.com
   }
   notification_email_from king_819@163.com
   smtp_server smtp.163.com
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
# VIP1
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    mcast_src_ip 192.168.18.211
    priority 100
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.18.200
    }
}

BackUP:

! Configuration File for keepalived
global_defs {
   notification_email {
      15251076067@163.com
   }
   notification_email_from king_819@163.com
   smtp_server smtp.163.com
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
# VIP1
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    mcast_src_ip 192.168.18.212
    priority 90
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.18.200
    }
}



以下是在CentOS上使用yum安装配置:

1、安装

 yum install keepalived -y

2、MASTER和BACKUP配置

MASTER

[root@wlm ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER    # 配置为主
    interface eno16777736    # 设置网卡
    virtual_router_id 51    # 虚拟路由ID,全局唯一
    priority 100        # 优先级,权重值
    advert_int 1        
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.10.10.50        # IP地址
    }
}

BACKUP

! Configuration File for keepalived

global_defs {
   notification_email {
        871703234@qq.com
   }

   notification_email_from 871703234@qq.com
   smtp_server smtp.qq.com
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eno16777736
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.10.10.50
    }
}

3、验证

两台重启服务

[root@wlm ~]# systemctl restart keepalived.service

使用ip add sh命令查看,在主的上面

[root@wlm keepalived]# ip add sh
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:4b:3e brd ff:ff:ff:ff:ff:ff
    inet 10.10.10.10/24 brd 10.10.10.255 scope global eno16777736
       valid_lft forever preferred_lft forever
    inet 10.10.10.50/32 scope global eno16777736
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fea3:4b3e/64 scope link 
       valid_lft forever preferred_lft forever

使用systemctl stop keepalived.service,VIP会自动切换到备用的上面去。



本文出自 “汪立明” 博客,请务必保留此出处http://afterdawn.blog.51cto.com/7503144/1888682

keepalived简单快速配置