搭建memcached 主主复制+keepalived 高可用
第一台:
yum -y install keepalived
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 eth0
virtual_router_id 51
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.100
}
}
virtual_server 192.168.1.100 11211 {
delay_loop 6
lb_algo rr
lb_kind NAT
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.10 11211 {
weight 1
notify_down /root/memcached.sh
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 11211
}
}
}
echo "/usr/bin/systemctl stop keepalived"> /root/memcached.sh
chmod +x memcached.sh
systemctl start keepalived
ip addr show dev eth0
第二台:
yum -y install keepalived
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 eth0
virtual_router_id 51
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.100
}
}
virtual_server 192.168.1.100 11211 {
delay_loop 6
lb_algo rr
lb_kind NAT
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.11 11211 {
weight 1
notify_down /root/memcached.sh
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 11211
}
}
}
echo "/usr/bin/systemctl stop keepalived"> /root/memcached.sh
chmod +x memcached.sh
systemctl start keepalived
ip addr show dev eth0
验证(断掉有虚拟ip的一台):
killall memcached #杀死memcached进程
netstat -napt |grep memcached 查询相关进程