15.2.4. lvs-VS/TUN安装配置

Date:

2018-10

15.2.4.1. 环境

服务器列表

默认硬件、系统版本全部相同,只是主机名不同和网络配置不同

主机名

IP

lvs_vip_01

192.168.1.166

lvs_rip_web01

192.168.1.187

lvs_rip_web02

192.168.1.163

系统版本

CentOS release 6.6 (Final)

硬件环境

x86_64

lvsadm

ipvsadm-1.26

15.2.4.2. 安装配置

IP隧道模式官方资料

http://www.linuxvirtualserver.org/zh/lvs3.html#4

15.2.4.2.1. 配置说明

本lvs实例是基于IP隧道的实例配置。且调度算法使用rr(官方叫做轮叫,本人习惯叫做轮询算法。权重使用默认都是1)

15.2.4.2.2. lvs_vip_01安装配置过程

安装配置过程:

  1[root@lvs_vip_01 ~]# mkdir /home/tools -p
  2[root@lvs_vip_01 ~]# ll /home
  3total 4
  4drwxr-xr-x. 2 root root 4096 Nov  2 02:51 tools
  5[root@lvs_vip_01 ~]# lsmod|grep ip_vs
  6[root@lvs_vip_01 ~]# cd /home/tools
  7[root@lvs_vip_01 tools]# pwd
  8/home/tools
  9[root@lvs_vip_01 tools]# ls
 10[root@lvs_vip_01 tools]# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
 11--2018-11-02 02:55:23--  http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
 12Resolving www.linuxvirtualserver.org... 173.255.202.51, 2600:3c00::f03c:91ff:fe96:fcc2
 13Connecting to www.linuxvirtualserver.org|173.255.202.51|:80... connected.
 14HTTP request sent, awaiting response... 200 OK
 15Length: 41700 (41K) [application/x-gzip]
 16Saving to: “ipvsadm-1.26.tar.gz”
 17
 18100%[===================================================================================================================================>] 41,700       194K/s   in 0.2s
 19
 202018-11-02 02:55:25 (194 KB/s) - “ipvsadm-1.26.tar.gz” saved [41700/41700]
 21
 22[root@lvs_vip_01 tools]# ls
 23ipvsadm-1.26.tar.gz
 24[root@lvs_vip_01 tools]# rpm -qa libnl* popt*
 25popt-1.13-7.el6.x86_64
 26libnl-1.1.4-2.el6.x86_64
 27
 28[root@lvs_vip_01 tools]#
 29[root@lvs_vip_01 tools]# yum install libnl* popt* -y
 30Loaded plugins: fastestmirror, security
 31Setting up Install Process
 32Determining fastest mirrors
 33* base: ftp.sjtu.edu.cn
 34* extras: mirrors.tuna.tsinghua.edu.cn
 35* updates: mirrors.tuna.tsinghua.edu.cn
 36base                                                                                                                                                  | 3.7 kB     00:00
 37base/primary_db                                                                                                                                       | 4.7 MB     00:00
 38extras                                                                                                                                                | 3.4 kB     00:00
 39extras/primary_db                                                                                                                                     |  26 kB     00:00
 40updates                                                                                                                                               | 3.4 kB     00:00
 41updates/primary_db                                                                                                                                    | 1.9 MB     00:00
 42Package libnl-1.1.4-2.el6.x86_64 already installed and latest version
 43Package popt-1.13-7.el6.x86_64 already installed and latest version
 44Resolving Dependencies
 45--> Running transaction check
 46---> Package libnl-devel.x86_64 0:1.1.4-2.el6 will be installed
 47---> Package libnl3.x86_64 0:3.2.21-8.el6 will be installed
 48---> Package libnl3-cli.x86_64 0:3.2.21-8.el6 will be installed
 49---> Package libnl3-devel.x86_64 0:3.2.21-8.el6 will be installed
 50---> Package libnl3-doc.x86_64 0:3.2.21-8.el6 will be installed
 51---> Package popt-devel.x86_64 0:1.13-7.el6 will be installed
 52---> Package popt-static.x86_64 0:1.13-7.el6 will be installed
 53--> Finished Dependency Resolution
 54
 55Dependencies Resolved
 56
 57=============================================================================================================================================================================
 58Package                                      Arch                                   Version                                      Repository                            Size
 59=============================================================================================================================================================================
 60Installing:
 61libnl-devel                                  x86_64                                 1.1.4-2.el6                                  base                                 707 k
 62libnl3                                       x86_64                                 3.2.21-8.el6                                 base                                 183 k
 63libnl3-cli                                   x86_64                                 3.2.21-8.el6                                 base                                  58 k
 64libnl3-devel                                 x86_64                                 3.2.21-8.el6                                 base                                  56 k
 65libnl3-doc                                   x86_64                                 3.2.21-8.el6                                 base                                  10 M
 66popt-devel                                   x86_64                                 1.13-7.el6                                   base                                  21 k
 67popt-static                                  x86_64                                 1.13-7.el6                                   base                                  21 k
 68
 69Transaction Summary
 70=============================================================================================================================================================================
 71Install       7 Package(s)
 72
 73Total download size: 11 M
 74Installed size: 30 M
 75Downloading Packages:
 76(1/7): libnl-devel-1.1.4-2.el6.x86_64.rpm                                                                                                             | 707 kB     00:00
 77(2/7): libnl3-3.2.21-8.el6.x86_64.rpm                                                                                                                 | 183 kB     00:00
 78(3/7): libnl3-cli-3.2.21-8.el6.x86_64.rpm                                                                                                             |  58 kB     00:00
 79(4/7): libnl3-devel-3.2.21-8.el6.x86_64.rpm                                                                                                           |  56 kB     00:00
 80(5/7): libnl3-doc-3.2.21-8.el6.x86_64.rpm                                                                                                             |  10 MB     00:02
 81(6/7): popt-devel-1.13-7.el6.x86_64.rpm                                                                                                               |  21 kB     00:00
 82(7/7): popt-static-1.13-7.el6.x86_64.rpm                                                                                                              |  21 kB     00:00
 83-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 84Total                                                                                                                                        3.6 MB/s |  11 MB     00:03
 85Running rpm_check_debug
 86Running Transaction Test
 87Transaction Test Succeeded
 88Running Transaction
 89Installing : libnl3-3.2.21-8.el6.x86_64                                                                                                                                1/7
 90Installing : libnl3-cli-3.2.21-8.el6.x86_64                                                                                                                            2/7
 91Installing : popt-devel-1.13-7.el6.x86_64                                                                                                                              3/7
 92Installing : popt-static-1.13-7.el6.x86_64                                                                                                                             4/7
 93Installing : libnl3-devel-3.2.21-8.el6.x86_64                                                                                                                          5/7
 94Installing : libnl3-doc-3.2.21-8.el6.x86_64                                                                                                                            6/7
 95Installing : libnl-devel-1.1.4-2.el6.x86_64                                                                                                                            7/7
 96Verifying  : libnl3-devel-3.2.21-8.el6.x86_64                                                                                                                          1/7
 97Verifying  : libnl-devel-1.1.4-2.el6.x86_64                                                                                                                            2/7
 98Verifying  : popt-static-1.13-7.el6.x86_64                                                                                                                             3/7
 99Verifying  : popt-devel-1.13-7.el6.x86_64                                                                                                                              4/7
