目錄
一、基于 CentOS 7 構(gòu)建 LVS-DR 群集
1、準(zhǔn)備四臺虛擬機(jī)
2、配置負(fù)載調(diào)度器(192.168.2.130)
3、部署共享存儲(192.168.2.133)
4、配置兩個Web服務(wù)器(192.168.2.131、192.168.2.132)
測試集群
二、配置nginx負(fù)載均衡。
1、安裝部署nginx
2、負(fù)載均衡服務(wù)器192.168.2.130
3、web1服務(wù)器192.168.2.131,web2服務(wù)器192.168.2.132
4、配置hosts文件
一、基于 CentOS 7 構(gòu)建 LVS-DR 群集
1、準(zhǔn)備四臺虛擬機(jī)
ip | 角色 |
---|---|
192.168.2.130 vip:192.168.2.200 |
DR服務(wù)器 |
192.168.2.131 | Web服務(wù)器1 |
192.168.2.132 | Web服務(wù)器2 |
192.168.2.133 | NFS服務(wù)器 |
2、配置負(fù)載調(diào)度器(192.168.2.130)
systemctl stop firewalld
modprobe ip_vs
cat /proc/net/ip_vs
yum -y install ipvsadm
(1)配置虛擬IP地址(vip:192.168.2.200)
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vim ifcfg-ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.2.200
NETMASK=255.255.255.255
[root@localhost network-scripts]# ifup ens33:0
[root@localhost network-scripts]# ifconfig ens33:0
(2)調(diào)整proc響應(yīng)參數(shù)
[root@localhost ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
?(3)手工執(zhí)行配置負(fù)載分配策略
[root@localhost ~]# ipvsadm-save > /etc/sysconfig/ipvsadm
[root@localhost ~]# systemctl start ipvsadm
[root@localhost ~]# ipvsadm -C
[root@localhost ~]# ipvsadm -A -t 192.168.2.200:80 -s rr
[root@localhost ~]# ipvsadm -a -t 192.168.2.200:80 -r 192.168.2.131:80 -g
[root@localhost ~]# ipvsadm -a -t 192.168.2.200:80 -r 192.168.2.132:80 -g
[root@localhost ~]# ipvsadm
3、部署共享存儲(192.168.2.133)
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# yum -y install nfs-utils rpcbind
[root@localhost ~]# mkdir /opt/blue /opt/summer
[root@localhost ~]# chmod 777 /opt/blue /opt/summer
[root@localhost ~]# vim /etc/exports
/usr/share *(ro,sync)
/opt/blue 192.168.2.0/24(rw,sync)
/opt/summer 192.168.2.0/24(rw,sync)
[root@localhost ~]# systemctl start nfs.service
[root@localhost ~]# systemctl start rpcbind.service
4、配置兩個Web服務(wù)器(192.168.2.131、192.168.2.132)
兩個服務(wù)器相同的配置步驟
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vim ifcfg-lo:0
[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ifconfig lo:0
配置主機(jī)路由
[root@localhost network-scripts]# route add -host 192.168.2.200 dev lo:0
[root@localhost network-scripts]# vim /etc/rc.local
/sbin/route add -host 192.168.2.200 dev lo:0
[root@localhost network-scripts]# chmod +x /etc/rc.d/rc.local
調(diào)整內(nèi)核的 ARP 響應(yīng)參數(shù)以阻止更新 VIP 的 MAC 地址,避免發(fā)生沖突
[root@localhost network-scripts]# vim /etc/sysctl.conf
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@localhost network-scripts]# yum -y install nfs-utils rpcbind httpd lsof
[root@localhost network-scripts]# systemctl start rpcbind
[root@localhost network-scripts]# systemctl start httpd
[root@localhost network-scripts]# lsof -i:80
[root@localhost network-scripts]# showmount -e 192.168.2.133
?
--192.168.2.131---
mount.nfs 192.168.2.131:/opt/blue /var/www/html
echo 'this is 131 web' > /var/www/html/index.html
--192.168.2.132---
mount.nfs 192.168.2.132:/opt/summer /var/www/html
echo 'this is 132 web' > /var/www/html/index.html
文章來源:http://www.zghlxwxcb.cn/news/detail-650966.html
測試集群
?文章來源地址http://www.zghlxwxcb.cn/news/detail-650966.html
二、配置nginx負(fù)載均衡。
1、安裝部署nginx
2、負(fù)載均衡服務(wù)器192.168.2.130
[root@localhost ~]# vim /etc/nginx/conf.d/nginx.conf
server{
listen 80;
server_name www.first.com;
location /{
proxy_pass http://web_server;
}
}
upstream web_server{
server 192.168.2.131;
server 192.168.2.132;
}
3、web1服務(wù)器192.168.2.131,web2服務(wù)器192.168.2.132
[root@localhost ~]# echo "Welcome to 131 server:192.168.2.131" > /root/index.html
[root@localhost ~]# echo "Welcome to 132 server:192.168.2.132" > /root/index.html
4、配置hosts文件
192.168.2.130 www.first.com
到了這里,關(guān)于構(gòu)建 LVS-DR 群集、配置nginx負(fù)載均衡。的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!