案例環境
調度服務器一臺:
IP地址:192.168.100.10(內網)
192.168.73.10(外網)
Web服務器兩臺:
IP地址:192.168.100.11(Server1)
IP地址:192.168.100.12(Server2)
NFS共享服務器一臺:
IP地址:192.168.100.13 (內網)
拓撲圖:

配置步驟
LVS調度器
1、添加兩張網卡,一張用于內網通信,另一張用于外網通信
2、配置LVS調度器
[root@LVS-Server ~]# modprobe ip_vs ###加載LVS內核模塊(LVS現已成為Linux內核的一部分,默認編譯為ip_vs模塊,必要時能夠自動呼叫,以下操作能夠手動加載ip_vs模塊,并查看當前系統中的ip_vs模塊的版本資訊)
[root@LVS-Server ~]# cat /proc/net/ip_vs
IP Virtual Server version 1.2.1 (size=4096) ###版本資訊
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
[root@LVS-Server ~]# rpm -ivh /mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm ###安裝管理軟體ipvsadm,不需要啟動
[root@LVS-Server ~]# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
[root@LVS-Server ~]# sysctl -p
net.ipv4.ip_forward = 1
[root@LVS-Server ~]# vi nat.sh ###編輯調度服務器腳本
#!/bin/bash
echo "1" > /proc/sys/net/ipv4/ip_forward ###開啟路由地址轉換
ipvsadm -C ###清除內核虛擬服務器表中的所有記錄
ipvsadm -A -t 192.168.73.10:80 -s rr ###創建虛擬服務器
ipvsadm -a -t 192.168.73.10:80 -r 192.168.100.11:80 -m ###添加服務器節點
ipvsadm -a -t 192.168.73.10:80 -r 192.168.100.12:80 -m ###添加服務器節點
ipvsadm -Ln ###查看節點狀態,“-n”以數字形式顯示顯示地址,埠資訊
[root@LVS-Server ~]# sh nat.sh
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.73.10:80 rr
-> 192.168.100.11:80 Masq 1 0 0
-> 192.168.100.12:80 Masq 1 0 0
ipvsadm命令選項決議:
-C:清除內核虛擬服務器表中的所有記錄
-A:增加一臺新的虛擬服務器
-t:說明虛擬服務器提供的是tcp的服務
-s rr:啟用輪詢演算法
-a:在一個虛擬服務器中增加一臺新的真實服務器
-r:指定真實服務器
-m:指定LVS的作業模式為NAT模式
ipvsadm:啟用LVS功能
NFS服務器安裝
1.安裝rpcbind和nfs-utils軟體包(默認安裝),啟動服務rpcbind和nfs
[root@NFS-Server ~]# yum -y install rpcbind
[root@NFS-Server ~]# yum -y install nfs-utils
[root@NFS-Server ~]# systemctl start nfs
[root@NFS-Server ~]# systemctl start rpcbind
2.創建共享目錄并編輯組態檔,重啟服務,查看發布的共享
[root@NFS-Server ~]# mkdir /opt/web1 /opt/web2
[root@NFS-Server ~]# vi /opt/web1/index.html
<h1>Server1</h1>
[root@NFS-Server ~]# vi /opt/web2/index.html
<h1>Server2</h1>
[root@NFS-Server ~]# vi /etc/exports
/opt/web1 192.168.100.11/24(ro)
/opt/web2 192.168.100.12/24(ro)
[root@NFS-Server ~]# systemctl restart nfs
[root@NFS-Server ~]# systemctl restart rpcbind
[root@NFS-Server ~]# showmount -e
Export list for NFS-Server:
/opt/web2 192.168.100.12/24
/opt/web1 192.168.100.11/24
Web服務器配置
配置Server1
[root@Server1 ~]# route -n ###查看是否有默認路由生成
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.100.10 0.0.0.0 UG 100 0 0 ens33
192.168.100.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@Server1 ~]# yum -y install httpd
[root@Server1 ~]# showmount -e 192.168.100.13 ###查看nfs服務器發布的共享
Export list for 192.168.100.13:
/opt/web2 192.168.100.12/24
/opt/web1 192.168.100.11/24
[root@Server1 ~]# mount 192.168.100.13:/opt/web1 /var/www/html ###掛載
[root@Server1 ~]# systemctl start httpd
配置Server2
[root@Server2 ~]# route -n ###查看是否有默認路由生成
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.100.10 0.0.0.0 UG 100 0 0 ens33
192.168.100.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@Server2 ~]# yum -y install httpd
[root@Server2 ~]# showmount -e 192.168.100.13 ###查看nfs服務器發布的共享
Export list for 192.168.100.13:
/opt/web2 192.168.100.12/24
/opt/web1 192.168.100.11/24
[root@Server2 ~]# mount 192.168.100.13:/opt/web2 /var/www/html ###掛載
[root@Server2 ~]# systemctl start httpd
驗證
在win10服務器中輸入192.168.73.10地址驗證是否為輪詢調度,
第一次是訪問節點1的網頁內容,重繪瀏覽器,第二次是訪問節點2的網頁內容,實驗成功,

重繪

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/204130.html
標籤:其他
上一篇:Linux系統學習系列——Linux系統日志管 理(上)
下一篇:nginx學習從入門到精通