100Verifying  : libnl3-cli-3.2.21-8.el6.x86_64                                                                                                                            5/7
101Verifying  : libnl3-3.2.21-8.el6.x86_64                                                                                                                                6/7
102Verifying  : libnl3-doc-3.2.21-8.el6.x86_64                                                                                                                            7/7
103
104Installed:
105libnl-devel.x86_64 0:1.1.4-2.el6  libnl3.x86_64 0:3.2.21-8.el6     libnl3-cli.x86_64 0:3.2.21-8.el6  libnl3-devel.x86_64 0:3.2.21-8.el6  libnl3-doc.x86_64 0:3.2.21-8.el6
106popt-devel.x86_64 0:1.13-7.el6    popt-static.x86_64 0:1.13-7.el6
107
108Complete!
109[root@lvs_vip_01 tools]# rpm -qa libnl* popt*
110libnl3-3.2.21-8.el6.x86_64
111libnl3-devel-3.2.21-8.el6.x86_64
112popt-1.13-7.el6.x86_64
113libnl-1.1.4-2.el6.x86_64
114libnl3-cli-3.2.21-8.el6.x86_64
115popt-static-1.13-7.el6.x86_64
116libnl3-doc-3.2.21-8.el6.x86_64
117popt-devel-1.13-7.el6.x86_64
118libnl-devel-1.1.4-2.el6.x86_64
119[root@lvs_vip_01 tools]# ls
120ipvsadm-1.26.tar.gz
121[root@lvs_vip_01 tools]# tar -xf ipvsadm-1.26.tar.gz
122[root@lvs_vip_01 tools]# ls
123ipvsadm-1.26  ipvsadm-1.26.tar.gz
124[root@lvs_vip_01 tools]# cd ipvsadm-1.26
125[root@lvs_vip_01 ipvsadm-1.26]# ls
126config_stream.c  contrib  dynamic_array.c  ipvsadm.8  ipvsadm-restore    ipvsadm-save    ipvsadm.sh    ipvsadm.spec.in  Makefile             README      VERSION
127config_stream.h  debian   dynamic_array.h  ipvsadm.c  ipvsadm-restore.8  ipvsadm-save.8  ipvsadm.spec  libipvs          PERSISTENCE_ENGINES  SCHEDULERS
128[root@lvs_vip_01 ipvsadm-1.26]# make
129make -C libipvs
130make[1]: Entering directory `/home/tools/ipvsadm-1.26/libipvs'`
131gcc -Wall -Wunused -Wstrict-prototypes -g -fPIC -DLIBIPVS_USE_NL  -DHAVE_NET_IP_VS_H -c -o libipvs.o libipvs.c
132gcc -Wall -Wunused -Wstrict-prototypes -g -fPIC -DLIBIPVS_USE_NL  -DHAVE_NET_IP_VS_H -c -o ip_vs_nl_policy.o ip_vs_nl_policy.c
133ar rv libipvs.a libipvs.o ip_vs_nl_policy.o
134ar: creating libipvs.a
135a - libipvs.o
136a - ip_vs_nl_policy.o
137gcc -shared -Wl,-soname,libipvs.so -o libipvs.so libipvs.o ip_vs_nl_policy.o
138make[1]: Leaving directory `/home/tools/ipvsadm-1.26/libipvs'`
139gcc -Wall -Wunused -Wstrict-prototypes -g  -DVERSION=\"1.26\" -DSCHEDULERS=\""rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq"\" -DPE_LIST=\""sip"\" -DHAVE_POPT -DHAVE_NET_IP_VS_H -c -o ipvsadm.o ipvsadm.c
140ipvsadm.c: In function ‘print_largenum’:
141ipvsadm.c:1383: warning: field width should have type ‘int’, but argument 2 has type ‘size_t’
142gcc -Wall -Wunused -Wstrict-prototypes -g  -DVERSION=\"1.26\" -DSCHEDULERS=\""rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq"\" -DPE_LIST=\""sip"\" -DHAVE_POPT -DHAVE_NET_IP_VS_H -c -o config_stream.o config_stream.c
143gcc -Wall -Wunused -Wstrict-prototypes -g  -DVERSION=\"1.26\" -DSCHEDULERS=\""rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq"\" -DPE_LIST=\""sip"\" -DHAVE_POPT -DHAVE_NET_IP_VS_H -c -o dynamic_array.o dynamic_array.c
144gcc -Wall -Wunused -Wstrict-prototypes -g -o ipvsadm ipvsadm.o config_stream.o dynamic_array.o libipvs/libipvs.a -lpopt -lnl
145[root@lvs_vip_01 ipvsadm-1.26]# echo $?
1460
147[root@lvs_vip_01 ipvsadm-1.26]# make install
148make -C libipvs
149make[1]: Entering directory `/home/tools/ipvsadm-1.26/libipvs'`
150make[1]: Nothing to be done for `all'.`
151make[1]: Leaving directory `/home/tools/ipvsadm-1.26/libipvs'`
152if [ ! -d /sbin ]; then mkdir -p /sbin; fi
153install -m 0755 ipvsadm /sbin
154install -m 0755 ipvsadm-save /sbin
155install -m 0755 ipvsadm-restore /sbin
156[ -d /usr/man/man8 ] || mkdir -p /usr/man/man8
157install -m 0644 ipvsadm.8 /usr/man/man8
158install -m 0644 ipvsadm-save.8 /usr/man/man8
159install -m 0644 ipvsadm-restore.8 /usr/man/man8
160[ -d /etc/rc.d/init.d ] || mkdir -p /etc/rc.d/init.d
161install -m 0755 ipvsadm.sh /etc/rc.d/init.d/ipvsadm
162[root@lvs_vip_01 ipvsadm-1.26]#
163[root@lvs_vip_01 ipvsadm-1.26]#
164[root@lvs_vip_01 ipvsadm-1.26]# lsmod|grep ip_vs
165[root@lvs_vip_01 ipvsadm-1.26]# /sbin/ipvsadm
166IP Virtual Server version 1.2.1 (size=4096)
167Prot LocalAddress:Port Scheduler Flags
168-> RemoteAddress:Port           Forward Weight ActiveConn InActConn
169[root@lvs_vip_01 ipvsadm-1.26]#
170[root@lvs_vip_01 ipvsadm-1.26]# lsmod|grep ip_vs
171ip_vs                 125694  0
172libcrc32c               1246  1 ip_vs
173ipv6                  334932  270 ip_vs,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6
174[root@lvs_vip_01 ipvsadm-1.26]#
175[root@lvs_vip_01 ipvsadm-1.26]# ifconfig eth0:0 192.168.1.250/24
176[root@lvs_vip_01 ipvsadm-1.26]# ifconfig
177eth0      Link encap:Ethernet  HWaddr 00:0C:29:12:76:B6
178        inet addr:192.168.1.166  Bcast:192.168.161.255  Mask:255.255.255.0
179        inet6 addr: fe80::20c:29ff:fe12:76b6/64 Scope:Link
180        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
181        RX packets:14142 errors:0 dropped:0 overruns:0 frame:0
182        TX packets:6611 errors:0 dropped:0 overruns:0 carrier:0
183        collisions:0 txqueuelen:1000
184        RX bytes:19317256 (18.4 MiB)  TX bytes:501456 (489.7 KiB)
185
186eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:12:76:B6
187        inet addr:192.168.1.250  Bcast:192.168.161.255  Mask:255.255.255.0
188        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
189
190lo        Link encap:Local Loopback
191        inet addr:127.0.0.1  Mask:255.0.0.0
192        inet6 addr: ::1/128 Scope:Host
193        UP LOOPBACK RUNNING  MTU:65536  Metric:1
194        RX packets:0 errors:0 dropped:0 overruns:0 frame:0
195        TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
196        collisions:0 txqueuelen:0
197        RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
198
199[root@lvs_vip_01 ipvsadm-1.26]# ping 192.168.1.250
200PING 192.168.1.250 (192.168.1.250) 56(84) bytes of data.
20164 bytes from 192.168.1.250: icmp_seq=1 ttl=64 time=0.024 ms
202^C
203--- 192.168.1.250 ping statistics ---
2041 packets transmitted, 1 received, 0% packet loss, time 935ms
205rtt min/avg/max/mdev = 0.024/0.024/0.024/0.000 ms
206
207[root@lvs_vip_01 ~]# ipvsadm -L -n
208IP Virtual Server version 1.2.1 (size=4096)
209Prot LocalAddress:Port Scheduler Flags
210-> RemoteAddress:Port           Forward Weight ActiveConn InActConn
211[root@lvs_vip_01 ~]# ipvsadm -A -t 192.168.1.250:80 -s rr
212[root@lvs_vip_01 ~]# ipvsadm -a -t 192.168.1.250:80 -r 192.168.1.187 -i
213[root@lvs_vip_01 ~]# ipvsadm -a -t 192.168.1.250:80 -r 192.168.1.163 -i
214[root@lvs_vip_01 ~]# ipvsadm -L -n
215IP Virtual Server version 1.2.1 (size=4096)
216Prot LocalAddress:Port Scheduler Flags
217-> RemoteAddress:Port           Forward Weight ActiveConn InActConn
218TCP  192.168.1.250:80 rr
219-> 192.168.1.187:80           Masq    1      0          0
220-> 192.168.1.163:80           Masq    1      0          0
221
222[root@lvs_vip_01 ipvsadm-1.26]#     ntpdate pool.ntp.org
223    sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
224    setenforce 0
225    /etc/init.d/iptables stop
226    chkconfig iptables off
2272 Nov 03:18:06 ntpdate[1837]: 87.120.166.8 rate limit response from server.
2282 Nov 03:18:06 ntpdate[1837]: 37.247.53.178 rate limit response from server.
2291 Nov 19:18:06 ntpdate[1837]: step time server 87.120.166.8 offset -28800.986290 sec
230[root@lvs_vip_01 ipvsadm-1.26]#     sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
231[root@lvs_vip_01 ipvsadm-1.26]#     setenforce 0
232[root@lvs_vip_01 ipvsadm-1.26]#     /etc/init.d/iptables stop
233iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
234iptables: Flushing firewall rules:                         [  OK  ]
235iptables: Unloading modules:                               [  OK  ]
236[root@lvs_vip_01 ipvsadm-1.26]#     chkconfig iptables off

