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 
相关推荐
冰橙子id5 小时前
centos7编译安装LNMP架构
mysql·nginx·架构·centos·php
十年磨一剑~5 小时前
centos查看开启关闭防火墙状态
linux·运维·centos
鳄鱼杆7 小时前
服务器 | Centos 9 系统中,如何部署SpringBoot后端项目?
服务器·spring boot·centos
杰哥技术分享7 小时前
在 CentOS 上安装 Docker 和 Docker Compose 并配置使用国内镜像源
linux·docker·centos
myhyyyyyy11 小时前
centos中的ulimit命令
centos
jiunian_cn1 天前
【Linux】centos软件安装
linux·运维·centos
睡觉待开机1 天前
0. MySQL在Centos 7环境安装
数据库·mysql·centos
舰长1151 天前
Ubuntu挂载本地镜像源(像CentOS 一样挂载本地镜像源)
linux·ubuntu·centos
米粉03051 天前
深入剖析Nginx:从入门到高并发架构实战
java·运维·nginx·架构
Chuncheng's blog1 天前
CentOS 7如何编译安装升级gcc至7.5版本?
linux·运维·c++·centos