lvs dr 模型的实现
1、配置Directo
(1)配置vip地址
~]# ifconfig eno16777728:0 172.16.46.9 netmask 255.255.255.255 broadcast 172.16.46.9 up
(2)定义集群服务
~]# ipvsadm -A -t 172.16.46.9:80 -s rr
~]# ipvsadm -a -t 172.16.46.9:80 -r 172.16.46.2 -g
~]# ipvsadm -a -t 172.16.46.9:80 -r 172.16.46.4 -g
2、配置RS服务器
(1)在RS1、RS2修改内核参数
~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
~]# echo 1 > /proc/sys/net/ipv4/conf/eno16777728/arp_ignore
~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
~]# echo 2 > /proc/sys/net/ipv4/conf/eno16777728/arp_announce
(2)在RS1、RS2上配置vip地址,添加其主机路由
~]# ifconfig lo:0 172.16.46.9 netmask 255.255.255.255 broadcast 172.16.46.9 up
~]# route add -host 172.16.46.9 dev lo:0
3、HTTP服务器配置安装
(1)安装http服务
~]# yum install httpd -y
(2)配置web首页
编辑RS1的首页内容为“A”,RS2的首页内容为“B”
(3)启动http服务
~]# systemctl start httpd.service
4、lvs测试
~]# curl http://172.16.46.9
A
~]# curl http://172.16.46.9
B
lvs dr 模持久连接的实现
1、每端口
(1)、定义集群服务
~]# ipvsadm -A -t 172.16.46.9:80 -s rr -p 600
~]# ipvsadm -a -t 172.16.46.9:80 -r 172.16.46.2 -g
~]# ipvsadm -a -t 172.16.46.9:80 -r 172.16.46.4 -g
2、每客户端
(1)、定义集群服务
~]# ipvsadm -A -t 172.16.46.9:0 -s rr -p 600
~]# ipvsadm -a -t 172.16.46.9:0 -r 172.16.46.2 -g
~]# ipvsadm -a -t 172.16.46.9:0 -r 172.16.46.4 -g
3、每FWM
(1)在Directo上搭建CA
~]# cd /etc/pki/CA/
CA]# (umask 077;openssl genrsa -out private/cakey.pem 2048)
CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -day 365
CA]# echo 01 > serial
CA]# touch index.txt
(2)配置SSL服务
1.1 生成私钥
~]# cd /etc/httpd/conf
conf]# mkdir ssl
conf]# cd ssl/
ssl]# (umask 077;openssl genrsa -out httpd.key 2048)
1.2 生成证书签署请求
ssl]# openssl req -new -key httpd.key -out httpd.csr -days 365
1.3 服务器证书签署(在CA服务器上)
CA]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
~]# scp httpd.crt [email protected]:/etc/httpd/conf/ssl
conf.d]# scp -rp ssl/ [email protected]:/etc/httpd/conf/
1.4 安装ssl模块及配置ssl.conf
]# yum install mod_ssl -y
(3)、定义集群服务
~]# iptables -t mangle -A PREROUTING -d 172.16.46.9 -p tcp --dport 80 -j MARK --set-mark 123
~]# iptables -t mangle -A PREROUTING -d 172.16.46.9 -p tcp --dport 443 -j MARK --set-mark 123
~]# ipvsadm -A -f 123 -s rr -p 600
~]# ipvsadm -a -f 123 -r 172.16.46.2 -g
~]# ipvsadm -a -f 123 -r 172.16.46.4 -g
~]# ipvsadm -L
(4)持久连接模版