您好,登錄后才能下訂單哦!
下文給大家?guī)砘谥苯勇酚赡J剑―R)的負載均衡群集的概述及其構(gòu)建,希望能夠給大家在實際運用中帶來一定的幫助,負載均衡涉及的東西比較多,理論也不多,網(wǎng)上有很多書籍,今天我們就用億速云在行業(yè)內(nèi)累計的經(jīng)驗來做一個解答。
一、開始配置DR模式LVS
準備工作:
Centos 7操作系統(tǒng)四臺;
Centos01模擬Web1云服務器:IP地址/192.168.100.10
Centos02模擬Web2服務器:IP地址/192.168.100.20
Centos03模擬NFS服務器: IP地址/192.168.100.30
Centos05模擬LVS服務器: IP地址/192.168.100.50
Windows 客戶端一臺;
[root@centos05 ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens32
/etc/sysconfig/network-scripts/ifcfg-ens32:0 <!--復制網(wǎng)卡配置文件-->
[root@centos05 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32:0
<!--配置VIP地址網(wǎng)卡,設置VIP地址為192.168.100.253-->
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
NAME=ens32:0 <!--修改名字-->
DEVICE=ens32:0 <!--修改名字-->
ONBOOT=yes
IPADDR=192.168.100.253 <!--修改IP地址-->
NATEMASK=255.255.255.0
[root@centos05 ~]# systemctl restart network <!--重啟網(wǎng)卡服務-->
[root@centos05 ~]# ifconfig <!--查看是否配置成功-->
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.50 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::20c:29ff:fe16:c54b prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:16:c5:4b txqueuelen 1000 (Ethernet)
RX packets 2795 bytes 1095013 (1.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1371 bytes 182001 (177.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens32:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.253 netmask 255.255.255.0 broadcast 192.168.100.255
ether 00:0c:29:16:c5:4b txqueuelen 1000 (Ethernet)
[root@centos05 ~]# vim /etc/sysctl.conf
<!--修改LVS服務器的內(nèi)核配置文件支持DR模式-->
net.ipv4.ip_forward = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens32.send_redirects = 0
[root@centos05 ~]# sysctl -p <!--刷新-->
[root@centos05 ~]# modprobe ip_vs <!--加載ip_vs模塊-->
[root@centos05 ~]# yum -y install ipvsadm <!--安裝ipvsadm工具-->
[root@centos05 ~]# ipvsadm -C <!--清除原有策略-->
[root@centos05 ~]# ipvsadm -A -t 192.168.100.253:80 -s rr <!--配置調(diào)度服務器IP地址-->
[root@centos05 ~]# ipvsadm -a -t 192.168.100.253:80 -r 192.168.100.10:80 -g -w 1
<!--添加物理服務器-->
[root@centos05 ~]# ipvsadm -a -t 192.168.100.253:80 -r 192.168.100.20:80 -g -w 1
<!--添加物理服務器-->
[root@centos05 ~]# ipvsadm-save > /etc/sysconfig/ipvsadm <!--導出策略備份-->
[root@centos04 ~]# ipvsadm -ln <!--確認群集當前策略-->
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.100.253:80 rr
-> 192.168.100.10:80 Route 1 0 0
-> 192.168.100.20:80 Route 1 0 0
[root@centos01 ~]# yum -y install httpd <!--安裝http服務-->
[root@centos01 ~]# echo "www.benet.com" > /var/www/html/index.html
<!--準備測試網(wǎng)頁,等看到負載均衡的效果后,再掛載共享存儲設備-->
[root@centos01 ~]# systemctl start httpd <!--啟動http服務-->
[root@centos01 ~]# systemctl enable httpd <!--設置為開機自啟動-->
[root@centos01 ~]# cp /etc/sysconfig/network-scripts/ifcfg-lo
/etc/sysconfig/network-scripts/ifcfg-lo:0 <!--生成虛擬網(wǎng)卡-->
[root@centos01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-lo:0
<!--編輯虛擬網(wǎng)卡監(jiān)聽地址為lvs服務器的VIP地址-->
DEVICE=lo:0
IPADDR=192.168.100.253
NETMASK=255.255.255.255
ONBOOT=yes
[root@centos01 ~]# systemctl restart network <!--重啟網(wǎng)卡服務-->
[root@centos01 ~]# ifconfig <!--查看配置是否生效-->
lo:0: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 192.168.100.253 netmask 255.255.255.255
loop txqueuelen 1 (Local Loopback)
[root@centos01 ~]# vim /etc/sysctl.conf <!--修改web服務器ARP響應-->
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@centos01 ~]# sysctl -p <!--刷新-->
[root@centos02 ~]# yum -y install httpd <!--安裝http服務-->
[root@centos02 ~]# echo "www.accp.com" > /var/www/html/index.html
<!--準備測試網(wǎng)頁,等看到負載均衡的效果后,再掛載共享存儲設備-->
[root@centos02 ~]# systemctl start httpd <!--啟動http服務-->
[root@centos02 ~]# systemctl enable httpd <!--設置為開機自啟動-->
[root@centos01 ~]# scp /etc/sysctl.conf root@192.168.100.20:/etc/
<!--拷貝第一臺web服務器/etc/sysctl.conf配置文件到第二臺web服務器的/etc/目錄下-->
The authenticity of host '192.168.100.30 (192.168.100.20)' can't be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.20' (ECDSA) to the list of known hosts.
root@192.168.100.20's password:
sysctl.conf
[root@centos01 ~]# scp /etc/sysconfig/network-scripts/ifcfg-lo:0
<!--拷貝lo:0網(wǎng)卡配置文件到第二臺web服務器--> root@192.168.100.20:/etc/sysconfig/network-scripts/
root@192.168.100.20's password:
ifcfg-lo:0 100% 70 177.3KB/s 00:00
[root@centos02 ~]# sysctl -p <!--在第二臺web服務器更新配置-->
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@centos02 ~]# systemctl restart network <!--第二臺web服務器重啟網(wǎng)卡服務-->
客戶端配置和服務器同網(wǎng)段IP地址,瀏覽器訪問http://192.168.100.253
關閉瀏覽器刪除緩存,重新訪問就會得到一個新的頁面,實現(xiàn)了負載均衡
[root@centos03 ~]# yum -y install rpcbind nfs-utils <!--安裝NFS系統(tǒng)-->
[root@centos03 ~]# mkdir /web <!--創(chuàng)建共享網(wǎng)站根目錄文件-->
[root@centos03 ~]# echo "www.nfs.com" > /web/index.html <!--網(wǎng)站主頁寫入測試數(shù)據(jù)-->
[root@centos03 ~]# vim /etc/exports <!--修改nfs主配置文件共享/web目錄,
允許100.10讀取共享目錄, 100.20允許讀取和寫入共享目錄-->
/web 192.168.100.10(ro) 192.168.100.20(rw)
[root@centos03 ~]# systemctl start rpcbind <!--啟動rpcbind-->
[root@centos03 ~]# systemctl start nfs <!--啟動nfs服務-->
[root@centos03 ~]# systemctl enable rpcbind <!--設置開機自動啟動-->
[root@centos03 ~]# systemctl enable nfs <!--設置開機自動啟動-->
[root@centos03 ~]# showmount -e 192.168.100.30 <!--查看共享目錄-->
Export list for 192.168.100.30:
/web 192.168.100.20,192.168.100.10
[root@centos01 ~]# mount 192.168.100.30:/web /var/www/html/
<!--掛載共享目錄到網(wǎng)站服務器的根目錄-->
[root@centos01 ~]# cat /var/www/html/index.html <!--查看是否掛載成功-->
www.nfs.com
[root@centos01 ~]# systemctl restart httpd <!--重啟httpd服務-->
[root@centos02 ~]# mount 192.168.100.30:/web /var/www/html/
<!--掛載共享目錄到網(wǎng)站服務器的根目錄-->
[root@centos02 ~]# cat /var/www/html/index.html <!--查看是否掛載成功-->
www.nfs.com
[root@centos02 ~]# systemctl restart httpd <!--重啟httpd服務-->
使用tail -f /var/log/httpd/access.log查看訪問成功日志,一定要想監(jiān)聽再去訪問才可以看到效果
[root@centos01 ~]# vim /etc/fstab
192.168.100.30:/web /var/www/html/ nsf defaults 0 0
[root@centos02 ~]# vim /etc/fstab
192.168.100.30:/web /var/www/html/ nsf defaults 0 0
看了以上關于基于直接路由模式(DR)的負載均衡群集的概述及其構(gòu)建,如果大家還有什么地方需要了解的可以在億速云行業(yè)資訊里查找自己感興趣的或者找我們的專業(yè)技術工程師解答的,億速云技術工程師在行業(yè)內(nèi)擁有十幾年的經(jīng)驗了。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。