1、基于 CentOS 7 构建 LVS-DR 群集。 2、配置nginx负载均衡

一、基于CentOS7和、构建LVS-DR群集

准备四台虚拟机

ip 作用
192.168.27.150 客户端
192.168.27.151 LVS
192.168.27.152 RS
192.168.27.152 RS

关闭防火墙

python 复制代码
[root@localhost ~]# systemctl stop firewalld

安装ifconfig

python 复制代码
yum install net-tools.x86_64 -y

1、DS上

1.1 配置LVS虚拟IP
python 复制代码
安装ipvsadm
yum install ipvsadm -y
 
增加IP
ifconfig ens33:200 192.168.27.200 netmask 255.255.255.255 up
1.2 手工执行配置添加LVS服务并增加两天RS
python 复制代码
[root@localhost ~]# ipvsadm -C
[root@localhost ~]# ipvsadm -A -t 192.168.27.200:80 -s rr
[root@localhost ~]# ipvsadm -a -t 192.168.27.200:80 -r 192.168.27.151:80 -g
[root@localhost ~]# ipvsadm -a -t 192.168.27.200:80 -r 192.168.27.152:80 -g

2、在RS端(第三、四台)上

2.1 配置WEB服务器
python 复制代码
yum install httpd -y

2.2 配置默认主页

python 复制代码
hostname -I 取地址
 
[root@backup ~]# echo "web test page, ip is `hostname -I`." > /var/www/html/index.html

2.3 启动服务

python 复制代码
[root@backup ~]# systemctl start httpd

2.4 测试:在客户端访问WEB服务器

python 复制代码
[root@localhost ~]# curl 192.168.27.147
web test page, ip is 192.168.27.147 .
[root@localhost ~]# curl 192.168.27.148
web test page, ip is 192.168.27.148 .

2.5 绑定VIP

python 复制代码
ifconfig lo:200 192.168.27.200 netmask 255.255.255.255 up

2.6 配置主机路由

python 复制代码
route add -host 192.168.27.200 dev lo

2.7 抑制ARP响应

python 复制代码
调整内核参数,关闭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

二、配置nginx负载均衡

环境准备

python 复制代码
主机名 ip地址        作用
node1 192.168.27.140 负载均衡服务器
node2 192.168.27.141 Web服务器
node3 192.168.27.142 Web服务器

配置

1、配置主机文件vhost.conf

python 复制代码
[root@node1 ~]# vim /etc/nginx/conf.d/vhost.conf
	upstream web_pools {
      server 192.168.27.141:80;
      server 192.168.27.142:80;
	}
	server {
      listen 80;
      server_name www1.ming.com;
 
      location / {
        proxy_pass http://web_pools;
      }
}
解释:proxy_pass 是反向代理

2、检查语法并重启服务

python 复制代码
#检查语法是否正确
[root@node1 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

#重启服务
[root@node1 ~]# systemctl restart nginx

3、配置hosts文件

python 复制代码
#在linux中修改
[root@node1 ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.27.140 www1.ming.com
#测试
[root@node1 ~]# for((i=1;i<=4;i++))
> do
> curl www1.ming.com
> done
web test page,ip is 192.168.27.141 
web test page ,ip is 192.168.27.142 
web test page,ip is 192.168.27.141 
web test page ,ip is 192.168.27.142 
相关推荐
做运维的阿瑞1 小时前
CentOS 7 停止维护后 YUM 源配置速查手册
linux·运维·centos
草莓熊Lotso2 小时前
Linux 权限管理进阶:从 umask 到粘滞位的深度解析
linux·运维·服务器·人工智能·ubuntu·centos·unix
Thexhy12 小时前
在 CentOS 7 的 Linux 系统中配置 NFS
linux·运维·学习·centos
就叫飞六吧13 小时前
Nginx 主要的几种负载均衡模式
运维·nginx·负载均衡
程序员陆通21 小时前
CentOS/AlmaLinux 9 中 SSH 服务启动失败:OpenSSL 版本不匹配解决
linux·centos·ssh
李少兄21 小时前
解决 CentOS 8 报错:Failed to download metadata for repo ‘BaseOS‘
linux·运维·centos
脚踏实地的大梦想家1 天前
【Docker】P2 Docker 命令:从Nginx部署到镜像分享的全流程指南
java·nginx·docker
ayaya_mana2 天前
CentOS 7/8/9 一键安装 Python 3.10+ 并配置默认版本
linux·python·centos
IT 小阿姨(数据库)2 天前
PostgreSQL pg_stat_bgwriter 视图各个字段详解
linux·数据库·sql·postgresql·centos
Thexhy2 天前
在centos 7上配置FIP服务器的详细教程!!!
linux·运维·centos