注意

有的资料说要开启路由转发。但是我测试没有开启路由转发也可以成功。如果需要开启路由转发,命令:

15.2.4.2.3. lvs_rip_web01安装配置过程

安装配置过程:

  1[root@lvs_rip_web01 ~]# mkdir /home/tools -p
  2[root@lvs_rip_web01 ~]# ll /home
  3total 4
  4drwxr-xr-x. 2 root root 4096 Nov  2 02:51 tools
  5[root@lvs_rip_web01 ~]# lsmod|grep ip_vs
  6[root@lvs_rip_web01 ~]# echo '0' > /proc/sys/net/ipv4/ip_forward
  7[root@lvs_rip_web01 ~]# echo '1' > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
  8[root@lvs_rip_web01 ~]# echo '2' > /proc/sys/net/ipv4/conf/tunl0/arp_announce
  9[root@lvs_rip_web01 ~]# echo '1' > /proc/sys/net/ipv4/conf/all/arp_ignore
 10[root@lvs_rip_web01 ~]# echo '2' > /proc/sys/net/ipv4/conf/all/arp_announce
 11[root@lvs_rip_web01 ~]# echo '0' > /proc/sys/net/ipv4/conf/tunl0/rp_filter
 12[root@lvs_rip_web01 ~]# echo '0' > /proc/sys/net/ipv4/conf/all/rp_filter
 13[root@lvs_rip_web01 ~]# cd /home/tools
 14[root@lvs_rip_web01 tools]# pwd
 15/home/tools
 16[root@lvs_rip_web01 tools]# ls
 17[root@lvs_rip_web01 tools]# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
 18--2018-11-02 02:55:23--  http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
 19Resolving www.linuxvirtualserver.org... 173.255.202.51, 2600:3c00::f03c:91ff:fe96:fcc2
 20Connecting to www.linuxvirtualserver.org|173.255.202.51|:80... connected.
 21HTTP request sent, awaiting response... 200 OK
 22Length: 41700 (41K) [application/x-gzip]
 23Saving to: “ipvsadm-1.26.tar.gz”
 24
 25100%[===================================================================================================================================>] 41,700       193K/s   in 0.2s
 26
 272018-11-02 02:55:25 (193 KB/s) - “ipvsadm-1.26.tar.gz” saved [41700/41700]
 28
 29[root@lvs_rip_web01 tools]# ls
 30ipvsadm-1.26.tar.gz
 31[root@lvs_rip_web01 tools]# rpm -qa libnl* popt*
 32popt-1.13-7.el6.x86_64
 33libnl-1.1.4-2.el6.x86_64
 34
 35[root@lvs_rip_web01 tools]#
 36[root@lvs_rip_web01 tools]# yum install libnl* popt* -y
 37Loaded plugins: fastestmirror, security
 38Setting up Install Process
 39Determining fastest mirrors
 40* base: mirrors.njupt.edu.cn
 41* extras: mirrors.njupt.edu.cn
 42* updates: ftp.sjtu.edu.cn
 43base                                                                                                                                                  | 3.7 kB     00:00
 44http://mirrors.njupt.edu.cn/centos/6.10/os/x86_64/repodata/1aa8754bde2f3921d67cca4bb70d9f587fb858a24cc3d1f66d3315292a89fc20-primary.sqlite.bz2: [Errno 14] PYCURL ERROR 7 - "couldn't connect to host"
 45Trying other mirror.
 46base/primary_db                                                                                                                                       | 4.7 MB     00:00
 47extras                                                                                                                                                | 3.4 kB     00:00
 48http://mirrors.njupt.edu.cn/centos/6.10/extras/x86_64/repodata/0eb1b6b805b166a5f14cd3ad42db731169281d059ffbcdb1ebc157c0e4f675cf-primary.sqlite.bz2: [Errno 14] PYCURL ERROR 7 - "couldn't connect to host"
 49Trying other mirror.
 50extras/primary_db                                                                                                                                     |  26 kB     00:00
 51updates                                                                                                                                               | 3.4 kB     00:00
 52updates/primary_db                                                                                                                                    | 1.9 MB     00:00
 53Package libnl-1.1.4-2.el6.x86_64 already installed and latest version
 54Package popt-1.13-7.el6.x86_64 already installed and latest version
 55Resolving Dependencies
 56--> Running transaction check
 57---> Package libnl-devel.x86_64 0:1.1.4-2.el6 will be installed
 58---> Package libnl3.x86_64 0:3.2.21-8.el6 will be installed
 59---> Package libnl3-cli.x86_64 0:3.2.21-8.el6 will be installed
 60---> Package libnl3-devel.x86_64 0:3.2.21-8.el6 will be installed
 61---> Package libnl3-doc.x86_64 0:3.2.21-8.el6 will be installed
 62---> Package popt-devel.x86_64 0:1.13-7.el6 will be installed
 63---> Package popt-static.x86_64 0:1.13-7.el6 will be installed
 64--> Finished Dependency Resolution
 65
 66Dependencies Resolved
 67
 68=============================================================================================================================================================================
 69Package                                      Arch                                   Version                                      Repository                            Size
 70=============================================================================================================================================================================
 71Installing:
 72libnl-devel                                  x86_64                                 1.1.4-2.el6                                  base                                 707 k
 73libnl3                                       x86_64                                 3.2.21-8.el6                                 base                                 183 k
 74libnl3-cli                                   x86_64                                 3.2.21-8.el6                                 base                                  58 k
 75libnl3-devel                                 x86_64                                 3.2.21-8.el6                                 base                                  56 k
 76libnl3-doc                                   x86_64                                 3.2.21-8.el6                                 base                                  10 M
 77popt-devel                                   x86_64                                 1.13-7.el6                                   base                                  21 k
 78popt-static                                  x86_64                                 1.13-7.el6                                   base                                  21 k
 79
 80Transaction Summary
 81=============================================================================================================================================================================
 82Install       7 Package(s)
 83
 84Total download size: 11 M
 85Installed size: 30 M
 86Downloading Packages:
 87(1/7): libnl-devel-1.1.4-2.el6.x86_64.rpm                                                                                                             | 707 kB     00:00
 88(2/7): libnl3-3.2.21-8.el6.x86_64.rpm                                                                                                                 | 183 kB     00:00
 89(3/7): libnl3-cli-3.2.21-8.el6.x86_64.rpm                                                                                                             |  58 kB     00:00
 90(4/7): libnl3-devel-3.2.21-8.el6.x86_64.rpm                                                                                                           |  56 kB     00:00
 91(5/7): libnl3-doc-3.2.21-8.el6.x86_64.rpm                                                                                                             |  10 MB     00:02
 92(6/7): popt-devel-1.13-7.el6.x86_64.rpm                                                                                                               |  21 kB     00:00
 93(7/7): popt-static-1.13-7.el6.x86_64.rpm                                                                                                              |  21 kB     00:00
 94-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 95Total                                                                                                                                        4.0 MB/s |  11 MB     00:02
 96Running rpm_check_debug
 97Running Transaction Test
 98Transaction Test Succeeded
 99Running Transaction
