注意:部分文章发布时间较长,可能存在未知因素,购买时建议在本站搜索商家名称,先充分了解商家动态。
交流:唯一投稿邮箱:hostvps@88.com。
在购买VPS主机之前,我一般都会先查看一下别人使用该VPS主机的评价,尤其是VPS主机的线路是我最关心的地方。因为国外的VPS主机商非常多,但是真正从国内访问速度快的机房也就是那么几个。线路不好,速度慢的VPS,并不适合搭建中文网站。同时,我也发现了另一个问题,那就是某一个VPS主机在最开始测试时线路质量很好,但是随着用户的增多VPS主机访问也越来越不稳定了,这是最开始使用VPS主机没有想到的。所以,迫切需要一个国外VPS主机线路监控报告,能够直观地了解VPS主机线路的变化。满足上面要求的,恐怕只有Smokeping了。Smokeping是一个开源免费的网络性能监控工具,主要用于监视网络性能,包括常规的 ping,dig,echoping,curl等,可以 监视 www 服务器性能,监视 dns 查询性能,监视 s-s-h 性能等。最重要的是Smokeping的图表非常直观。Smokeping采用rrdtool做支持,生成的网络延迟数据转化图表非常漂亮,支持交互式图形浏览,你可以查看任意时间段的监控数据。Smokeping也可以部署主/从分布式测量,即用一台服务器作为“主”,其它的服务器作为“从”并向“主”服务器传输数据,最后汇总形成系统监控数据图表。本篇文章就来分享一下Smokeping安装与配置方法,你也可以自己按照下面的方法来给VPS主机作一个“体检”:一、Smokeping安装前准备Smokeping官网:https://oss.oetiker.ch/smokeping/index.en.htmlhttps://github.com/oetiker/SmokePingSmokeping需要以下组件依赖(有optional为可选项):RRDtool 1.2.x or laterFPing (optional)EchoPing (Optional)Curl (Optional)dig (Optional)S-S-H (Optional)WebserverPerl 5.8.8 or later(对应的模块如下)FCGICGI, CGI::FastConfig::GrammarLWPSocket6 (optional)Net::Telnet (optional)Net::OpenS-S-H (optional)Net::.DNS (optional)Net::LDAP (optional)IO::Socket::SSL (optional)Authen::Radius (optional)Smokeping官网推荐用Apache来运行,当然也可以使用Nginx,但是你需要配置好Nginx FCGI才行。本篇文章测试的环境是:CentOS 6.8+Apache。执行以下命令安装相关组件依赖:#临时修改hostnamesudo hostname ping.wzfou.com#查看是否成功hostname#永久修改Hostnamevi /etc/sysconfig/network#修改原hostname为ping.wzfou.com#查看是否成功hostname#禁用SELinuxvi /etc/selinux/configSELINUX = disabled#同步时间yum -y install ntpdatentpdate times.aliyun.com#安装epel源wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmrpm -ivh epel-release-6-8.noarch.rpm#备用地址:https://www.ucblog.net/wzfou/epel-release-6-8.noarch.rpm#安装rrdtool与依赖库yum -y install perl perl-Net-Telnet perl-Net-DNS perl-LDAP perl-libwww-perl perl-RadiusPerl perl-IO-Socket-SSL perl-Socket6 perl-CGI-SpeedyCGI perl-FCGI perl-CGI-SpeedCGI perl-Time-HiRes perl-ExtUtils-MakeMaker perl-RRD-Simple rrdtool rrdtool-perl curl fping echoping httpd httpd-devel gcc make wget libxml2-devel libpng-devel glib pango pango-devel freetype freetype-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel mod_fastcgi mod_ssl git bind-utils fping#安装中文字体yum -y install wqy-zenhei-fonts #DNS需要用到TCPPing命令,安装方法如下: 首先安装tcptraceroute: yum install tcptraceroute 然后下载: wget http://www.vdberg.org/~richard/tcpping 赋予权限后移动到/usr/bin目录下即可使用: chmod 755 tcpping mv tcpping /usr/bin/ 经过测试,发现tcpping的IP必须要有80服务才行安装过程中可能会出现某个依赖找不到情况,一般影响不大,你只要在下面的操作中能够正常进行就可以了。二、下载Smokeping安装并配置执行以下命令开始安装Smokeping:wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.9.tar.gztar zxvf smokeping-2.6.9.tar.gzcd smokeping-2.6.9./configure –prefix=/usr/local/smokeping./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty#备用地址:https://www.ucblog.net/wzfou/smokeping-2.6.9.tar.gz安装过程中,可能会出现下面的提示:** Aborting Configure ****************************** If you know where perl can find the missing modules, set the PERL5LIB environment variable accordingly. FIRST though, make sure that ‘perl’ starts the perl binary you want to use for SmokePing. Now you can install local copies of the missing modules by running ./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty The RRDs perl module is part of RRDtool. Either use the rrdtool package provided by your OS or install rrdtool from source. If you install from source, the RRDs module is located PREFIX/lib/perl#这是因为缺少相应的perl模块,直接按照提示执行:./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty#继续执行操作:./configure –prefix=/usr/local/smokeping/usr/bin/gmake install执行以下命令开始配置Smokeping:#创建 cache、data、var 数据目录cd /usr/local/smokepingmkdir cache data var#创建日志touch /var/log/smokeping.log#授权chown apache:apache cache data varchown apache:apache /var/log/smokeping.log#修改配置文件cd /usr/local/smokeping/htdocs/mv smokeping.fcgi.dist smokeping.fcgicd /usr/local/smokeping/etcmv config.dist config#vim config#cgiurl = http://some.url/smokeping.cgi…#step = 300#ping = 5你可以用Vim打开config文件,或者自己使用SFTP登录用编辑器打开config文件,此处你需要修改一下cgiurl,替换成你的IP或者域名,详细的config请看下一部分。最后,给密码文件赋予权限:chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist三、安装Apache并配置Smokeping刚才我们通过Yum的方法已经安装好了Apache,这里我们需要修改Apache的配置文件,将IP或者域名调整访问到Smokeping路径,命令如下:vim /etc/httpd/conf/httpd.conf#在最后添加以下内容Alias /cache “/usr/local/smokeping/cache/”Alias /cropper “/usr/local/smokeping/htdocs/cropper/”Alias /smokeping “/usr/local/smokeping/htdocs/smokeping.fcgi”<Directory “/usr/local/smokeping”>AllowOverride NoneOptions AllAddHandler cgi-script .fcgi .cgiOrder allow,denyAllow from allDirectoryIndex smokeping.fcgi</Directory>########################################################如果你想让你的Smokeping访问不公开,你可以设置访问密码vim /etc/httpd/conf/httpd.confAlias /cache “/usr/local/smokeping/cache/”Alias /cropper “/usr/local/smokeping/htdocs/cropper/”Alias /smokeping “/usr/local/smokeping/htdocs/smokeping.fcgi”<Directory “/usr/local/smokeping”>AllowOverride NoneOptions AllAddHandler cgi-script .fcgi .cgiAllowOverride AuthConfigOrder allow,denyAllow from allAuthName “Smokeping”AuthType BasicAuthUserFile /usr/local/smokeping/htdocs/htpasswdRequire valid-userDirectoryIndex smokeping.fcgi</Directory>#再执行设置密码htpasswd -c /usr/local/smokeping/htdocs/htpasswd admin以上你可以用Vim命令,也可以自己用编辑器将配置文件下载到本地进行编辑。设置 Smokeping、Apache 开机启动:echo “/usr/local/smokeping/bin/smokeping –logfile=/var/log/smokeping.log 2>&1 &” >> /etc/rc.localchkconfig httpd on四、 Smokeping启动和遇到的问题执行以下命令即启动 Smokeping:/etc/init.d/httpd start/usr/local/smokeping/bin/smokeping –logfile=/var/log/smokeping.log2>&1&打开你的浏览器访问:ip或者域名/smokeping,你就可以看到Smokeping默认的界面了。4.1 Smokeping支持中文问题默认的Smokeping显示中文会乱码,我们刚刚在上面给Linux安装了中文字体,现在执行:vim /usr/local/smokeping/lib/Smokeping/Graphs.pm,在’–end’, $tasks[0][2],增加一行字体配置部分(’–font’, “TITLE:20:WenQuanYi Zen Hei Mono”,),如下:… if ($mode =~ /[anc]/){ my $val = 0; for my $host (@hosts){ my ($graphret,$xs,$ys) = RRDs::graph (“dummy”, ‘–start’, $tasks[0][1], ‘–end’, $tasks[0][2], ‘–font’, “TITLE:20:WenQuanYi Zen Hei Mono”, “DEF:maxping=$cfg->{General}{datadir}${host}.rrd:median:AVERAGE”, ‘PRINT:maxping:MAX:%le’ ); my $ERROR = RRDs::error(); return “RRDtool did not understand your input: $ERROR.” if $ERROR; $val = $graphret->[0] if $val < $graphret->[0]; } $val = 1e-6 if $val =~ /nan/i; $max = { $tasks[0][1] => $val * 1.5 }; }…如下图设置:然后,执行:vim /usr/local/smokeping/etc/config,增加一行代码charset= utf-8,如下:…***Presentation ***charset= utf-8template = /usr/local/smokeping/etc/basepage.html.dist…4.2 Smokeping域名访问及SSL证书如果你不想让Smokeping访问时带上/Smokeping这么一个尾巴,你可在Apache配置中修改如下:Alias / “/usr/local/smokeping/htdocs/smokeping.fcgi” 给域名添加SSL证书也很简单,首先为你的域名申请一个SSL证书,阿里云、腾讯云等都提供了免费一年的SSL证书可供申请。傲盾互联的虚拟主机都有免费的SSL证书。刚才我们已经通过Yum的方式安装了mod_ssl,现在你可以进入到:/etc/httpd/conf.d,然后替换你的Key、CRT、CA路径,找到如下代码(注意你的证书路径):# Server Certificate:# Point SSLCertificateFile at a PEM encoded certificate. If# the certificate is encrypted, then you will be prompted for a# pass phrase. Note that a kill -HUP will prompt again. A new# certificate can be generated using the genkey(1) command.SSLCertificateFile /etc/pki/tls/certs/domain.crt# Server Private Key:# If the key is not combined with the certificate, use this# directive to point at the key file. Keep in mind that if# you’ve both a RSA and a DSA private key you can configure# both in parallel (to also allow the use of DSA ciphers, etc.)SSLCertificateKeyFile /etc/pki/tls/certs/domain.key# Certificate Authority (CA):# Set the CA certificate verification path where to find CA# certificates for client authentication or alternatively one# huge file containing all of them (file must be PEM encoded)SSLCACertificateFile /etc/pki/tls/certs/domainca.crt请将你下载下来的CA根证书、CRT域名证书和密钥Key上传到/etc/pki/tls/certs/目录,然后将上面的三个路径进行替换。最后重启Apache,就可以看到SSL证书生效了。4.3 Smokeping不显示数据的问题这个问题一般是由于目录权限导致的,你可以查看Apache日志错误提示,同时保持cache data var这三个文件夹里面生成的文件属性为可读写且拥有者为:apache:apache。五、Smokeping模板及Config配置详解Smokeping模板文件basepage.html.dist。在basepage.html.dist里你可以修改Smokeping的CSS样式、增加Html内容(包括图片、文字)、修改标题链接等等。Smokeping Config配置文件详解,相关的中文说明如下:*** General *** ##全局配置owner = charlie.cui@zerounix.com ##联系人(显示在网页上)contact = charlie.cui@zerounix.com ##联系人邮箱mailhost = mail.zerounix.com ##邮件服务主机sendmail = /usr/sbin/sendmail ##发送邮件件的二进制可执行程序# NOTE: do not put the Image Cache below cgi-bin# since all files under cgi-bin will be executed … this is not# good for images.imgcache = /usr/local/smokeping/cache ##生成图片的缓存imgurl = cache ##cache 定义cgi程序显示图片的url目录datadir = /usr/local/smokeping/data ##rrd文件的位置piddir = /usr/local/smokeping/varcgiurl = http://some.url/smokeping.cgi ##smokeping访问地址smokemail = /usr/local/smokeping/etc/smokemail ##发送邮件的邮件内容模板tmail = /usr/local/smokeping/etc/tmail ##HTML邮件模板的路径# specify this to get syslog loggingsyslogfacility = local0 ##syslog日志记录的设备编号# each probe is now run in its own process# disable this to revert to the old behaviour# concurrentprobes = no *** Alerts *** ##报警配置to = monitor@zerounix.com from = mon@zerounix.com +网络中断type = rttpattern = !=U,==Ucomment = 网络中断priority = 1 +中断恢复type = rttpattern = ==U,!=U,!=Ucomment = 中断恢复priority = 2 +严重丢包type = losspattern = >50%comment = 丢包大于50%priority = 3 +丢包报警type = losspattern = >10%,>10%,>10%comment = 连续3次丢包10%以上priority = 4 +网络延迟type = rttpattern = >180,>180,>180comment = 连续3次延时180以上priority = 5 *** Database ***step = 60pings = 10 # consfn mrhb steps total AVERAGE 0.5 1 1008AVERAGE 0.5 12 4320 MIN 0.5 12 4320 MAX 0.5 12 4320AVERAGE 0.5 144 720 MAX 0.5 144 720 MIN 0.5 144 720 *** Presentation *** ##模板文件路径 template = /tmp/smokeping-31631-build/etc/basepage.html.dist + charts menu = Chartstitle = The most interesting destinations ++ stddevsorter = StdDev(entries=>4)title = Top Standard Deviationmenu = Std Deviationformat = Standard Deviation %f ++ maxsorter = Max(entries=>5)title = Top Max Roundtrip Timemenu = by Maxformat = Max Roundtrip Time %f seconds ++ losssorter = Loss(entries=>5)title = Top Packet Lossmenu = Lossformat = Packets Lost %f ++ mediansorter = Median(entries=>5)title = Top Median Roundtrip Timemenu = by Medianformat = Median RTT %f seconds + overview width = 600height = 50range = 10h + detail width = 600height = 200unison_tolerance = 2 “Last 3 Hours” 3h”Last 30 Hours” 30h”Last 10 Days” 10d”Last 400 Days” 400d #+ hierarchies#++ owner#title = Host Owner#++ location#title = Location *** Probes *** ##探针+ FPingbinary = /usr/local/sbin/fping + DNSbinary = /usr/bin/diglookup = name.example*** Slaves *** ##“从”服务器设置secrets=/usr/local/smokeping/etc/smokeping_secrets+boomerdisplay_name=boomercolor=0000ff +slave2display_name=anothercolor=00ff00 *** Targets *** ##监控目标 probe = FPing menu = Toptitle = Network Latency Grapherremark = Welcome to the SmokePing website of xxx Company. \ Here you will learn all about the latency of our network. + Testmenu= Targets#parents = owner:/Test/James location:/ ++ James menu = Jamestitle =Jamesalerts = somelossslaves = boomer slave2host = james.address ++ MultiHostmenu = Multihosttitle = James and James as seen from Boomerhost = /Test/James /Test/James~boomer添加监控目标。*** Targets ***监控主机是分层结构,用+表示,例如第一层“+”,第二层“++”一次类推。这里给出一个从本地Ping到三大网络并返回数据的示例代码:+ Othermenu = 三大网络监控title = 监控统计++ dianxinmenu = 电信网络监控title = 电信网络监控列表host = /Other/dianxin/dianxin-bj /Other/dianxin/dianxin-hlj /Other/dianxin/dianxin-tj /Other/dianxin/dianxin-sc /Other/dianxin/dianxin-sh /Other/dianxin/dianxin-gz+++ dianxin-bjmenu = 北京电信title = 北京电信alerts = somelosshost = 202.96.199.133 +++ dianxin-hljmenu = 黑龙江电信title = 黑龙江电信alerts = somelosshost = 219.147.198.242 +++ dianxin-tjmenu = 天津电信title = 天津电信alerts = somelosshost = 219.150.32.132 +++ dianxin-scmenu = 四川电信title = 四川电信alerts = somelosshost = 61.139.2.69 +++ dianxin-shmenu = 上海电信title = 上海电信alerts = somelosshost = 116.228.111.118 +++ dianxin-gzmenu = 广东电信title = 广东电信alerts = somelosshost = 113.111.211.22 ++ liantongmenu = 联通网络监控title = 联通网络监控列表host = /Other/liantong/liantong-bj /Other/liantong/liantong-hlj /Other/liantong/liantong-tj /Other/liantong/liantong-sc /Other/liantong/liantong-sh /Other/liantong/liantong-gz +++ liantong-bjmenu = 北京联通title = 北京联通alerts = somelosshost = 61.135.169.121 +++ liantong-hljmenu = 黑龙江联通title = 黑龙江联通alerts = somelosshost = 202.97.224.69 +++ liantong-tjmenu = 天津联通title = 天津联通alerts = somelosshost = 202.99.96.68 +++ liantong-scmenu = 四川联通title = 四川联通alerts = somelosshost = 119.6.6.6 +++ liantong-shmenu = 上海联通title = 上海联通alerts = somelosshost = 210.22.84.3 +++ liantong-gzmenu = 广东联通title = 广东联通alerts = somelosshost = 221.5.88.88 ++ yidongmenu = 移动网络监控title = 移动网络监控列表host = /Other/yidong/yidong-bj /Other/yidong/yidong-hlj /Other/yidong/yidong-tj /Other/yidong/yidong-sc /Other/yidong/yidong-sh /Other/yidong/yidong-gz +++ yidong-bjmenu = 北京移动title = 北京移动alerts = somelosshost = 221.130.33.52 +++ yidong-hljmenu = 黑龙江移动title = 黑龙江移动alerts = somelosshost = 211.137.241.35 +++ yidong-tjmenu = 天津移动title = 天津移动alerts = somelosshost = 211.137.160.5 +++ yidong-scmenu = 四川移动title = 四川移动alerts = somelosshost = 218.201.4.3 +++ yidong-shmenu = 上海移动title = 上海移动alerts = somelosshost = 117.131.19.23 +++ yidong-gzmenu = 广东移动title = 广东移动alerts = somelosshost = 211.136.192.6六、Smokeping主从服务器分布式部署上面我们在配置文件中看到了:*** Slaves *** ,这就是部署主从服务器用的。说明如下:*** Slaves ***secrets=/usr/local/smokeping/etc/smokeping_secrets.dist# 定义通信用的秘钥文件,里面包含slave的名字以及对应密码+ wzfou # slave的名字display_name=挖站否 # slave的别名location=杭州电信机房 # 这个字段用来定义slave主机的位置,类似于descriptioncolor=0000ff # slave收集的数据在图像中显示的颜色6.1 Smokeping主服务器设置先按照上面的方法部署好主服务器Smokeping,然后修改smokeping_secrets.dist里面的内容,如下图设置好Slave名称和密码:通信用的秘钥文件内容为“slave的名字:密码”,这里需要注意秘钥文件的权限,由于smokeping的master/slave是通过smokeping程序进行验证的,所以这个秘钥文件owner必须是smokeping进程的运行用户身份,并且权限为600。命令如下:chown apache:apache /usr/local/smokeping/etc/smokeping_secrets.distchmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist接着,将定义的Slave节点分配给你需要监控的主机,如下说明:*** Targets ***++ changzhou ## 一级菜单,这个值将会作为data下的一个目录名被创建 menu = 常州机房 ## 定义web上显示的菜单名title = 常州机房 ## 标题名称+++ dianxin ## 监控主机,数据将会被存放在 data/changzhou/dianxin目录下menu = 电信机房 ## web上显示的名称 title = 电信机房监控 ##网页标题alerts = someloss ## 报警slaves = wzfou ## slave节点 host = wzfou.com ## 被监控的主机IP或者域名 从上面的配置我们可以看出关键地方是要在*** Targets *** 中添加一行:slaves = wzfou ## slave节点,表示slaves 会像主服务器一样在此目标展开监控。6.2 Smokeping从服务器设置请按照上文的方法在从服务器中配置好Smokeping,不需要任何配置,也不需要修改Apache配置,只要保证Smokeping正常安装并运行即可。Smokeping启动从服务器有几个参数需要了解:–master-url:当smokeping运行在slave模式下,使用该项指定master的访问url(web接口,用以通信)–slave-name:默认情况下,不指定此项时,slave连接到master后,master会以slave的hostname作为slavename,如果不希望这样做,就需要手动指定改选项–shared-secret:和master通信认证的密码文件–cache-dir:当smokeping运行在slave模式下,临时数据存放在master上的目录路径–pid-dir:slave模式下,其pid存放的目录路径。可选参数,默认继承–cache-dir参数的值同样的,确保你的Smokeping从服务器的smokeping_secrets.dist文件owner是smokeping进程的运行用户身份,并且权限为600,且从服务器的smokeping_secrets.dist中只要写密码,这一点和主服务器不同。这是我的Smokeping从服务器启动命令示例(需要注意的就是替换slave的名称):/usr/local/smokeping/bin/smokeping –master-url=https://ping.wzfou.com/ –cache-dir=/usr/local/smokeping/cache/ –shared-secret=/usr/local/smokeping/etc/smokeping_secrets.dist –slave-name=wzfou –logfile=/var/log/smokeping_slave.logCopy七、总结Smokeping真的是一个非常强大的网络性能监控工具,效果可以查看:ping.wzfou.com。Smokeping还有不少的探针可供使用,例如Ping、DNS、Curl、Https、SMTP、FTP、TCP、LDAP等,甚至还有不少的插件可以自己安装并开发。(点击放大)这是Smokeping的图表,非常直观,且容易看懂。(点击放大)文件权限问题。这是一个很容易出现问题的地方,修改了config文件后都会在data\cache\var中产生数据,如果文件权限不是apache将直接导致rrd文件不更新,web页面没有图像,或者web页面有图像但没有数据。你可以在在服务器执行以下命令解决问题:pkill smokepingchown -R apache:apache /usr/local/smokeping/datachown -R apache:apache /usr/local/smokeping/cache/etc/init.d/httpd restart ##重启Apache/usr/local/smokeping/bin/smokeping –reload 重启smokeping。每次修改配置文件后需要重启smokeping进程,否则会出现各种问题。重启smokeping命令如下:/usr/local/smokeping/bin/smokeping –restart或/usr/local/smokeping/bin/smokeping –reload或pkill smokeping/usr/local/smokeping/bin/smokepingmaster/slave服务器没有数据。对于master/slave的架构,首先确保slave-name和master配置文件中配置的slave节点名以及密钥文件中的节点名相对应。再查看一下master的密钥文件(包含slave节点名和密码)与slave的密码文件(只有密码)是否对应。最后就是密钥属性权限一定要是600。PS:2017年11月11日更新,Smokeping在服务器网络监控方面比较出色,但是如果想要对整个服务器的内存、CPU、连接等指数进行详细的监控,可以试试企业级的Zabbix:Zabbix安装与使用-强大的服务器性能监控工具掌控服务器软硬件资源。文章出自:挖站否 https://wzfou.com/smokeping/,部分内容参考自yufei.im、Ken Lai 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。