一、 操作系统的安装
1. 操作系统的选择
操作系统的版本为Red Hat AS4 update5版本。
2. 操作系统的安装
系统选择最小安装。开启防火墙,防火墙开启ssh及www两项服务端口,在安装系统的时候关掉SELinux;
系统分区时创建三个交换分区,每个交换分区的大小为实际物理内存的2倍,三个交换分区的优先级相同。
3. 检测系统
# more /var/log/messages //检查有无系统内核级错误信息
# demesg //检查硬件设备是否有错误信息
# ifconfig //检查网卡设置是否正确
# ping www.163.com // 检查网络是否正常
4. 关闭不需要的服务
# setup //选择启动的服务
进入system service 选项。以space 键选定所需服务。以下仅列出需要启动的服务,未列出的服务一律关闭:
crond
microcode_ctl
network
ntpd
iptables
sshd
syslog
5. 定时校正服务器时间
# crontab –e
0 4 * * * /usr/sbin/ntpdate 210.72.145.44
以上命令设置好后存盘。
# /sbin/service crond reload
机器将在每天的4:00根据中国国家授时中心的NTP服务器时间自动校准时间。
二、 Apache的安装
1. Apache版本选择
服务器Apache选择2.2版,2.2版的Apache能在混合多进程、 多线程模式下运行,使很多配置的可扩缩性得到改善。
2. Apache编译安装
默认情况下,apache安装完以后,是不允许被cache的。如果外接了cache或squid服务器要求进行web加速的话,就需要在httpd.conf里进行设置,当然前提是在安装apache的时候要激活mod_cache的模块。
安装与配置的步骤
apache 编译配置:
# ./buildconf
./configure \
--with-mpm=worker \
--enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache \
--enable-mods=max \
--enable-mod-share=most
参数 -with-mpm={prefork,worker},这个是设置Apache的多任务处理的。prefork是指每个连接一个进程,也就是多进程并行处理;而worker是多线程并行处理。支持多线程处理是apache 2的一大改进。
#make
#make install
检验是否安装了cache模块:
/usr/local/apache2/bin/apachectl –l
如果有mod_cache.c
mod_disk_cache.c
mod_mem_cache.c
这3个模块,说明该apache已经可以支持cache。
3. Apache配置
更改httpd.conf的设置
vi /usr/local/apache2/conf/httpd.conf
在末尾添加上:
# 启用有效期控制
expiresactive on
ExpiresByType text/html A1800 # html 文件有效期为30分钟
ExpiresByType text/htm A1800 # htm 文件有效期为30分钟
ExpiresByType text/shtml A1800 # shtml 文件有效期为30分钟
ExpiresByType image/gif A86400 # gif文件有效期为一天
ExpiresByType image/jpeg A86400 # jig 文件有效期为一天
ExpiresByType image/png A86400 # png文件有效期为一天
ExpiresByType text/css A86400 # css文件有效期为一天
ExpiresByType text/js A86400 # js文件有效期为一天
设置虚拟目录
然后保存退出。
启动apache
参数的解释:
ExpiresByType 在apache应答时在网页文件添加http头,以控制文档的有效性和持久性。
# 启用有效期控制
ExpiresActive On
# GIF有效期为1个月
ExpiresByType image/gif A2592000
# HTML文档的有效期是最后修改时刻后的一星期
ExpiresByType text/html M14404800
"M"表示源文件的最后修改时刻,"A"表示客户端对源文件的访问时刻。
如果使用"M",所有缓存服务器中的当前同一文档副本都将在同一时刻过期。
如果使用"A",则每个客户端所得到的有效期是不一样的,如果设定文件过期时间为10分钟,当地一个用户在早上8点访问该文件,该文件被缓存后,默认十分钟过期,即该文件将在8:10过期,第二个用户于8:09访问该文件,那么该文件的过期时间将从8:09分开始计算,文件缓存十分钟,文件将在8:19分过期。
使用了“A”,表明Apache控制文件过期采用了客户端访问该文件最后的时间加上文件的有效期作为过期时间。
三、 squid的安装和设置
1. squid版本选择
本方案选则squid的版本为squid-2.6.STABLE17,并采用二进制包安装。
2. squid的编译安装
解压缩squid源码包,并进行编译安装:
#tar xzvf squid-2.6.tar.gz
#cd squid-2.6
./configure --prefix=/usr/local/squid --enable-dlmalloc --with-pthreads --enable-poll \ --disable-internal-dns --enable-stacktrace --enable-removal-policies="heap,lru" \ --enable-delay-pools --enable-storeio="aufs,coss,diskd,ufs" --enable-arp-acl \ --enable-err-language="Simplify_Chinese"--enable-underscore--enable-snmp \ --enable-default-err-languages="Simplify_Chinese" --enable-linux-netfilter \ --disable-ident-lookups --enable-async-io=80
编译参数解释:
--enable-cache-digests 使用缓存摘要,此项目的是为了在Squid集群服务之间迅速发现缓存对象,在本地使用,可以加快请求时,检索缓存内容的速度。
--enable-cahce-digests :加快请求时检索缓存内容的速度。
--enable-snmp 使Squid支持SNMP接口
--enable-async-io=80 :这个主要是设置使用异步模式来运行squid,--enable-icmp :加入icmp支持
--enable-kill-parent-hack :关掉suqid的时候,要不要连同父进程一起关掉
--enable-poll :应启用Poll (轮询)函数而不是select函数
--enable-linux-netfilter :可以支持透明代理
--enable-underscore :允许解析的URL中出现下划先,因为默认squid会认为带下划线的URL地址是非法的,并拒绝访问该地址。
#make
#make install
Squid安装完成了。
3. squid参数配置
# vi squid.conf 代码如下:
#监听服务器的80端口,反向代理,支持域名和IP的虚拟主机
http_port 219.234.80.151:80 vhost vport
#将icp通讯端口设置为3130
icp_port 3130
#设置源Web服务器的ip和端口
cache_peer 219.234.80.141 parent 80 0 no-query originserver no-digest name=cache0
#设置web服务器优先级第二的源地址及端口
cache_peer 219.234.80.142parent 80 0 no-query originserver no-digest name=cache1
#设置web服务器优先级第三的源地址及端口
#配置本机squid允许接受访问的域名,请注意name的对应
cache_peer 219.234.80.143 parent 80 0 no-query originserver no-digest name=cache2
注:以上源服务器优先级配置为cache1的优先级配置,cache2上的优先级配置如下:
cache_peer 219.234.80.142 parent 80 0 no-query originserver no-digest name=cache0
cache_peer 219.234.80.143 parent 80 0 no-query originserver no-digest name=cache1
cache_peer 219.234.80.141 parent 80 0 no-query originserver no-digest name=cache2
以下参数为共同参数:
#允许以下端口的代理
acl Safe_ports port 80
acl Safe_ports port 3130
#Squid信息设置
visible_hostname www.lotour.com
cache_mgr admin@lotour.com
#squid使用的用户组和用户名
cache_effective_user nobody
cache_effective_group nobody
#tcp receive buffer size
tcp_recv_bufsize 65535 bytes
client_persistent_connections off
server_persistent_connections on
#for security set half_closed_clients off
half_closed_clients off
#设置Squid所能使用的内存共1024MB,这个值因人而异,缓存设置应为物理缓存的25%,当缓存空间使用达到95%时新的内容将取代旧的而不直接添加到目录中,直到空间又下降到90%才停止这一活动
cache_mem 1024MB
cache_swap_low 90
cache_swap_high 95
#设置缓存服务器中缓存文件的大小,在设定数值范围外的文件将不被缓存。
maximum_object_size 4096 KB
minimum_object_size 0 KB
maximum_object_size_in_memory 4096 KB #设定缓存服务器中内存中可以缓存的文件最大值
ipcache_size 1024
ipcache_low 90
ipcache_high 95
cache_replacement_policy lru #磁盘缓存置换策略使用最近最少使用
memory_replacement_policy lru #内存置换策略使用最近最少使用算法
#磁盘缓存的类型和目录,大小,一二级目录的设置,这里磁盘缓存大小是10240MB,都是 16* 256 级子目录
cache_dir ufs /cache0 10240 16 256
cache_dir ufs /cache1 10240 16 256
#这个设置是不记录store.log (记录储存管理的活动)
cache_store_log none
#日志保留最近30个文件,每天轮询三次,即保留最近十天的内容.
logfile_rotate 30
#设置默认刷新规则,关于refresh_pattern参数的解释见备注
refresh_pattern -i .html 1440 50% 10080 reload-into-ims
refresh_pattern -i .htm 1440 50% 10080 reload-into-ims
refresh_pattern -i .shtml 1440 50% 10080 reload-into-ims
refresh_pattern -i .png 4320 50% 20160 reload-into-ims
refresh_pattern -i .gif 4320 50% 20160 reload-into-ims
refresh_pattern -i .bmp 4320 50% 20160 reload-into-ims
refresh_pattern -i .jpg 4320 50% 20160 reload-into-ims
refresh_pattern -i .js 4320 50% 20160 reload-into-ims
refresh_pattern -i .css 4320 50% 20160 reload-into-ims
refresh_pattern -i .swf 4320 50% 20160 reload-into-ims
#不要相信ETag 因为有gzip
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
#设置超时策略以节省服务器资源
#设置squid多长时间为请求寻找转发的路径,超过设定时间放弃转发.
forward_timeout 20 seconds
#设置squid多长时间等待TCP连接到请求服务器或者邻居服务器,时间超过此值Squid试图寻找转发请求的路径.
connect_timeout 15 seconds
#应用于服务器端连接,每次成功读取数据之后,timeout就设置为这个值.如果这个设置时间之后在所设定的时间内没有数据再被读,请求就中止.
read_timeout 3 minutes
#初始化连接建立后,多长时间去等待HTTP请求.
request_timeout 1 minutes
#先前的请求完成后,在一个持续的连接中多长时间去等待下一个HTTP请求
persistent_request_timeout 15 seconds
#允许一个客户保持连接到缓存进程的最大保留时间值.
client_lifetime 15 minutes
#关闭squid时,缓存程序处于关闭等待状态,当接收到关闭命令后,在设定的时间过后向用户返回超时信息。
shutdown_lifetime 5 seconds
#设置网页错误信息在缓存中的保留时间
negative_ttl 10 seconds
#打开emulate_httpd_log选项,将使Squid仿照Aapche的日志格式
emulate_httpd_log on
#日志格式combined的设置
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %h" "%{User-Agent}>h" %Ss:%Sh
#这里是设置pid和日志文件的位置,因人而异,同时日志格式是combined,awstats可以直接调用分析了
pid_filename /usr/local/squid/var/squid.pid
cache_log /usr/local/squid/var/logs/cache.log
access_log /usr/local/squid/var/logs/access.log combined
#设置不想缓存的目录或者文件类型
acl all src 0.0.0.0/0.0.0.0
acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip.exe
.aspx .asp
cache deny QUERY
#错误文档
error_directory /usr/local/squid/share/errors/Simplify_Chinese
#允许没有被明确禁止的客户进行访问。
http_access allow all
保存配置文件退出。初始化和启动squid
# /usr/local/squid/sbin/squid -z
# /usr/local/squid/sbin/squid -NCd1
第一条命令是先初始化squid缓存哈希子目录,只需执行一次即可。
启动squid:./bin/RunCache &
使用squid附带的启动脚本来启动squid,有个好处就是,如果squid的进程死了的话,这个脚本会自动启动squid,对于运行在线上的服务器来说,这点很重要了。
开机自动运行squid
修改开机自动运行文件,将 /usr/local/squid/bin/RunCache & 加进开机自动执行的程序中。
第一次是以 root 身份启动,所以,/usr/local/squid/var/squid.out 及 /usr/local/squid/var/squid.pid 的拥有者是 root ,这会造成下列以 nobody 身份启动 squid 时,会有错误出现,所以,必须在第二次由 rc.local 启动前,先行将 squid.out 及 squid.pid 两个文件的所有者(owner)改为 nobody,即是
chown nobody:nobody /usr/local/squid/var/squid.out
chown nobody:nobody /usr/local/squid/var/logs/squid.pid
在 /etc/rc.d/rc.local 中加入 /usr/local/squid/bin/RunCache &
4. 第二机房缓存服务器配置文件
第二机房缓存服务器配置文件与第一机房缓存服务器配置文件基本相同,只需修改如下参数:
#设置源Web服务器的ip和端口
cache_peer源服务器地址parent 80 0 no-query originserver no-digest name=cache0
#连接B服务器的Squid工作在sibling模式并指定其端口
cache_peer 第二机房主缓存服务器地址 sibling 80 3130 name=cache1
缓存服务器之间的连接工作在Sibling模式,当Squid Server工作在Sibling模式时。当Squid Server没有资料时会先向Sibling连接的Squid Server要资料,如果Sibling没资料,就跳过它直接到internet 源服务器去获取。
四、 配置参数及选项的设置
参数
参数选项值
默认参数值
建议参数值
建议参数选项值
建议原因
http_port
3128
vhost vport
80
vhost vport
设置80端口是因为服务器要提供web加速,使用vhost、vport使缓存服务器支持域名及IP地址访问。
icp_port
3130
3130
缓存服务器之间的通讯协议为ICP,通讯端口为3130,设置缓存服务器间互相通信
cache_peer
Parent no-query originserver no-digest
Parent no-query originserver no-digest
本地没有缓存对象时,可以到parent服务器获取缓存对象, no-query本地缓存服务器不会向子级服务器提出查询请求. Originserver设置从源服务器获取数据。no-digest不再从内存摘要中查询其他缓存服务器。
Cache_peer_ domain
.lotour.com
指定访问域名,对该域名的访问,都将从所设定的服务器上读取源文件
tcp_recv_ bufsize
0 bytes
65535 bytes
TCP连接接收缓冲区大小,控制服务器的连接数。
client_persistent_connections
ON
OFF
不保持客户端与缓存服务器链路层的长时间链接,节省服务器资源。
server_persistent_connections
ON
ON
保持缓存服务器与源服务器链路层的长时间链接,方便缓存服务器读取数据。
half_closed_ clients
ON
OFF
为安全和节省资源,关闭客户端的半连接
cache_ mem
8M
1G
设置缓存内存大小为物理内存大小的25%,根据缓存服务器的配置设置为1G,设置过大容易造成服务器当机。
cache_ swap_low
90%
90%
当缓存内容低于在此设定的数值时,文件直接添加到缓存中,而不是取代缓存中的旧文件。
cache_ swap_high
95%
95%
当缓存空间达到设定的数值后,新内容将取代旧的内容,而不直接添加到缓存中。
maximum_ object_ size
4096K
4096K
设定磁盘缓存文件的最大值,大于该数值的文件不会被缓存
minimum_ object_ size
0 K
0 K
设定磁盘缓存文件的最小值,小于该数值的文件不会被缓存
maximum_ object_size_in_ memory
8K
4096K
设定内存中缓存单个文件的最大值,如果大于设定值,文件不会被缓存。
cache_dir
100M
16*256级子目录
Ufs 磁盘文件格式 /usr/local/squid/var/cache
10G
Ufs
/cache
1G的磁盘空间约需要32M内存作内存交换,根据网站现有文件大小,确保能保存3-7天缓存的内容。建议设定10G的磁盘空间作为磁盘缓存,使用16*256级子目录,目录位于/cache下
cache_ store_log
None
None
缓存服务器存储频繁,记录存储管理的日志庞大,且对管理员无意义,所以我们选择不记录缓存服务器存储管理的活动
refresh_ pattern(参数详细解释见备注)
reload-into-ims
reload-into-ims
为没有明确过时期限的响应设置过期规则,使用reload-into-ims 参数时squid在转发请求之前,先发送If-Modified-Since头部到原服务器判断文件是否修改过,根据返回值确定是否重新加载数据。
forward_ timeout
4 minutes
20 seconds
设置squid多长时间为请求寻找转发的路径,超过设定时间放弃转发.
connect_ timeout
1 minute
15
seconds
设置squid多长时间等待TCP连接到请求服务器或者邻居服务器,时间超过此值Squid试图寻找转发请求的路径
read_ timeout
15 minutes
3
minutes
应用于服务器端连接,每次成功读之后,timeout就设置为这个值.如果这个设置时间之后没有数据再被读,请求就中止.
request_ timeout
5 minutes
1
minutes
初始化连接建立后,多长时间去等待HTTP请求
persistent_ request_ timeout
2 minutes
15
seconds
先前的请求完成后,在一个持续的连接中多长时间去等待下一个HTTP请求
client_ lifetime
1 day
15
minutes
客户连接到缓存服务器后,缓存服务器保留该进程的最大时间,从第一次链接开始计时。
shutdown_ lifetime
30 seconds
5
seconds
关闭squid时,缓存程序处于关闭等待状态,当接收到关闭命令后,在设定的时间过后向用户返回超时信息。
Negative_tll
10
minutes
设置网页错误信息在缓存中的保留时间。
emulate_ httpd_log
On
设置日志格式,与apache日志格式一致.
http_access
Deny all
allow all
允许没有被明确禁止的客户进行访问
五、 缓存服务器监控配置
实时监控程序主要为三部分:第一部分为流量统计,对当天日志进行分析,获得用户访问的流量统计图表以web方式输出。第二部分为流量监控,主要监控机器的性能,主要包括cpu,mem,swap,disk等。第三部分为squid实时监控.监控squid运行的状态信息,包括如当前内存缓存信息,磁盘缓存信息,服务请求统计,资源使用,存储目录统计监控,源服务器状态等。
1. 环境准备
安装包
Systat 内存状态统计
gd-1.8.4-4 图形支持包
gd-devel-1.8.4-4
perl-5.6.0-17 perl的语言支持
perl-CGI
mod_perl-1.24_01-3
libpng-1.0.12-2 png图形支持库
libpng-devel-1.0.12-2
gcc-2.96-98 c编译器
gcc-g77-2.96-98
gcc-c++-2.96-98
zlib-1.1.3-24
zlib-devel-1.1.3-24
httpd(apache)
net-snmp snmp协议
mrtg
2. 监控配置
2.1. 用awstats建立流量统计,日志分析
squid配置的日志为apache的格式,所以用awstats分析。
2.1.1. Awstats编译安装与配置:
Ø 下载awstats-6.5-1.tar.gz
Ø 解压安装Tar zxvf awstats-6.5-1.tar.gz –C /usr/local
Cd !$/awstats-6.5-1/tools
./awstats_configure.pl
Ø 修改配置文件vi /etc/awstats/awstats.192.168.6.67.conf
LogFile="/usr/local/squid/var/logs/access.log" 配置要统计的日志文件
LogType=W要分析的日志格式与Apache相同
DirData="/var/lib/awstats"设置数据的存储目录
Ø 每天生成当日的统计分析
02 5 * * * /usr/local/awstats/tools/awstats_updateall.pl
Ø 配置认证与授权
AuthType Basic
AuthName “admin”
AuthUserFile /usr/local/apache/htdocs/awstats.pwd
Require valid-user
Ø 创建口令文件,并添加用户
Cd /usr/local/apache/htdocs/
Htpasswd –c awstats.pwd admin
Chown apache.apache swstats.pwd
Ø 测试
http://192.168.6.67/awstats/awstats.pl?config=192.168.6.67
2.2. 建立mrtg监控
2.2.1. rpm –ivh mrtg.*.rpm
配置SNMP 让他可以配合MRTG工作。
Ø 编辑/etc/snmp/snmpd.conf
把下面的#号去掉
#view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc #在89行
把下面的语句#在62行
access notConfigGroup "" any noauth exact systemview none none
改为:
access notConfigGroup "" any noauth exact mib2 none none
改完重启一下snmp
Service snmpd restat
Ø 生成一个配置文件把配置文件放在apache默认目录下:
Cfgmaker –output=/usr/local/apache/htdocs/mrtg/mrtg.cfg squid@192.168.6.67
修改配置文件,添加对/opt/mrtg目录下cpu.sh df.pl diskio.sh diskperf.sh mem.sh space.sh swap.sh等脚本的调用以收集信息。
Ø 修改配置文件Vi /usr/local/apache/htdocs/mrtg/mrtg.cfg
WorkDir: /usr/local/apache/htdocs/mrtg设置mrtg的主目录
Options[_]: growright, bits把注释去掉
Ø 生成主页,把生成的主页放到指定的mrtg主目录下。
/usr/bin/indexmaker –output=/usr/local/apache/htdocs/mrtg/index.html –titile=squid.lotour.com /usr/local/apache/htdocs/mrtg/mrtg.cfg
Ø 在/opt/下建立mrtg目录,分别建立程序cpu.sh df.pl diskio.sh diskperf.sh mem.sh space.sh swap.sh,让mrtg配置文件每5分钟调用一次所有这些脚本以收集系统运行的状态信息。(详细代码见附脚本文件)
Ø 手工建立一个配置文件,让所有用户可以访问vi /usr/local/apache/conf/mrtg.cfg
Alias /mrtg /usr/local/apache/htdocs/mrtg
Order deny,allow
Allow from all
Ø 配置认证与授权
AuthType Basic
AuthName “admin”
AuthUserFile /usr/local/apache/htdocs/mrtg.pwd
Require valid-user
Ø 创建口令文件,并添加用户
Cd /usr/local/apache/htdocs/
Htpasswd –c mrtg.pwd admin
Chown apache.apache mrtg.pwd
Ø 设置计划任务每天收集日志分析
*/5 * * * * env /usr/bin/mrtg /usr/local/apache/htdocs/mrtg/mrtg.cfg 每五分钟收集一次状态信息。
02 4 * * * /usr/bin/indexmaker --output=/usr/local/apache/htdocs/mrtg/index.html --title=lotour67.lotour.com /usr/local/apache/htdocs/mrtg/mrtg.cfg
Ø 测试
访问: http://192.168.6.67/mrtg/
2.3. 实时监控squid
Ø 将脚本复制到web站点的CGI目录
Cp /usr/local/squid/cachemgr.cgi /usr/local/apache/htdocs/cgi-bin
Ø 配置对cgi的支持
Vi /usr/local/apache/conf/httpd.conf
ScriptAlias /cgi-bin/ “/usr/local/apache/htdocs/cgi-bin”
AllowOverride None
Option None
Order allow,deny
Allow from all
AddHandler cgi-script .cgi .pl
Chmod 755 /usr/local/apache/htdocs/cgi-bin/cachemgr.cgi
Ø 配置授权认证,只有管理员可以查看
AuthType Basic
AuthName “admin”
AuthUserFile /usr/local/squid/etc/squid.pwd
Require valid-user
Ø 创建口令文件,并添加用户
Cd /usr/local/squid/etc/
Htpasswd –c squid.pwd admin
Chown apache.apache squid.pwd
Ø 测试
/usr/local/apache/bin/apachectl –k restart
在客户端的浏览器中:
http://192.168.6.67:8080/cgi-bin/cachemgr.cgi
主要实时监控如下参数:
Memory Utilization内存使用监控
IP Cache Stats and Contents IP缓存统计(IP缓存的个数,命中率等)
General Runtime Information 缓存运行状态监控
5 Minute Average of Counters平均5分钟的缓存访问统计
60 Minute Average of Counters平均60分钟的缓存访问统计、
Cache Utilization缓存使用监控
Peer Cache Statistics 源服务器统计
Store Directory Stats存储目录和文件使用监控
Request Forwarding Statistics请求转发统计监控
以及其它方面的参数等。
把以上参数采集统计,分析。
2.4. 测试
访问http://www.lotour.com
点击尽可能所有的网页,
注意:1、400,403,500等错误情况。
2、内存池状态,确定磁盘使用的极限周期。
3、是否发现磁盘收发队列及其情况
3. 附脚本文件
[root@lotour67 mrtg]# cat cpu.sh
#!/bin/bash
cpuusr=`/usr/bin/sar -u 1 3 |grep Average |awk '{print $3}'`
cpusys=`/usr/bin/sar -u 1 3 |grep Average |awk '{print $5}'`
UPtime=`/usr/bin/uptime |awk '{print $3""$4""$5}'`
echo $cpuusr
echo $cpusys
echo $UPtime
hostname
[root@lotour67 mrtg]# cat df.pl
#!/usr/bin/perl
foreach $filesystem (`df -kl | grep -v "Filesystem"`)
{
@df = split(/\s+/,$filesystem);
$total += $df[1];
$usage += $df[2];
}
print "$total\n";
print "$usage\n";
hostname
[root@lotour67 mrtg]# cat diskperf.sh
#!/bin/bash
hd=hda
disk=/dev/$hd
KBread_sec=`iostat -x $disk|grep $hd |awk '{print $8}'`
KBwrite_sec=`iostat -x $disk|grep $hd |awk '{print $9}'`
echo "$KBread_sec"
echo "$KBwrite_sec"
hostname
[root@lotour67 mrtg]# cat mem.sh
#!/bin/bash
# This script to monitor the mem usage.
totalmem=`/usr/bin/free |grep Mem |awk '{print $2}'`
usedmem=`/usr/bin/free |grep Mem |awk '{print $3}'`
echo "$totalmem"
echo "$usedmem"
[root@lotour67 mrtg]# cat swap.sh
#!/bin/bash
# This script to monitor the swap usage.
totalswap=`/usr/bin/free |grep Swap |awk '{print $2}'`
usedswap=`/usr/bin/free |grep Swap |awk '{print $3}'`
echo "$totalswap"
echo "$usedswap"
六、 备注:
1. refresh_pattern参数解释
refresh_pattern的作用:
用于确定一个页面进入cache后,它在cache中停留的时间。
语法:
refresh_pattern [-i] regexp min percent max [options]
几个概念:
resource age =对象进入cache的时间-对象的last_modified
response age =当前时间-对象进入cache的时间
LM-factor=(response age)/(resource age)
举个例子,这里只考虑percent, 不考虑min 和 max
例如:refresh_pattern 20%
假设源服务器上www.aaa.com/index.htm ---last-modified
2008-01-10 02:00:00
squid上 proxy.aaa.com/index.htm index.htm进入cache的时间
2008-01-10 03:00:00
1)如果当前时间 2008-01-10 03:00:00
resource age =3点-2点=60分钟
response age =0分钟
index.htm还可以在cache停留的时间(resource age)*20%=12分钟
请您注册登录超级码客,加载全部码客文章内容... |