oracle linux7 安装 nagios
1、配置好163的yum源,安装apache和php
略.2、列出nagio依赖包,先不安装,根据依赖包列表先按照依赖包,减少后面编译的麻烦
yum install nagios nagios-plugins nrpe nagios-common
Dependencies Resolved
=====================================================
Install 1 Package (+32 Dependent packages)
Total download size: 14 M
Installed size: 46 M
Is this ok [y/d/N]: N
根据上面列出的依赖包,先把依赖包安装
yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
yum install -y fontconfig
yum install -y fontpackages-filesystem
yum install -y gd
yum install -y lyx-fonts
yum install -y perl
yum install -y perl-Carp
yum install -y perl-Encode
yum install -y perl-Exporter
yum install -y perl-File-Path
yum install -y perl-File-Temp
yum install -y perl-Filter
yum install -y perl-Getopt-Long
yum install -y perl-HTTP-Tiny
yum install -y perl-PathTools
yum install -y perl-Pod-Escapes
yum install -y perl-Pod-Perldoc
yum install -y perl-Pod-Simple
yum install -y perl-Pod-Usage
yum install -y perl-Scalar-List-Utils
yum install -y perl-Socket
yum install -y perl-Storable
yum install -y perl-Text-ParseWords
yum install -y perl-Time-HiRes
yum install -y perl-Time-Local
yum install -y perl-constant
yum install -y perl-libs
yum install -y perl-macros
yum install -y perl-parent
yum install -y perl-podlators
3、建立用户、获取安装包
useradd -s /sbin/nologin nagios #/sbin/nologin会导致nagios服务无法启动,后面会改成/bin/bash
groupadd nagcmd
groupadd nagios
usermod -a -G nagios,nagcmd nagios
mkdir /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios
wget https://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.3.4/nagios-4.3.4.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz
4、安装nagios,configure仔细看输出,会提示额外的一些包
./configure --prefix=/usr/local/nagios --enable-embedded-perl --with-command-group=nagcmd
[root@rac1201 nagios-4.3.4]# ./configure --prefix=/usr/local/nagios --enable-embedded-perl --with-command-group=nagcmd
checking for a BSD-compatible install... /usr/bin/install -c
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/soft/soft/nagios-4.3.4':
configure: error: no acceptable C compiler found in $PATH
yum install -y gcc glibc glibc-common 后通过
Boutell's GD library is required to compile the statusmap, trends
and histogram CGIs. Get it from http://www.boutell.com/gd/, compile
it, and use the --with-gd-lib and --with-gd-inc arguments to specify
the locations of the GD library and include files.
NOTE: In addition to the gd-devel library, you'll also need to make
sure you have the png-devel and jpeg-devel libraries installed
on your system.
NOTE: After you install the necessary libraries on your system:
1. Make sure /etc/ld.so.conf has an entry for the directory in
which the GD, PNG, and JPEG libraries are installed.
2. Run 'ldconfig' to update the run-time linker options.
3. Run 'make clean' in the Nagios distribution to clean out
any old references to your previous compile.
4. Rerun the configure script.
NOTE: If you can't get the configure script to recognize the GD libs
on your system, get over it and move on to other things. The
CGIs that use the GD libs are just a small part of the entire
Nagios package. Get everything else working first and then
revisit the problem. Make sure to check the nagios-users
mailing list archives for possible solutions to GD library
problems when you resume your troubleshooting.
yum install -y gd-devel png-devel jpeg-devel
make all
make install
make install-init
make install-commandmode
make install-config
[root@rac1201 nagios-4.3.4]# make install-exfoliation
*** Exfoliation theme installed ***
NOTE: Use 'make install-classicui' to revert to classic Nagios theme
make install-exfoliation --这个应该不需要执行了
4、安装插件,没碰到问题
# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios
# make && make install
为了监控mysql,重新编译
make clean
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-mysql=/usr/local/mysql/lib
# make && make install
5、安装nrpe
163的yum源碰到冲突,改成本地源安装依赖包
--> Finished Dependency Resolution
Error: Package: libcom_err-devel-1.42.9-10.el7.x86_64 (base)
Requires: libcom_err(x86-64) = 1.42.9-10.el7
Installed: libcom_err-1.42.9-10.0.1.el7.x86_64 (@anaconda/7.4)
libcom_err(x86-64) = 1.42.9-10.0.1.el7
Available: libcom_err-1.42.9-10.el7.x86_64 (base)
libcom_err(x86-64) = 1.42.9-10.el7
Error: Package: 1:openssl-devel-1.0.2k-8.el7.x86_64 (base)
Requires: openssl-libs(x86-64) = 1:1.0.2k-8.el7
Installed: 1:openssl-libs-1.0.2k-8.0.1.el7.x86_64 (@anaconda/7.4)
openssl-libs(x86-64) = 1:1.0.2k-8.0.1.el7
Available: 1:openssl-libs-1.0.2k-8.el7.x86_64 (base)
openssl-libs(x86-64) = 1:1.0.2k-8.el7
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
本地源安装openssl
[root@rac1201 yum.repos.d]# more ol7.repo
[ol7]
name=Oracle Linux $releasever Latest ($basearch)
baseurl=file:///mnt
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=0
enabled=1
[root@rac1201 yum.repos.d]# yum install openssl-devel
./configure --prefix=/usr/local/nagios
make all
make install-plugin
General Options:
-------------------------
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios
6、修改配置文件
/etc/httpd/conf/httpd.conf
#
User nagios
Group nagios
#
<IfModule dir_module>
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php
</IfModule>
#
最后添加
IncludeOptional conf.d/*.conf
#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>
/usr/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin
7、启动nagios
/etc/init.d/nagios start启动服务报错
查看报错信息
[root@rac1201 init.d]# systemctl status nagios.service
* nagios.service - LSB: Starts and stops the Nagios monitoring server
Loaded: loaded (/etc/rc.d/init.d/nagios; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2017-10-25 19:10:16 CST; 19s ago
Docs: man:systemd-sysv-generator(8)
Process: 11932 ExecStart=/etc/rc.d/init.d/nagios start (code=exited, status=8)
Oct 25 19:10:16 rac1201 systemd[1]: Starting LSB: Starts and stops the Nagios monitoring server...
Oct 25 19:10:16 rac1201 su[11936]: (to nagios) root on none
Oct 25 19:10:16 rac1201 nagios[11932]: Starting nagios:This account is currently not available.
Oct 25 19:10:16 rac1201 nagios[11932]: ERROR: Could not create or update '/usr/local/nagios/var/nagios.configtest'
Oct 25 19:10:16 rac1201 systemd[1]: nagios.service: control process exited, code=exited status=8
Oct 25 19:10:16 rac1201 systemd[1]: Failed to start LSB: Starts and stops the Nagios monitoring server.
Oct 25 19:10:16 rac1201 systemd[1]: Unit nagios.service entered failed state.
Oct 25 19:10:16 rac1201 systemd[1]: nagios.service failed.
猜测权限问题,修改登录shell
[root@rac1201 nrpe-3.2.1]# usermod -s /bin/bash nagios
[root@rac1201 nrpe-3.2.1]# /etc/init.d/nagios start
启动成功
8、监控配置
hosts.cfg
define host{
use linux-server ;引用主机linux-server的属性信息,linux-server主机在templates.cfg文件中进行了定义。
host_name rac3 ;主机名
alias rac3 ;主机别名
address 172.167.3.175 ;被监控的主机地址,这个地址可以是ip,也可以是域名。
}
define host{
use linux-server ;引用主机linux-server的属性信息,linux-server主机在templates.cfg文件中进行了定义。
host_name rac1 ;主机名
alias rac1 ;主机别名
address 172.167.3.70 ;被监控的主机地址,这个地址可以是ip,也可以是域名。
}
#定义一个主机组
define hostgroup{
hostgroup_name rac-servers ;主机组名称,可以随意指定。
alias rac-servers ;主机组别名
members rac3,rac1 ;主机组成员,其中“Nagios-Linux”就是上面定义的主机。
}
services.cfg
define service{
use local-service ;引用local-service服务的属性值,local-service在templates.cfg文件中进行了定义。
host_name rac3,rac1,rac12-nagios ;指定要监控哪个主机上的服务,“Nagios-Server”在hosts.cfg文件中进行了定义。
service_description check-host-alive ;对监控服务内容的描述,以供维护人员参考。
check_command check-host-alive ;指定检查的命令。
}
cgi.cfg
default_user_name=nagiosadmin
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
参考文档
http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html