Centos7下安装部署nagios-server

目录

1. nagios简介

2. 服务器准备

2.1 主机信息+IP地址

#一台虚拟机
hostname:nagios-server
ip:ip_address

2.2 查看主机的系统版本信息

[root@nagios-server tools]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

2.3 暂时关掉Selinux和防火墙

[root@nagios-server tools]# sed -i "s#enforcing#disabled#g" /etc/sysconfig/selinux 
[root@nagios-server tools]# cat /etc/sysconfig/selinux 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     disabled - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of disabled.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
[root@nagios-server tools]# setenforce 0  &&    getenforce
Permissive
---------------------------------------------------------------------------------------------------------------------------------------
[root@nagios-server tools]# firewall-cmd --state
running
[root@nagios-server tools]# systemctl stop firewalld.service
[root@nagios-server tools]# firewall-cmd --state               
not running

3. 安装nagios依赖包和需要的环境

3.1 安装nagios依赖包

[root@nagios-server tools]#  yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel 

3.2 安装nagios-server需要的环境 (LAMP: httpd服务+数据库服务+php)

说明:

  1. Apache 和PHP虽然不是安装nagios 所必须的,但nagios是借助apache提供的web监控界面,通过web监控界面可以清晰的看到被监控主机、资源的运行状态,因此,安装一个web服务是很必要的。
  2. 另外需要注意的是:nagios在nagios3.1.x版本以后,配置web监控界面时都需要php的支持。
  3. 关于LAMP环境部署搭建可以直接参考之前的博文: Centos7.2下LAMP环境快速搭建

4. 下载nagios相关安装包

4.1 nagios服务端主程序

[root@nagios-server ~]# cd /home/tools/
[root@nagios-server tools]# wget https://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.3.2/nagios-4.3.2.tar.gz
[root@nagios-server tools]# ll
-rw-r--r--.  1 root root  11096863 4月  22 2019 nagios-4.3.2.tar.gz

4.2 nagios服务端插件

[root@nagios-server tools]# cd /home/tools/
[root@nagios-server tools]# wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
[root@nagios-server tools]# ll
-rw-r--r--. 1 root root 11096863 4月  22 2019 nagios-4.3.2.tar.gz
-rw-r--r--.  1 root root   2782610 3月  12 00:58 nagios-plugins-2.3.3.tar.gz

4.3 nagios客户端代理检测程序

[root@nagios-server tools]# cd /home/tools/
[root@nagios-server tools]# wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.0/nrpe-3.2.0.tar.gz
[root@nagios-server tools]# ll
-rw-r--r--.  1 root root 11096863 4月  22 2019 nagios-4.3.2.tar.gz
-rw-r--r--.  1 root root  2782610 3月  12 00:58 nagios-plugins-2.3.3.tar.gz
-rw-r--r--.  1 root root   517743 6月  28 2017 nrpe-3.2.0.tar.g

5. nagios服务端程序安装部署

5.1 安装部署nagios服务端主程序

