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 
相关推荐
IT 小阿姨(数据库)3 小时前
PostgreSQL REST API 介绍
运维·数据库·sql·postgresql·centos
stark张宇6 小时前
攻克 CRMRB 部署难点:从 PHP 扩展、数据库配置到进程守护
nginx·centos·php
罗政6 小时前
【免费】轻量级服务器centos监控程序+内存+cpu+nginx+适合小型站长使用
服务器·nginx·centos
椎49519 小时前
苍穹外卖前端nginx错误之一解决
运维·前端·nginx
noravinsc1 天前
centos如何做的时间同步
linux·运维·centos
2301_787328491 天前
25.负载均衡-Nginx、HAProxy、LVS 全解析
nginx·负载均衡·lvs
siriuuus1 天前
Nginx 负载均衡调度算法
运维·nginx·负载均衡
tcwgq1 天前
Centos Stream 8 搭建Cas Server
linux·elasticsearch·centos
1白天的黑夜11 天前
Linux (5)| 入门进阶:Linux 权限管理的基础规则与实践
linux·运维·服务器·centos
IT 小阿姨(数据库)1 天前
PostgreSQL etcd 集群介绍
运维·数据库·sql·postgresql·centos·etcd