100Installing : libnl3-3.2.21-8.el6.x86_64                                                                                                                                1/7
101Installing : libnl3-cli-3.2.21-8.el6.x86_64                                                                                                                            2/7
102Installing : popt-devel-1.13-7.el6.x86_64                                                                                                                              3/7
103Installing : popt-static-1.13-7.el6.x86_64                                                                                                                             4/7
104Installing : libnl3-devel-3.2.21-8.el6.x86_64                                                                                                                          5/7
105Installing : libnl3-doc-3.2.21-8.el6.x86_64                                                                                                                            6/7
106Installing : libnl-devel-1.1.4-2.el6.x86_64                                                                                                                            7/7
107Verifying  : libnl3-devel-3.2.21-8.el6.x86_64                                                                                                                          1/7
108Verifying  : libnl-devel-1.1.4-2.el6.x86_64                                                                                                                            2/7
109Verifying  : popt-static-1.13-7.el6.x86_64                                                                                                                             3/7
110Verifying  : popt-devel-1.13-7.el6.x86_64                                                                                                                              4/7
111Verifying  : libnl3-cli-3.2.21-8.el6.x86_64                                                                                                                            5/7
112Verifying  : libnl3-3.2.21-8.el6.x86_64                                                                                                                                6/7
113Verifying  : libnl3-doc-3.2.21-8.el6.x86_64                                                                                                                            7/7
114
115Installed:
116libnl-devel.x86_64 0:1.1.4-2.el6  libnl3.x86_64 0:3.2.21-8.el6     libnl3-cli.x86_64 0:3.2.21-8.el6  libnl3-devel.x86_64 0:3.2.21-8.el6  libnl3-doc.x86_64 0:3.2.21-8.el6
117popt-devel.x86_64 0:1.13-7.el6    popt-static.x86_64 0:1.13-7.el6
118
119Complete!
120[root@lvs_rip_web01 tools]# rpm -qa libnl* popt*
121libnl3-3.2.21-8.el6.x86_64
122libnl3-devel-3.2.21-8.el6.x86_64
123popt-1.13-7.el6.x86_64
124libnl-1.1.4-2.el6.x86_64
125libnl3-cli-3.2.21-8.el6.x86_64
126popt-static-1.13-7.el6.x86_64
127libnl3-doc-3.2.21-8.el6.x86_64
128popt-devel-1.13-7.el6.x86_64
129libnl-devel-1.1.4-2.el6.x86_64
130[root@lvs_rip_web01 tools]# ls
131ipvsadm-1.26.tar.gz
132[root@lvs_rip_web01 tools]# tar -xf ipvsadm-1.26.tar.gz
133[root@lvs_rip_web01 tools]# ls
134ipvsadm-1.26  ipvsadm-1.26.tar.gz
135[root@lvs_rip_web01 tools]# cd ipvsadm-1.26
136[root@lvs_rip_web01 ipvsadm-1.26]# ls
137config_stream.c  contrib  dynamic_array.c  ipvsadm.8  ipvsadm-restore    ipvsadm-save    ipvsadm.sh    ipvsadm.spec.in  Makefile             README      VERSION
138config_stream.h  debian   dynamic_array.h  ipvsadm.c  ipvsadm-restore.8  ipvsadm-save.8  ipvsadm.spec  libipvs          PERSISTENCE_ENGINES  SCHEDULERS
139[root@lvs_rip_web01 ipvsadm-1.26]# make
140make -C libipvs
141make[1]: Entering directory `/home/tools/ipvsadm-1.26/libipvs'`
142gcc -Wall -Wunused -Wstrict-prototypes -g -fPIC -DLIBIPVS_USE_NL  -DHAVE_NET_IP_VS_H -c -o libipvs.o libipvs.c
143gcc -Wall -Wunused -Wstrict-prototypes -g -fPIC -DLIBIPVS_USE_NL  -DHAVE_NET_IP_VS_H -c -o ip_vs_nl_policy.o ip_vs_nl_policy.c
144ar rv libipvs.a libipvs.o ip_vs_nl_policy.o
145ar: creating libipvs.a
146a - libipvs.o
147a - ip_vs_nl_policy.o
148gcc -shared -Wl,-soname,libipvs.so -o libipvs.so libipvs.o ip_vs_nl_policy.o
149make[1]: Leaving directory `/home/tools/ipvsadm-1.26/libipvs'`
150gcc -Wall -Wunused -Wstrict-prototypes -g  -DVERSION=\"1.26\" -DSCHEDULERS=\""rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq"\" -DPE_LIST=\""sip"\" -DHAVE_POPT -DHAVE_NET_IP_VS_H -c -o ipvsadm.o ipvsadm.c
151ipvsadm.c: In function ‘print_largenum’:
152ipvsadm.c:1383: warning: field width should have type ‘int’, but argument 2 has type ‘size_t’
153gcc -Wall -Wunused -Wstrict-prototypes -g  -DVERSION=\"1.26\" -DSCHEDULERS=\""rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq"\" -DPE_LIST=\""sip"\" -DHAVE_POPT -DHAVE_NET_IP_VS_H -c -o config_stream.o config_stream.c
154gcc -Wall -Wunused -Wstrict-prototypes -g  -DVERSION=\"1.26\" -DSCHEDULERS=\""rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq"\" -DPE_LIST=\""sip"\" -DHAVE_POPT -DHAVE_NET_IP_VS_H -c -o dynamic_array.o dynamic_array.c
155gcc -Wall -Wunused -Wstrict-prototypes -g -o ipvsadm ipvsadm.o config_stream.o dynamic_array.o libipvs/libipvs.a -lpopt -lnl
156[root@lvs_rip_web01 ipvsadm-1.26]# echo $?
1570
158[root@lvs_rip_web01 ipvsadm-1.26]# make install
159make -C libipvs
160make[1]: Entering directory `/home/tools/ipvsadm-1.26/libipvs'`
161make[1]: Nothing to be done for `all'.`
162make[1]: Leaving directory `/home/tools/ipvsadm-1.26/libipvs'`
163if [ ! -d /sbin ]; then mkdir -p /sbin; fi
164install -m 0755 ipvsadm /sbin
165install -m 0755 ipvsadm-save /sbin
166install -m 0755 ipvsadm-restore /sbin
167[ -d /usr/man/man8 ] || mkdir -p /usr/man/man8
168install -m 0644 ipvsadm.8 /usr/man/man8
169install -m 0644 ipvsadm-save.8 /usr/man/man8
170install -m 0644 ipvsadm-restore.8 /usr/man/man8
171[ -d /etc/rc.d/init.d ] || mkdir -p /etc/rc.d/init.d
172install -m 0755 ipvsadm.sh /etc/rc.d/init.d/ipvsadm
173[root@lvs_rip_web01 ipvsadm-1.26]#
174[root@lvs_rip_web01 ipvsadm-1.26]# lsmod|grep ip_vs
175[root@lvs_rip_web01 ipvsadm-1.26]# lsmod|grep ipip
176[root@lvs_rip_web01 ipvsadm-1.26]# modprobe ipip
177[root@lvs_rip_web01 ipvsadm-1.26]# lsmod|grep ipip
178ipip                    8371  0
179tunnel4                 2943  1 ipip
180[root@lvs_rip_web01 ipvsadm-1.26]# ifconfig -a
181eth0      Link encap:Ethernet  HWaddr 00:0C:29:6F:BC:1F
182        inet addr:192.168.1.187  Bcast:192.168.1.255  Mask:255.255.255.0
183        inet6 addr: fe80::20c:29ff:fe6f:bc1f/64 Scope:Link
184        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
185        RX packets:69 errors:0 dropped:0 overruns:0 frame:0
186        TX packets:51 errors:0 dropped:0 overruns:0 carrier:0
187        collisions:0 txqueuelen:1000
188        RX bytes:8165 (7.9 KiB)  TX bytes:8098 (7.9 KiB)
189
190lo        Link encap:Local Loopback
191        inet addr:127.0.0.1  Mask:255.0.0.0
192        inet6 addr: ::1/128 Scope:Host
193        UP LOOPBACK RUNNING  MTU:65536  Metric:1
194        RX packets:0 errors:0 dropped:0 overruns:0 frame:0
195        TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
196        collisions:0 txqueuelen:0
197        RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
198
199tunl0     Link encap:IPIP Tunnel  HWaddr
200        NOARP  MTU:1480  Metric:1
201        RX packets:0 errors:0 dropped:0 overruns:0 frame:0
202        TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
203        collisions:0 txqueuelen:0
204        RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
205[root@lvs_rip_web01 ipvsadm-1.26]# /sbin/ipvsadm
206IP Virtual Server version 1.2.1 (size=4096)
207Prot LocalAddress:Port Scheduler Flags
208-> RemoteAddress:Port           Forward Weight ActiveConn InActConn
209[root@lvs_rip_web01 ipvsadm-1.26]#
210[root@lvs_rip_web01 ipvsadm-1.26]# lsmod|grep ip_vs
211ip_vs                 125694  0
212libcrc32c               1246  1 ip_vs
213ipv6                  334932  270 ip_vs,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6
214[root@lvs_rip_web01 ipvsadm-1.26]# route
215Kernel IP routing table
216Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
217192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
218link-local      *               255.255.0.0     U     1002   0        0 eth0
219default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
220[root@lvs_rip_web01 ipvsadm-1.26]# route add default gw 192.168.1.166
221[root@lvs_rip_web01 ipvsadm-1.26]# route del default gw 192.168.1.1
222[root@lvs_rip_web01 ipvsadm-1.26]# route
223Kernel IP routing table
224Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
225192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
226link-local      *               255.255.0.0     U     1002   0        0 eth0
227default         192.168.1.166   0.0.0.0         UG    0      0        0 eth0
228[root@lvs_rip_web01 ipvsadm-1.26]# ipvsadm -L -n
229IP Virtual Server version 1.2.1 (size=4096)
230Prot LocalAddress:Port Scheduler Flags
231-> RemoteAddress:Port           Forward Weight ActiveConn InActConn
232[root@lvs_rip_web01 ipvsadm-1.26]# ifconfig tunl0 192.168.1.250/24
233[root@lvs_rip_web01 ipvsadm-1.26]#
234[root@lvs_rip_web01 ipvsadm-1.26]# yum install httpd -y
235Loaded plugins: fastestmirror, security
236Setting up Install Process
237Loading mirror speeds from cached hostfile
238* base: mirrors.njupt.edu.cn
239* extras: mirrors.njupt.edu.cn
240* updates: ftp.sjtu.edu.cn
241Resolving Dependencies
242--> Running transaction check
243---> Package httpd.x86_64 0:2.2.15-69.el6.centos will be installed
244--> Processing Dependency: httpd-tools = 2.2.15-69.el6.centos for package: httpd-2.2.15-69.el6.centos.x86_64
245--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-69.el6.centos.x86_64
246--> Running transaction check
247---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed
248---> Package httpd-tools.x86_64 0:2.2.15-69.el6.centos will be installed
249--> Finished Dependency Resolution
250
251Dependencies Resolved
252
253================================================================================================================================================
254Package                             Arch                         Version                                      Repository                  Size
255================================================================================================================================================
256Installing:
257httpd                               x86_64                       2.2.15-69.el6.centos                         base                       836 k
258Installing for dependencies:
259apr-util-ldap                       x86_64                       1.3.9-3.el6_0.1                              base                        15 k
260httpd-tools                         x86_64                       2.2.15-69.el6.centos                         base                        81 k
261
262Transaction Summary
263================================================================================================================================================
264Install       3 Package(s)
265
266Total download size: 932 k
267Installed size: 3.2 M
268Downloading Packages:
269(1/3): apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm                                                                          |  15 kB     00:00
270http://mirrors.njupt.edu.cn/centos/6.10/os/x86_64/Packages/httpd-2.2.15-69.el6.centos.x86_64.rpm: [Errno 14] PYCURL ERROR 7 - "couldn't connect to host"
271Trying other mirror.
272(2/3): httpd-2.2.15-69.el6.centos.x86_64.rpm                                                                             | 836 kB     00:00
273(3/3): httpd-tools-2.2.15-69.el6.centos.x86_64.rpm                                                                       |  81 kB     00:00
274------------------------------------------------------------------------------------------------------------------------------------------------
275Total                                                                                                            43 kB/s | 932 kB     00:21
276Running rpm_check_debug
277Running Transaction Test
278Transaction Test Succeeded
279Running Transaction
280Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                                                                                         1/3
281Installing : httpd-tools-2.2.15-69.el6.centos.x86_64                                                                                      2/3
282Installing : httpd-2.2.15-69.el6.centos.x86_64                                                                                            3/3
283Verifying  : httpd-tools-2.2.15-69.el6.centos.x86_64                                                                                      1/3
284Verifying  : httpd-2.2.15-69.el6.centos.x86_64                                                                                            2/3
285Verifying  : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                                                                                         3/3
286
287Installed:
288httpd.x86_64 0:2.2.15-69.el6.centos
289
290Dependency Installed:
291apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1                                httpd-tools.x86_64 0:2.2.15-69.el6.centos
292
293Complete!
294[root@lvs_rip_web01 ipvsadm-1.26]#     ntpdate pool.ntp.org
295    sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
296    setenforce 0
297    /etc/init.d/iptables stop
298    chkconfig iptables off
2991 Nov 19:18:07 ntpdate[1732]: step time server 87.120.166.8 offset -28800.933704 sec
300[root@lvs_rip_web01 ipvsadm-1.26]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
301[root@lvs_rip_web01 ipvsadm-1.26]# setenforce 0
302[root@lvs_rip_web01 ipvsadm-1.26]# /etc/init.d/iptables stop
303iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
304iptables: Flushing firewall rules:                         [  OK  ]
305iptables: Unloading modules:                               [  OK  ]
306[root@lvs_rip_web01 ipvsadm-1.26]# chkconfig iptables off
307[root@lvs_rip_web01 ipvsadm-1.26]# sed -i "277i ServerName 127.0.0.1:80" /etc/httpd/conf/httpd.conf
308[root@lvs_rip_web01 ipvsadm-1.26]# /etc/init.d/httpd start
309Starting httpd:                                            [  OK  ]
310[root@lvs_rip_web01 ipvsadm-1.26]# ll /var/www/html/
311total 0
312[root@lvs_rip_web01 ipvsadm-1.26]# echo '192.168.1.187    this lvs is working'>>/var/www/html/index.html

