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

Nagios服务器端安装部署详解(1)

[复制链接]

尚未签到

发表于 2017-4-20 09:35:23 | 显示全部楼层 |阅读模式
  下载地址如下:http://sourceforge.net/projects/nagios/files/
具体详细下载地址:http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.6.tar.gz

  1 开始下载:
wget http://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.0.6/nagios-4.0.6.tar.gz/download?use_mirror=jaist
如下图所示,下载free版本的。
DSC0000.jpg

  安装前准备工作,安装一些lib包
  [iyunv@cache-2 root]# yum -y install httpd gcc glibc glibc-common
  # yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel


  2进行selinux设置,或者关闭selinux
  查看SELinux状态:
  (1)/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态
  SELinux status: enabled
  (2)getenforce ##也可以用这个命令检查
  关闭SELinux:
  (3)临时关闭(不用重启机器):
  setenforce 0 ##设置SELinux成为permissive模式
  ##setenforce 1设置SELinux成为enforcing模式
  (4)修改配置文件需要重启机器:
  修改/etc/selinux/config文件
  将SELINUX=enforcing改为SELINUX=disabled
  重启机器即可


  3开始准备nagios安装环境
  (1)添加nagios运行所需要的用户和组:
  groupadd nagcmd
  useradd -m nagios
  usermod -a -G nagcmd nagios
  把apache加入到nagcmd组,以便于在通过web Interface操作nagios时能够具有足够的权限:
  # usermod -a -G nagcmd apache


  4编译安装准备
  ./configure--with-command-group=nagios--prefix=/opt/app/nagios--enable-embedded-perl--with-httpd-conf=/usr/local/apache2/conf

[iyunv@cache-2 nagios-4.0.6]# ./configure --with-command-group=nagios  --prefix=/opt/app/nagios --enable-embedded-perl  --with-httpd-conf=/usr/local/apache2/conf
checking for a BSD-compatible install... /usr/bin/install -c
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
.............................
HTML URL:  http://localhost/nagios/
CGI URL:  http://localhost/nagios/cgi-bin/
Traceroute (used by WAP):  /bin/traceroute

Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.






  5 开始make安装
5.1 make all

[iyunv@cache-2 nagios-4.0.6]#make all

cd ./base && make
make[1]: Entering directory `/root/nagios-4.0.6/base'
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nagios.o nagios.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE   -c -o broker.o broker.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE   -c -o nebmods.o nebmods
.........................
For more information on obtaining support for Nagios, visit:
http://support.nagios.com
*************************************************************
Enjoy.







5.2 make install
[iyunv@cache-2 nagios-4.0.6]# make install
cd ./base && make install
make[1]: Entering directory `/root/nagios-4.0.6/base'
make install-basic
make[2]: Entering directory `/root/nagios-4.0.6/base'
.....................................................
make[2]: Entering directory `/root/nagios-4.0.6/cgi'
for file in *.cgi; do \
/usr/bin/strip /usr/local/nagios/sbin/$file; \
done




5.3 make install-config
[iyunv@cache-2 nagios-4.0.6]# make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
....................................................
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
*** Config files installed ***



  5.4 make install-commandmode

[iyunv@cache-2 nagios-4.0.6]# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***
Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.


  
5.5 make install-init


[iyunv@cache-2 nagios-4.0.6]# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios
*** Init script installed ***



  [iyunv@cache-2 nagios-4.0.6]#
  加到启动项里面去:
  # chkconfig --add nagios
  # chkconfig --level 35 nagios on
  # chkconfig --list nagios

DSC0001.jpg
  检查主机配置文件是否正确:
  /var/www/nagios/bin/nagios -v /var/www/nagios/etc/nagios.cfg
  

  5.6 Check安装是否正确:
  5.6.1说明:
  切换目录到安装路径(这里是/usr/local/nagios),看是否存在etc、bin、sbin、share、var这五个目录,如果存在则可以表明程序被正确的安装到系统了。Nagios各个目录用途说明如下:
  bin Nagios可执行程序所在目录
  etc Nagios配置文件所在目录
  sbin Nagios CGI文件所在目录,也就是执行外部命令所需文件所在的目录
  share Nagios网页文件所在的目录
  libexec Nagios外部插件所在目录
  var Nagios日志文件、lock等文件所在的目录
  var/archives Nagios日志自动归档目录
  var/rw用来存放外部命令文件的目录


  5.6.2 check
cd /usr/local/nagios
ll


[iyunv@cache-2 nagios-4.0.6]# cd /usr/local/nagios
[iyunv@cache-2 nagios]# ll
总用量 24
drwxrwxr-x.  2 nagios nagios 4096 5月   5 15:31 bin
drwxrwxr-x.  3 nagios nagios 4096 5月   5 15:32 etc
drwxrwxr-x.  2 nagios nagios 4096 5月   5 15:31 libexec
drwxrwxr-x.  2 nagios nagios 4096 5月   5 15:31 sbin
drwxrwxr-x. 10 nagios nagios 4096 5月   5 15:31 share
drwxrwxr-x.  5 nagios nagios 4096 5月   5 15:32 var



  5.7 安装nagios插件
wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz

