缓存类型:代理式缓存(递归方式);旁挂式缓存(迭代)
缓存机制:过期机制(Expires)、条件式缓存(通过最近文件修改时间戳或Etag的扩展标签来辨别)。
过期时间:Expires
HTTP/1.0
Expires:过期
HTTP/1.1
Cache-Control: maxage= (私有缓存,单位秒)
Cache-Control: s-maxage= (共有缓存)
缓存层级:
私有缓存:用户代理附带的本地缓存机制;
公共缓存:反向代理服务器的缓存功能;
条件式请求:
Last-Modified/If-Modified-Since:基于文件的修改时间戳来
判别:Etag/If-None-Match:基于文件的校验码来判别;
User-Agent <--> private cache <--> public cache <--> public cache 2 <--> Original Server
Web Page Cache:squid --> varnish varnish官方站点: http://www.varnish-cache.org/
缓存空间耗尽:LRU,最近最少使用;
web后台restful简单架构模型
工作逻辑
首先对上篇进行简单的回顾
1. 安装
http :// repo . varnish - cache . org / redhat / varnish -3.0/ el 6/ x 86_64/
yum localinstall -y varnish-3.0.3-1.el6.x86_64.rpm varnish-libs-3.0.3-1.el6.x86_64.rpm
2. 配置
# vi /etc/varnish/default.vcl
###配置一个后端服务器
backend web1 {
.host = "192.168.0.188";
.port = "80";
}
###配置 varnish 服务端口
# vi /etc/sysconfig/varnish
VARNISH_LISTEN_PORT=80
# service varnish start
###查看缓存命中情况
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT from westos cache";
}
else {
set resp.http.X-Cache = "MISS from westos cache";
}
return (deliver);
}
# service varnish reload
###测试缓存命中
# curl -I 192.168.0.250
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Red Hat)
Last-Modified: Mon, 20 Aug 2012 15:22:19 GMT
ETag: "1c13aa-16-4c7b4135e08a6"Content-Type: text/html; charset=UTF-8
Content-Length: 22
Accept-Ranges: bytes
Date: Fri, 24 Aug 2012 14:30:40 GMT
X-Varnish: 766467032
Age: 0
Via: 1.1 varnish
Connection: keep-alive
X-Cache: MISS from westos cache #未命中
# curl -I 192.168.0.250
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Red Hat)
Last-Modified: Mon, 20 Aug 2012 15:22:19 GMT
ETag: "1c13aa-16-4c7b4135e08a6"
Content-Type: text/html; charset=UTF-8
Content-Length: 22
Accept-Ranges: bytes
Date: Fri, 24 Aug 2012 14:30:54 GMT
X-Varnish: 766467033 766467032
Age: 14
Via: 1.1 varnish
Connection: keep-alive
X-Cache: HIT from westos cache
#命中
### 通过 varnishadm 手动清除缓存
# varnishadm ban.url .*$
#清除所有
# varnishadm ban.url /index.html
#清除 index.html 页面缓存
# varnishadm ban.url /admin/$
#清除 admin 目录缓存
###定义多个不同域名站点的后端服务器
backend web1 {
.host = "192.168.0.188";
.port = "80";
}
backend web2 {
.host = "192.168.0.189";
.port = "80";
}
#当访问 www.westos.org 域名时从 web1 上取数据,访问 bbs.westos.org 域名时到 web2 取数据,
访问其他页面报错。
sub vcl_recv {
if (req.http.host ~ "^(www.)?westos.org") {
set req.http.host = "www.westos.org";
set req.backend = web1;
} elsif (req.http.host ~ "^bbs.westos.org") {
set req.backend = web2;
} else {error 404 "westos cache";
}
}
# service varnish reload
###定义负载均衡
#定义健康检查
probe healthcheck {
.url = "/index.html"; # 哪个 url 需要 varnish 请求
.interval = 5s; #检查的间隔时间
.timeout = 1s; #等待多长时间探针超时
.window = 5; #维持 5 个 sliding window 的结果
.threshold = 3; #至少有三次 window 是成功的,就宣告 bachend 健康
}
backend web1 {
.host = "192.168.0.2";
.port = "80";
.probe = healthcheck;
}
backend web2 {
.host = "192.168.0.3";
.port = "80";
.probe = healthcheck;
}
director lb round-robin {
{
.backend = web1;
{
}
.backend = web2;
#把多个后端聚合为一个组,并检测后端健康状况
}
}sub vcl_recv {
if (req.http.host ~ "^(www.)?westos.org") {
set req.http.host = "www.westos.org";
set req.backend = lb;
return (pass);
#为了测试方便,不进行缓存。
} elsif (req.http.host ~ "^bbs.westos.org") {
set req.backend = web2;
} else {
error 404 "westos cache";
}
}
# service varnish reload
首先接着昨天配置好的
配置过程
Server1安装varnish
Server2和server3安装httpd
真机域名解析
Server1 安装httpd,由于varnish和httpd端口冲突,需要先更改httpd端口
[root@server1 mnt]# yum install httpd -y
[root@server1 mnt]# vim /etc/httpd/conf/httpd.conf
更改Listen 80 为 8080
安装php
[root@server1 mnt]# yum install php -y
安装unzip
[root@server1 mnt]# yum install unzip
解压下载的bansys.zip到默认发布目录
[root@server1 mnt]# unzip bansys.zip -d /var/www/html/
[root@server1 mnt]# cd /var/www/html/
[root@server1 html]# ls
bansys
[root@server1 html]# cd bansys/
[root@server1 bansys]# ls
class_socket.php config.php index.php purge_action.php static
[root@server1 bansys]# mv * ..
[root@server1 bansys]# ls
[root@server1 bansys]# cd ..
[root@server1 html]# ls
bansys class_socket.php config.php index.php purge_action.php static
[root@server1 html]# vim config.php
<?php
//varnish主机列表
//可定义多个主机列表
$var_group1 = array(
'host' => array('172.25.53.1'),
'port' => '80',
);
//varnish群组定义
//对主机列表进行绑定
$VAR_CLUSTER = array(
'www.westos.org' => $var_group1,
);
//varnish版本
//2.x和3.x推送命令不一样
$VAR_VERSION = "3";
?>
~
[root@server1 html]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.25.53.1 for ServerName
[ OK ]
[root@server1 html]# netstat -antlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1104/varnishd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 909/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 985/master
tcp 0 0 127.0.0.1:6082 0.0.0.0:* LISTEN 1103/varnishd
tcp 0 0 172.25.53.1:22 172.25.53.250:34570 ESTABLISHED 1051/sshd
tcp 0 0 :::8080 :::* LISTEN 1260/httpd
tcp 0 0 :::80 :::* LISTEN 1104/varnishd
tcp 0 0 :::22 :::* LISTEN 909/sshd
tcp 0 0 ::1:25 :::* LISTEN 985/master
浏览器输入172.25.53.1:8080
---------------------
[root@server1 ~]# cd /etc/varnish/
[root@server1 varnish]# vim default.vcl
# server.
acl westos {
"127.0.0.1";
"172.25.53.0"/24;
}
backend web1 {
.host = "172.25.53.2";
.port = "80";
}
director westos round-robin {
{.backend = web1;}
{.backend = web2;}
}
sub vcl_recv {
if (req.request == "BAN") {
if (!client.ip ~ westos) {
error 405 "Not allowed.";
}
ban("req.url ~ " + req.url);
error 200 "ban added";
}
if (req.http.host ~ "^(www.)?westos.org") {
set req.http.host = "www.westos.org";
set req.backend = westos;
#return (pass);
} elsif (req.http.host ~ "^bbs.westos.org") {
set req.backend = web2;
} else {error 404 "westos cache";
}
}
[root@server1 varnish]# /etc/init.d/varnish reload
Loading vcl from /etc/varnish/default.vcl
Current running config name is reload_2018-07-29T09:27:50
Using new config name reload_2018-07-29T09:49:47
VCL compiled.
available 0 boot
available 2 reload_2018-07-29T09:27:50
active 0 reload_2018-07-29T09:49:47
Done
浏览器推送如下
效果为一推送就清缓存
[root@foundation53 ~]# curl www.westos.org/index.html -I
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Red Hat)
Last-Modified: Sun, 29 Jul 2018 01:56:43 GMT
ETag: "3fec7-19-57219a8150d19"
Content-Type: text/html; charset=UTF-8
Content-Length: 25
Accept-Ranges: bytes
Date: Sun, 29 Jul 2018 02:12:57 GMT
X-Varnish: 1542537175
Age: 0
Via: 1.1 varnish
Connection: keep-alive
[root@foundation53 ~]# curl www.westos.org/index.html -I
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Red Hat)
Last-Modified: Sun, 29 Jul 2018 01:56:43 GMT
ETag: "3fec7-19-57219a8150d19"
Content-Type: text/html; charset=UTF-8
Content-Length: 25
Accept-Ranges: bytes
Date: Sun, 29 Jul 2018 02:12:58 GMT
X-Varnish: 1542537176 1542537175
Age: 1
Via: 1.1 varnish
Connection: keep-alive
[root@foundation53 ~]# curl www.westos.org/index.html -I
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Red Hat)
Last-Modified: Sun, 29 Jul 2018 01:56:43 GMT
ETag: "3fec7-19-57219a8150d19"
Content-Type: text/html; charset=UTF-8
Content-Length: 25
Accept-Ranges: bytes
Date: Sun, 29 Jul 2018 02:12:59 GMT
X-Varnish: 1542537177 1542537175
Age: 2
Via: 1.1 varnish
Connection: keep-alive
VS集群有DR、TUN、NAT三种配置模式,可以对www服务、FTP服务、MAIL服务等做负载均衡,下面通过搭建www服务的负载均衡实例,讲述基于DR模式的LVS集群配置。
[root@server1 ~]# /etc/init.d/varnish stop
Stopping Varnish Cache: [ OK ]
[root@server1 ~]# /etc/init.d/httpd stop
Stopping httpd: [ OK ]
[root@server1 ~]# cd /etc/yum.repos.d/
[root@server1 yum.repos.d]# ls
rhel-source.repo
[root@server1 yum.repos.d]# vim rhel-source.repo
[root@server1 yum.repos.d]# cat rhel-source.repo
[rhel-source]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=http://172.25.53.250/rhel6.5
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[HighAvailability]
name=HighAvailability
baseurl=http://172.25.53.250/rhel6.5/HighAvailability
gagchack=0
[LoadBalancer]
name=LoadBalancer
baseurl=http://172.25.53.250/rhel6.5/LoadBalancer
gagchack=0
[ResilientStorage]
name=ResilientStorage
baseurl=http://172.25.53.250/rhel6.5/ResilientStorage
gagchack=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=http://172.25.53.250/rhel6.5/ScalableFileSystem
gagchack=0
[root@server1 yum.repos.d]# yum repolist
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
HighAvailability | 3.9 kB 00:00
HighAvailability/primary_db | 43 kB 00:00
LoadBalancer | 3.9 kB 00:00
LoadBalancer/primary_db | 7.0 kB 00:00
ResilientStorage | 3.9 kB 00:00
ResilientStorage/primary_db | 47 kB 00:00
ScalableFileSystem | 3.9 kB 00:00
ScalableFileSystem/primary_db | 6.8 kB 00:00
rhel-source | 3.9 kB 00:00
repo id repo name status
HighAvailability HighAvailability 56
LoadBalancer LoadBalancer 4
ResilientStorage ResilientStorage 62
ScalableFileSystem ScalableFileSystem 7
rhel-source Red Hat Enterprise Linux 6Server - x86_64 - Source 3,690
repolist: 3,819
[root@server1 yum.repos.d]# yum install ipvsadm -y
添加一条新的虚拟IP记录。这个新的IP是192.168.60.200
[root@server1 yum.repos.d]# ipvsadm -A -t 172.25.53.100:80 -s rr
在新加虚拟IP记录中添加两条新的Real Server记录,并且指定LVS 的工作模式为直接路由模式。
[root@server1 yum.repos.d]# ipvsadm -a -t 172.25.53.100:80 -r 172.25.53.2:80 -g
[root@server1 yum.repos.d]# ipvsadm -a -t 172.25.53.100:80 -r 172.25.53.3:80 -g
[root@server1 yum.repos.d]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.53.100:80 rr
-> 172.25.53.2:80 Route 1 0 0
-> 172.25.53.3:80 Route 1 0 0
在同一个lan下
[root@server1 yum.repos.d]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:07:35:d5 brd ff:ff:ff:ff:ff:ff
inet 172.25.53.1/24 brd 172.25.53.255 scope global eth0
inet6 fe80::5054:ff:fe07:35d5/64 scope link
valid_lft forever preferred_lft forever
[root@server1 yum.repos.d]# ip addr add 172.25.53.100/24 dev eth0
[root@server1 yum.repos.d]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:07:35:d5 brd ff:ff:ff:ff:ff:ff
inet 172.25.53.1/24 brd 172.25.53.255 scope global eth0
inet 172.25.53.100/24 scope global secondary eth0
inet6 fe80::5054:ff:fe07:35d5/64 scope link
valid_lft forever preferred_lft forever
[root@server1 yum.repos.d]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.53.100:80 rr
-> 172.25.53.2:80 Route 1 0 0
-> 172.25.53.3:80 Route 1 0 0
[root@server2 ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.25.53.2 for ServerName
[ OK ]
[root@server2 ~]# netstat -antlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 910/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 986/master
tcp 0 0 172.25.53.2:22 172.25.53.250:40588 ESTABLISHED 1037/sshd
tcp 0 0 :::80 :::* LISTEN 1140/httpd
tcp 0 0 :::22 :::* LISTEN 910/sshd
tcp 0 0 ::1:25 :::* LISTEN 986/master
[root@server2 ~]# ip addr add 172.25.53.100/24 dev eth0
[root@server2 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:bb:9d:87 brd ff:ff:ff:ff:ff:ff
inet 172.25.53.2/24 brd 172.25.53.255 scope global eth0
inet 172.25.53.100/24 scope global secondary eth0
inet6 fe80::5054:ff:febb:9d87/64 scope link
valid_lft forever preferred_lft forever
[root@server3 ~]# /etc/init.d/httpd start
Starting httpd:
[root@server3 ~]# ip addr add 172.25.53.100/24 dev eth0
[root@server3 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:d9:ad:d1 brd ff:ff:ff:ff:ff:ff
inet 172.25.53.3/24 brd 172.25.53.255 scope global eth0
inet 172.25.53.100/24 scope global secondary eth0
inet6 fe80::5054:ff:fed9:add1/64 scope link
valid_lft forever preferred_lft forever
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org - server3
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org -server2
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org - server3
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org -server2
[root@server1 yum.repos.d]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.53.100:80 rr
-> 172.25.53.2:80 Route 1 0 2
-> 172.25.53.3:80 Route 1 0 2
但是现在
获取到的ip地址不固定
[root@foundation53 ~]# arp -an | grep 100
? (172.25.53.100) at 52:54:00:07:35:d5 [ether] on br0
[root@foundation53 ~]# arp -d 172.25.53.100
[root@foundation53 ~]# ping 172.25.53.100
PING 172.25.53.100 (172.25.53.100) 56(84) bytes of data.
64 bytes from 172.25.53.100: icmp_seq=1 ttl=64 time=0.205 ms
^C
--- 172.25.53.100 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.205/0.205/0.205/0.000 ms
[root@foundation53 ~]# arp -an | grep 100
? (172.25.53.100) at 52:54:00:d9:ad:d1 [ether] on br0
各个ip
[root@server1 yum.repos.d]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:07:35:d5 brd ff:ff:ff:ff:ff:ff
inet 172.25.53.1/24 brd 172.25.53.255 scope global eth0
inet 172.25.53.100/24 scope global secondary eth0
inet6 fe80::5054:ff:fe07:35d5/64 scope link
valid_lft forever preferred_lft forever
[root@server2 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:bb:9d:87 brd ff:ff:ff:ff:ff:ff
inet 172.25.53.2/24 brd 172.25.53.255 scope global eth0
inet6 fe80::5054:ff:febb:9d87/64 scope link
valid_lft forever preferred_lft forever
[root@server3 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:d9:ad:d1 brd ff:ff:ff:ff:ff:ff
inet 172.25.53.3/24 brd 172.25.53.255 scope global eth0
inet 172.25.53.100/24 scope global secondary eth0
inet6 fe80::5054:ff:fed9:add1/64 scope link
valid_lft forever preferred_lft forever
由此可见同一局域网多个重复ip 那么物理机获取到的不固定
此时需要设置server2和3
[root@server2 ~]# yum install -y arptables_jf
[root@server2 ~]# arptables -L
Chain IN (policy ACCEPT)
target source-ip destination-ip source-hw destination-hw hlen op hrd pro
Chain OUT (policy ACCEPT)
target source-ip destination-ip source-hw destination-hw hlen op hrd pro
Chain FORWARD (policy ACCEPT)
target source-ip destination-ip source-hw destination-hw hlen op hrd pro
[root@server2 ~]# arptables -A IN -d 172.25.53.100 -j DROP
[root@server2 ~]# arptables -A OUT -s 172.25.53.100 -j mangle --mangle-ip-s 172.25.53.2
[root@server2 ~]# /etc/init.d/arptables_jf save
Saving current rules to /etc/sysconfig/arptables: [ OK ]
[root@server2 ~]# /etc/init.d/arptables_jf start
Flushing all current rules and user defined chains: [ OK ]
Clearing all current rules and user defined chains: [ OK ]
Applying arptables firewall rules: [ OK ]
Server3设置与server相同
[root@server2 ~]# yum install -y arptables_jf
[root@server3 ~]# arptables -A IN -d 172.25.53.100 -j DROP
[root@server3 ~]# arptables -A OUT -s 172.25.53.100 -j mangle --mangle-ip-s 172.25.53.3
[root@server3 ~]# /etc/init.d/arptables_jf save
Saving current rules to /etc/sysconfig/arptables: [ OK ]
至此,物理机都是获取的是server1的ip
[root@foundation53 ~]# arp -d 172.25.53.100
[root@foundation53 ~]# ping 172.25.53.100
PING 172.25.53.100 (172.25.53.100) 56(84) bytes of data.
64 bytes from 172.25.53.100: icmp_seq=1 ttl=64 time=0.183 ms
^C
--- 172.25.53.100 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.183/0.183/0.183/0.000 ms
[root@foundation53 ~]# arp -an | grep 100
? (172.25.53.100) at 52:54:00:07:35:d5 [ether] on br0
[root@foundation53 ~]# arp -d 172.25.53.100
[root@foundation53 ~]# ping 172.25.53.100
PING 172.25.53.100 (172.25.53.100) 56(84) bytes of data.
64 bytes from 172.25.53.100: icmp_seq=1 ttl=64 time=0.172 ms
^C
--- 172.25.53.100 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.172/0.172/0.172/0.000 ms
[root@foundation53 ~]# arp -an | grep 100
? (172.25.53.100) at 52:54:00:07:35:d5 [ether] on br0
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org - server3
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org -server2
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org - server3
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org -server2
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org -server2
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org - server3
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org -server2
[root@server1 yum.repos.d]# /etc/init.d/httpd stop
Stopping httpd: [ OK ]
[root@server1 yum.repos.d]# vim /etc/httpd/conf/httpd.conf
将8080改回来
[root@server1 yum.repos.d]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.25.53.1 for ServerName
[ OK ]
[root@server1 yum.repos.d]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.53.100:80 rr
-> 172.25.53.2:80 Route 1 0 0
-> 172.25.53.3:80 Route 1 0 0
停掉server2的httpd
[root@server2 ~]# /etc/init.d/httpd stop
Stopping httpd: [ OK ]
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org - server3
[root@foundation53 ~]# curl 172.25.53.100
curl: (7) Failed connect to 172.25.53.100:80; Connection refused
[root@foundation53 ~]# curl 172.25.53.100
www.westos.org - server3
[root@foundation53 ~]# curl 172.25.53.100
curl: (7) Failed connect to 172.25.53.100:80; Connection refused
如果server2,3同时停掉
Server1会自己上,自己发布自己的发布目录下的文件