15.2.4.2.4. lvs_rip_web02安装配置过程

安装配置过程:

  1[root@lvs_rip_web02 ~]# mkdir /home/tools -p
  2[root@lvs_rip_web02 ~]# ll /home
  3total 4
  4drwxr-xr-x. 2 root root 4096 Nov  2 02:51 tools
  5[root@lvs_rip_web02 ~]# lsmod|grep ip_vs
  6[root@lvs_rip_web02 ~]# echo '0' > /proc/sys/net/ipv4/ip_forward
  7[root@lvs_rip_web02 ~]# echo '1' > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
  8[root@lvs_rip_web02 ~]# echo '2' > /proc/sys/net/ipv4/conf/tunl0/arp_announce
  9[root@lvs_rip_web02 ~]# echo '1' > /proc/sys/net/ipv4/conf/all/arp_ignore
 10[root@lvs_rip_web02 ~]# echo '2' > /proc/sys/net/ipv4/conf/all/arp_announce
 11[root@lvs_rip_web02 ~]# echo '0' > /proc/sys/net/ipv4/conf/tunl0/rp_filter
 12[root@lvs_rip_web02 ~]# echo '0' > /proc/sys/net/ipv4/conf/all/rp_filter
 13[root@lvs_rip_web02 ~]# cd /home/tools
 14[root@lvs_rip_web02 tools]# pwd
 15/home/tools
 16[root@lvs_rip_web02 tools]# ls
 17[root@lvs_rip_web02 tools]# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
 18--2018-11-02 02:55:23--  http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
 19Resolving www.linuxvirtualserver.org... 173.255.202.51, 2600:3c00::f03c:91ff:fe96:fcc2
 20Connecting to www.linuxvirtualserver.org|173.255.202.51|:80... connected.
 21HTTP request sent, awaiting response... 200 OK
 22Length: 41700 (41K) [application/x-gzip]
 23Saving to: “ipvsadm-1.26.tar.gz”
 24
 25100%[===================================================================================================================================>] 41,700       189K/s   in 0.2s
 26
 272018-11-02 02:55:25 (189 KB/s) - “ipvsadm-1.26.tar.gz” saved [41700/41700]
 28
 29[root@lvs_rip_web02 tools]# ls
 30ipvsadm-1.26.tar.gz
 31[root@lvs_rip_web02 tools]# rpm -qa libnl* popt*
 32popt-1.13-7.el6.x86_64
 33libnl-1.1.4-2.el6.x86_64
 34
 35[root@lvs_rip_web02 tools]#
 36[root@lvs_rip_web02 tools]# yum install libnl* popt* -y
 37Loaded plugins: fastestmirror, security
 38Setting up Install Process
 39Determining fastest mirrors
 40* base: mirrors.huaweicloud.com
 41* extras: mirrors.huaweicloud.com
 42* updates: mirrors.huaweicloud.com
 43base                                                                                                                                                  | 3.7 kB     00:00
 44base/primary_db                                                                                                                                       | 4.7 MB     00:00
 45extras                                                                                                                                                | 3.4 kB     00:00
 46extras/primary_db                                                                                                                                     |  26 kB     00:00
 47updates                                                                                                                                               | 3.4 kB     00:00
 48updates/primary_db                                                                                                                                    | 1.9 MB     00:00
 49Package libnl-1.1.4-2.el6.x86_64 already installed and latest version
 50Package popt-1.13-7.el6.x86_64 already installed and latest version
 51Resolving Dependencies
 52--> Running transaction check
 53---> Package libnl-devel.x86_64 0:1.1.4-2.el6 will be installed
 54---> Package libnl3.x86_64 0:3.2.21-8.el6 will be installed
 55---> Package libnl3-cli.x86_64 0:3.2.21-8.el6 will be installed
 56---> Package libnl3-devel.x86_64 0:3.2.21-8.el6 will be installed
 57---> Package libnl3-doc.x86_64 0:3.2.21-8.el6 will be installed
 58---> Package popt-devel.x86_64 0:1.13-7.el6 will be installed
 59---> Package popt-static.x86_64 0:1.13-7.el6 will be installed
 60--> Finished Dependency Resolution
 61
 62Dependencies Resolved
 63
 64=============================================================================================================================================================================
 65Package                                      Arch                                   Version                                      Repository                            Size
 66=============================================================================================================================================================================
 67Installing:
 68libnl-devel                                  x86_64                                 1.1.4-2.el6                                  base                                 707 k
 69libnl3                                       x86_64                                 3.2.21-8.el6                                 base                                 183 k
 70libnl3-cli                                   x86_64                                 3.2.21-8.el6                                 base                                  58 k
 71libnl3-devel                                 x86_64                                 3.2.21-8.el6                                 base                                  56 k
 72libnl3-doc                                   x86_64                                 3.2.21-8.el6                                 base                                  10 M
 73popt-devel                                   x86_64                                 1.13-7.el6                                   base                                  21 k
 74popt-static                                  x86_64                                 1.13-7.el6                                   base                                  21 k
 75
 76Transaction Summary
 77=============================================================================================================================================================================
 78Install       7 Package(s)
 79
 80Total download size: 11 M
 81Installed size: 30 M
 82Downloading Packages:
 83(1/7): libnl-devel-1.1.4-2.el6.x86_64.rpm                                                                                                             | 707 kB     00:00
 84(2/7): libnl3-3.2.21-8.el6.x86_64.rpm                                                                                                                 | 183 kB     00:00
 85(3/7): libnl3-cli-3.2.21-8.el6.x86_64.rpm                                                                                                             |  58 kB     00:00
 86(4/7): libnl3-devel-3.2.21-8.el6.x86_64.rpm                                                                                                           |  56 kB     00:00
 87(5/7): libnl3-doc-3.2.21-8.el6.x86_64.rpm                                                                                                             |  10 MB     00:02
 88(6/7): popt-devel-1.13-7.el6.x86_64.rpm                                                                                                               |  21 kB     00:00
 89(7/7): popt-static-1.13-7.el6.x86_64.rpm                                                                                                              |  21 kB     00:00
 90-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 91Total                                                                                                                                        3.7 MB/s |  11 MB     00:02
 92Running rpm_check_debug
 93Running Transaction Test
 94Transaction Test Succeeded
 95Running Transaction
 96Installing : libnl3-3.2.21-8.el6.x86_64                                                                                                                                1/7
 97Installing : libnl3-cli-3.2.21-8.el6.x86_64                                                                                                                            2/7
 98Installing : popt-devel-1.13-7.el6.x86_64                                                                                                                              3/7
 99Installing : popt-static-1.13-7.el6.x86_64                                                                                                                             4/7
