一、先配置好DR模式
二、模拟实验
1.新建一个虚拟机server4并配置好ip和主机名
2.源码编译keepalived
server1:
tar zxf keepalived-2.0.17.tar.gz
yum install -y gcc openssl-devel
cd keepalived-2.0.17/
./configure --prefix=/usr/local/keepalived --with-init=systemd
make && make install
scp keepalived-2.0.17.tar.gz root@172.25.2.4:/root
server4:
tar zxf keepalived-2.0.17.tar.gz
yum install -y gcc openssl-devel
cd keepalived-2.0.17/
./configure --prefix=/usr/local/keepalived --with-init=systemd
make && make install
ln -s /usr/local/keepalived/etc/keepalived/ /etc/
制作软链接并编辑配置文件
ln -s /usr/local/keepalived/etc/keepalived/ /etc/
vim /etc/keepalived/keepalived.conf
写入:
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
interface eth0
virtual_router_id 2
virtual_ipaddress {
172.25.2.100
}
virtual_server 172.25.2.100 80
lb_kind DR
real_server 172.25.2.2.2 80 {
TCP_CHECK {
weight 1
connect_timeout 3
retry 3
delay_before_retry 3
}
}
#把real_server以下的全部删除 再复制一个server3的
ip addr del 172.25.2.100/24 dev eth0
scp /etc/keepalived/keepalived.conf server4:/etc/keepalived/ #将编辑好的配置文件发送到server4
3.测试:
systemctl start keepalived.service
ip a
在server1上:关闭keepalived服务看ip是否会漂移到server4上
server1上的172.25.2.100 ip消失
server4:出现172.25.2.100 ip
查看是否轮循:
关掉server3的httpd服务,会在server1上受到邮件: