- 部署规划
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.虚拟机网络配置
N[1-n]主机lo:0接口上的vip在后面步骤设置。 /**DR eth0**/ [[email protected] ~]#ifconfig eth0 192.168.13.210 netmask 255.255.255.0 up [[email protected] ~]#route add default gw 192.168.13.1 dev eth0 /**vip所在网卡都加一条特殊路由,意思是以目标地址进来的请求数据包, 那么响应数据包的源地址都应为该设备上的ip地址**/ [[email protected] ~]#route add -host 192.168.13.210 dev eth0 /**DR eth1**/ [[email protected] ~]#ifconfig eth1 192.168.19.3 netmask 255.255.255.0 up [[email protected] ~]#route add default gw 192.168.19.6 dev eth1 [[email protected] ~]#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**/ [[email protected] ~]#ifconfig eth0 192.168.19.4 netmask 255.255.255.0 up [[email protected] ~]#route add default gw 192.168.19.6 dev eth0 [[email protected] ~]#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**/ [[email protected] ~]#ifconfig eth0 192.168.19.5 netmask 255.255.255.0 up [[email protected] ~]#route add default gw 192.168.19.6 dev eth0 [[email protected] ~]#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**/ [[email protected] ~]#ifconfig eth0 192.168.19.7 netmask 255.255.255.0 up [[email protected] ~]#route add default gw 192.168.19.6 dev eth0 [[email protected] ~]#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**/ [[email protected] ~]#ifconfig eth0 192.168.19.8 netmask 255.255.255.0 up [[email protected] ~]#route add default gw 192.168.19.6 dev eth0 [[email protected] ~]#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**/ [[email protected] ~]#ifconfig eth0 192.168.19.9 netmask 255.255.255.0 up [[email protected] ~]#route add default gw 192.168.19.6 dev eth0 [[email protected] ~]#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**/ [[email protected] ~]#ifconfig eth0 192.168.19.10 netmask 255.255.255.0 up [[email protected] ~]#route add default gw 192.168.19.6 dev eth0 [[email protected] ~]#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不能同时开。
[[email protected] ~]#chkconfig iptables off [[email protected] ~]#service iptables stop [[email protected] ~]#setenforce
(1)在N1和N2上安装nginx
nginx-1.6.2.tar.gz
[[email protected] ~]#yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel [[email protected] ~]#mv nginx-1.6.2.tar.gz /usr/local/src [[email protected] ~]#cd /usr/local/src [[email protected] src]#tar -zxvf nginx-1.6.2.tar.gz [[email protected] src]#cd nginx-1.6.2 [[email protected] src]#./configure [[email protected] src]#make [[email protected] src]#make install [[email protected] src]#cd /usr/local/nginx [[email protected] nginx]#echo "test nginx 192.168.19.4" > html/index.html /**在N1上执行**/ [[email protected] nginx]#echo "test nginx 192.168.19.5" > html/index.html /**在N2上执行**/ [[email protected] nginx]#sbin/nginx /**启动nginx**/ [[email protected] nginx]#vi /etc/rc.local /usr/local/nginx/sbin/nginx :wq
(2)安装tomcat(略)
(3)在DR上安装ipadm和ipvs(ipvs模块编绎在linux内核不用安装)
[[email protected] nginx]#grep -i ‘vs‘ /boot/config-2.6.32-642.el6.x86_64 /**查看ipvs模块是否存在**/ [[email protected] nginx]#yum install ipvsadm
5.配置N[1-n]的lo:0接口的vip
/**N1和N2 设置禁用arp的内核参数,为了让别的主机发现不要它,不与外界通迅**/ [[email protected] ~]#sysctl -w net.ipv4.conf.lo.arp_announce=2 [[email protected] ~]#sysctl -w net.ipv4.conf.all.arp_announce=2 [[email protected] ~]#sysctl -w net.ipv4.conf.lo.arp_ignore=1 [[email protected] ~]#sysctl -w net.ipv4.conf.all.arp_ignore=1 /**N1和N2 lo:0**/ /**禁止这个网卡与外界通迅,设置广播为自已,掩码4个255,表示网络中只有自已本身一个主机**/ [[email protected] ~]#ifconfig lo:0 192.168.13.210 broadcast 192.168.13.210 netmask 255.255.255.255 up /**vip所在网卡都加一条特殊路由,意思是以目标地址进来的请求数据包, 那么响应数据包的源地址都应为该设备上的ip地址**/ [[email protected] ~]#route add -host 192.168.13.210 dev lo:0 [[email protected] ~]#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服务
[[email protected] ~]#ipvsadm -C [[email protected] ~]#ipvsadm -A -t 192.168.13.210:80 -s wlc [[email protected] ~]#ipvsadm -a -t 192.168.13.210:80 -r 192.168.19.4 -g -w 1 [[email protected] ~]#ipvsadm -a -t 192.168.13.210:80 -r 192.168.19.5 -g -w 2 [[email protected] ~]#ipvsadm -L -n [[email protected] ~]#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.测试
时间: 2024-10-24 22:27:55