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

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

关闭防火墙

root@localhost \~\]# systemctl stop firewalld 安装ifconfig yum install net-tools.x86_64 -y 准备四台虚拟机 IP 用途 19.168.244.144 客户端 192.168.244.145 lvs 192.168.244.148 RS 192.168.244.149 RS 在DS上 配置LVS虚拟IP 安装ipvsadm yum install ipvsadm -y 增加IP ifconfig ens33:200 192.168.244.200 netmask 255.255.255.255 up 手工执行配置添加LVS服务并增加两台RS \[root@localhost \~\]# ipvsadm -C \[root@localhost \~\]# ipvsadm -A -t 192.168.244.200:80 -s rr \[root@localhost \~\]# ipvsadm -a -t 192.168.244.200:80 -r 192.168.226.151:80 -g ### **在RS端(第三台、第四台) 上** ### **配置Web服务器** yum install httpd -y ### **配置默认主页** hostname -I 取地址 \[root@backup \~\]# echo "web test page, ip is \`hostname -I\`." \> /var/www/html/index.html ### **启动服务** \[root@backup \~\]# systemctl start httpd ### **绑定VIP** ifconfig lo:200 192.168.244.200 netmask 255.255.255.255 up ### **配置主机路由** route add -host 192.168.244.200 dev lo ### **抑制ARP响应** 调整内核参数,关闭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 ## **在客户端上测试** \[root@localhost \~\]# for ((i=1;i\<=6;i++)); do curl 192.168.244.200; done web test page,ip is 192.168.244.148 web test page,ip is 192.168.244.149 web test page,ip is 192.168.244.148 web test page,ip is 192.168.244.149 **配置nginx负载均衡。** ## **安装部署nginx** ## **内网服务器145** \[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 \[root@localhost \~\]# systemctl restart nginx ## **内网服务器148** \[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 \[root@localhost \~\]# systemctl restart nginx ## **内网服务器144** \[root@localhost \~\]# vim /etc/nginx/conf.d/lb_test.conf upstream www_server_pools { server 192.168.244.145:80 weight=1; server 192.168.244.148: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 \[root@localhost \~\]# for ((i=1;i\<=6;i++)); do curl web1.haha.com; done 192.168.244.148 web1 192.168.244.145 web1 192.168.244.148 web1

相关推荐
板鸭〈小号〉1 天前
connect 的断线重连
运维·服务器
wydaicls1 天前
Linux 内核伙伴系统在快速路径分配内存时,对一个内存区域(Zone)进行水位线检查和内存压力评估的关键逻辑
linux·服务器
今天只学一颗糖1 天前
Linux学习笔记--GPIO子系统和PinCtrl子系统
linux·笔记·学习
黄昏晓x1 天前
Linux----权限
linux·运维·服务器
小白不想白a1 天前
【shell】每日shell练习(系统服务状态监控/系统性能瓶颈分析)
linux·运维·服务器
一匹电信狗1 天前
【MySQL】数据库的相关操作
linux·运维·服务器·数据库·mysql·ubuntu·小程序
迦蓝叶1 天前
JAiRouter v1.0.0 正式发布:企业级 AI 服务网关的开源解决方案
java·运维·人工智能·网关·spring·ai·开源
bugtraq20211 天前
为什么.NET的System.IO.Compression无法解压zlib流
linux·运维·服务器
咖啡教室1 天前
每日一个计算机小知识:Linux
linux·后端
insight^tkk1 天前
【Docker】记录一次使用docker部署dify网段冲突的问题
运维·人工智能·docker·ai·容器