在DR模式基础上配置keepalived,DR配置请看前一篇博客
主机名称 | 操作系统 | IP地址 | 安装包 |
---|---|---|---|
DR服务器 | CentOS7.6 | 内网:192.168.40.80 | ipvsadm |
备DR服务器 | CentOS7.6 | 内网:192.168.40.81 | ipvsadm |
NFS服务器 | CentOS7.6 | 192.168.40.50 | rpcbind、nfs-utils |
node1 | CentOS7.6 | 192.168.40.60 | rpcbind、nfs-utils、httpd |
node2 | CentOS7.6 | 192.168.40.61 | rpcbind、nfs-utils、httpd |
客户端 | CentOS7.6 | 192.168.40.88 | / |
NFS服务器:192.168.40.50
这里的步骤和上一篇一致,这里就仅发布操作文档
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
yum -y install nfs-utils rpcbind
systemctl start rpcbind.service
systemctl start nfs.service
systemctl enable nfs.service
systemctl enable rpcbind.service
mkdir /opt/rain
mkdir /opt/drop
chmod 777 /opt/rain
chmod 777 /opt/drop
vim /etc/exports
/opt/rain 192.168.40.0/24(rw,sync)
/opt/drop 192.168.40.0/24(rw,sync)
exportfs -rv
node1:192.168.40.80 虚拟地址 (VIP):192.168.40.66
node2:192.168.40.81 虚拟地址 (VIP):192.168.40.66
vim /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.40.66 #VIP
NETMASK=255.255.255.255
ONBOOT=yes
ifup lo:0
ifconfig lo:0
#设置临时的路由,重启失效
route add -host 192.168.40.66 dev lo:0
#开机自动添加路由
vim /etc/rc.local
/sbin/route add -host 192.168.40.66 dev lo:0
chmod +x /etc/rc.d/rc.local
vim /etc/sysctl.conf
......
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
sysctl -p
yum install -y nfs-utils rpcbind httpd
systemctl start rpcbind
systemctl enable rpcbind
systemctl start httpd.service
systemctl enable httpd.service
node1:192.168.40.60
showmount -e 192.168.40.80
mount.nfs 192.168.40.60:/opt/rain /var/www/html
echo 'this is rain123456789 web!' > /var/www/html/index.html
node2:192.168.40.61
showmount -e 192.168.40.81
mount.nfs 192.168.40.61:/opt/drop /var/www/html
echo 'this is drop987654321 web!' > /var/www/html/index.html
(主DR)主负载调度器:192.168.40.80
(备DR)备负载调度器:192.168.40.81
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
modprobe ip_vs
cat /proc/net/ip_vs
yum -y install ipvsadm
vim /etc/sysctl.conf
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
sysctl -p
主:192.168.40.80
ipvsadm-save > /etc/sysconfig/ipvsadm
systemctl start ipvsadm.service
ipvsadm -C
#这里-t指定的虚拟地址为本机ens33网卡ip
ipvsadm -A -t 192.168.40.80:80 -s rr
ipvsadm -a -t 192.168.40.80:80 -r 192.168.40.60:80 -g
ipvsadm -a -t 192.168.40.80:80 -r 192.168.40.61:80 -g
ipvsadm
ipvsadm -ln
备:192.168.40.81
ipvsadm-save > /etc/sysconfig/ipvsadm
systemctl start ipvsadm.service
ipvsadm -C
#这里-t指定的虚拟地址为本机ens33网卡ip
ipvsadm -A -t 192.168.40.81:80 -s rr
ipvsadm -a -t 192.168.40.81:80 -r 192.168.40.60:80 -g
ipvsadm -a -t 192.168.40.81:80 -r 192.168.40.61:80 -g
ipvsadm
ipvsadm -ln
主DR负载调度器1:192.168.40.80
备DR负载调度器2:192.168.40.81
yum -y install keepalived
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
vim keepalived.conf
......
#定义全局参数
global_defs {
#10行修改,邮件服务指向本地
smtp_server 127.0.0.1
#12行修改,指定服务器(路由器)的名称,主备服务器名称须不同,主为LVS_01,备为LVS_02
router_id LVS_01
#14行修改;加注释;vrrp_strict:严格遵守VRRP协议。下列情况将会阻止启动Keepalived:1. 没有VIP地址。2. 单播邻居。3. 在VRRP版本2中有IPv6地址。
#vrrp_strict
}
#定义VRRP热备实例参数
vrrp_instance VI_1 {
#20行修改;指定热备状态,主为MASTER,备为BACKUP
state MASTER
#21行修改;指定承载vip地址的物理接口
interface ens33
#22行修改;指定虚拟路由器的ID号,每个热备组保持一致
virtual_router_id 66
#23行修改;指定优先级,数值越大优先级越高,主为100,备为90
priority 100
#通告间隔秒数(心跳频率)
advert_int 1
#定义认证信息,每个热备组保持一致
authentication {
#认证类型
auth_type PASS
#27行修改,指定验证密码,主备服务器保持一致
auth_pass 123123
}
#指定群集vip地址
virtual_ipaddress {
192.168.40.66
}
}
#34行修改,指定虚拟服务器地址(VIP)、端口,定义虚拟服务器和Web服务器池参数
virtual_server 192.168.40.66 80 {
#健康检查的间隔时间(秒)
delay_loop 6
#指定调度算法,轮询(rr)
lb_algo rr
#37行修改,指定群集工作模式,直接路由(DR)
lb_kind DR
#连接保持时间(秒)
persistence_timeout 50
#应用服务采用的是TCP协议
protocol TCP
#41行修改,指定第一个Web节点的地址、端口
real_server 192.168.40.60 80 {
#节点的权重
weight 1
#43行删除,添加以下健康检查方式
TCP_CHECK {
#添加检查的目标端口
connect_port 80
#添加连接超时(秒)
connect_timeout 3
#添加重试次数
nb_get_retry 3
#添加重试间隔
delay_before_retry 4
}
}
#添加第二个 Web节点的地址、端口
real_server 192.168.40.61 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
}
#删除后面多余的配置
systemctl start keepalived
#查看虚拟网卡vip
ip addr show dev ens33
192.168.40.81
这里通过 2台客户端访问
192.168.40.77及192.168.40.88