基于 CentOS 7 构建 LVS-DR 群集。
关闭防火墙
[root@localhost ~]# systemctl stop firewalld
安装ifconfig
yum install net-tools.x86_64 -y
准备四台虚拟机
IP 用途
19.168.244.144 客户端
192.168.244.145 lvs
192.168.244.148 RS
192.168.244.149 RS
在DS上
配置LVS虚拟IP
安装ipvsadm
yum install ipvsadm -y
增加IP
ifconfig ens33:200 192.168.244.200 netmask 255.255.255.255 up
手工执行配置添加LVS服务并增加两台RS
[root@localhost ~]# ipvsadm -C
[root@localhost ~]# ipvsadm -A -t 192.168.244.200:80 -s rr
[root@localhost ~]# ipvsadm -a -t 192.168.244.200:80 -r 192.168.226.151:80 -g
在RS端(第三台、第四台) 上
配置Web服务器
yum install httpd -y
配置默认主页
hostname -I 取地址
[root@backup ~]# echo "web test page, ip is `hostname -I`." > /var/www/html/index.html
启动服务
[root@backup ~]# systemctl start httpd
绑定VIP
ifconfig lo:200 192.168.244.200 netmask 255.255.255.255 up
配置主机路由
route add -host 192.168.244.200 dev lo
抑制ARP响应
调整内核参数,关闭arp响应
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
在客户端上测试
[root@localhost ~]# for ((i=1;i<=6;i++)); do curl 192.168.244.200; done
web test page,ip is 192.168.244.148
web test page,ip is 192.168.244.149
web test page,ip is 192.168.244.148
web test page,ip is 192.168.244.149
配置nginx负载均衡。
安装部署nginx
内网服务器145
[root@localhost ~]# vim /etc/nginx/conf.d/vhost.conf
server {
listen 80;
server_name web1.yunjisuan.com;
location / {
root /usr/share/nginx/html/web1;
index index.html index.htm;
}
access_log /usr/share/nginx/html/web1/logs/access_bbs.log main;
}
[root@localhost ~]# mkdir -p /usr/share/nginx/html/web1/logs
[root@localhost ~]# echo "`hostname -I `web1" > /usr/share/nginx/html/web1/index.html
[root@localhost ~]# nginx -t
[root@localhost ~]# systemctl restart nginx
内网服务器148
[root@localhost ~]# vim /etc/nginx/conf.d/vhost.conf
server {
listen 80;
server_name web1.yunjisuan.com;
location / {
root /usr/share/nginx/html/web1;
index index.html index.htm;
}
access_log /usr/share/nginx/html/web1/logs/access_bbs.log main;
}
[root@localhost ~]# mkdir -p /usr/share/nginx/html/web1/logs
[root@localhost ~]# echo "`hostname -I `web1" > /usr/share/nginx/html/web1/index.html
[root@localhost ~]# nginx -t
[root@localhost ~]# systemctl restart nginx
内网服务器144
[root@localhost ~]# vim /etc/nginx/conf.d/lb_test.conf
upstream www_server_pools {
server 192.168.244.145:80 weight=1;
server 192.168.244.148:80 weight=1;
}
server {
listen 80;
server_name web1.haha.com;
location / {
proxy_pass http://www_server_pools;
proxy_set_header Host $host;
}
}
客户端
[root@localhost ~]# vim /etc/hosts
[root@localhost ~]# for ((i=1;i<=6;i++)); do curl web1.haha.com; done
192.168.244.148 web1文章来源地址https://www.toymoban.com/news/detail-671529.html
192.168.244.145 web1文章来源:https://www.toymoban.com/news/detail-671529.html
192.168.244.148 web1
到了这里,关于基于 CentOS 7 构建 LVS-DR 群集,配置nginx负载均衡。的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!