设为首页 收藏本站
查看: 1577|回复: 0

第一章:nagios 下载&安装

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-11-22 17:13:05 | 显示全部楼层 |阅读模式
一、安装前的准备
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库和开发库
[iyunv@bairui212 Packages] yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
[iyunv@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
[iyunv@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

[iyunv@localhost yum.repos.d]#
[iyunv@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运行所需要的用户和组:

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

[iyunv@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添加为服务
[iyunv@bairui212 nagios-4.0.6]# chkconfig --add nagios
[iyunv@bairui212 nagios-4.0.6]# chkconfig nagios off
[iyunv@bairui212 nagios-4.0.6]# chkconfig --level 35 nagios on
[iyunv@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
[iyunv@bairui212 nagios]# tar -zxvf httpd-2.4.7.tar.gz
[iyunv@bairui212 httpd-2.4.7]# cd httpd-2.4.7
[iyunv@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.  Pleaseread the documentation.  
发现可能是gcc版本太低了,可能是apache版本太高,换低点的2.2.23版本吧。
下载地址: http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz
[iyunv@bairui212 httpd-2.2.23]# tar -zxvf httpd-2.2.23.tar.gz[iyunv@bairui212 httpd-2.4.7]# ./configure --prefix=/usr/local/apache
make && make install[iyunv@bairui212 httpd-2.2.23]# make[iyunv@bairui212 httpd-2.2.23]# make install
到usr/local/apache 目录 看一下,安装后生成一下文件,不过权限都是root的[iyunv@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版本


[iyunv@bairui212 php-5.4.26]# tar -xvf php-5.4.26.tar.gz
[iyunv@bairui212 php-5.4.26]# cd php-5.4.26
[iyunv@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包
[iyunv@bairui212 php-5.4.26]# yum install libxml2 –y
[iyunv@bairui212 php-5.4.26]# yum install libxml2-devel –y


继续make,成功了: Make && make install[iyunv@bairui212 php-5.4.26]# make[iyunv@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   --注意这里有个空&#26684;

</IfModule>


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

#setting for nagios

ScriptAlias /nagios/cgi-bin&quot;/usr/local/nagios/sbin&quot;

<Directory &quot;/usr/local/nagios/sbin&quot;>
     AuthType Basic
     Options ExecCGI
     AllowOverride None
     Order allow,deny
     Allow from all
     AuthName &quot;Nagios Access&quot;
     AuthUserFile /usr/local/nagios/etc/htpasswd  //用于此目录访问身份验证的文件              
     Require valid-user
</Directory>

Alias /nagios &quot;/usr/local/nagios/share&quot;

<Directory &quot;/usr/local/nagios/share&quot;>
     AuthType Basic
     Options None
     AllowOverride None
     Order allow,deny
     Allow from all
     AuthName &quot;nagios Access&quot;
     AuthUserFile /usr/local/nagios/etc/htpasswd
     Require valid-user
</Directory>


11. 创建apache目录验证文件

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

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

用户名:  david
密码:注意密码记好
查看认证文件的内容:

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

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



12. 启动apache服务:

[iyunv@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  中修改的时候有个空&#26684;我给去掉了,丫丫的。<IfModule dir_module>  
  DirectoryIndex index.html index.php  
  AddType application/x-httpd-php .php   --注意这里有个空&#26684;

</IfModule>


[iyunv@bairui212 bin]# /usr/local/apache/bin/apachectl start
httpd: apr_sockaddr_info_get() failed for bai rui212httpd: 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/,可以打开了,如下所示:
DSC0000.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-142294-1-1.html 上篇帖子: CentOS 5.2安装nagios实现短信告警 下篇帖子: nagios应用2- 监控linux服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表