老男人百科 > 百科 > 正文

linux重启服务器命令(重启linux服务器命令)

2023-04-07 17:40:39 阅读( 6857)

Varnish作为反向代理软件,应用于Web前端,其良好的Cache性能使得网站承载能力有很大提升,下面记录下最近使用在Varnish学习与应用中的实践体会,本篇主要内容:安装配置监控。

二、配置文件

1.配置Varnish启动参数,比如指定相应的执行脚本,即vcl文件Varnish管理端口,默认为6082,可以改成自定义端口,比如2000。

VARNISH_ADMIN_LISTEN_PORT=2000监听端口,默认为8080,一般改为80

VARNISH_LISTEN_PORT=80指定缓存文件存放路径

VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin

缓存文件varnish_storage.bin在32位操作系统下最多只能支持2G。

如果需要更大的缓存文件,需要安装64 as linux操作系统。

2、配置varnish为服务形式运行

3.0以上版本是安装varnish后自动配置的,也就是可以直接使用service varnish start命令执行。

对于3.0以下的版本,需要手动配置相应的配置文件。

1)在相应版本的安装包下找到varnish.initr文件,例如

C:/./varnish-3.0.1/redhat/varnish-3.0.1/redhat/varnish.initrc

3)如果参数是默认配置形式,如/sysconfig/Varnish,则可以省略步骤2)。

4) Rename varnish. initrc as glossy surface.

5) Copy the varnish to /etc/rc.d/init.d/

6) Specify the execution authority chmod700/etc/rc.d/init.d/varnish for the glossy surface.

7) chkconfig --add varnish三、查看Varnish运行状态

ps -aux|grep varnishd

正常结果如下

也可以通过top |grep varnishd查看四、查看Varnish日志

1.使用varnishlog命令查看日志,并且可以添加一些参数。具体可以通过-h得到参数描述。

例如,varnishlog -i txurl命令用于查看哪些url指向源。

2.将日志保存到文件中。

您需要使用varnishncsa指令,例如

Varnishncsa-w/var/lib/varnish/varnish.log saves the varnish log in a file.

文件格式为文本格式,方便查看五、查看Varnish缓存情况

1、通过varnishstat 查看当前及自启动以来的请求及缓存命中情况

结果数据的含义:

第一行显示的是varnish自启动到现在运行了多长时间,如上图显示的是45天0小时11分27秒

第二行显示的是启动这个命令的时间,这个三数字最终会变为10,100,1000;分别代表10秒,100秒,1000秒

第三行显示的是命中率,分别对象上面的时间,分别是10秒内的命中率,100秒内的命中率,1000秒内的命中率

从第四行开始下面的数据就分为4列

第一列为总数值,第二列为每秒中的数值,第三列自命令(varnishstat)启动以来的平均值,第四列是描述

其中几个比较重要的是

Client connections accepted:表示客户端向反向代理服务器成功发送HTTP请求的总数量

Client requests received:表示到现在为止,浏览器向反向代理服务器发送HTTP请求的累积次数,由于可能会使用长连接,

所以这个值一般会大于Client connections accepted

cache-hit :代表缓存命中次数

miss-hit :代表未命中次数

worker threads :代表当前工作线程的数量

expired objects :代表过期对象的个数

LRU nuked objects :代表缓存可使用的内存以达上线而不得不移除的对象个数

LRU moved objects :代表LRU策略被移动的对象个数

Total header bytes :代表缓存的请求头对象的大小

Total body bytes:代表缓存的请求体对象大小

命中率公式:cache-hit/Client requests received

2、若每次查看varnish当前缓存情况都要登录Server,有点麻烦

可以用php(可以用其它语言)编写一段程序,远程查看

代码可以参考如下,3.0以下的版本可以通过Socket连接到Varnish管理端口,通过stat命令查看,3.0以上没有stat命令,只能通过下面的方法解决

?php

$outfile=shell_exec('/usr/bin/varnishstat -x ');

$xml=simplexml_load_string($outfile);

echo $xml-getName() . 'br /';

foreach($xml-children() as $child)

{

//$tmpName='';

foreach($child-children() as $subChild)

{

if ($subChild-getName()=='name' )

{

$tmpName=$subChild;

}

else if ($subChild-getName()=='value' )

{

if ($tmpName!='')

{

$arys['$tmpName']=$subChild;

$tmpName='';

}

}

else

{

continue;

}

}

}

function byteReduce($bytes)

{

if ($bytes1099511627776)

{

return round($bytes/1099511627776).'TB';

}

else if ($bytes 1073741824)

{

return round($bytes/1073741824).'GB';

}

else if ($bytes1048576)

{

return round($bytes/1048576).'MB';

}

else if ($bytes1024)

{

return round($bytes/1024).'KB';

}

else

{

return $bytes.'B';

}

}

echo 'client_conn: '.$arys['client_conn'] . 'br /';

echo 'client_req: '.$arys['client_req'] . 'br /';

echo 'cache_hit: '.$arys['cache_hit'] . 'br /';

echo 'cache_miss: '.$arys['cache_miss'] . 'br /';

echo 'Cache hit rate: '.round(($arys['cache_hit']/$arys['client_req'])*100).' % br/';

echo 'LRU nuked objects: '.$arys[n_lru_nuked].'br/';

echo ' '.byteReduce($arys['s_bodybytes']+$arys['s_hdrbytes']).' Acc Content ('.byteReduce($arys['s_hdrbytes']).' header '.byteReduce($arys['s_bodybytes']).' Body)';

?

页面效果如

当然为了查看实时情况,可以在这监控页加个html定时刷新

若已经部署了专业的监控工具如catic ,则可以通过配置,在catic中查看Varnish 运行状态

3.0以上版本,需要一个php页面输出结果echo shell_exec('/usr/bin/varnishstat -x ');然后catic中配置下即可

专题页