三臺服務器:一臺做爲 director,兩臺做爲 real server
director 有一個外網網卡(192.168.199.158) 和一個內網ip(192.168.1.155)
兩個 real server 上只有內網 ip (192.168.1.182) 和 (192.168.1.183),而且須要把兩個 real server 的內網網關設置爲 director 的內網 ip(192.168.1.155)後面有詳細過程
wget http://nginx.org/download/nginx-1.16.0.tar.gz 安裝nginx
vip : 192.168.40.124
rip : 192.168.40.155
192.168.40.123
調度器安裝:
一、關閉防火牆
二、安裝ipvsadm
yum install ipvsadm -y
三、添加表 -D刪除整個表 -d刪除一條 (不加上算法)
ipvsadm -A -t 192.168.40.124:8080 -s(調度算法) rr(輪詢算法)
添加記錄(調度的對象,web)
ipvsadm -a -t 192.168.40.124:8080 -r 192.168.40.155
ipvsadm -a -t 192.168.40.124:8080 -r 192.168.40.123
四、設置vip地址
ifconfig ens33:1 192.168.40.124/32nginx
route add -host 192.168.40.124 dev ens33:1web
echo 1 > /proc/sys/net/ipv4/ip_forward算法
兩臺Web 服務上配置安裝
虛擬隱藏VIPvim
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announcebash
在lo上設置VIP地址
ifconfig lo:0 192.168.40.124/32
添加路由
route add -host 192.168.40.124 dev lo:0服務器
調度器
ipvsadm -Lnide
wget http://nginx.org/download/nginx-1.16.0.tar.gz 安裝nginx
Director節點: (ens33 192.168.199.169 vip eth0:0 192.168.199.158)
Real server1: (ens33 192.168.199.111 vip lo:0 192.168.199.158)
Real server2: (ens33 192.168.199.231 vip lo:0 192.168.199.158)code
arp_announce 2 arp_ignore 1
#! /bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
ipv=/sbin/ipvsadm
dip=192.168.199.122
vip=192.168.199.38
rs1=192.168.199.143
rs2=192.168.199.241
ifconfig ens33:0 down
ifconfig ens33:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip dev eth0:0
$ipv -C
$ipv -A -t $vip:80 -s wrr
$ipv -a -t $vip:80 -r $rs1:80 -g -w 3
$ipv -a -t $vip:80 -r $rs2:80 -g -w 1server
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++對象
#! /bin/bashvip=192.168.199.38ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 uproute add -host $vip lo:0echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignoreecho "2" >/proc/sys/net/ipv4/conf/lo/arp_announceecho "1" >/proc/sys/net/ipv4/conf/all/arp_ignoreecho "2" >/proc/sys/net/ipv4/conf/all/arp_announce++++++++++++++++++++++++++++++++++++++++++++++++++++++++++