Linux 安装运行 Keepalived
Linux Keepalived About 2,706 words前置条件
安装gcc
、openssl-devel
、popt-devel
。
yum install -y gcc openssl-devel popt-devel
下载 Keepalived
wget https://www.keepalived.org/software/keepalived-2.0.18.tar.gz
解压
tar zxvf keepalived-2.0.18.tar.gz
编译安装
进入解压目录
cd keepalived-2.0.18.tar.gz
配置
./configure
编译安装
make && make install
运行前配置
以下所有配置文件都在下载后解压的keepalived-2.0.18
文件夹下。
- 拷贝
keepalived
执行文件
cp keepalived-2.0.18/keepalived/etc/init.d/keepalived /etc/init.d/
- 创建
keepalived
文件夹
mkdir /etc/keepalived
- 拷贝配置文件
cp keepalived-2.0.18/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
- 拷贝系统配置
cp keepalived-2.0.18/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
- 拷贝
keepalived
命令至/usr/sbin
下
cp /usr/local/sbin/keepalived /usr/sbin/
修改 Keepalived 配置
vim /etc/keepalived/keepalived.conf
配置示例
MASTER
! 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_NGINX_MASTER
vrrp_skip_check_adv_addr
#vrrp_strict # 严格遵守vvrp协议,不注释访问不了VIP
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER # 指定keepalived的角色,MASTER为主,BACKUP为备
interface eth0
virtual_router_id 51 # 虚拟路由编号,主从要一致
priority 100 # 优先级,数值越大,获取处理请求的优先级越高,step建议为50
advert_int 1 # 检查间隔,默认为1s(vrrp组播周期秒数)
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
#192.168.200.16
#192.168.200.17
#192.168.200.18
192.168.153.50/24 # 定义虚拟ip(VIP),可多设,每行一个
}
}
BACKUP
! 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_NGINX_BACKUP
vrrp_skip_check_adv_addr
#vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state BACKUP # 指定keepalived的角色,MASTER为主,BACKUP为备
interface eth0
virtual_router_id 51 # 虚拟路由编号,主从要一致
nopreempt # 不抢占VIP,MASTER恢复时VIP交给MASTER,只在BACKUP设置
priority 50 # 优先级,数值越大,获取处理请求的优先级越高,step建议为50
advert_int 1 # 检查间隔,默认为1s(vrrp组播周期秒数)
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
#192.168.200.16
#192.168.200.17
#192.168.200.18
192.168.153.50/24 # 定义虚拟ip(VIP),可多设,每行一个
}
}
添加防火墙规则
编辑iptables
文件
vim /etc/sysconfig/iptables
接受vrrp
(必须配置在REJECT
之上)
-A INPUT -p vrrp -j ACCEPT
启动服务
service keepalived start
查看日志
tail -f /var/log/messages
Views: 2,654 · Posted: 2019-08-06
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...