100Installing : libnl3-devel-3.2.21-8.el6.x86_64                                                                                                                          5/7
101Installing : libnl3-doc-3.2.21-8.el6.x86_64                                                                                                                            6/7
102Installing : libnl-devel-1.1.4-2.el6.x86_64                                                                                                                            7/7
103Verifying  : libnl3-devel-3.2.21-8.el6.x86_64                                                                                                                          1/7
104Verifying  : libnl-devel-1.1.4-2.el6.x86_64                                                                                                                            2/7
105Verifying  : popt-static-1.13-7.el6.x86_64                                                                                                                             3/7
106Verifying  : popt-devel-1.13-7.el6.x86_64                                                                                                                              4/7
107Verifying  : libnl3-cli-3.2.21-8.el6.x86_64                                                                                                                            5/7
108Verifying  : libnl3-3.2.21-8.el6.x86_64                                                                                                                                6/7
109Verifying  : libnl3-doc-3.2.21-8.el6.x86_64                                                                                                                            7/7
110
111Installed:
112libnl-devel.x86_64 0:1.1.4-2.el6  libnl3.x86_64 0:3.2.21-8.el6     libnl3-cli.x86_64 0:3.2.21-8.el6  libnl3-devel.x86_64 0:3.2.21-8.el6  libnl3-doc.x86_64 0:3.2.21-8.el6
113popt-devel.x86_64 0:1.13-7.el6    popt-static.x86_64 0:1.13-7.el6
114
115Complete!
116[root@lvs_rip_web02 tools]# rpm -qa libnl* popt*
117libnl3-3.2.21-8.el6.x86_64
118libnl3-devel-3.2.21-8.el6.x86_64
119popt-1.13-7.el6.x86_64
120libnl-1.1.4-2.el6.x86_64
121libnl3-cli-3.2.21-8.el6.x86_64
122popt-static-1.13-7.el6.x86_64
123libnl3-doc-3.2.21-8.el6.x86_64
124popt-devel-1.13-7.el6.x86_64
125libnl-devel-1.1.4-2.el6.x86_64
126[root@lvs_rip_web02 tools]# ls
127ipvsadm-1.26.tar.gz
128[root@lvs_rip_web02 tools]# tar -xf ipvsadm-1.26.tar.gz
129[root@lvs_rip_web02 tools]# ls
130ipvsadm-1.26  ipvsadm-1.26.tar.gz
131[root@lvs_rip_web02 tools]# cd ipvsadm-1.26
132[root@lvs_rip_web02 ipvsadm-1.26]# ls
133config_stream.c  contrib  dynamic_array.c  ipvsadm.8  ipvsadm-restore    ipvsadm-save    ipvsadm.sh    ipvsadm.spec.in  Makefile             README      VERSION
134config_stream.h  debian   dynamic_array.h  ipvsadm.c  ipvsadm-restore.8  ipvsadm-save.8  ipvsadm.spec  libipvs          PERSISTENCE_ENGINES  SCHEDULERS
135[root@lvs_rip_web02 ipvsadm-1.26]# make
136make -C libipvs
137make[1]: Entering directory `/home/tools/ipvsadm-1.26/libipvs'`
138gcc -Wall -Wunused -Wstrict-prototypes -g -fPIC -DLIBIPVS_USE_NL  -DHAVE_NET_IP_VS_H -c -o libipvs.o libipvs.c
139gcc -Wall -Wunused -Wstrict-prototypes -g -fPIC -DLIBIPVS_USE_NL  -DHAVE_NET_IP_VS_H -c -o ip_vs_nl_policy.o ip_vs_nl_policy.c
140ar rv libipvs.a libipvs.o ip_vs_nl_policy.o
141ar: creating libipvs.a
142a - libipvs.o
143a - ip_vs_nl_policy.o
144gcc -shared -Wl,-soname,libipvs.so -o libipvs.so libipvs.o ip_vs_nl_policy.o
145make[1]: Leaving directory `/home/tools/ipvsadm-1.26/libipvs'`
146gcc -Wall -Wunused -Wstrict-prototypes -g  -DVERSION=\"1.26\" -DSCHEDULERS=\""rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq"\" -DPE_LIST=\""sip"\" -DHAVE_POPT -DHAVE_NET_IP_VS_H -c -o ipvsadm.o ipvsadm.c
147ipvsadm.c: In function ‘print_largenum’:
148ipvsadm.c:1383: warning: field width should have type ‘int’, but argument 2 has type ‘size_t’
149gcc -Wall -Wunused -Wstrict-prototypes -g  -DVERSION=\"1.26\" -DSCHEDULERS=\""rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq"\" -DPE_LIST=\""sip"\" -DHAVE_POPT -DHAVE_NET_IP_VS_H -c -o config_stream.o config_stream.c
150gcc -Wall -Wunused -Wstrict-prototypes -g  -DVERSION=\"1.26\" -DSCHEDULERS=\""rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq"\" -DPE_LIST=\""sip"\" -DHAVE_POPT -DHAVE_NET_IP_VS_H -c -o dynamic_array.o dynamic_array.c
151gcc -Wall -Wunused -Wstrict-prototypes -g -o ipvsadm ipvsadm.o config_stream.o dynamic_array.o libipvs/libipvs.a -lpopt -lnl
152[root@lvs_rip_web02 ipvsadm-1.26]# echo $?
1530
154[root@lvs_rip_web02 ipvsadm-1.26]# make install
155make -C libipvs
156make[1]: Entering directory `/home/tools/ipvsadm-1.26/libipvs'`
157make[1]: Nothing to be done for `all'.`
158make[1]: Leaving directory `/home/tools/ipvsadm-1.26/libipvs'`
159if [ ! -d /sbin ]; then mkdir -p /sbin; fi
160install -m 0755 ipvsadm /sbin
161install -m 0755 ipvsadm-save /sbin
162install -m 0755 ipvsadm-restore /sbin
163[ -d /usr/man/man8 ] || mkdir -p /usr/man/man8
164install -m 0644 ipvsadm.8 /usr/man/man8
165install -m 0644 ipvsadm-save.8 /usr/man/man8
166install -m 0644 ipvsadm-restore.8 /usr/man/man8
167[ -d /etc/rc.d/init.d ] || mkdir -p /etc/rc.d/init.d
168install -m 0755 ipvsadm.sh /etc/rc.d/init.d/ipvsadm
169[root@lvs_rip_web02 ipvsadm-1.26]#
170[root@lvs_rip_web02 ipvsadm-1.26]#
171[root@lvs_rip_web02 ipvsadm-1.26]# lsmod|grep ip_vs
172[root@lvs_rip_web02 ipvsadm-1.26]# /sbin/ipvsadm
173IP Virtual Server version 1.2.1 (size=4096)
174Prot LocalAddress:Port Scheduler Flags
175-> RemoteAddress:Port           Forward Weight ActiveConn InActConn
176[root@lvs_rip_web02 ipvsadm-1.26]#
177[root@lvs_rip_web02 ipvsadm-1.26]# lsmod|grep ip_vs
178[root@lvs_rip_web02 ipvsadm-1.26]# lsmod|grep ipip
179[root@lvs_rip_web02 ipvsadm-1.26]# modprobe ipip
180[root@lvs_rip_web02 ipvsadm-1.26]# lsmod|grep ipip
181ipip                    8371  0
182tunnel4                 2943  1 ipip
183[root@lvs_rip_web02 ipvsadm-1.26]# ifconfig -a
184eth0      Link encap:Ethernet  HWaddr 00:0C:29:A8:D7:AF
185        inet addr:192.168.1.163  Bcast:192.168.1.255  Mask:255.255.255.0
186        inet6 addr: fe80::20c:29ff:fea8:d7af/64 Scope:Link
187        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
188        RX packets:80 errors:0 dropped:0 overruns:0 frame:0
189        TX packets:55 errors:0 dropped:0 overruns:0 carrier:0
190        collisions:0 txqueuelen:1000
191        RX bytes:9107 (8.8 KiB)  TX bytes:8586 (8.3 KiB)
192
193lo        Link encap:Local Loopback
194        inet addr:127.0.0.1  Mask:255.0.0.0
195        inet6 addr: ::1/128 Scope:Host
196        UP LOOPBACK RUNNING  MTU:65536  Metric:1
197        RX packets:0 errors:0 dropped:0 overruns:0 frame:0
198        TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
199        collisions:0 txqueuelen:0
200        RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
201
202tunl0     Link encap:IPIP Tunnel  HWaddr
203        NOARP  MTU:1480  Metric:1
204        RX packets:0 errors:0 dropped:0 overruns:0 frame:0
205        TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
206        collisions:0 txqueuelen:0
207        RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
208[root@lvs_rip_web02 ipvsadm-1.26]# route
209Kernel IP routing table
210Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
211192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
212link-local      *               255.255.0.0     U     1002   0        0 eth0
213default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
214[root@lvs_rip_web02 ipvsadm-1.26]# route add default gw 192.168.1.166
215[root@lvs_rip_web02 ipvsadm-1.26]# route del default gw 192.168.1.1
216[root@lvs_rip_web02 ipvsadm-1.26]# route
217Kernel IP routing table
218Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
219192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
220link-local      *               255.255.0.0     U     1002   0        0 eth0
221default         192.168.1.166   0.0.0.0         UG    0      0        0 eth0
222[root@lvs_rip_web02 ipvsadm-1.26]# ipvsadm -L -n
223IP Virtual Server version 1.2.1 (size=4096)
224Prot LocalAddress:Port Scheduler Flags
225-> RemoteAddress:Port           Forward Weight ActiveConn InActConn
226[root@lvs_rip_web02 ipvsadm-1.26]# ifconfig tunl0 192.168.1.250/24
227[root@lvs_rip_web02 ipvsadm-1.26]#
228[root@lvs_rip_web02 ipvsadm-1.26]# yum install httpd -y
229Loaded plugins: fastestmirror, security
230Setting up Install Process
231Loading mirror speeds from cached hostfile
232* base: mirrors.huaweicloud.com
233* extras: mirrors.huaweicloud.com
234* updates: mirrors.huaweicloud.com
235Resolving Dependencies
236--> Running transaction check
237---> Package httpd.x86_64 0:2.2.15-69.el6.centos will be installed
238--> Processing Dependency: httpd-tools = 2.2.15-69.el6.centos for package: httpd-2.2.15-69.el6.centos.x86_64
239--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-69.el6.centos.x86_64
240--> Running transaction check
241---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed
242---> Package httpd-tools.x86_64 0:2.2.15-69.el6.centos will be installed
243--> Finished Dependency Resolution
244
245Dependencies Resolved
246
247================================================================================================================================================
248Package                             Arch                         Version                                      Repository                  Size
249================================================================================================================================================
250Installing:
251httpd                               x86_64                       2.2.15-69.el6.centos                         base                       836 k
252Installing for dependencies:
253apr-util-ldap                       x86_64                       1.3.9-3.el6_0.1                              base                        15 k
254httpd-tools                         x86_64                       2.2.15-69.el6.centos                         base                        81 k
255
256Transaction Summary
257================================================================================================================================================
258Install       3 Package(s)
259
260Total download size: 932 k
261Installed size: 3.2 M
262Downloading Packages:
263(1/3): apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm                                                                          |  15 kB     00:00
264(2/3): httpd-2.2.15-69.el6.centos.x86_64.rpm                                                                             | 836 kB     00:00
265(3/3): httpd-tools-2.2.15-69.el6.centos.x86_64.rpm                                                                       |  81 kB     00:00
266------------------------------------------------------------------------------------------------------------------------------------------------
267Total                                                                                                           2.6 MB/s | 932 kB     00:00
268Running rpm_check_debug
269Running Transaction Test
270Transaction Test Succeeded
271Running Transaction
272Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                                                                                         1/3
273Installing : httpd-tools-2.2.15-69.el6.centos.x86_64                                                                                      2/3
274Installing : httpd-2.2.15-69.el6.centos.x86_64                                                                                            3/3
275Verifying  : httpd-tools-2.2.15-69.el6.centos.x86_64                                                                                      1/3
276Verifying  : httpd-2.2.15-69.el6.centos.x86_64                                                                                            2/3
277Verifying  : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                                                                                         3/3
278
279Installed:
280httpd.x86_64 0:2.2.15-69.el6.centos
281
282Dependency Installed:
283apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1                                httpd-tools.x86_64 0:2.2.15-69.el6.centos
284
285Complete!
286[root@lvs_rip_web02 ipvsadm-1.26]#     ntpdate pool.ntp.org
287    sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
288    setenforce 0
289    /etc/init.d/iptables stop
290    chkconfig iptables off
2911 Nov 19:18:08 ntpdate[1629]: step time server 87.120.166.8 offset -28800.981356 sec
292[root@lvs_rip_web02 ipvsadm-1.26]#     sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
293[root@lvs_rip_web02 ipvsadm-1.26]#     setenforce 0
294[root@lvs_rip_web02 ipvsadm-1.26]#     /etc/init.d/iptables stop
295iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
296iptables: Flushing firewall rules:                         [  OK  ]
297iptables: Unloading modules:                               [  OK  ]
298[root@lvs_rip_web02 ipvsadm-1.26]#     chkconfig iptables off
299[root@lvs_rip_web02 ipvsadm-1.26]# sed -i "277i ServerName 127.0.0.1:80" /etc/httpd/conf/httpd.conf
300[root@lvs_rip_web02 ipvsadm-1.26]# /etc/init.d/httpd start
301Starting httpd:                                            [  OK  ]
302[root@lvs_rip_web02 ipvsadm-1.26]# ll /var/www/html/
303total 0
304[root@lvs_rip_web02 ipvsadm-1.26]# echo '192.168.1.163    this lvs is working'>>/var/www/html/index.html

