群集的含義
面臨問題
解決方法
根據群集所針對的目標差異,可分為三種型別
負載均衡群集(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