LVS负载均衡化群集

              LVS负载均衡化群集

一,基本配置
Centos01:
在这里插入图片描述
在这里插入图片描述

Centos02:
在这里插入图片描述
在这里插入图片描述

Centos03:
在这里插入图片描述
在这里插入图片描述

Centos04:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
二.配置LVS服务器
1.安装LVS(centos04,系统盘)
安装ipvsadm
[root@centos08 ~]# yum -y install ipvsadm
在这里插入图片描述

设置服务开机自动启动
[root@centos08 ~]# systemctl enable ipvsadm
在这里插入图片描述
清空默认规则
[root@centos08 ~]# ipvsadm -C
在这里插入图片描述

查看规则
在这里插入图片描述
保存
[root@centos08 ~]# ipvsadm-save
在这里插入图片描述

2.搭建服务器池(centos01,centos02,系统盘)
Centos01:
[root@centos ~]# yum -y install httpd
在这里插入图片描述

[root@centos ~]# echo “www.benet.com” > /var/www/html/index.html
[root@centos ~]# systemctl start httpd
[root@centos ~]# systemctl enable httpd
在这里插入图片描述

Centos02:
[root@centos ~]# yum -y install httpd
在这里插入图片描述

[root@centos ~]# echo “www.accp.com” > /var/www/html/index.html
[root@centos ~]# systemctl start httpd
[root@centos ~]# systemctl enable httpd
在这里插入图片描述

3.开启路由转发功能(centos04)
[root@centos08 ~]# vim /etc/sysctl.conf
在这里插入图片描述

net.ipv4.ip_forward = 1
在这里插入图片描述

[root@centos08 ~]# sysctl -p
在这里插入图片描述

4.配置LVS的NAT模式 (centos04)
创建负载均衡器指定IP地址192.168.200.40端口80算法使用rr
[root@centos08 ~]# ipvsadm -A -t 192.168.200.40:80 -s rr
在这里插入图片描述

负载均衡池添加网站服务器
[root@centos08 ~]# ipvsadm -a -t 192.168.200.40:80 -r 192.168.100.10:80 -m -w 1
[root@centos08 ~]# ipvsadm -a -t 192.168.200.40:80 -r 192.168.100.20:80 -m -w 1
在这里插入图片描述
保存规则
[root@centos08 ~]# ipvsadm-save
在这里插入图片描述

查看规则
[root@centos08 ~]# ipvsadm -Ln
在这里插入图片描述

轮寻验证:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

5.安装共享存储(centos03,centos01,centos02,系统盘)
Centos03:
安装共享存储服务
[root@centos07 ~]# yum -y install rpcbubd nfs-utils
在这里插入图片描述

创建共享存储根目录
[root@centos07 ~]# mkdir /web
[root@centos07 ~]# echo “www.nfs.com” > /web/index.html
在这里插入图片描述

配置NFS允许WEB服务器访问存储
[root@centos07 ~]# vim /etc/exports
在这里插入图片描述

/web 192.168.100.10(rw) 192.168.100.20(rw)
在这里插入图片描述

启动服务
[root@centos07 ~]# systemctl start nfs
[root@centos07 ~]# systemctl start rpcbind
[root@centos07 ~]# systemctl enable nfs
[root@centos07 ~]# systemctl enable rpcbind
在这里插入图片描述

检查共享存储
[root@centos07 ~]# showmount -e 192.168.100.30
在这里插入图片描述

Centos01:
网站链接共享存储
[root@centos ~]# vim /etc/fstab
在这里插入图片描述

192.168.100.30:web /var/www/html nfs defaults,_netdev 0 0
在这里插入图片描述

重启:
[root@centos ~]# reboot
在这里插入图片描述

查看共享存储
[root@centos ~]# df -Th
在这里插入图片描述

查看日志
[root@centos ~]# tail -f /var/log/httpd/access_log
在这里插入图片描述

Centos02:
[root@centos ~]# vim /etc/fstab
在这里插入图片描述

192.168.100.30:web /var/www/html nfs defaults,_netdev 0 0
在这里插入图片描述

[root@centos ~]# reboot
在这里插入图片描述

查看共享存储
[root@centos ~]# df -Th
在这里插入图片描述

查看日志
[root@centos ~]# tail -f /var/log/httpd/access_log
在这里插入图片描述

验证:
在这里插入图片描述
在这里插入图片描述

5.配置LVS的DR模式
将centos04恢复干净系统
生成虚拟网卡:
[root@centos08 ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-
ens33:0
在这里插入图片描述

[root@centos08 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33:0
在这里插入图片描述
在这里插入图片描述

[root@centos08 ~]# systemctl restart network
在这里插入图片描述

生成虚接口:
Centos01:
[root@centos ~]# cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:0
在这里插入图片描述

[root@centos ~]# vim /etc/sysconfig/network-scripts/ifcfg-lo:0
在这里插入图片描述
在这里插入图片描述

[root@centos ~]# systemctl restart network
在这里插入图片描述

Centos02:
[root@centos ~]# cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:0
在这里插入图片描述

[root@centos ~]# vim /etc/sysconfig/network-scripts/ifcfg-lo:0
在这里插入图片描述
在这里插入图片描述

[root@centos ~]# systemctl restart network
在这里插入图片描述

修改LVS服务器内核参数禁止响应客户端请求(centos04)
[root@centos08 ~]# vim /etc/sysctl.conf
在这里插入图片描述

net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
在这里插入图片描述

[root@centos08 ~]# sysctl -p
在这里插入图片描述

修改网站内核参数运行响应客户端请求 (centos01,centos02)
Centos01:
[root@centos ~]# vim /etc/sysctl.conf
在这里插入图片描述

net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
在这里插入图片描述

[root@centos ~]# sysctl -p
在这里插入图片描述

Centos02:
[root@centos ~]# vim /etc/sysctl.conf
在这里插入图片描述

net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
在这里插入图片描述

[root@centos ~]# sysctl -p
在这里插入图片描述

指定LVS负载均衡器的IP地址和端口(centos04)
安装ipvsadm
[root@centos08 ~]# yum -y install ipvsadm
在这里插入图片描述

设置服务开机自动启动
[root@centos08 ~]# systemctl enable ipvsadm
在这里插入图片描述

清空默认规则
[root@centos08 ~]# ipvsadm -C
在这里插入图片描述

查看规则
[root@centos08 ~]# ipvsadm -Ln
在这里插入图片描述

保存
[root@centos08 ~]# ipvsadm-save
在这里插入图片描述

设置DR规则:
[root@centos08 ~]# ipvsadm -A -t 192.168.100.254:80 -s rr
[root@centos08 ~]# ipvsadm -a -t 192.168.100.254:80 -r 192.168.100.10:80 -g -w 1
[root@centos08 ~]# ipvsadm -a -t 192.168.100.254:80 -r 192.168.100.20:80 -g -w 1
在这里插入图片描述

查看规则
在这里插入图片描述

保存规则
[root@centos08 ~]# ipvsadm-save
在这里插入图片描述

监控日志:(centos01,centos02)
Centos01:
[root@centos ~]# tail -f /var/log/httpd/access_log
在这里插入图片描述

Centos02:
[root@centos ~]# tail -f /var/log/httpd/access_log
在这里插入图片描述

验证:
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值