5.1.1 解压安装包
[root@nagios-server tools]# tar xf nagios-4.3.2.tar.gz
[root@nagios-server tools]# ll
总用量 13564
drwxrwxr-x. 18 root root     4096 5月  10 2017 nagios-4.3.2
-rw-r--r--.  1 root root 11096863 4月  22 2019 nagios-4.3.2.tar.gz
-rw-r--r--.  1 root root  2782610 3月  12 00:58 nagios-plugins-2.3.3.tar.gz
-rw-r--r--.  1 root root   517743 6月  28 2017 nrpe-3.2.0.tar.g
5.1.2 配置编译
[root@nagios-server tools]# cd nagios-4.3.2
[root@nagios-server nagios-4.3.2]# ll
总用量 528
drwxrwxr-x.  2 root root   4096 5月  10 2017 base
drwxrwxr-x.  2 root root   4096 5月  10 2017 cgi
-rw-rw-r--.  1 root root  23089 5月  10 2017 Changelog
drwxrwxr-x.  2 root root   4096 5月  10 2017 common
-rwxrwxr-x.  1 root root  43765 5月  10 2017 config.guess
-rwxrwxr-x.  1 root root  36345 5月  10 2017 config.sub
-rwxrwxr-x.  1 root root 208041 5月  10 2017 configure  #编译安装脚本
-rw-rw-r--.  1 root root  26252 5月  10 2017 configure.ac
drwxrwxr-x.  4 root root   4096 5月  10 2017 contrib
-rw-rw-r--.  1 root root   8438 5月  10 2017 daemon-init.in
drwxrwxr-x.  2 root root   4096 5月  10 2017 docs
-rw-rw-r--.  1 root root    886 5月  10 2017 doxy.conf
-rwxrwxr-x.  1 root root   7025 5月  10 2017 functions
drwxrwxr-x. 11 root root   4096 5月  10 2017 html
drwxrwxr-x.  2 root root   4096 5月  10 2017 include
-rwxrwxr-x.  1 root root     77 5月  10 2017 indent-all.sh
-rwxrwxr-x.  1 root root    161 5月  10 2017 indent.sh
-rw-rw-r--.  1 root root    422 5月  10 2017 INSTALLING
-rwxrwxr-x.  1 root root   5869 5月  10 2017 install-sh
-rw-rw-r--.  1 root root    841 5月  10 2017 LEGAL
drwxrwxr-x.  2 root root   4096 5月  10 2017 lib
-rw-rw-r--.  1 root root  18002 5月  10 2017 LICENSE
-rw-rw-r--.  1 root root  14449 5月  10 2017 Makefile.in
-rwxrwxr-x.  1 root root    461 5月  10 2017 make-tarball
-rwxrwxr-x.  1 root root    818 5月  10 2017 mkpackage
drwxrwxr-x.  2 root root     60 5月  10 2017 module
-rw-rw-r--.  1 root root   9064 5月  10 2017 nagios.spec
-rw-rw-r--.  1 root root    244 5月  10 2017 nagios.sysconfig
-rw-rw-r--.  1 root root    210 5月  10 2017 pkginfo.in
-rw-rw-r--.  1 root root     15 5月  10 2017 README
-rw-rw-r--.  1 root root   3157 5月  10 2017 README.asciidoc
drwxrwxr-x.  3 root root   4096 5月  10 2017 sample-config
-rwxrwxr-x.  1 root root   1284 5月  10 2017 subst.in
drwxrwxr-x.  5 root root   4096 5月  10 2017 t
drwxrwxr-x.  4 root root   4096 5月  10 2017 tap
drwxrwxr-x.  2 root root     29 5月  10 2017 test
-rw-rw-r--.  1 root root   5543 5月  10 2017 THANKS
drwxrwxr-x.  4 root root   4096 5月  10 2017 t-tap
-rwxrwxr-x.  1 root root   2624 5月  10 2017 update-version
-rw-rw-r--.  1 root root    643 5月  10 2017 UPGRADING
drwxrwxr-x.  3 root root     35 5月  10 2017 worker
drwxrwxr-x.  2 root root   4096 5月  10 2017 xdata

指定安装路径

[root@nagios-server nagios-4.3.2]# ./configure --prefix=/usr/local/nagios && echo $?
5.1.3 编译安装

make all 编译所有

[root@nagios-server nagios-4.3.2]# make all && echo $?

make install 编译安装

[root@nagios-server nagios-4.3.2]# make install &&  echo $?

make install-init 把nagios做成一个运行脚本,使nagios开机启动

[root@nagios-server nagios-4.3.2]# make install-init  &&  echo $?    

make install-commandmode 把配置文件样例复制到nagios的安装目录

[root@nagios-server nagios-4.3.2]# make install-commandmode && echo $?

make install-config 给外部命令访问nagios配置文件的权限

[root@nagios-server nagios-4.3.2]# make install-config && echo $?
5.1.4 设置nagios开机自启动

chkconfig --add nagios 将nagios添加到系统服务

[root@nagios-server nagios-4.3.2]# chkconfig --add nagios && echo $?

chkconfig --level 35 nagios on 设置3 5 运行模式下开启nagios

[root@nagios-server nagios-4.3.2]# chkconfig --level 35 nagios on && echo $?
[root@nagios-server nagios-4.3.2]# chkconfig --list nagios
注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 
      如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
      欲查看对特定 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

