nagios服务搭建及常见报错处理
搭建lamp安装epel源
rpm -ivh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
epel.repo epel-testing.repo
修改epel.repo中的enable=1
yum install -y mysqlmysql-server php-mysql httpd php php-pdo lm_sensors net-snmp php-snmpnet-snmp-utils perl-Net-Daemon perl-PlRPC perl-DBI rrdtool perl-rrdtoolperl-DBD-MySQL net-snmp-libs libart_lgpl-devel
service httpdstart
如果启动报错:# service httpd start
Starting httpd: httpd:Could not reliably determine the server's fully qualified domain name, using192.168.2.211 for ServerName
vi /etc/httpd/conf/httpd.conf
将ServerName www.example.com:80前面的注释去掉
root@linux211 conf]# service httpdstart
Starting httpd:
service mysqld start
# service mysqldstart
Initializing MySQL database:Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have tocopy
support-files/mysql.server to the rightplace for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THEMySQL root USER !
To do so, start the server, then issuethe following commands:
/usr/bin/mysqladmin -u root password'new-password'
/usr/bin/mysqladmin -u root -h linux211password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option ofremoving the test
databases and anonymous user created bydefault.This is
strongly recommended for productionservers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon withmysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the/usr/bin/mysqlbug script!
The latest information about MySQL isavailable on the web at
http://www.mysql.com
Support MySQL by buying support/licensesat http://shop.mysql.com
[ OK]
Starting mysqld:[ OK]
设置为开机启动
chkconfig httpd on
chkconfig mysqld on
查看防火墙状态
#/etc/init.d/iptables status
Firewall is stopped.
如果没有关闭,就关闭防火墙
/etc/init.d/iptablesstop
验证lamp是否可用
vim /var/www/html/index.php
http://ip地址/index.php
http://s3.运维网.com/wyfs02/M00/12/B4/wKiom1MMc-_geQxRAAFK2GPNOcE750.jpg
显示除了php的版本信息,说明lamp是可用的
2.安装nagios
groupadd nagcmd
useradd -m nagios
usermod -a -G nagcmdnagios
把apache加入到nagcmd组,以便于在通过web Interface操作nagios时能够具有足够的权限
usermod -a -G nagcmdapache
下载Nagios,开始编译安装
wget http://sourceforge.net/projects/nagios/?source=directory
--2014-02-2514:01:05--http://sourceforge.net/projects/nagios/?source=directory
Resolvingsourceforge.net... 216.34.181.60
Connecting tosourceforge.net|216.34.181.60|:80... connected.
HTTP request sent,awaiting response... 200 OK
Length: 43274 (42K)
Saving to: `index.html?source=directory'
100%[=============================================================================================================================>]43,274 51.3K/s in 0.8s
2014-02-25 14:01:08(51.3 KB/s) - `index.html?source=directory' saved
下载nagios安装包
wget http://prdownloads.sourceforge.net/sourceforge/nagios
/nagios-3.4.3.tar.gz
tar -zxvfnagios-3.4.3.tar.gz
cd nagios
# ./configure --with-command-group=nagcmd
checking for aBSD-compatible install... /usr/bin/install -c
checking build systemtype... x86_64-unknown-linux-gnu
checking host systemtype... x86_64-unknown-linux-gnu
checking for gcc...gcc
checking for Ccompiler default output file name... a.out
checking whether theC compiler works... yes
checking whether weare cross compiling... no
checking for suffixof executables...
checking for suffixof object files... o
checking whether weare using the GNU C compiler... yes
checking whether gccaccepts -g... yes
checking for gccoption to accept ANSI C... none needed
checking whether makesets $(MAKE)... yes
checking for strip.../usr/bin/strip
checking how to runthe C preprocessor... gcc -E
checking for egrep...grep -E
checking for ANSI Cheader files... yes
checking whethertime.h and sys/time.h may both be included... yes
checking forsys/wait.h that is POSIX.1 compatible... yes
checking forsys/types.h... yes
checking forsys/stat.h... yes
checking forstdlib.h... yes
checking forstring.h... yes
checking formemory.h... yes
checking forstrings.h... yes
checking forinttypes.h... yes
checking forstdint.h... yes
checking forunistd.h... yes
checking arpa/inet.husability... yes
checking arpa/inet.hpresence... yes
checking forarpa/inet.h... yes
checking ctype.husability... yes
checking ctype.hpresence... yes
checking forctype.h... yes
checking dirent.husability... yes
checking dirent.hpresence... yes
make all
make: Enteringdirectory `/root/nagios/base'
gcc -Wall -g -O2-DHAVE_CONFIG_H -DNSCORE -c -obroker.o broker.c
gcc -Wall -g -O2-DHAVE_CONFIG_H -DNSCORE -c -onebmods.o nebmods.c
gcc -Wall -g -O2-DHAVE_CONFIG_H -DNSCORE -c -o ../common/shared.o ../common/shared.c
gcc -Wall -g -O2-DHAVE_CONFIG_H -DNSCORE -c -ochecks.o checks.c
make install
make install-init
make install-config
makeinstall-commandmode
实现在httpd的配置文件目录(conf.d)中创建Nagios的Web程序配置文件
makeinstall-webconf
创建一个登录nagios web程序的用户,这个用户帐号在以后通过web登录nagios认证时所用
htpasswd -c/usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password foruser nagiosadmin
以上过程配置结束以后需要重新启动httpd:
servicehttpd restart
Stopping httpd:
Starting httpd:
编译、安装nagios-plugins
下载安装包
wget http://assets.nagios.com/downloads/nagiosplugins/
nagios-plugins-1.5.tar.gz
tar -zxvfnagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure --with-nagios-user=nagios--with-nagios-group=nagios
make
make install
把nagios添加为系统服务并将之加入到自动启动服务队列
chkconfig --add nagios
chkconfig nagios on
检查其主配置文件的语法是否正确
/usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg
Checking contact groups...
Checked 1 contact groups.
Checking serviceescalations...
Checked 0 service escalations.
Checking servicedependencies...
Checked 0 service dependencies.
Checking hostescalations...
Checked 0 host escalations.
Checking hostdependencies...
Checked 0 host dependencies.
Checking commands...
Checked 24 commands.
Checking timeperiods...
Checked 5 time periods.
Checking for circularpaths between hosts...
Checking for circularhost and service dependencies...
Checking global eventhandlers...
Checking obsessivecompulsive processor commands...
Checking miscsettings...
Total Warnings: 0
Total Errors: 0
Things look okay - Noserious problems were detected during the pre-flight check
启动nagios服务
service nagios start
http://s3.运维网.com/wyfs02/M02/12/B4/wKioL1MMc-mCGBGaAAD_erisuuo166.jpg
http://s3.运维网.com/wyfs02/M01/12/B4/wKiom1MMdA6yND59AAGaPBdKoAA467.jpg
安装NRPE
wgethttp://prdownloads.sourceforge.net/sourceforge/
nagios/nrpe-2.13.tar.gz
tar -zxvfnrpe-2.13.tar.gz
cd nrpe-2.13
./configure
checking for initgroups...yes
checking forclosesocket... no
checking forsocklen_t... yes
checking for type ofsocket size... size_t
checking for SSLheaders... SSL headers found in /usr/local/ssl
checking for SSLlibraries... configure: error: Cannot find ssl libraries
安装缺失的库
yum -y installopenssl-devel
然后重新执行./configure就ok啦
checking forstrtoul... yes
checking forinitgroups... yes
checking forclosesocket... no
checking forsocklen_t... yes
checking for type ofsocket size... size_t
checking for SSLheaders... SSL headers found in /usr/local/ssl
checking for SSLlibraries... SSL libraries found in /usr/lib64
*** Generating DHParameters for SSL/TLS ***
Generating DHparameters, 512 bit long safe prime, generator 2
This is going to takea long time
........................+......................+.+......................+........................................+....................+.......+.....+............+........................................................................++*++*++*++*++*++*
checking for Kerberosinclude files... could not find include files
checking for perl.../usr/bin/perl
configure: creating./config.status
config.status:creating Makefile
config.status:creating src/Makefile
config.status:creating subst
config.status:creating include/config.h
*** Configurationsummary for nrpe 2.13 11-11-2011 ***:
General Options:
-------------------------
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios
Review the optionsabove for accuracy.If they look okay,
type 'make all' tocompile the NRPE daemon and client.
make all
cp src/check_nrpe/usr/local/nagios/libexec/
至此服务端搭建成功
客户端配置
tar -zxvfnagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
/configure--with-nagios-user=nagios --with-nagios-group=nagios
make
报错
/usr/bin/install:invalid user `nagios'
make: *** Error 1
make: Leavingdirectory `/opt/nagios/nagios-plugins-1.5/plugins'
make: *** Error 2
make: Leavingdirectory `/opt/nagios/nagios-plugins-1.5/plugins'
make: *** Error 1
解决办法如下
useradd nagios
mkdir /usr/local/nagios 如果目录存在就不需要创建了
chown nagios:nagios/usr/local/nagios
ll /usr/local
make
make install
安装NRPE
tar -zxvfnrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
cp src/check_nrpe /usr/local/nagios/libexec/
vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,server IP
vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote PluginExecutor)
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server =/usr/local/nagios/bin/nrpe
server_args = -c/usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure+= USERID
disable = no
only_from = 127.0.0.1 192.168.2.211
vim /etc/services
nrpe 5666/tcp #nrpe
service xinetd star
# service xinetd start
xinetd: unrecognizedservice
报错处理
yum -y install xinetd
安装成功之后执行
service xinetd star
#service xinetd start
Starting xinetd:
测试NRPE是否正常工作
/usr/local/nagios/libexec/check_nrpe-H 127.0.0.1
root@tomcat1nrpe-2.13]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.13
cd /usr/local/nagios/
ls
cd etc/
ll
mkdir objects
为服务端增加NRPE命令
vi commands.cfg
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$-c $ARG1$
}
页:
[1]