第一章:nagios 下载&安装



一、安装前的准备

1.下载到核心源码:

    http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.6.tar.gz  

2.下载插件包:

 http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz

3. nagios服务器端软件和客户端插件


  http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz

4.安装PHP

  http://cn2.php.net/distributions/php-5.4.26.tar.gz


5. 安装apache

下载 wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz

-------------------------------------------------------------------------------------------------------------

二、开始安装

1.源码安装前需要先确定 已经安装 apache,gcc,GD库和开发库

[root@bairui212 Packages] yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

[root@bairui212 Packages]# rpm -qa gcc glibc glibc-common gd gd-devel xinetd openssl-devel

mount -o loop  /dev/cdrom /mnt  挂载磁盘

glibc-2.12-1.47.el6.x86_64
gcc-4.4.6-3.el6.x86_64
gd-2.0.35-10.el6.x86_64
openssl-devel-1.0.0-20.el6.x86_64
xinetd-2.3.14-33.el6.x86_64
glibc-common-2.12-1.47.el6.x86_64

需要的包已经有了
------------------------------------------------------------------------------------------------------------
2. 配置YUM

yum
cd /etc/yum.repos.d        有的是这个文件 rhel-debuginfo.repo
[root@localhost yum.repos.d]# vi rhel5.repo
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///mnt/Server
enabled=1
gpgcheck=0