nagios          0:关    1:关    2:开    3:开    4:开    5:开    6:关
5.1.5 验证nagios主程序是否被正确安装

切换目录到安装路径(这里是/usr/local/nagios),看是否存在etc、bin、sbin、share、var 这五个目录,如果存在则可以表明程序被正确的安装到系统了。

[root@nagios-server nagios-4.3.2]# cd /usr/local/nagios/
[root@nagios-server nagios]# ll
总用量 8
drwxrwxr-x.  2 nagios nagios   36 5月   8 14:40 bin 
drwxrwxr-x.  3 nagios nagios   70 5月   8 14:41 etc
drwxrwxr-x.  2 nagios nagios    6 5月   8 14:40 libexec
drwxrwxr-x.  2 nagios nagios 4096 5月   8 14:40 sbin
drwxrwxr-x. 14 nagios nagios 4096 5月   8 14:40 share
drwxrwxr-x.  5 nagios nagios   42 5月   8 14:40 var
目录 说明
bin 可执行程序所在目录
etc 配置文件所在目录
libexec 外部插件所在目录
sbin CGI文件所在目录,也就是执行外部命令所需文件所在的目录
share 网页文件所在的目录
var 日志文件、lock 等文件所在的目录
var/archives 日志自动归档目录
var/rw 用来存放外部命令文件的目录

5.2 安装部署nagios服务端插件

5.2.1 解压安装包
[xzds@DSCQ-Nagios nagios]$ cd /home/tools/
[root@nagios-server tools]# tar xf nagios-plugins-2.3.3.tar.gz
[root@nagios-server tools]# ll
总用量 14076
drwxrwxr-x. 18 root root     4096 5月   8 14:39 nagios-4.3.2
-rw-r--r--.  1 root root 11096863 4月  22 2019 nagios-4.3.2.tar.gz
drwxr-xr-x. 15 root root     4096 3月  12 00:58 nagios-plugins-2.3.3
-rw-r--r--.  1 root root  2782610 3月  12 00:58 nagios-plugins-2.3.3.tar.gz
-rw-r--r--.  1 root root   517743 6月  28 2017 nrpe-3.2.0.tar.gz
5.2.2 配置编译
[root@nagios-server tools]# cd nagios-plugins-2.3.3
[root@nagios-server nagios-plugins-2.3.3]# ll
总用量 3452
-rw-r--r--. 1 root root   80541 1月  17 2017 ABOUT-NLS
-rw-r--r--. 1 root root    2332 1月  17 2017 acinclude.m4
-rw-r--r--. 1 root root    1275 1月  17 2017 ACKNOWLEDGEMENTS
-rw-r--r--. 1 root root   42202 3月  12 00:57 aclocal.m4
-rw-r--r--. 1 root root     417 12月  5 05:53 AUTHORS
drwxr-xr-x. 3 root root    4096 3月  12 00:58 build-aux
-rw-r--r--. 1 root root  890609 3月  12 00:58 ChangeLog
-rw-r--r--. 1 root root    4918 12月  5 05:53 CODING
-rw-r--r--. 1 root root   78119 3月  12 00:58 config.h.in
-rwxr-xr-x. 1 root root   18163 1月  17 2017 config.rpath
drwxr-xr-x. 2 root root      56 3月  12 00:58 config_test
-rwxr-xr-x. 1 root root 2022791 3月  12 00:58 configure  #编译安装脚本
-rw-r--r--. 1 root root   69121 3月  12 00:57 configure.ac
-rw-r--r--. 1 root root   35147 1月  17 2017 COPYING
-rw-r--r--. 1 root root    3716 1月  17 2017 FAQ
drwxr-xr-x. 4 root root    8192 3月  12 00:58 gl
-rw-r--r--. 1 root root   15578 3月  12 00:58 INSTALL
-rw-r--r--. 1 root root     443 1月  17 2017 LEGAL
drwxr-xr-x. 3 root root    4096 3月  12 00:58 lib
drwxr-xr-x. 2 root root      54 3月  12 00:58 m4
-rw-r--r--. 1 root root    2144 12月  5 05:53 Makefile.am
-rw-r--r--. 1 root root   67135 3月  12 00:58 Makefile.in
-rwxr-xr-x. 1 root root    3474 1月  17 2017 mkinstalldirs
-rw-r--r--. 1 root root    6471 3月  12 00:58 nagios-plugins.spec
-rw-r--r--. 1 root root    6491 12月  5 05:53 nagios-plugins.spec.in
-rw-r--r--. 1 root root   46403 3月  12 00:57 NEWS
-rw-r--r--. 1 root root   17504 12月  5 05:53 NPTest.pm
-rwxr-xr-x. 1 root root    1161 3月  12 00:57 NP-VERSION-GEN
drwxr-xr-x. 2 root root    4096 3月  12 00:58 perlmods
drwxr-xr-x. 5 root root      46 1月  17 2017 pkg
drwxr-xr-x. 4 root root    4096 3月  12 00:58 plugins
drwxr-xr-x. 3 root root     101 3月  12 00:58 plugins-root
drwxr-xr-x. 3 root root    4096 3月  12 00:58 plugins-scripts
drwxr-xr-x. 2 root root    4096 3月  12 00:58 po
-rw-r--r--. 1 root root    5440 12月  5 05:53 README
-rw-r--r--. 1 root root       6 3月  12 00:58 release
-rw-r--r--. 1 root root    3304 1月  17 2017 REQUIREMENTS
-rw-r--r--. 1 root root    3871 1月  17 2017 SUPPORT
drwxr-xr-x. 2 root root      79 3月  12 00:58 tap
-rwxr-xr-x. 1 root root     831 1月  17 2017 test.pl.in
-rw-r--r--. 1 root root    6265 12月  5 05:54 THANKS
drwxr-xr-x. 2 root root      81 3月  12 00:58 tools

