通过Keepalived实现Redis双机
Redis是一个高性能的kv数据库,我们用Redis构建了一套消息系统。
Redis架构为Master Slave结构,通过keepalived进行状态检查,故障迁移,达到高可用的目的。
下载keepalived
#wget http://www.keepalived.org/software/keepalived-1.2.9.tar.gz
编译安装keepalived,编译时需要指定内核目录,否则Use IPVS Framework为NO。
#./configure --prefix=/usr/local/keepalived \ --with-kernel-dir=/usr/src/kernels/3.9.10-100.fc17.x86_64 \ --enable-snmp \ --enable-sha1
配置keepalived信息如下图:
编译与安装:
#make && make install
结果报错了,重新指定配置参数,去掉 --with-kernel-dir
配置信息如下图:
在次编译安装,OK,顺利通过安装成功!
现在可以将/usr/local/keepalived下相应文件拷贝到系统对应目录
配置keepalived
在配置keepalived.conf配置文件之前先备份一份keepalived.conf文件后在进行配置
#cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
在Master机器配置keepalived
[root@node3 etc]# more /etc/keepalived/keepalived.conf global_defs { notification_email { [email protected] } notification_email_from keepalived@node3 router_id node3 } vrrp_instance mes_Redis { state MASTER interface eth0 garp_master_delay 10 smtp_alert virtual_router_id 3 priority 100 nopreempt advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.172.100 } }
在Slave机器配置keepalived
[root@node4 etc]# more /etc/keepalived/keepalived.conf global_defs { notification_email { [email protected] } notification_email_from keepalived@node4 router_id node4 } vrrp_instance mes_Redis { state BACKUP interface eth0 garp_master_delay 10 smtp_alert virtual_router_id 3 priority 90 nopreempt advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.172.100 } }
配置防火墙
打开Master和Slave机器上的防火墙
[root@node3 ~]# more /etc/sysconfig/iptables # Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 9022 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT -A INPUT -p 112 -j ACCEPT -A INPUT -p 255 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT [root@node3 ~]# iptables-restore /etc/sysconfig/iptables
Keepalived 的详细介绍:请点这里
Keepalived 的下载地址:请点这里
推荐阅读:
相关推荐
MichelinMessi 2020-06-21
GenvenLiang 2020-06-15
Jaystrong 2020-06-10
zwmnhao0 2020-06-07
DriveCar 2020-06-06
CurrentJ 2020-05-28
xiunai 2020-05-15
极地雪狼 2020-05-15
后厂村老司机 2020-04-19
yongzhang 2020-05-11
快乐de馒头 2020-04-22
yungame 2020-04-21
快乐de馒头 2020-04-11
畅聊架构 2020-03-28
泥淖 2020-03-26
yevvzi 2020-03-01
xcznb 2020-02-28
sunnyxuebuhui 2020-02-16
OwenJi 2020-02-15