群集的含义
面临问题
解决方法
根据群集所针对的目标差异,可分为三种类型
负载均衡群集(Load Balance Cluster)
高可用群集(High Availability Cluster)
高性能运算群集(High Performance Computer Cluster)
负载均衡的结构
群集的负载调度技术有三种工作模式
LVS的负载调度算法
轮询轮询 (Round Robin)
加权轮询 (Weighted Round Robin)
最少连接 (Least Connections)
加权最少连接 (Weighted Least Connections)
环境
IP地址规划
名称 | IP | 网关 |
---|---|---|
调度器 | 对外公网:20.0.0.21 (NAT) | / |
调度器 | 私有网络:192.168.100.21 (VM1) | / |
WE1 | 私有网络:192.168.100.22(VM1) | 192.168.100.21 |
WE2 | 私有网络:192.168.100.23 (VM1 ) | 192.168.100.21 |
存储服务器 | 192.168.100.24(VM1) | 192.168.100.21(可配可不配) |
真机 | 20.0.0.1(VM8) | 20.0.0.21 |
调度器配置 (192.168.100.21)
[root@localhost ~]# yum -y install ipvsadm
[root@localhost ~]# modprobe ip_vs ##加载ip_vs模块
[root@localhost ~]# cat /proc/net/ip_vs ##查看ip_vs模块是否加载成功
[root@localhost ~]# ipvsadm -A -t 20.0.0.21:80 -s rr ##创建虚拟服务器
[root@localhost ~]# ipvsadm -a -t 20.0.0.21:80 -r 192.168.100.22:80 -m ##添加服务器节点
[root@localhost ~]# ipvsadm -a -t 20.0.0.21:80 -r 192.168.100.23:80 -m
[root@localhost ~]# ipvsadm -ln ##查看节点状态
[root@localhost ~]# ipvsadm-save > /opt/ipvsadm ##保存负载分配策略
[root@localhost ~]# cat /opt/ipvsadm ##确认保存结果
[root@localhost ~]# vi /etc/sysctl.conf ##开启调度服务器路由转发功能
net.ipv4.ip_forward = 1
[root@localhost ~]# sysctl -p ##让内核参数立即生效
存储服务器配置(192.168.100.24)
[root@localhost ~]# rpm -q nfs-utils ##最小化安装需要yum -y install nfs-utils
[root@localhost ~]# rpm -q rpcbind ##最小化安装需要yum -y install rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# mkdir /opt/51xit /opt/52xit ##创建两个目录
[root@localhost ~]# echo "this is www.51xit.top" >/opt/51xit/index.html
[root@localhost ~]# echo "this is www.52xit.top" >/opt/52xit/index.html
[root@localhost opt]# vi /etc/exports ##配置NFS服务器的相关信息
/opt/51xit 192.168.100.0/24(rw,sync)
/opt/52xit 192.168.100.0/24(rw,sync)
[root@localhost opt]# systemctl restart nfs rpcbind ##重启
[root@localhost opt]# systemctl enable nfs rpcbind ##开机自启
[root@localhost opt]# showmount -e ##查询NFS服务器的相关信息(仅显示被客户挂载的目录名)
Export list for localhost.localdomain:
/opt/52xit 192.168.100.0/24
/opt/51xit 192.168.100.0/24
WE1配置(192.168.100.22)
[root@localhost ~]# showmount -e 192.168.100.24
Export list for 192.168.100.24:
/opt/52xit 192.168.100.0/24
/opt/51xit 192.168.100.0/24
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# mount 192.168.100.24:/opt/51xit /var/www/html/ ##临时挂载
[root@localhost ~]# vi /etc/fstab ##永久挂载
192.168.100.24:/opt/51xit /var/www/html nfs defaults,_netdev 0 0
[root@localhost ~]# init 6 ##最好重启检测下
###登录192.168.100.22测试网站是否正常####
WE2配置 (192.168.100.23)
[root@localhost ~]# showmount -e 192.168.100.24
Export list for 192.168.100.24:
/opt/52xit 192.168.100.0/24
/opt/51xit 192.168.100.0/24
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# mount 192.168.100.24:/opt/52xit /var/www/html/ ##临时挂载
[root@localhost ~]# vi /etc/fstab ##永久挂载
192.168.100.24:/opt/52xit /var/www/html nfs defaults,_netdev 0 0
[root@localhost ~]# init 6 ##重启测试
###登录192.168.100.23测试网站是否正常####
添加一个新网卡(ens37):
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens37 #复制ens33到ens37
[root@localhost ~]# nmcli connection ##查看UUID信息
[root@localhost ~]# route -n ##查看路由条目 把地址以数字的形式显示
注释:
每一个UUID只能一个网卡使用!!
【可能遇到的问题】
[root@localhost ~]# showmount -e 192.168.100.24
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
[root@localhost ~]# showmount -e
Export list for localhost.localdomain:
【解决方案】
(1)检查防火墙和核心防护
[root@localhost ~]# systemctl status firewalld
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
(2)检查共享列表有没有设置
[root@localhost ~]# cat /etc/exports
/opt/51xit 192.168.100.0/24(rw,sync)
/opt/52xit 192.168.100.0/24(rw,sync)
[root@localhost ~]# systemctl restart nfs
[root@localhost ~]# systemctl restart rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl enable rpcbind