基础运维:基于IP实现网页分流

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基础运维:基于IP实现网页分流相关的知识,希望对你有一定的参考价值。

一、说明

想要流量分流,在一个接口上设置多IP的方式,是可以实现的,在互联网上需要访问的域名,一般人并不知道什么是IP,就是知道IP,可能他们理解的IP(知识财产权)跟你理解的IP(互联网协议)并不一样。基于IP的分流,目的在于访问这些IP时打开的网页是一致的。分流网页有很多种,这只是其中的一种而已。

二、多IP设置

1.复制网络配置文件

[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# ls
ifcfg-ens33  ifdown-isdn      ifdown-tunnel  ifup-isdn    ifup-Team
ifcfg-lo     ifdown-post      ifup           ifup-plip    ifup-TeamPort
ifdown       ifdown-ppp       ifup-aliases   ifup-plusb   ifup-tunnel
ifdown-bnep  ifdown-routes    ifup-bnep      ifup-post    ifup-wireless
ifdown-eth   ifdown-sit       ifup-eth       ifup-ppp     init.ipv6-global
ifdown-ippp  ifdown-Team      ifup-ippp      ifup-routes  network-functions
ifdown-ipv6  ifdown-TeamPort  ifup-ipv6      ifup-sit     network-functions-ipv6
[[email protected] network-scripts]# cp ifcfg-ens33 ifcfg-ens33:1

2.修改配置文件

[[email protected] network-scripts]# vim ifcfg-ens33:1
TYPE="Ethernet"
BOOTPROTO="dhcp"
NAME="ens33:1"
DEVICE="ens33:1"
ONBOOT="yes"
IPADDR=192.168.116.100
PREFIX=24
GATEWAY=192.168.116.255
[[email protected] network-scripts]# 

3.重启网络服务

[[email protected] network-scripts]# systemctl restart network
[[email protected] network-scripts]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:47:c4:9f brd ff:ff:ff:ff:ff:ff
    inet 192.168.116.129/24 brd 192.168.116.255 scope global noprefixroute dynamic ens33
       valid_lft 1798sec preferred_lft 1798sec
    inet 192.168.116.100/24 brd 192.168.116.255 scope global secondary noprefixroute ens33:1
       valid_lft forever preferred_lft forever
    inet6 fe80::ab30:473d:fe9e:9d7e/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[[email protected] network-scripts]# 

4.本地测试网络连通性

[C:~]$ ping 192.168.116.100
正在 Ping 192.168.116.100 具有 32 字节的数据:
来自 192.168.116.100 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.116.100 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.116.100 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.116.100 的回复: 字节=32 时间<1ms TTL=64

192.168.116.100 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms
[C:~]$ 

三、网页分流

1.设置网页

[[email protected] nginx]# mkdir /server/web/test1
[[email protected] nginx]# mkdir /server/web/test2
[[email protected] nginx]# mv /server/web/
index.html  test1/      test2/      
[[email protected] nginx]# cp /server/web/index.html  /server/web/test1/
[[email protected] nginx]# cp /server/web/index.html  /server/web/test2/
[[email protected] nginx]# cat /server/web/index.html 
<h1 align=center>vhost</h1>
[[email protected] nginx]# vim /server/web/test2/index.html 
[[email protected] nginx]# cat /server/web/test2/index.html 
<h1 align=center>test2 vhost</h1>
[[email protected] nginx]# 

2.创建NGINX配置文件

[[email protected] nginx]# ls
conf  html  logs  sbin
[[email protected] nginx]# cd conf/
[[email protected] conf]# ls
fastcgi.conf            koi-utf             nginx.conf           uwsgi_params
fastcgi.conf.default    koi-win             nginx.conf.default   uwsgi_params.default
fastcgi_params          mime.types          scgi_params          win-utf
fastcgi_params.default  mime.types.default  scgi_params.default
[[email protected] conf]# mkdir vhost
[[email protected] conf]# vim nginx.conf
include vhost/*.conf;   #在最后括号上添加
[[email protected] conf]# ls
fastcgi.conf            koi-utf             nginx.conf           uwsgi_params
fastcgi.conf.default    koi-win             nginx.conf.default   uwsgi_params.default
fastcgi_params          mime.types          scgi_params          vhost
fastcgi_params.default  mime.types.default  scgi_params.default  win-utf
[[email protected] conf]# cd vhost/
[[email protected] vhost]# ls
test1.conf  test2.conf
[[email protected] vhost]# cat test1.conf 
server {
    listen 80;
    server_name 192.168.116.129 ;
    index   index.html index.htm index.php;
    root  /server/web/test1 ;

}
[[email protected] vhost]# cat test2.conf 
server {
    listen 80;
    server_name 192.168.116.100 ;
    index   index.html index.htm index.php;
    root  /server/web/test2 ;

}
[[email protected] vhost]# 

3.重启NGINX服务

[[email protected] vhost]# /usr/local/nginx/sbin/nginx -s reload

如果是第一次启动NGINX服务,执行这条命令:
[[email protected] vhost]# /usr/local/nginx/sbin/nginx

4.访问网页
技术分享图片

5.设置访问同一个网页

[[email protected] vhost]# vim /server/web/index.html 
[[email protected] vhost]# cat  /server/web/index.html 
<h1 align=center>test1 and test2 share  web page</h1>
[[email protected] vhost]# vim test2.conf 
[[email protected] vhost]# vim test1.conf 
[[email protected] vhost]# /usr/local/nginx/sbin/nginx -s reload
[[email protected] vhost]# cat test1.conf 
server {
    listen 80;
    server_name 192.168.116.129 ;
    index   index.html index.htm index.php;
    root  /server/web ;

}
[[email protected] vhost]# cat test2.conf 
server {
    listen 80;
    server_name 192.168.116.100 ;
    index   index.html index.htm index.php;
    root  /server/web ;

}
[[email protected] vhost]# 

6.访问网页
技术分享图片

至此基于IP实现网页分流已完成

以上是关于基础运维:基于IP实现网页分流的主要内容,如果未能解决你的问题,请参考以下文章

通过Nginx反向代理实现IP分流

网络分流器-TCP报文重组和会话规则-网络分流器

Linux运维基础:网站流量度量

Linux运维基础:网站流量度量

Linux运维之道之ENGINEER1.2(HTTP服务基础,网页内容访问,安全web)

如何软路由做分流