Ivs(DR模式)+nginx+tomcat

Ivs(DR模式)+nginx+tomcat

实验要求:

Ivs实现四层转发+nginx实现7层转发(动态)
访问Ivs的vip地址可以实现动静分离。

客户端:192.168.11.136
调度器:192.168.11.139
nginx1:192.168.11.137
nginx2:192.168.11.138
tomcat1:192.168.11.140
tomcat2:192.168.11.141

在这里插入图片描述

调度器配置

[root@test4 network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@test4 network-scripts]# cat ifcfg-ens33:0
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.11.100
NETMAST=255.255.255.255

[root@test4~]yum install -y ipvsadm*
[root@test4 ~]# ipvsadm -a -t 192.168.11.137:80 -s rr
[root@test4 ~]# ipvsadm -e -t 192.168.11.100:80 -r 192.168.11.137:80 -w1
[root@test4 ~]# ipvsadm -e -t 192.168.11.100:80 -r 192.168.11.138:80 -w1
[root@test4 ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.11.100:80 rr
  -> 192.168.11.137:80            Route   1      0          0         
  -> 192.168.11.138:80            Route   1      0          0  
[root@test4 conf]# vim /etc/sysctl.conf 
net.ipv4.ip_forward=0
#关闭数据包转发功能
net.ipv4.conf.all.send_redirects=0
#禁止系统发送icmp重定向的消息
net.ipv4.conf.default.send_redirects=0
#禁止默认网络接口发送icmp重定向的消息
net.ipv4.conf.ens33.send_redirects=0
#针对ens33设备,禁止发送icmp重定向消息

[root@test4 conf]# sysctl -p

nginx1需要修改的配置 192.168.11.137

[root@test3 conf]# vim /etc/sysctl.conf
net.ipv4.conf.lo.arp_ignore=1
#设置回环接口忽略来自任何接口的ARP请求
net.ipv4.conf.lo.arp_announce=2
#设置回环地址仅仅公告本地的ip地址,但是不响应ARP请求
net.ipv4.conf.all.arp_ignore=1
#设置所有接口忽略来自任何接口的ARP请求
net.ipv4.conf.all.arp_announce=2
#设置所有接口仅仅公告本地的ip地址,但是不响应ARP请求
[root@test4 conf]# sysctl -p
[root@test2 conf]# pwd
/usr/local/nginx/conf
[root@test2 conf]# vim nginx.conf

http {
    include       mime.types;
    default_type  application/octet-stream;

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;

   upstream tomcat_server {
     server 192.168.11.140:8080;
     server 192.168.11.141:8080;
}
    
        server {
        listen       80;
        server_name  www.test.com;

        charset utf-8;

        location ~ .*\.jsp$ {

        proxy_pass http://tomcat_server;
        proxy_set_header HOST $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|css)$ {
        root /usr/local/nginx/html;
        expires 10d;
         }
 

nginx2需要修改的配置 192.168.11.138

[root@test3 conf]# vim /etc/sysctl.conf
net.ipv4.conf.lo.arp_ignore=1
#设置回环接口忽略来自任何接口的ARP请求
net.ipv4.conf.lo.arp_announce=2
#设置回环地址仅仅公告本地的ip地址,但是不响应ARP请求
net.ipv4.conf.all.arp_ignore=1
#设置所有接口忽略来自任何接口的ARP请求
net.ipv4.conf.all.arp_announce=2
#设置所有接口仅仅公告本地的ip地址,但是不响应ARP请求
[root@test4 conf]# sysctl -p
[root@test2 conf]# pwd
/usr/local/nginx/conf
[root@test2 conf]# vim nginx.conf

http {
    include       mime.types;
    default_type  application/octet-stream;

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;

   upstream tomcat_server {
     server 192.168.11.140:8080;
     server 192.168.11.141:8080;
}
    
        server {
        listen       80;
        server_name  www.test.com;

        charset utf-8;

        location ~ .*\.jsp$ {

        proxy_pass http://tomcat_server;
        proxy_set_header HOST $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|css)$ {
        root /usr/local/nginx/html;
        expires 10d;
         }
 

tomcat1 需要修改的配置 192.168.11.140

148 <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
149 <Context docBase="/usr/local/tomcat/webapps/xy102" path="" reloadable="true" />

tomcat2 需要修改的配置 192.168.11.141

148 <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
149 <Context docBase="/usr/local/tomcat/webapps/xy102" path="" reloadable="true" />

packWARs=“true” autoDeploy=“true” xmlValidation=“false” xmlNamespaceAware=“false”>
149


  • 10
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码要你命

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值