构建 LVS-DR 群集、配置nginx负载均衡。

目录

[一、基于 CentOS 7 构建 LVS-DR 群集](#一、基于 CentOS 7 构建 LVS-DR 群集)

1、准备四台虚拟机

2、配置负载调度器(192.168.2.130)

3、部署共享存储(192.168.2.133)

4、配置两个Web服务器(192.168.2.131、192.168.2.132)

测试集群

二、配置nginx负载均衡。

1、安装部署nginx

2、负载均衡服务器192.168.2.130

3、web1服务器192.168.2.131,web2服务器192.168.2.132

4、配置hosts文件


一、基于 CentOS 7 构建 LVS-DR 群集

1、准备四台虚拟机

ip 角色
192.168.2.130 vip:192.168.2.200 DR服务器
192.168.2.131 Web服务器1
192.168.2.132 Web服务器2
192.168.2.133 NFS服务器

2、配置负载调度器(192.168.2.130)

systemctl stop firewalld
modprobe ip_vs
cat /proc/net/ip_vs
yum -y install ipvsadm

(1)配置虚拟IP地址(vip:192.168.2.200)

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vim ifcfg-ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.2.200
NETMASK=255.255.255.255


[root@localhost network-scripts]# ifup ens33:0
[root@localhost network-scripts]# ifconfig ens33:0

(2)调整proc响应参数

[root@localhost ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0

(3)手工执行配置负载分配策略

[root@localhost ~]# ipvsadm-save > /etc/sysconfig/ipvsadm
[root@localhost ~]# systemctl start ipvsadm
[root@localhost ~]# ipvsadm -C
[root@localhost ~]# ipvsadm -A -t 192.168.2.200:80 -s rr
[root@localhost ~]# ipvsadm -a -t 192.168.2.200:80 -r 192.168.2.131:80 -g
[root@localhost ~]# ipvsadm -a -t 192.168.2.200:80 -r 192.168.2.132:80 -g
[root@localhost ~]# ipvsadm

3、部署共享存储(192.168.2.133)

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# yum -y install nfs-utils rpcbind
[root@localhost ~]# mkdir /opt/blue /opt/summer
[root@localhost ~]# chmod 777 /opt/blue /opt/summer
[root@localhost ~]# vim /etc/exports
/usr/share *(ro,sync)
/opt/blue 192.168.2.0/24(rw,sync)
/opt/summer 192.168.2.0/24(rw,sync)

[root@localhost ~]# systemctl start nfs.service 
[root@localhost ~]# systemctl start rpcbind.service

4、配置两个Web服务器(192.168.2.131、192.168.2.132)

两个服务器相同的配置步骤

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vim ifcfg-lo:0
[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ifconfig lo:0

配置主机路由

[root@localhost network-scripts]# route add -host 192.168.2.200 dev lo:0
[root@localhost network-scripts]# vim /etc/rc.local
/sbin/route add -host 192.168.2.200 dev lo:0

[root@localhost network-scripts]# chmod +x /etc/rc.d/rc.local

调整内核的 ARP 响应参数以阻止更新 VIP 的 MAC 地址,避免发生冲突

[root@localhost network-scripts]# 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
[root@localhost network-scripts]# yum -y install nfs-utils rpcbind httpd lsof
[root@localhost network-scripts]# systemctl start rpcbind
[root@localhost network-scripts]# systemctl start httpd
[root@localhost network-scripts]# lsof -i:80
[root@localhost network-scripts]# showmount -e 192.168.2.133
--192.168.2.131---
mount.nfs 192.168.2.131:/opt/blue /var/www/html
echo 'this is 131 web' > /var/www/html/index.html

--192.168.2.132---
mount.nfs 192.168.2.132:/opt/summer /var/www/html
echo 'this is 132 web' > /var/www/html/index.html

测试集群

二、配置nginx负载均衡。

1、安装部署nginx

2、负载均衡服务器192.168.2.130

[root@localhost ~]# vim /etc/nginx/conf.d/nginx.conf
 
server{
        listen 80;
        server_name www.first.com;
        location /{
                proxy_pass http://web_server;
   }
}

upstream web_server{
        server 192.168.2.131;
        server 192.168.2.132;
}

3、web1服务器192.168.2.131,web2服务器192.168.2.132

[root@localhost ~]# echo "Welcome to 131 server:192.168.2.131" > /root/index.html
[root@localhost ~]# echo "Welcome to 132 server:192.168.2.132" > /root/index.html

4、配置hosts文件

192.168.2.130 www.first.com
相关推荐
铁锅与大鹅2 小时前
http+nginx
网络协议·nginx·http
千墨4 小时前
VMware安装Centos 9虚拟机+设置共享文件夹+远程登录
linux·运维·centos
s_fox_4 小时前
Nginx Embedded Variables 嵌入式变量解析(4)
java·网络·nginx
致奋斗的我们5 小时前
Nginx反向代理及负载均衡
linux·运维·mysql·nginx·负载均衡·shell·openeluer
不要吃栗子李6 小时前
高级运维:1. 对比 LVS 负载均衡群集的 NAT 模式和 DR 模式,比较其各自的优势 。2. 基于 openEuler 构建 LVS-DR 群集。
运维·负载均衡·lvs
招风的黑耳15 小时前
使用Nginx本地部署Axure生成的HTML文件,局域网内浏览器通过IP和地址访问
nginx·html·axure·本地部署
s_fox_17 小时前
nginx ngx_http_module(7) 指令详解
运维·nginx·http
若云止水18 小时前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_process_options
运维·nginx
s_fox_18 小时前
nginx ngx_http_module(9) 指令详解
运维·nginx·http
去看日出1 天前
Linux(centos)系统安装部署MySQL8.0数据库(GLIBC版本)
linux·数据库·centos