|
2.设备ip规划:
因为只是本机摸拟,设备全部用虚拟机,包括机器、路由器、交换机都可用vmware搞定。
除R1、C、S1是真实设备,其它都为虚拟设备,简单介绍下每个设备的情况。
R1:所在公司网络路由器。
C:自已的电脑。
S1:采用桥接模式就相当于连入了这个交换机,从而成为这网络的一部分,而这个网络一般就叫VMnet0。(不一定准切,但是这个道理)
S2:采用仅主机模式就接入了这个交换机,这个网络一般就叫VMnet1。
DR:两个网卡,一个桥接模式,一个仅主机模式。
N[1-n]:Nginx服务器,采用一个网卡,采用仅主机模式。
T[1-n]:Tomcat服务器,采用一个网卡,采用仅主机模式。
R2:软路由,采用两个网卡,一个桥接模式,一个仅主机模式。
设备名 | 接口名 | ip | 默认网关 | 子网掩码 | 接入模式 | C | 本机网卡 | 192.168.13.121 | 192.168.13.1 | 255.255.255.0 | - | R1 | lan口 | 192.168.13.1 | - | 255.255.255.0 | - | R2 | wan口 | 192.168.13.125 | 192.168.13.1 | 255.255.255.0 | 桥接 | R2 | lan口 | 192.168.19.6 | - | 255.255.255.0 | 仅主机 | DR | eth0 | 192.168.13.210(vip) | 192.168.13.1 | 255.255.255.0 | 桥接 | DR | eth1 | 192.168.19.3 | 192.168.19.6 | 255.255.255.0 | 仅主机 | N1 | eth0 | 192.168.19.4 | 192.168.19.6 | 255.255.255.0 | 仅主机 | N1 | lo:0 | 192.168.13.210(vip) | - | 255.255.255.255 | - | N2 | eth0 | 192.168.19.5 | 192.168.19.6 | 255.255.255.0 | 仅主机 | N2 | lo:0 | 192.168.13.210(vip) | - | 255.255.255.255 | - | T1 | eth0 | 192.168.19.7 | 192.168.19.6 | 255.255.255.0 | 仅主机 | T2 | eth0 | 192.168.19.8 | 192.168.19.6 | 255.255.255.0 | 仅主机 | T3 | eth0 | 192.168.19.9 | 192.168.19.6 | 255.255.255.0 | 仅主机 | T4 | eth0 | 192.168.19.10 | 192.168.19.6 | 255.255.255.0 | 仅主机 | | | | | | | | | | | | | | | | | | | | | | | | |
3.虚拟机网络配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
| N[1-n]主机lo:0接口上的vip在后面步骤设置。
/**DR eth0**/
[iyunv@server ~]#ifconfig eth0 192.168.13.210 netmask 255.255.255.0 up
[iyunv@server ~]#route add default gw 192.168.13.1 dev eth0
/**vip所在网卡都加一条特殊路由,意思是以目标地址进来的请求数据包,
那么响应数据包的源地址都应为该设备上的ip地址**/
[iyunv@server ~]#route add -host 192.168.13.210 dev eth0
/**DR eth1**/
[iyunv@server ~]#ifconfig eth1 192.168.19.3 netmask 255.255.255.0 up
[iyunv@server ~]#route add default gw 192.168.19.6 dev eth1
[iyunv@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.13.210 netmask 255.255.255.0 up
route add default gw 192.168.13.1 dev eth0
ifconfig eth1 192.168.19.3 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth1
:wq
/**N1 eth0**/
[iyunv@server ~]#ifconfig eth0 192.168.19.4 netmask 255.255.255.0 up
[iyunv@server ~]#route add default gw 192.168.19.6 dev eth0
[iyunv@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.19.4 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth0
:wq
/**N2 eth0**/
[iyunv@server ~]#ifconfig eth0 192.168.19.5 netmask 255.255.255.0 up
[iyunv@server ~]#route add default gw 192.168.19.6 dev eth0
[iyunv@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.19.5 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth0
:wq
/**T1 eth0**/
[iyunv@server ~]#ifconfig eth0 192.168.19.7 netmask 255.255.255.0 up
[iyunv@server ~]#route add default gw 192.168.19.6 dev eth0
[iyunv@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.19.7 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth0
:wq
/**T2 eth0**/
[iyunv@server ~]#ifconfig eth0 192.168.19.8 netmask 255.255.255.0 up
[iyunv@server ~]#route add default gw 192.168.19.6 dev eth0
[iyunv@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.19.8 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth0
:wq
/**T3 eth0**/
[iyunv@server ~]#ifconfig eth0 192.168.19.9 netmask 255.255.255.0 up
[iyunv@server ~]#route add default gw 192.168.19.6 dev eth0
[iyunv@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.19.9 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth0
:wq
/**T4 eth0**/
[iyunv@server ~]#ifconfig eth0 192.168.19.10 netmask 255.255.255.0 up
[iyunv@server ~]#route add default gw 192.168.19.6 dev eth0
[iyunv@server ~]#vi /etc/rc.local
ifconfig eth0 192.168.19.10 netmask 255.255.255.0 up
route add default gw 192.168.19.6 dev eth0
:wq
|
4.安装软件
在每台机上把防火墙都先关闭,避免干扰。dr上一定要关闭,因为ipvs和iptables不能同时开。
1
2
3
| [iyunv@server ~]#chkconfig iptables off
[iyunv@server ~]#service iptables stop
[iyunv@server ~]#setenforce
|
(1)在N1和N2上安装nginx
nginx-1.6.2.tar.gz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| [iyunv@server ~]#yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
[iyunv@server ~]#mv nginx-1.6.2.tar.gz /usr/local/src
[iyunv@server ~]#cd /usr/local/src
[iyunv@server src]#tar -zxvf nginx-1.6.2.tar.gz
[iyunv@server src]#cd nginx-1.6.2
[iyunv@server src]#./configure
[iyunv@server src]#make
[iyunv@server src]#make install
[iyunv@server src]#cd /usr/local/nginx
[iyunv@server nginx]#echo "test nginx 192.168.19.4" > html/index.html /**在N1上执行**/
[iyunv@server nginx]#echo "test nginx 192.168.19.5" > html/index.html /**在N2上执行**/
[iyunv@server nginx]#sbin/nginx /**启动nginx**/
[iyunv@server nginx]#vi /etc/rc.local
/usr/local/nginx/sbin/nginx
:wq
|
(2)安装tomcat(略)
(3)在DR上安装ipadm和ipvs(ipvs模块编绎在linux内核不用安装)
1
2
| [iyunv@server nginx]#grep -i 'vs' /boot/config-2.6.32-642.el6.x86_64 /**查看ipvs模块是否存在**/
[iyunv@server nginx]#yum install ipvsadm
|
5.配置N[1-n]的lo:0接口的vip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| /**N1和N2 设置禁用arp的内核参数,为了让别的主机发现不要它,不与外界通迅**/
[iyunv@server ~]#sysctl -w net.ipv4.conf.lo.arp_announce=2
[iyunv@server ~]#sysctl -w net.ipv4.conf.all.arp_announce=2
[iyunv@server ~]#sysctl -w net.ipv4.conf.lo.arp_ignore=1
[iyunv@server ~]#sysctl -w net.ipv4.conf.all.arp_ignore=1
/**N1和N2 lo:0**/
/**禁止这个网卡与外界通迅,设置广播为自已,掩码4个255,表示网络中只有自已本身一个主机**/
[iyunv@server ~]#ifconfig lo:0 192.168.13.210 broadcast 192.168.13.210 netmask 255.255.255.255 up
/**vip所在网卡都加一条特殊路由,意思是以目标地址进来的请求数据包,
那么响应数据包的源地址都应为该设备上的ip地址**/
[iyunv@server ~]#route add -host 192.168.13.210 dev lo:0
[iyunv@server ~]#vi /etc/rc.local
sysctl -w net.ipv4.conf.lo.arp_announce=2
sysctl -w net.ipv4.conf.all.arp_announce=2
sysctl -w net.ipv4.conf.lo.arp_ignore=1
sysctl -w net.ipv4.conf.all.arp_ignore=1
ifconfig lo:0 192.168.13.210 broadcast 192.168.13.210 netmask 255.255.255.255 up
route add -host 192.168.13.210 dev lo:0
:wq
|
6.开启DR并添加nginx服务
1
2
3
4
5
6
7
8
9
10
| [iyunv@server ~]#ipvsadm -C
[iyunv@server ~]#ipvsadm -A -t 192.168.13.210:80 -s wlc
[iyunv@server ~]#ipvsadm -a -t 192.168.13.210:80 -r 192.168.19.4 -g -w 1
[iyunv@server ~]#ipvsadm -a -t 192.168.13.210:80 -r 192.168.19.5 -g -w 2
[iyunv@server ~]#ipvsadm -L -n
[iyunv@server ~]#vi /etc/rc.local
ipvsadm -A -t 192.168.13.210:80 -s wlc
ipvsadm -a -t 192.168.13.210:80 -r 192.168.19.4 -g -w 1
ipvsadm -a -t 192.168.13.210:80 -r 192.168.19.5 -g -w 2
:wq
|
6.测试
|
|
|
|
|
|
|