本文介绍在Ubuntu 18.04系统中安装Nagios 4.4.2的方法,按照以下步骤操作即可。
1.首先更新系统,安装依赖 $sudo apt update $sudo apt upgrade $sudo apt install build-essential libgd-dev openssl libssl-dev unzip apache2
2.创建新的用户和组 $sudo useradd nagios $sudo groupadd nagcmd $sudo usermod -a -G nagcmd nagios
3.下载Nagios 4.4.2 相关链接:Nagios网站地址。 $ sudo wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.2.tar.gz TTP request sent, awaiting response... 200 OK Length: 11301454 (11M) [application/x-gzip] Saving to: ‘nagios-4.4.2.tar.gz’ nagios-4.4.2.tar.gz 100%[===================>] 10.78M 961KB/s in 11s 2019-01-13 13:20:31 (981 KB/s) - ‘nagios-4.4.2.tar.gz’ saved [11301454/11301454]
4.解压安装文件 $sudo tar xzvf nagios-4.4.2.tar.gz nagios-4.4.2/ nagios-4.4.2/.gitignore ... nagios-4.4.2/xdata/xsddefault.h ...... 略过
5.进入目录,使用刚才建立的用户和组做好安装准备 axing@AX:/opt/nagios-4.4.2$cd nagios-4.4.2 axing@AX:/opt/nagios-4.4.2$ $sudo ./configure --with-nagios-group=nagios --with-command-group=nagcmd
6.开始编译和安装编译好的部件 $ sudo make -j4 all $ sudo make install $ sudo make install-commandmode $ sudo make install-init $ sudo make install-config
7.安装apache2的nagios模板到apache2配置目录,将apache用户加入nagcmd组 sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf sudo usermod -a -G nagcmd www-data
8.下载和安装nagios插件 sudo wget http://www.nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz sudo tar xzvf nagios-plugins-2.2.1.tar.gz cd nagios-plugins-2.2.1 sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd --with-openssl sudo $ make -j4 sudo $ sudo make install
9.配置认证,用户名nagiosadmin,密码自己设 sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
10.整合apache2和nagios,重启服务 #nagios的基本配置文件在 /usr/local/nagios/etc/nagios.cfg文件里,这里先不细说 #启用apache的一些模块以支持nagios $ sudo a2enmod rewrite $ sudo a2enmod cgi $ sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/ #apache2的nagios配置文件看起来是这样的: $ sudo vim etc/apache2/sites-enabled/nagios.conf AllowOverride None <IfVersion >= 2.3> <RequireAll> Require all granted # Require host 127.0.0.1 AuthName "Nagios Access" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd.users Require valid-user </RequireAll> </IfVersion> <IfVersion < 2.3> Order allow,deny Allow from all Order deny,allow Deny from all Allow from 46.102.170.1 46.102.170.254 AuthName "Nagios Access" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd.users Require valid-user </IfVersion> </Directory>
11.创建nagios服务 nagios自身没有systemd的服务文件,要创建一个: $ sudo vim /etc/systemd/system/nagios.service 文件内容如下: [Unit] Description=Nagios BindTo=network.target [Install] WantedBy=multi-user.target [Service] Type=simple User=nagios Group=nagcmd ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg
12.启动重启服务 root@AX:/etc/systemd/system# systemctl start apache2 root@Nagios_THN:/etc/systemd/system# systemctl enable /etc/systemd/system/nagios.service Created symlink /etc/systemd/system/multi-user.target.wants/nagios.service → /etc/systemd/system/nagios.service. $ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg root@AX:/etc/systemd/system# systemctl start nagios #或者使用service nagios start 为了使用某些私有mib库,我还安装了snmp,把这些mib库拷贝到服务器上,mib文件存在目录: /usr/share/snmp/mibs/目录下 $ sudo apt install snmpd snmp snmp-mibs-downloader Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libsensors4 libsnmp-base libsnmp30 smistrip IPFIX-SELECTOR-MIB: 173 lines. IANAifType-MIB: 685 lines. IANA-LANGUAGE-MIB: 126 lines. IANA-ADDRESS-FAMILY-NUMBERS-MIB: 170 lines. IANA-RTPROTO-MIB: 102 lines. IANATn3270eTC-MIB: 303 lines. IANA-MALLOC-MIB: 69 lines. IANA-CHARSET-MIB: 361 lines. IANA-PRINTER-MIB: 2111 lines. IANA-FINISHER-MIB: 286 lines. IANA-ITU-ALARM-TC-MIB: 335 lines. IANA-GMPLS-TC-MIB: 359 lines. IANA-IPPM-METRICS-REGISTRY-MIB: 818 lines. IANA-MAU-MIB: 984 lines. Setting up libsnmp-base (5.7.3+dfsg-1.8ubuntu3.1) ... Setting up libsnmp30:amd64 (5.7.3+dfsg-1.8ubuntu3.1) ... Setting up snmpd (5.7.3+dfsg-1.8ubuntu3.1) ... Created symlink /etc/systemd/system/multi-user.target.wants/snmpd.service → /lib/systemd/system/snmpd.service. Setting up snmp (5.7.3+dfsg-1.8ubuntu3.1) ... Processing triggers for libc-bin (2.27-3ubuntu1) ... Processing triggers for ureadahead (0.100.0-20) ... Processing triggers for systemd (237-3ubuntu10.11) ...
13.ufw防火墙设置 如果启用防火墙的话,要允许ssh、snmp和http(80端口): # ufw status
注意事项 如果你没装snmp的话,在nagios目录/usr/local/nagios/libexec/下就不会有check_snmp文件,nagios上你会看到报错: (No output on stdout) stderr: execvp(/usr/local/nagios/libexec/check_snmp, ...) failed. errno is 2: No such file or directory 另外,不要忘记在被管理设备的snmp配置里允许这台服务器进行访问,也有community字串写错的。 按照以上13个步骤就可以搞定了,通过在浏览器中输入 http://{你的IP地址或域名}/nagios/ 来管理网络。
相关主题 |