2024-07-08
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Mode kerja LVS-DR (Linux Virtual Server DIrector Server) adalah mode kerja yang paling umum digunakan di lingkungan produksi.
Dalam mode LVS-DR, Director Server berfungsi sebagai pintu masuk akses ke cluster dan tidak digunakan sebagai gateway. Node DirectorServer dan Real Server harus berada di jaringan yang sama, dan data yang dikembalikan ke klien tidak perlu dikirim melalui Server Direktur. Untuk merespons akses ke seluruh cluster, Server Direktur dan Server Nyata perlu dikonfigurasi dengan alamat VIP.
#配置负载调度器
#配置虚拟IP地址VIP
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vi ifcfg-ens33:0
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.10.172
NETMASK=255.255.255.0
[root@localhost network-scripts]# systemctl restart network
#调整内核参数,禁止转发重定向报文由于 LVS 负载调度器和各节点需要共用 VIP 地址,应该关闭Linux 内核的重定向
[root@localhost ~]# vi /etc/sysctl.conf
#调整内核参数
net.ipv4.conf.all.send_redirects = 0 #重定向禁止
net.ipv4.conf.default.send_redirects = 0 #默认禁止网卡重定向
net.ipv4.conf.ens33.send_redirects = 0 #指定网卡禁止重定向
[root@localhost ~]# sysctl -p
#配置负载分配策略
[root@localhost ~]#yum -y install ipvsadm
[root@localhost ~]#ipvsadm -v \查看版本
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]#ipvsadm -C
[root@localhost ~]# ipvsadm -A -t 192.168.10.172:80 -s wrr
[root@localhost ~]# ipvsadm -a -t 192.168.10.172:80 -r 192.168.10.102 -g -w 1
[root@localhost ~]# ipvsadm -a -t 192.168.10.172:80 -r 192.168.10.103 -g -w 1
[root@localhost ~]# ipvsadm-save
-A -t localhost.localdomain:http -s rr
-a -t localhost.localdomain:http -r 192.168.10.102:http -g -w 1
-a -t localhost.localdomain:http -r 192.168.10.103:http -g -w 2
[root@localhost ~]# systemctl enable ipvsadm
-g:直接路由模式
#配置web节点服务器
#配置虚拟ip地址VIP
[root@localhost ~]# setenforce 0
[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]# vi ifcfg-lo:0
#修改
DEVICE=lo:0
NETMASK=255.255.255.255 子网掩码必须为255.255.255.255
IPADDR=192.168.10.172
ONBOOT=yes
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# ifconfig
[root@localhost network-scripts]# cd
[root@localhost ~]# vi /etc/rc.local
#添加
/sbin/route add -host 192.168.10.172 dev lo:0
[root@localhost ~]# route add -host 192.168.10.172 dev lo:0
#调整内核参数
[root@localhost ~]# vi /etc/sysctl.conf
#添加
net.ipv4.conf.all.arp_ignore = 1 #忽略arp请求
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
[root@localhost ~]# sysctl -p
#安装httpd创建测试网页
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# yum install nfs-utils
[root@localhost ~]# mount 192.168.10.104:/opt/wwwroot /var/www/html
[root@localhost ~]#vi /var/www/html/index.html