指定安装路径

[root@nagios-server nagios-plugins-2.3.3]# ./configure --prefix=/usr/local/nagios && echo $?
5.2.3 编译安装
[root@nagios-server nagios-plugins-2.3.3]#  make &&  make install  && echo $?
5.2.4 验证nagios插件程序是否被正确安装

切换目录到安装路径(这里是/usr/local/nagios/libexec) ,下看是否存在很多 check文件,若有则安装插件成功,若无就需要重新安装。

[root@nagios-server nagios-plugins-2.3.3]# ll /usr/local/nagios/
总用量 12
drwxrwxr-x.  2 nagios nagios   36 5月   8 14:40 bin
drwxrwxr-x.  3 nagios nagios   70 5月   8 14:41 etc
drwxr-xr-x.  2 root   root      6 5月   8 14:55 include
drwxrwxr-x.  2 nagios nagios 4096 5月   8 14:55 libexec 
drwxrwxr-x.  2 nagios nagios 4096 5月   8 14:40 sbin
drwxrwxr-x. 15 nagios nagios 4096 5月   8 14:55 share
drwxrwxr-x.  5 nagios nagios   42 5月   8 14:40 var
[root@dscq-236 nagios]# cd /usr/local/nagios/libexec/
[root@dscq-236 nagios]# cd /usr/local/nagios/libexec/
[root@dscq-236 libexec]# ll
总用量 6296
-rwxr-xr-x. 1 nagios nagios 177408 5月   9 08:52 check_apt
-rwxr-xr-x. 1 nagios nagios   2346 5月   9 08:52 check_breeze
-rwxr-xr-x. 1 nagios nagios 181664 5月   9 08:52 check_by_ssh
lrwxrwxrwx. 1 nagios nagios      9 5月   9 08:52 check_clamd -> check_tcp
-rwxr-xr-x. 1 nagios nagios 124896 5月   9 08:52 check_cluster
-r-xr-xr-x. 1 nagios nagios 178888 5月   9 08:52 check_dhcp
-rwxr-xr-x. 1 nagios nagios 310224 5月   9 08:52 check_disk
-rwxr-xr-x. 1 nagios nagios  10134 5月   9 08:52 check_disk_smb
-rwxr-xr-x. 1 nagios nagios  88512 5月   9 08:52 check_dummy
-rwxr-xr-x. 1 nagios nagios   5066 5月   9 08:52 check_file_age
-rwxr-xr-x. 1 nagios nagios   6504 5月   9 08:52 check_flexlm
lrwxrwxrwx. 1 nagios nagios      9 5月   9 08:52 check_ftp -> check_tcp
-rwxr-xr-x. 1 nagios nagios 353240 5月   9 08:52 check_http
-r-xr-xr-x. 1 nagios nagios 209672 5月   9 08:52 check_icmp
-rwxr-xr-x. 1 nagios nagios 135840 5月   9 08:52 check_ide_smart
-rwxr-xr-x. 1 nagios nagios  15275 5月   9 08:52 check_ifoperstatus
-rwxr-xr-x. 1 nagios nagios  13422 5月   9 08:52 check_ifstatus
lrwxrwxrwx. 1 nagios nagios      9 5月   9 08:52 check_imap -> check_tcp
-rwxr-xr-x. 1 nagios nagios   6985 5月   9 08:52 check_ircd
lrwxrwxrwx. 1 nagios nagios      9 5月   9 08:52 check_jabber -> check_tcp
-rwxr-xr-x. 1 nagios nagios 227840 5月   9 08:52 check_ldap
lrwxrwxrwx. 1 nagios nagios     10 5月   9 08:52 check_ldaps -> check_ldap
-rwxr-xr-x. 1 nagios nagios 169560 5月   9 08:52 check_load
-rwxr-xr-x. 1 nagios nagios   7068 5月   9 08:52 check_log
-rwxr-xr-x. 1 nagios nagios  25575 5月   9 08:52 check_mailq
-rwxr-xr-x. 1 nagios nagios 135056 5月   9 08:52 check_mrtg
-rwxr-xr-x. 1 nagios nagios 137600 5月   9 08:52 check_mrtgtraf
-rwxr-xr-x. 1 nagios nagios 173624 5月   9 08:52 check_mysql
-rwxr-xr-x. 1 nagios nagios 160536 5月   9 08:52 check_mysql_query
-rwxr-xr-x. 1 nagios nagios 148704 5月   9 08:52 check_nagios
lrwxrwxrwx. 1 nagios nagios      9 5月   9 08:52 check_nntp -> check_tcp
lrwxrwxrwx. 1 nagios nagios      9 5月   9 08:52 check_nntps -> check_tcp
-rwxr-xr-x. 1 nagios nagios 182768 5月   9 08:52 check_nt
-rwxr-xr-x. 1 nagios nagios 186024 5月   9 08:52 check_ntp
-rwxr-xr-x. 1 nagios nagios 175272 5月   9 08:52 check_ntp_peer
-rwxr-xr-x. 1 nagios nagios 171088 5月   9 08:52 check_ntp_time
-rwxr-xr-x. 1 nagios nagios 213088 5月   9 08:52 check_nwstat
-rwxr-xr-x. 1 nagios nagios   9468 5月   9 08:52 check_oracle
-rwxr-xr-x. 1 nagios nagios 155976 5月   9 08:52 check_overcr
-rwxr-xr-x. 1 nagios nagios 186920 5月   9 08:52 check_ping
lrwxrwxrwx. 1 nagios nagios      9 5月   9 08:52 check_pop -> check_tcp
-rwxr-xr-x. 1 nagios nagios 193456 5月   9 08:52 check_procs
-rwxr-xr-x. 1 nagios nagios 152648 5月   9 08:52 check_real
-rwxr-xr-x. 1 nagios nagios   9679 5月   9 08:52 check_rpc
-rwxr-xr-x. 1 nagios nagios   1630 5月   9 08:52 check_sensors
lrwxrwxrwx. 1 nagios nagios      9 5月   9 08:52 check_simap -> check_tcp
-rwxr-xr-x. 1 nagios nagios 239544 5月   9 08:52 check_smtp
lrwxrwxrwx. 1 nagios nagios      9 5月   9 08:52 check_spop -> check_tcp
-rwxr-xr-x. 1 nagios nagios 152312 5月   9 08:52 check_ssh
-rwxr-xr-x. 1 nagios nagios  12544 5月   9 08:52 check_ssl_validity
lrwxrwxrwx. 1 nagios nagios      9 5月   9 08:52 check_ssmtp -> check_tcp
-rwxr-xr-x. 1 nagios nagios 134056 5月   9 08:52 check_swap
-rwxr-xr-x. 1 nagios nagios 221984 5月   9 08:52 check_tcp
-rwxr-xr-x. 1 nagios nagios 153944 5月   9 08:52 check_time
lrwxrwxrwx. 1 nagios nagios      9 5月   9 08:52 check_udp -> check_tcp
-rwxr-xr-x. 1 nagios nagios 167496 5月   9 08:52 check_ups
-rwxr-xr-x. 1 nagios nagios 125048 5月   9 08:52 check_uptime
-rwxr-xr-x. 1 nagios nagios 123616 5月   9 08:52 check_users
-rwxr-xr-x. 1 nagios nagios   3270 5月   9 08:52 check_wave
-rwxr-xr-x. 1 nagios nagios 119160 5月   9 08:52 negate
-rwxr-xr-x. 1 nagios nagios 117896 5月   9 08:52 remove_perfdata
-rwxr-xr-x. 1 nagios nagios 112776 5月   9 08:52 urlize
-rwxr-xr-x. 1 nagios nagios   1914 5月   9 08:52 utils.pm
-rwxr-xr-x. 1 nagios nagios   2791 5月   9 08:52 utils.sh