[iyunv@cache-2 ~]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
--2014-05-05 15:52:52--  http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
正在解析主机 nagios-plugins.org... 72.14.186.43
正在连接 nagios-plugins.org|72.14.186.43|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
............................................
2014-05-05 15:53:00 (373 KB/s) - 已保存 “nagios-plugins-2.0.tar.gz” [2501847/2501847])
[iyunv@cache-2 ~]# tar -xvf nagios-plugins-2.0.tar.gz
[iyunv@cache-2 ~]# cd nagios-plugins-2.0
[iyunv@cache-2 ~]#./configure --with-nagios-user=nagios --with-nagios-group=nagios  --prefix=/usr/local/nagios --with-mysql
[iyunv@cache-2 ~]# make && make install





5.8 安装配置apache和php
(1)安装apache
下载 wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz

[iyunv@cache-2 ~]# wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz
--2014-05-05 16:15:48--  http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz
正在解析主机 archive.apache.org... 192.87.106.229, 140.211.11.131, 2001:610:1:80bc:192:87:106:229
正在连接 archive.apache.org|192.87.106.229|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:6747087 (6.4M) [application/x-gzip]
正在保存至: “httpd-2.4.7.tar.gz”
1% [=>                                                ..............................................................
2014-05-05 16:16:01 (574 KB/s) - 已保存 “httpd-2.4.7.tar.gz” [6747087/6747087])
  




  开始安装:
tar -xvf httpd-2.4.7.tar.gz
cd httpd-2.4.7
./configure --prefix=/usr/local/apache2
make && make install


[iyunv@cache-2 ~]# tar -xvf httpd-2.4.7.tar.gz
[iyunv@cache-2 ~]# cd httpd-2.4.7
[iyunv@cache-2 httpd-2.4.7]# ./configure --prefix=/usr/local/apache2
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -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: APR not found.  Please read the documentation.
Google之后,发现可能是gcc版本太低了,可能是apache版本太高,换低点的2.2.23版本吧。
wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz
tar -xvf  httpd-2.2.23.tar.gz
cd httpd-2.2.23
./configure --prefix=/usr/local/apache2
make && make install


  (2)安装php版本
  wgethttp://cn2.php.net/distributions/php-5.4.26.tar.gz
  tar -xvf php-5.4.26.tar.gz
  cd php-5.4.26
  ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
  有报错信息:
  Configuring extensions
  checking size of long... (cached) 8
  checking size of int... (cached) 4
  checking for int32_t... yes
  checking for uint32_t... yes
  checking for sys/types.h... (cached) yes
  checking for inttypes.h... (cached) yes
  checking for stdint.h... (cached) yes
  checking for string.h... (cached) yes
  checking for stdlib.h... (cached) yes
  checking for strtoll... yes
  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.
  需要重新安装lib包
  yum install libxml2 –y
  yum install libxml2-devel –y
  之后继续make,成功了:
  Make && make install

  [activating module `php5' in /usr/local/apache2/conf/httpd.conf]
  Installing PHP CLI binary: /usr/local/php/bin/
  Installing PHP CLI man page: /usr/local/php/php/man/man1/
  Installing PHP CGI binary: /usr/local/php/bin/
  Installing PHP CGI man page: /usr/local/php/php/man/man1/
  Installing build environment: /usr/local/php/lib/php/build/
  Installing header files: /usr/local/php/include/php/
  Installing helper programs: /usr/local/php/bin/
  program: phpize
  program: php-config
  Installing man pages: /usr/local/php/php/man/man1/
  page: phpize.1
  page: php-config.1
  Installing PEAR environment: /usr/local/php/lib/php/
  [PEAR] Archive_Tar - installed: 1.3.11
  [PEAR] Console_Getopt - installed: 1.3.1
  warning: pear/PEAR requires package "pear/Structures_Graph" (recommended version 1.0.4)
  warning: pear/PEAR requires package "pear/XML_Util" (recommended version 1.2.1)
  [PEAR] PEAR - installed: 1.9.4
  Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
  You may want to add: /usr/local/php/lib/php to your php.ini include_path
  [PEAR] Structures_Graph- installed: 1.0.4
  [PEAR] XML_Util - installed: 1.2.1
  /root/php/php-5.4.26/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
  ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar
  Installing PDO headers: /usr/local/php/include/php/ext/pdo/


  (3)配置apache
  Apache的配置文件在 /usr/local/apache2/conf/httpd.conf,vim打开
  将
  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>


  (4)创建apache目录验证文件
  在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:
  /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd david
  [iyunv@cache-2 php-5.4.26]# /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd david
  New password:
  Re-type new password:
  Adding password for user david
  查看认证文件的内容:
  [iyunv@cache-2 php-5.4.26]# cat /usr/local/nagios/etc/htpasswd
  david:$apr1$Pf9XIJjd$m5hR2vw70MlqwrChgN7zc/
  [iyunv@cache-2 php-5.4.26]#
  启动apache服务:
  /usr/local/apache2/bin/apachectl start
  

  [iyunv@cache-2 php-5.4.26]# /usr/local/apache2/bin/apachectl start
  httpd: Could not reliably determine the server's fully qualified domain name, using 10.254.3.41 for ServerName
  (98)Address already in use: make_sock: could not bind to address [::]:80
  (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
  no listening sockets available, shutting down
  Unable to open logs
  修改ServerName以及Port
  vi /usr/local/apache2/conf/httpd.conf
  ServerName改成10.xx.3.x1
  Listen 80改成Listen 81

  http://10.xx.3.x1:81/nagios/,可以打开了,如下所示:

DSC0002.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-366669-1-1.html 上篇帖子: 【转】Nagios:企业级系统监控方案 下篇帖子: 巧用escalations限制Nagios报警次数
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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