15.2.4.3. 测试

15.2.4.3.1. lvs_vip_01本地测试

1[root@lvs_vip_01 ipvsadm-1.26]# curl http://192.168.1.163
2192.168.1.163    this lvs is working
3[root@lvs_vip_01 ipvsadm-1.26]# curl http://192.168.1.187
4192.168.1.187    this lvs is working

15.2.4.3.2. lvs_rip_web01本地测试

1[root@lvs_rip_web01 ipvsadm-1.26]# curl http://192.168.1.187
2192.168.1.187    this lvs is working

15.2.4.3.3. lvs_rip_web02本地测试

1[root@lvs_rip_web02 ipvsadm-1.26]# curl http://192.168.1.163
2192.168.1.163    this lvs is working

15.2.4.3.4. 抓包分析

  1. 以下三台服务器都运行相应的命令
    • lvs_vip_01

      tcpdump -i eth0:0 dst port 80

    • lvs_rip_web01

      tcpdump -i eth0 src host 192.168.161.137 or dst host 192.168.161.137

    • lvs_rip_web02

      tcpdump -i eth0 src host 192.168.161.137 or dst host 192.168.161.137

  2. 从本地另一个IP为: 192.168.161.137 访问,即运行命令: curl http://192.168.1.250

  3. 查看监控的抓包信息:

15.2.4.4. 开机自启动

需要编写脚本校验然后开启。也可以结合keepalive做。