6. nagios web访问配置

6.1 创建nagios用户和用户组

[root@nagios-server tools]# useradd -s /sbin/nologin nagios
[root@nagios-server tools]# id nagios
uid=1004(nagios) gid=1004(nagios) 组=1004(nagios)
[root@nagios-server tools]# mkdir /usr/local/nagios
[root@nagios-server tools]# chown -R nagios.nagios /usr/local/nagios
[root@nagios-server tools]# ll -d /usr/local/nagios/
drwxr-xr-x. 2 nagios nagios 6 5月   8 14:36 /usr/local/nagios/

6.2 将apache用户加入到nagios用户组

说明:将apache用户加入到nagios用户组,便于在通过web操作nagios时能够具有足够的权限。

[root@nagios-server ~]# id apache
uid=48(apache) gid=48(apache) 组=48(apache)

[root@nagios-server ~]# id nagios
uid=1004(nagios) gid=1004(nagios) 组=1004(nagios)

[root@nagios-server ~]# usermod -G nagios apache
[root@nagios-server ~]# id apache
uid=48(apache) gid=48(apache) 组=48(apache),1004(nagios)

6.3 修改apache配置文件httpd.conf

6.3.1 根据需求修改apache监听端口
[root@nagios-server ~]# vi /usr/local/apache-2.4.43/conf/httpd.conf  +54

