1.完成nagios4.4的编译安装,能成功访问浏览器中安装后的web界面;
2.编译安装nagios-plugins,提供nagios所需插件,查看本地监控是否正常;
3.安装nrpe,在客户端上部署;并能连接主机;(NRPE依赖于nagios-plugins,所以要一起安装。)
IP | 备注 |
---|---|
192.168.174.128 | 关闭防火墙、服务器、同步时间 |
192.168.174.129 | 关闭防火墙、客户端、同步时间 |
下载
# yum install -y wget net-tools
#cd /usr/local/src
#wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.3.tar.gz
#wget --no-check-certificate -O nrpe.tar.gz https://github.com/NagiosEnterprises/nrpe/archive/nrpe-3.2.1.tar.gz
#wget --no-check-certificate -O nagios-plugins.tar.gzhttps://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
安装nagios-server服务端
安装依赖包
# yum install -y epel-release //安装扩展yum源
# yum -y install httpd httpd-devel gcc glibc glibc-common gd gd-devel perl-devel perl-CPAN fcgi perl-FCGI perl-FCGI-ProcManager openssl-devel
# yum install -y libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel curl-devel unzip //php依赖包
同步时间
# yum install -y ntpdate //安装同步时间工具
# ntpdate time.windows.com //linux同步与windows时间
解压nagios源码包
# tar zxvf nagios-4.3.1.tar.gz
进入解压后的目录
# cd nagios-4.3.1/ //创建ngaios用户和组(把nginx启动用户www加入到nagios相关组)
# useradd nagios -s /sbin/nologin
# useradd www
# id www
# groupadd nagcmd
# usermod -a -G nagcmd nagios
# usermod -a -G nagcmd www
# id -n -G nagios
# id -n -G www
配置nagios
# ./configure --prefix=/usr/local/nagios --with-command-group=nagcmd
编译和安装
# make all
# make install-init //安装生成/etc/rc.d/init.d/nagios 启动脚本
# make install-commandmode //设定相应nagios工作目录的权限
# make install-config //安装生成/usr/local/nagios/etc下的nagios相关配置文件
# make install //安装生成/usr/local/nagios/,其中/usr/local/nagios/share即nagiosWEB访问界面的站点目录
# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
生成apache配置文件
# make install-webconf //安装Nagios的WEB配置文件到Apache的conf.d目录下
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
if [ 0 -eq 1 ]; then \
ln -s /etc/httpd/conf.d/nagios.conf /etc/apache2/sites-enabled/nagios.conf; \
fi
*** Nagios/Apache conf file installed ***
生成nagios web界面的验证信息
[root@nagios nagios-4.3.1]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios
New password: ==> 输入密码,这里我输入的密码是000000,记住这个密码
Re-type new password: ==> 确认密码
Adding password for user nagios
修改apache配置文件
# vi /etc/httpd/conf/httpd.conf
Listen 80 ===> 修改为 Listen 8080
User apache ===> 修改为 User www
Group apache ===> 修改为 Group www
DirectoryIndex index.html ===> 修改为 DirectoryIndex index.php index.html
AddType application/x-gzip .gz .tgz ===> 下面添加一行内容 AddHandler application/x-httpd-php .php
# LoadModule foo_module modules/mod_foo.so ===> 下面添加一行内容
LoadModule php7_module modules/libphp7.so
编译一下php,自行下载
# cd /software/php-7.1.4/
# ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo -enable-tokenizer --enable-zip --with-apxs2
# make && make install
# cd /etc/httpd/
# ll /etc/httpd/modules/libphp7.so
-rwxr-xr-x 1 root root 38908880 4月 24 10:34 /etc/httpd/modules/libphp7.so ===> 可以看到这个模块已经生成
修改管理员(否则不是管理员无法使用一些操作,比如监控)
可以直接关闭身份验证
#vi /usr/local/nagios/etc/cgi.cfg
use_authentication=1 ==> use_authentication=0 1改为0
或
编辑/usr/local/nagios/etc/cgi.cfg文件,修改以下几个选项的值为自己创建的管理的用户,其实也可以直接在后面加上我们创建的用户名,用逗号隔开即可,如下所示:(修改前可先复制一个备份文件,免得改错)
# cp /usr/local/nagios/etc/cgi.cfg /usr/local/nagios/etc/cgi.cfg.bak
# vi /usr/local/nagios/etc/cgi.cfg
authorized_for_system_information=nagiosadmin,nagios
authorized_for_configuration_information=nagiosadmin,nagios
authorized_for_system_commands=nagiosadmin,nagios
authorized_for_all_services=nagiosadmin,nagios
authorized_for_all_hosts=nagiosadmin,nagios
authorized_for_all_service_commands=nagiosadmin,nagios
authorized_for_all_host_commands=nagiosadmin,nagios
直接用vi的修改方法: %s/nagiosadmin/nagiosadmin,nagios/g
启动apache
# systemctl start httpd
# systemctl enable httpd
启动nagios
# chkconfig nagios on
# systemctl start nagios
在浏览器输入ip:8080/nagios测试nagios-web页面是否可以打开
在弹出的框中输入上面htpasswd创建的用户密码
安装nagios-plugins插件
解压nagios-plugins源码包
# cd ../
# tar zxvf nagios-plugins-2.2.1.tar.gz
进入解压后的目录进行配置
# cd nagios-plugins-2.2.1/
# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagcmd --enable-perl-modules
编译及安装
# make && make install
安装nrpe
解压nrpe源码包
# cd ../
# tar zxvf nrpe-3.1.0.tar.gz
进去解压后的目录进行配置
# cd nrpe-3.1.0/
# ./configure
编译及安装
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# cp sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg
安装完成后,查看下libexec下面是否有插件
# ls /usr/local/nagios/libexec/
check_apt check_flexlm check_log check_ntp_peer check_smtp disable_active_service_checks
check_breeze check_fping check_mailq check_ntp_time check_spop disable_notifications
check_by_ssh check_ftp check_mrtg check_nwstat check_ssh distributed-monitoring
check_clamd check_http check_mrtgtraf check_oracle check_ssmtp enable_active_service_checks
check_cluster check_icmp check_mysql check_overcr check_swap enable_notifications
check_dhcp check_ide_smart check_mysql_query check_ping check_tcp eventhandlers
check_dig check_ifoperstatus check_nagios check_pop check_time negate
check_disk check_ifstatus check_nntp check_procs check_udp redundancy-scenario1
check_disk_smb check_imap check_nntps check_real check_ups submit_check_result
check_dns check_ircd check_nrpe check_rpc check_uptime urlize
check_dummy check_jabber check_nt check_sensors check_users utils.pm
check_file_age check_load check_ntp check_simap check_wave utils.sh
启动nrpe,并测试服务端本地是否可以连通
# /usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg
# echo "/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg" >> /etc/rc.local
# chmod +x /etc/rc.d/rc.local //centos 7下需要这一步, 不然/etc/rc.local中的内容开机可能不执行
# netstat -lnput|grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 67176/nrpe
tcp6 0 0 :::5666 :::* LISTEN 67176/nrpe
查看服务端本地是否可以连通
nagios客户端的安装
下载nagios-plugin和nrpe插件
# mkdir /software/
# cd /usr/local/src
# wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
# wget https://sourceforge.net/projects/nagios/files/nrpe-3.x/nrpe-3.1.0.tar.gz
安装nagios-plugin
安装依赖包
# yum install -y epel-release //安装扩展yum源
# yum install perl-devel perl-CPAN openssl-devel gcc gd gd-devel *openssl* -y
同步时间
# yum install -y ntpdate //安装同步时间工具
# ntpdate time.windows.com //linux同步与windows时间
创建用户
# useradd nagios -M -s /sbin/nologin
解压nagios-plugin源码包
# tar zxvf nagios-plugins-2.2.1.tar.gz
进入解压后的目录进行配置
# cd nagios-plugins-2.2.1/
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
编译及安装
# make && make install
安装nrpe插件
解压nrpe源码包
# cd ..
# tar zxvf nrpe-3.1.0.tar.gz
进入解压后的目录进行配置
# cd nrpe-3.1.0/
# ./configure
编译及安装
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# mkdir /usr/local/nagios/etc/
# cp sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg
安装完成后,查看下libexec下面是否有插件
# ls /usr/local/nagios/libexec/
check_apt check_dummy check_imap check_nagios check_overcr check_ssh negate
check_breeze check_file_age check_ircd check_nntp check_ping check_ssmtp urlize
check_by_ssh check_flexlm check_jabber check_nntps check_pop check_swap utils.pm
check_clamd check_fping check_load check_nrpe check_procs check_tcp utils.sh
check_cluster check_ftp check_log check_nt check_real check_time
check_dhcp check_http check_mailq check_ntp check_rpc check_udp
check_dig check_icmp check_mrtg check_ntp_peer check_sensors check_ups
check_disk check_ide_smart check_mrtgtraf check_ntp_time check_simap check_uptime
check_disk_smb check_ifoperstatus check_mysql check_nwstat check_smtp check_users
check_dns check_ifstatus check_mysql_query check_oracle check_spop check_wave
启动nrpe,并测试本地是否可以连通
# /usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg
# echo "/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg" >> /etc/rc.local
# chmod +x /etc/rc.d/rc.local // centos 7下需要这一步, 不然/etc/rc.local中的内容开机可能不执行
# netstat -lnput|grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 28296/nrpe
tcp6 0 0 :::5666 :::* LISTEN 28296/nrpe
# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v3.1.0-rc1
修改配置文件
# cd /usr/local/nagios/etc/
# vi nrpe.cfg
允许服务端IP和本机访问,192.168.174.128是nagios服务端IP地址
allowed_hosts=127.0.0.1,::1 ===> 修改为 allowed_hosts=127.0.0.1,::1,192.168.174.128
重启nrpe服务
# 方法一
# pkill nrpe
# /usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg
# 方法二
# kill -HUP `ps -ef|grep nrpe|awk 'NR==1{print $2}'`
在服务端测试是否可以连通客户端
# /usr/local/nagios/libexec/check_nrpe -H 192.168.174.129
NRPE v3.1.0-rc1