基于 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

相关推荐
红肤色4 分钟前
【网络安全基础】CentOS 7超详细安装教程(含镜像)
linux·运维·服务器·安全·网络安全·centos
良许Linux8 分钟前
为什么不让程序员直接对接客户,而是通过产品经理?
linux
钡铼技术物联网关12 分钟前
告别外置电路:IEPE接口如何重构精密测量生态?
linux·arm开发·5g·边缘计算
程序猿(雷霆之王)26 分钟前
Linux——冯 • 诺依曼体系结构&操作系统初识
linux·运维·服务器
宁zz1 天前
乌班图安装jenkins
运维·jenkins
大丈夫立于天地间1 天前
ISIS协议中的数据库同步
运维·网络·信息与通信
cg50171 天前
Spring Boot 的配置文件
java·linux·spring boot
暮云星影1 天前
三、FFmpeg学习笔记
linux·ffmpeg
rainFFrain1 天前
单例模式与线程安全
linux·运维·服务器·vscode·单例模式
GalaxyPokemon1 天前
Muduo网络库实现 [九] - EventLoopThread模块
linux·服务器·c++