Listen 80
修改为:  
Listen 8081
6.3.2 配置apache启动时的管理用户
[root@nagios-server ~]# vi /usr/local/apache-2.4.43/conf/httpd.conf  +66

User daemon 
Group daemon 
修改为:
User apache
Group apache
6.3.3 配置首页还可以跳转php页面
[root@nagios-server ~]# vi /usr/local/apache-2.4.43/conf/httpd.conf  +257

<IfModule dir_module> 
  DirectoryIndex index.html 
</IfModule> 

修改为:

<IfModule dir_module> 
  DirectoryIndex index.php index.html
</IfModule> 
6.3.4 服务器IP/域名:端口(不是必须)
[root@nagios-server ~]# vi /usr/local/apache-2.4.43/conf/httpd.conf  +198
如下内容:
#ServerName www.example.com:80
ServerName  127.0.0.1:8081
6.3.5 开启apache动态加载模块
说明: 如果不添加以下几行内容,动态文件无法被apache解析,打开页面就是直接下载文件
[root@nagios-server ~]# vi /usr/local/apache-2.4.43/conf/httpd.conf  +147
#LoadModule cgid_module modules/mod_cgid.so 取消注释
6.3.6 开启apache和php关联的模块
[root@nagios-server ~]# vi /usr/local/apache-2.4.43/conf/httpd.conf  +157
如下内容:
LoadModule php5_module modules/libphp5.so
6.3.7 添加对php的解析支持内容
说明: 如果不添加以下几行内容,php的文件被apache无法解析,打开页面就是直接下载文件
[root@nagios-server ~]# vi /usr/local/apache-2.4.43/conf/httpd.conf  +396
如下内容: 
AddType application/x-httpd-php .php .phtml              
AddType application/x-httpd-php-source .phps
6.3.8 将nagios和apache配置的web接口关联起来

