Nagios 是一个开源的服务器监测工具, 可以当发现问题时自动通知系统管理员。以下是 RHEL 及 CentOS 7 安装设定 Nagios 的方法。
首先要安装所需套件, 例如 HTTPD 及 PHP 等:
# yum install httpd php php-cli gd gd-devel gcc glibc glibc-common net-snmp wget
建立 Nagios 的帐号及群组, 并设定 Nagios 的群组接受经由网页接口传入的指令:
# useradd nagios
# passwd nagios
# groupadd nagcmd
# usermod -a -G nagcmd nagios
# usermod -a -G nagcmd apache
# passwd nagios
# groupadd nagcmd
# usermod -a -G nagcmd nagios
# usermod -a -G nagcmd apache
现在可以安装 Nagios, 先到官方网站下载 Nagios 的最新版本:
# cd /usr/local/src
# wget http://liquidtelecom.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.8/nagios-4.0.8.tar.gz
# tar xzf nagios-4.0.8.tar.gz
# cd nagios-4.0.8
# ./configure –with-command-group=nagcmd
# make all
# make install
# make install-init
# make install-config
# make install-commandmode
# make install-webconf
# wget http://liquidtelecom.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.8/nagios-4.0.8.tar.gz
# tar xzf nagios-4.0.8.tar.gz
# cd nagios-4.0.8
# ./configure –with-command-group=nagcmd
# make all
# make install
# make install-init
# make install-config
# make install-commandmode
# make install-webconf
安装好 Nagios 后, 从官方网站下载相关 plugins:
# cd /usr/local/src
# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
# tar xzf nagios-plugins-2.0.3.tar.gz
# cd nagios-plugins-2.0.3
# ./configure –with-nagios-user=nagios –with-nagios-group=nagios
# make
# make install
# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
# tar xzf nagios-plugins-2.0.3.tar.gz
# cd nagios-plugins-2.0.3
# ./configure –with-nagios-user=nagios –with-nagios-group=nagios
# make
# make install
安装好 Nagios 及它的 plugins 后, 设定 Nagios 管理接口的 Apache 密码保护, 以及设定 Apache 开机自动启动:
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# systemctl start httpd
# systemctl enable httpd
# systemctl start httpd
# systemctl enable httpd
现在启动 Nagios 及设定开机自动执行:
# systemctl start nagios
# chkconfig –add nagios
# chkconfig nagios on
# chkconfig –add nagios
# chkconfig nagios on
现在已经安装完成 Nagios, 假设服务器的 ip 是 192.168.1.100, 可以用浏览器透过以下网址登入 Nagios 的管理接口:
http://192.168.1.100/nagios
使用名称称是 “nagiosadmin”, 而密码是在上面用 htpasswd 设定的密码。
(1.) ./configure –with-nagios-user=nagios –with-nagios-group=nagios : plugins 最后 group 是不是 nagcmd
(2.) chkconfig –add nagios : 好像少一个 “-“
由于网页 theme 的问题,会将两个 “-” 显示成一个。