The company needs to build a monitoring platform in the near future, the main purpose is to realize the Server service or load abnormal timely alarm function, after the choice finally decided to use Nagios implementation
Install Nagios Core
The code is as follows |
Copy Code |
Yum-y install gcc glibc glibc-common gd gd-devel php openssl-devel httpd Useradd-m Nagios #添加一个名为nagios的用户来运行nagios Usermod-a-G Nagios Apache #将运行apache用户apache加入nagios组 wget http://ssh.xj123.info/monitor/nagios-3.5.0.tar.gz TAR-ZXF nagios-3.5.0.tar.gz Mkdir/etc/httpd/conf/extra//For storing HTTP configuration files on Nagios CD Nagios ./configure--prefix=/usr/local/nagios/--with-comman-group=nagios--with-httpd-conf=/etc/httpd/conf/extra/// Specify the configuration directory for the installation directory and users, groups, and HTTP Make All&&make Install Make Install-init;make install-config;make install-commandmode;make install-webconf//Initial build startup scripts, configuration files, Configuration files for command configuration modules and httpd |
Install Nagios Plugins
The code is as follows |
Copy Code |
wget http://ssh.xj123.info/monitor/nagios-plugins-1.5.tar.gz TAR-ZXF nagios-plugins-1.5.tar.gz CD nagios-plugins-1.5 ./configure--with-nagios-user=nagios--with-nagios-group=nagios--prefix=/usr/local/nagios///Specify installation directory and users and groups Make All&&make Install |
Configure Apache
The code is as follows |
Copy Code |
Htpasswd-c/usr/local/nagios/etc/htpasswd.users nagiosadmin//Create login username nagiosadmin and password, username and password for Web login Vim/etc/httpd/conf/httpd.conf #添加如下行, let nagios.conf take effect
Include conf/extra/nagios.conf |
Start all services
The code is as follows |
Copy Code |
Chkconfig--add Nagios Chkconfig Nagios on Chkconfig httpd on Service Nagios Start Service httpd Start |
Install Nrpe
Client Install Nagios Plugin
The code is as follows |
Copy Code |
Useradd-s/sbin/nologin Nagios//Add Nagios User Cd/usr/local/src Tar zxvf nagios-plugins-1.4.16.tar.gz CD nagios-plugins-1.4.16 ./configure--with-nagios-user=nagios--with-nagios-group=nagios--prefix=/usr/local/nagios///Specify the installation directory and run the software users and groups Make&&make Install |
Client Installation Nrpe
The code is as follows |
Copy Code |
wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz TAR-ZXF nrpe-2.14.tar.gz CD nrpe-2.14 ./configure--with-nagios-user=nagios--with-nagios-group=nagios--prefix=/usr/local/nagios/ Make all Make Install-plugin;make Install-daemon;make install-daemon-config ls/usr/local/nagios/libexec///Verify Installation |
Client configuration, startup, test Nrpe
code is as follows |
copy code |
cd/usr/local/nagios/ Vim etc/nrpe.cfg #找到allowed_ Hosts add server-side ip:allowed_hosts=127.0.0.1,23. Monitor server IP /usr/local/nagios/bin/nrpe-c/usr/local/nagios/ etc/nrpe.cfg–d //Start Nrpe daemon NETSTAT-UTPLN |grep nrpe // To see if the Nrpe process has started normally TCP 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 17619/nrpe Echo/U Sr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg-d ">>/etc/rc.local / Add Nrpe to boot automatically /usr/local/nagios/libexec/check_nrpe-h 127.0.0.1 Nrpe v2.14 //nrpe test results, this result is that Nrpe is working correctly |
Customizing monitoring content
The code is as follows |
Copy Code |
Vim/usr/local/nagios/etc/nrpe.cfg
Command[check_users]=/usr/local/nagios/libexec/check_users-w 5-c #监控登陆的用户数量 Command[check_load]=/usr/local/nagios/libexec/check_load-w 15,10,5-c 30,25,20 #监控CPU的负载 Command[check_sda2]=/usr/local/nagios/libexec/check_disk-w 20%-C 10%-p/dev/sda2 #监控磁盘利用率, where the sda2 must be the actual hard disk partition, can use Fdisk–l to check Command[check_swap]=/usr/local/nagios//libexec/check_swap-w 20-c #监控交换空间 Command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs-w 5-c 10-s Z #监控进程中的僵尸进程 Command[check_total_procs]=/usr/local/nagios/libexec/check_procs-w 150-c #监控所有进程
|
Note: The content in parentheses after the command is defined as a variable, and the variable name can be specified arbitrarily, only as long as it is consistent with the server configuration file.
Server-side Install Nrpe plugin
The code is as follows |
Copy Code |
wget http://ssh.xj123.info/monitor/nrpe-2.14.tar.gz TAR-ZXF nrpe-2.14.tar.gz CD nrpe-2.14 ./configure--with-nagios-user=nagios-with-nagios-group=nagios--prefix=/usr/local/nagios/ Make All;make Install-plugin; Make Install-daemon;make install-daemon-config//install Check_nrpe plugin to/usr/local/nagios/libexec/directory /usr/local/nagios/libexec/check_nrpe-h Client IP
NRPE v2.14//This result indicates that it can communicate with client |
Configuring Nagios servers to support remote monitoring
Add a Monitor Host
The code is as follows |
Copy Code |
Cd/usr/local/nagios/etc/objects Vim Host.cfg
Define Host{ Use Linux-server HOST_NAME Slaves Address 192.168.8.15 } |
Define the services to be monitored
The code is as follows |
Copy Code |
# vim Services.cfg #定义要监控的服务 Define Service{ Use Local-service HOST_NAME Slaves Service_description http Check_command check_http } |
Add Definition Check_nrpe Command
The code is as follows |
Copy Code |
Vim Commands.cfg #定义check_nrpe监控命令 Define Command{ Command_name Check_nrpe Command_line $USER 1$/check_nrpe-h $HOSTADDRESS $-C $ARG 1$ } |
Add Host.cfg and Ervices.cfg to Nagios.cfg
The code is as follows |
Copy Code |
Cd/usr/local/nagios/etc Vim Nagios.cfg Cfg_file=/usr/local/nagios//etc/objects/host.cfg Cfg_file=/usr/local/nagios//etc/objects/services.cfg |
Modify Accept Alert Mailbox
The code is as follows |
Copy Code |
Vim Contacts.cfg Email test@test.com; #请修改为自己的邮箱地址 |
Test and start Nagios service
The code is as follows |
Copy Code |
/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg #检测配置文件是否正确
Total warnings:0 Total errors:0 #结果表示配置无错误
Service Nagios Restart #重启Nagios服务 Vim Contacts.cfg Email test@test.com; #请修改为自己的邮箱地址 |
Test and start Nagios service
code is as follows |
copy code |
/usr/local /nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg #检测配置文件是否正确 Total warnings:0 Total errors:0 #结果表示配置无错误 Service nagios restart #重启Nagios服务 |