[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: rhnplugin, security
Cleaning up Everything

--------------------------------------------------------------------------------------------------------
3 进行selinux设置,或者关闭selinux

 查看SELinux状态:

 (1)/usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态

         SELinux status:                 enabled

 (2)getenforce                     ##也可以用这个命令检查


关闭iptables很及seliunx 

vi /etc/selinux/config
SELINUX=disabled   ---修改 需要重启
SELINUXTYPE=targeted
#setenforce 0 

两节点关闭防火墙另一种方式:
chkconfig --list|grep ip
chkconfig  ip6tables off
chkconfig  iptables off
service ip6tables stop
service iptables stop

-----------------------------------------------------------------------------------------------------------

4 开始准备nagios安装环境

  (1) 添加nagios运行所需要的用户和组:

[root@bairui212 Packages]# groupadd nagcmd
[root@bairui212 Packages]# useradd -m nagios
[root@bairui212 Packages]# usermod -a -G nagcmd nagios
[root@bairui212 Packages]# passwd nagios
     
         
把apache加入到nagcmd组,以便于在通过web Interface操作nagios时能够具有足够的权限:

[root@bairui212 Packages]# usermod -a -G nagcmd apache
    


5. 安装主程序


[nagios@bairui212 nagios-4.0.6]$ ./configure --with-command-group=nagios --prefix=/usr/local/nagios --enable-embedded-perl --with-httpd-conf=/usr/local/apache/conf 


安装:
# make all
# make install
# make install-commandmode
# make install-config
# make install-init
# make install-webconf


这里nagios的编译不同于其他的软件,需要好几步才能完成,我们来解释一下make这几步的意思
make install  安装主要的程序、CGI、HTML文件等等。
make install-commandmode 赋予外部命令访问nagios配置文件的权限
make install-config 将nagios的配置文件的例子复制到nagios的安装目录下
make install-init 将nagios做成一个运行脚本,放入init.d中,使nagios可以随系统的开机而启动
make install-webconf配置apache的web接口,如果运行出错,是因为你的apache是自己编译安装的

不是yum安装的,webconf生成的文件会放在/etc/httpd/conf.d/下,因为找不到这个目录,
所以出错编译安装完成后:
# ls /usr/local/nagios
bin  etc  include  libexec  share
 查看是否有上面的文件,如果有到此nagios就算是安装完了。

 5.1  那么我们来看看这上面几个目录下的文件都有什么意义。

bin          nagios执行程序所在目录,这个目录只有一个文件nagios
etc          nagios配置文件位置,初始安装完成后,只有几个*.cfg-sample文件
sbin        nagios  Cgi文件所在目录,也就是执行外部命令所需文件所在的目录
share     nagios网页文件所在的目录
var          nagios日志文件、spid等文件所在的目录

nagios的主程序安装完毕后,为了以防万一我们来检查一下/usr/local/nagios的目录权限
如果不是nagios的属主那么要将属主进行修改,否则nagios没有权限来运行。


[nagios@bairui212 nagios]$ ll
总用量 24
drwxrwxr-x  2 nagios nagios 4096 10月 24 14:12 bin
drwxrwxr-x  3 nagios nagios 4096 10月 24 14:13 etc
drwxrwxr-x  2 nagios nagios 4096 10月 24 14:12 libexec
drwxrwxr-x  2 nagios nagios 4096 10月 24 14:12 sbin
drwxrwxr-x 10 nagios nagios 4096 10月 24 14:12 share
drwxrwxr-x  5 nagios nagios 4096 10月 24 14:12 var

有以上文件夹,权限都是nagios用户的

 6. 将nagios添加为服务

[root@bairui212 nagios-4.0.6]# chkconfig --add nagios
[root@bairui212 nagios-4.0.6]# chkconfig nagios off
[root@bairui212 nagios-4.0.6]# chkconfig --level 35 nagios on
[root@bairui212 nagios-4.0.6]# chkconfig --list nagios 
nagios              0:关闭     1:关闭     2:关闭     3:启用     4:关闭     5:启用     6:关闭


7.安装nagios插件

插件对于nagios来说是非常重要的,插件的版本对于nagios主程序之间的关联并不大
各个版本基本都可以使用。
# tar zxvf nagios-plugins-1.4.15.tar.gz
# cd nagios-plugins
# #./configure --with-nagios-user=nagios --with-nagios-group=nagcmd --prefix=/usr/local/nagios --with-mysql    nagios-plugins是安装到nagios的主目录下的
# make
# make install
安装完成后/usr/local/nagios生成目录libexec,这就是nagios所需要的插件


7.1 检查工作:

再次检查nagios主目录的属主,一定要是nagios,不能是root
如果属主不正确
#chown -R nagios.nagios /usr/local/nagios
nagios的用户不需要登录shell 所以如果为了安全
vi /etc/passwd
nagios:x:500:500::/home/nagios:/bin/bash
修改为:
nagios:x:500:500::/home/nagios:/bin/nologin
那么nagios用户则不能够登录shell

8. 安装配置apache

[root@bairui212 nagios]# tar -zxvf httpd-2.4.7.tar.gz
[root@bairui212 httpd-2.4.7]# cd httpd-2.4.7
[root@bairui212 httpd-2.4.7]# ./configure --prefix=/usr/local/apache
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long linesand -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APRnot found.  Please read the documentation.  
 发现可能是gcc版本太低了,可能是apache版本太高,换低点的2.2.23版本吧。

下载地址:  http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz

[root@bairui212 httpd-2.2.23]# tar -zxvf httpd-2.2.23.tar.gz
[root@bairui212 httpd-2.4.7]# ./configure --prefix=/usr/local/apache

make && make install
[root@bairui212 httpd-2.2.23]# make
[root@bairui212 httpd-2.2.23]# make install

到usr/local/apache 目录 看一下,安装后生成一下文件,不过权限都是root的
[root@bairui212 apache]# ll
总用量 60
drwxr-xr-x  2 root   root    4096  6月 10 16:14 bin
drwxr-xr-x  2 root   root    4096  6月 10 16:14 build
drwxr-xr-x  2 root   root    4096  6月 10 16:14 cgi-bin
drwxrwxr-x  4 nagios nagios  4096  6月 10 16:14 conf
drwxr-xr-x  3 root   root    4096  6月 10 16:14 error
drwxr-xr-x  2 root   root    4096  8月 22 2012 htdocs
drwxr-xr-x  3 root   root    4096  6月 10 16:14 icons
drwxr-xr-x  2 root   root    4096  6月 10 16:14 include
drwxr-xr-x  3 root   root    4096  6月 10 16:14 lib
drwxr-xr-x  2 root   root    4096  6月 10 16:14 logs
drwxr-xr-x  4 root   root    4096  6月 10 16:14 man
drwxr-xr-x 14 root   root   12288  8月 22 2012 manual
drwxr-xr-x  2 root   root    4096  6月 10 16:14 modules


9.安装php版本


[root@bairui212 php-5.4.26]# tar -xvf php-5.4.26.tar.gz 
[root@bairui212 php-5.4.26]# cd php-5.4.26
[root@bairui212 php-5.4.26]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs

checking for atoll... yes
checking for strftime... (cached) yes
checking which regex library to use... php
checking whether to enable LIBXML support... yes
checking libxml2 install dir... no
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation. 少包了


9.1 需要重新安装lib包 

[root@bairui212 php-5.4.26]# yum install libxml2 –y
[root@bairui212 php-5.4.26]# yum install libxml2-devel –y 


继续make,成功了: 
Make && make install
[root@bairui212 php-5.4.26]# make
[root@bairui212 php-5.4.26]# make install


10 . 配置apache

Apache的配置文件在 /usr/local/apache/conf/httpd.conf ,vi打开


User daemon 
Group daemon 

修改成:
User nagios 
Group nagios



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

修改成:

<IfModule dir_module> 
  DirectoryIndex index.html index.php 
  AddType application/x-httpd-php .php   --注意这里有个空格

</IfModule> 


为了安全起见:nagios的web监控页面需要经过授权才能访问,这需要增加验证配置,即在httpd.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>


11. 创建apache目录验证文件

在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:

[root@bairui212 bin]# ./htpasswd -c /usr/local/nagios/etc/htpasswd david
New password:
Re-type new password:
Adding password for user david

用户名:  david 
密码:注意密码记好

查看认证文件的内容:

[root@cache-2 php-5.4.26]#  cat /usr/local/nagios/etc/htpasswd

[root@bairui212 bin]# cat /usr/local/nagios/etc/htpasswd
david:$apr1$n6cA7f6.$A7lc6GqHKZ0071P7Se2d1/



12. 启动apache服务:

[root@bairui212 bin]# /usr/local/apache/bin/apachectl start

Syntax error on line 170 of /usr/local/apache/conf/httpd.conf:
AddType requires at least two arguments, a mime type followed by one or more file extensions 报错了

原因是: /usr/local/apache/conf/httpd.conf  中修改的时候有个空格我给去掉了,丫丫的。
<IfModule dir_module>  
  DirectoryIndex index.html index.php  
  AddType application/x-httpd-php .php   --注意这里有个空格

</IfModule> 


[root@bairui212 bin]# /usr/local/apache/bin/apachectl start

httpd: apr_sockaddr_info_get() failed for bai rui212
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName 报错了


修改ServerName以及Port

vi /usr/local/apache2/conf/httpd.conf

ServerName 改成  ServerName bairui212:80
 
http://192.168.0.212:80/nagios/,可以打开了,如下所示: 

第一章:nagios 下载&安装_第1张图片

你可能感兴趣的:(nagios,nagios,下载安装)