当前位置: 首页 > news >正文

CentOS 7 构建 LVS-DR 群集 nginx负载均衡

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

DS(Director Server):DIP 192.168.231.132 & VIP 192.168.231.200

[root@132 ~]# nmcli c show
NAME   UUID                                  TYPE      DEVICE 
ens33  c89f4a1a-d61b-4f24-a260-6232c8be18dc  ethernet  ens33  
[root@132 ~]# nmcli c m ens33 +ipv4.addresses 192.168.231.200/24
[root@132 ~]# nmcli c up ens33
[root@132 ~]# yum install ipvsadm -y
[root@132 ~]# ipvsadm -A -t 192.168.231.200:80 -s rr
[root@132 ~]# ipvsadm -a -t 192.168.231.200:80 -r 192.168.231.136 -g -w 1
[root@132 ~]# ipvsadm -a -t 192.168.231.200:80 -r 192.168.231.137 -g -w 1
[root@132 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.231.200:80 rr-> 192.168.231.136:80           Route   1      0          0         -> 192.168.231.137:80           Route   1      0          0   

rs1

[root@137 ~]# yum install net-tools.x86_64
[root@137 ~]# yum install httpd -y
[root@137 ~]# echo "web test pages ip is `hostname -I`" > /var/www/html/index.html
[root@137 ~]# systemctl restart httpd
[root@137 ~]# ifconfig lo:200 192.168.231.200 netmask 255.255.255.255 up
[root@137 ~]# route add -host 192.168.231.200 dev lo
[root@137 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.231.2   0.0.0.0         UG    100    0        0 ens33
192.168.231.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.231.200 0.0.0.0         255.255.255.255 UH    0      0        0 lo
[root@137 ~]# echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@137 ~]# echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@137 ~]# echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@137 ~]# echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce

rs2

[root@136 ~]# yum install net-tools.x86_64
[root@136 ~]# yum install httpd -y
[root@136 ~]# echo "web test pages ip is `hostname -I`" > /var/www/html/index.html
[root@136 ~]# ifconfig lo:200 192.168.231.200 netmsak 255.255.255.255 up
[root@136 ~]# ifconfig lo:200 192.168.231.200 netmask 255.255.255.255 up
[root@136 ~]# echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@136 ~]# echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@136 ~]# echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@136 ~]# echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce

测试


2、配置nginx负载均衡。

132内网服务器

yum localinstall  nginx-1.22.0-1.el7.ngx.x86_64.rpm
[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
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost ~]# systemctl restart nginx

136内网服务器

yum localinstall  nginx-1.22.0-1.el7.ngx.x86_64.rpm
[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
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost ~]# systemctl restart nginx

137代理服务器

yum localinstall  nginx-1.22.0-1.el7.ngx.x86_64.rpm
[root@localhost ~]# vim /etc/nginx/conf.d/lb_test.conf
upstream www_server_pools {server 192.168.231.132:80 weight=1;server 192.168.231.136: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
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.231.137 web1.haha.com
[root@localhost ~]# for ((i=1;i<=4;i++)); do curl web1.haha.com; done
192.168.231.136 web1
192.168.231.132 web1
192.168.231.136 web1
192.168.231.132 web1

http://www.lryc.cn/news/113181.html

相关文章:

  • ESP32学习笔记(52)————三轴加速度ADXL345使用(SPI方式)
  • Camunda 7.x 系列【4】 Camunda Modeler 功能介绍
  • 呼叫中心系统管理和优化的关键指标
  • UML箭头汇总
  • 【STM32零基础入门教程03】GPIO输入输出之GPIO框图分析
  • 高效管理,PDM系统与BOM系统携手合作
  • Elasticsearch 使用scroll滚动技术实现大数据量搜索、深度分页问题 和 search
  • 了解Swarm 集群管理
  • 【Docker】Docker私有仓库的使用
  • 基于arcFace+faiss开发构建人脸识别系统
  • C#设计模式(15)命令模式(Command Pattern)
  • 快速排序和qsort函数详解详解qsort函数
  • 搭建 elasticsearch8.8.2 伪集群 windows
  • C++ 运算符重载为成员函数
  • 51单片机程序烧录教程
  • Linux C++ 链接数据库并对数据库进行一些简单的操作
  • Linux进程间通信--msgsnd函数的作用
  • P1629 邮递员送信(最短路)(内附封面)
  • 网络安全--原型链污染
  • Harbor企业镜像仓库部署
  • 【AI】《动手学-深度学习-PyTorch版》笔记(十一):分类问题-softmax回归
  • 【排序算法略解】(十种排序的稳定性,时间复杂度以及实现思想)(含代码)(完工于2023.8.3)
  • 学编程实用网站
  • Camunda 7.x 系列【5】 员工请假流程模型
  • 【C++从0到王者】第十七站:手把手教你写一个stack和queue及deque的底层原理
  • ffmpeg.c源码与函数关系分析
  • GD32F103待机模式与唤醒
  • 【Linux初阶】基础IO - 动静态库 | 初识、生成、链接、加载
  • 为Git仓库设置签名信息
  • iOS开发Swift开发UI页面链式调用库推荐