为了安全起见,一般情况下要让nagios 的web 监控页面必须经过授权才能访问,这需要增加验证配置,
即在httpd.conf 文件最后添加如下代码:

[root@nagios-server ~]# vi /usr/local/apache-2.4.43/conf/httpd.conf  +520
#setting for nagios 
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" 
<Directory "/usr/local/nagios/sbin"> 
     AuthType Basic 
     Options ExecCGI 
     AllowOverride None 
     Order allow,deny 
     Allow from all 
     AuthName "Nagios Access" 
     AuthUserFile /usr/local/nagios/etc/htpasswd
     Require valid-user 
</Directory> 
Alias /nagios "/usr/local/nagios/share" 
<Directory "/usr/local/nagios/share"> 
     AuthType Basic 
     Options None 
     AllowOverride None 
     Order allow,deny 
     Allow from all 
     AuthName "nagios Access" 
     AuthUserFile /usr/local/nagios/etc/htpasswd 
     Require valid-user 
</Directory>

6.4 给apache授权nagios的web访问页面的权限

[root@nagios-server ~]# find / -name htpasswd
/home/tools/httpd-2.4.43/support/htpasswd
/usr/local/nagios/etc/htpasswd
/usr/local/apache-2.4.43/bin/htpasswd
[root@nagios-server ~]# /usr/local/apache-2.4.43/bin/htpasswd -c /usr/local/nagios/etc/htpasswd   nagiosadmin 
New password: 
Re-type new password: 
Adding password for user nagiosadmin

6.5 配置 /usr/local/nagios/etc/cgi.cfg

此文件用来控制相关cgi脚本,如果想在nagios的web监控界面执行cgi脚本,例如重启nagios进程、关闭nagios通知、停止nagios主机检测等,这时就需要配置cgi.cfg文件了。
由于nagios的web监控界面默认验证用户为david,所以只需在cgi.cfg文件中添加刚刚创建的nagiosadmin用户的执行权限就可以了,需要修改或者加入以下配置信息:

[root@nagios-server ~]# vi /usr/local/nagios/etc/cgi.cfg +103
default_user_name=david
authorized_for_system_information=nagiosadmin,david  
authorized_for_configuration_information=nagiosadmin,david  
authorized_for_system_commands=david
authorized_for_all_services=nagiosadmin,david  
authorized_for_all_hosts=nagiosadmin,david
authorized_for_all_service_commands=nagiosadmin,david  
authorized_for_all_host_commands=nagiosadmin,david 

7. 重启apache

[root@nagios-server ~]#  /usr/local/apache-2.4.43/bin/apachectl  restart && echo $?
0

8. 启动与停止nagios

8.1 通过初始化脚本启动停止重启nagios

[root@dscq-236 objects]# chown -R nagios:nagios /usr/local/nagios/
[root@nagios-server objects]# systemctl start nagios.service &&  echo $?
0
[root@nagios-server objects]# systemctl stop nagios.service &&  echo $?
0
[root@nagios-server objects]# systemctl restart nagios.service &&  echo $?
0
[root@nagios-server objects]# systemctl status nagios.service &&  echo $?
0

8.2 手工方式启动nagios

[root@nagios-server objects]# systemctl stop nagios.service &&  echo $?
0
[root@nagios-server objects]#  /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg && echo $?
0

9. 重新开启防火墙,针对apache服务监听端口进行配置

[root@nagios-server objects]#  systemctl start firewalld.service
[root@nagios-server objects]# firewall-cmd --zone=public --permanent --add-port=8081/tcp && firewall-cmd --reload     &&    firewall-cmd --list-ports   
success
success
8081/tcp 1124/tcp

nagios监控页面访问地址:http://ip_address:8081/nagios
通过web浏览器访问nagios监控页面,通过此web监控界面可以清晰的看到被监控主机、资源的运行状态。
关于如何配置nagios监控项,请查看下一篇博文:Centos7下nagios-server监控项配置

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章