内网监控利器

在游戏运维中有最长用的就是使用nagios监控游戏服务器。nagios是一款比较成熟的监控软件。对被监控的主机从负载到进程、网络端口、系统服务等都能做监控,香港服务器,而且当出现问题时候能发出邮件警报。

一、nagios的安装(root用户下安装)

安装必要的包

yum install httpd php gcc glibc glibc-common gd gd-devel

建立相应的用户和用户组

useradd -m nagiospasswd nagiosgroupadd nagcmdusermod -a -G nagcmd nagiosusermod -a -G nagcmd apache

下载并解压nagios的安装包

http:-zxf nagios-3.2.3.tar.gz

开始configure

cd nagios-3.2.3./configure –with-command-group=nagcmdmake all-initmake install-configmake install-commandmode

这样基本的就安装好了。但是现在不要启动nagios,还要修改/usr/local/nagios/etc/objects/contacts.cfg文件,定义报警邮箱。

安装web接口

make install-webconf htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin #添加web登录用户并设置密码service httpd restart

安装nagios监控插件

tar xzf nagios-plugins-1.4.11.tar.gzcd nagios-plugins-1.4.11./configure –with-nagios-user=nagios –with-nagios-group=nagios#添加开机自启动chkconfig –add nagioschkconfig nagios on

校验配置文件

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg#启动naigosservice nagios start

二、nagios配置

首先是发送邮件报警命令的定义,给个例子如下,所有的命令定义最好都写在command.cfg中。

# command definitiondefine command{command_name notify-host-by-emailcommand_line /usr/bin/printf |/usr/local/bin/sendEmail.pl -f -t $CONTACTEMAIL$ -s -u -xu -xp }# command definitiondefine command{command_name notify-service-by-emailcommand_line /usr/bin/printf | /usr/local/bin/sendEmail.pl -f Lenwood@mail.-xu Lenwood@mail.163.com -xp passwordforserect}

解释一下:

(1)上面用到了很多变量,这都是nagios能够提供的,如$HOSTNAME$就是出问题的那台服务器的主机名。

(2)粗体部分需要修改为自己用来发送邮件报警的邮箱,香港虚拟主机,这个我就随便举了个例子。

(3)这里使用sendEmail.pl这个perl脚本来发送邮件,不适用sendmail的原因是sendmail有时候不可靠,虚拟主机,尤其是DNS解析有问题的时候。

其他命令的定义先不写,多半都是使用/path/to/nagios/libexec/目录下的一些插件,如check_ping、check_smtp、check_http等。

三、总结的nagios非常实用的技巧

nagios主要是添加新机器比较恶心,所以我使用shell脚本的方式添加,这样不论是添加1台还是1000台的监控,只要有hostname和IP地址对应信息,都只需5分钟。

例如,给出host记录如下

#/home/nagios/hosts.txt内容如下game_web110.96.19.51game_web210.96.19.52game_ope10.96.19.53game_db110.96.19.54game_db210.96.19.55

添加新的服务器监控必须在nagios中定义主机和这个主机需要监控的服务。我的解决方法是分别写两个模板,然后通过/home/nagios/hosts.txt替换模板中的主机名和IP。

(1)host定义模板

host_template.cfg内容如下define host {uselinux-serverhost_namehostnameaddress ipaddresshostgroupshostgroupnamecontact_groups lenwood}

好了,开始批量替换

`;ip=`echo $line|awk `;sed host_template.cfg|sed |sed >>host.cfg;done</home/nagios/hosts.txt

这样就都替换好了,其中GAME是事先定义好的“主机分组名”。

(2)serive定义模板

#service_template.cfg内容如下define service {host_name hostnameuse generic-serviceservice_description SSHcheck_command check_ssh!22servicegroups SSH# notifications_enabled 0contact_groups lenwood}…..还有其他很多服务的定义。

然后就可以批量写SSH服务检测的定义了。命令如下:

`;sed service_template.cfg >$host.cfg;done</home/nagios/hosts.txt

这就是我在使用nagios过程中的一些体会。

把艰辛的劳作看作是生命的必然,

内网监控利器

相关文章:

你感兴趣的文章:

标签云: