micromax 发表于 2019-1-12 12:27:41

Nagios服务端安装

  系统环境:
  # cat /etc/redhat-release
  CentOS release 6.9 (Final)
  

  1、更新yum源
  mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  wget -O /etc/yum.repos.d/CentOS-Base.repo   http://mirrors.aliyun.com/repo/Centos-6.repo
  

  2.调整字符集
  echo 'export LC_ALL=C'>>/etc/profile
  source /etc/profile
  

  3.关闭iptables与selinux
  

  4.更新系统时间
  /usr/sbin/ntpdate pool.ntp.org
  然后放入定时任务
  

  5.安装gcc和LAMP
  yum install gcc glibc glibc-common gd gd-devel php-gd httpd php mysql* unzip -y
  

  6.添加用户
  # useradd -m nagios
  # useradd apache
  # groupadd nagcmd
  # usermod -a -G nagcmd nagios
  # usermod -a -G nagcmd apache
  

  7.下载与安装nagios
  # unzip oldboy_training_nagios_soft.zip
  Archive:oldboy_training_nagios_soft.zip
  inflating: check_memory.pl #内存监控插件
  inflating: check_mysql   #mysql监控插件
  inflating: Class-Accessor-0.31.tar.gz
  extracting: Config-Tiny-2.12.tar.gz
  inflating: libart_lgpl-2.3.17.tar.gz
  inflating: Math-Calc-Units-1.07.tar.gz
  inflating: Nagios-Plugin-0.34.tar.gz
  inflating: nrpe-2.12.tar.gz#客户端的nrpe守护进程
  inflating: Params-Validate-0.91.tar.gz
  inflating: pnp-0.4.14.tar.gz #nagios的web图形展示程序
  inflating: Regexp-Common-2010010201.tar.gz
  inflating: rrdtool-1.2.14.tar.gz#nagios的画图工具
  inflating: check_iostat#io监控插件
  inflating: nagios-3.5.1.tar.gz#nagios主程序
  inflating: nagios-plugins-1.4.16.tar.gz#nagios插件
  # tar xf nagios-3.5.1.tar.gz
  # cd nagios
  # ./configure --with-command-group=nagcmd
  # make all
  # make install
  。。。。。。。。。。。。。。。。。。。。。。。。
  make install-init
  - This installs the init script in /etc/rc.d/init.d
  

  make install-commandmode
  - This installs and configures permissions on the
  directory for holding the external command file
  

  make install-config
  - This installs sample config files in /usr/local/nagios/etc
  

  make: Leaving directory `/root/tools/nagios'
  

  # 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 ***
  

  # make install-commandmode
  /usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
  chmod g+s /usr/local/nagios/var/rw
  

  *** External command directory configured ***
  

  # 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/cgi.cfg /usr/local/nagios/etc/cgi.cfg
  /usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
  /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
  /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
  /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
  /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
  /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
  /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.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 ***
  

  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.
  

  # make install-webconf
  /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
  

  *** Nagios/Apache conf file installed ***
  

  8.配置web认证
  # vi /etc/httpd/conf.d/nagios.conf
  # SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
  # Last Modified: 11-26-2005
  #
  # This file contains examples of entries that need
  # to be incorporated into your Apache web server
  # configuration file.Customize the paths, etc. as
  # needed to fit your system.
  

  ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
  

  
  #SSLRequireSSL
  Options ExecCGI
  AllowOverride None
  Order allow,deny
  Allow from all
  #Order deny,allow
  #Deny from all
  #Allow from 127.0.0.1
  AuthName "Nagios Access"
  AuthType Basic
  AuthUserFile /usr/local/nagios/etc/htpasswd.users
  Require valid-user
  
  

  Alias /nagios "/usr/local/nagios/share"
  # htpasswd -cb /usr/local/nagios/etc/htpasswd.users oldboy 123456#创建登录nagios的web用户名和密码
  Adding password for user oldboy
  

  9.安装nagios插件
  # yum -y install perl-devel
  # tar xf nagios-plugins-1.4.16.tar.gz
  # cd nagios-plugins-1.4.16
  # ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
  # make && make install
  # ll /usr/local/nagios/libexec/|wc -l
  60#此处为60-61个左右
  # cd ../
  

  10.安装nrpe
  # tar xf nrpe-2.12.tar.gz
  # cd nrpe-2.12
  # ./configure
  # make all
  # make install-plugin
  # make install-daemon
  # make install-daemon-config
  

  11.启动服务与检查
  # /etc/init.d/nagios start
  Starting nagios: done.
  # /etc/init.d/httpd start
  Starting httpd:                                       
  # netstat -tunlp|grep 80
  tcp      0      0 :::80                     :::*                        LISTEN      7853/httpd
  # ps -ef|grep nagios
  nagios    7841   10 16:31 ?      00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
  root      7871 538450 16:32 pts/0    00:00:00 grep nagios
  

  最后成果图:
https://s1.运维网.com/wyfs02/M01/9C/C2/wKioL1l1s-nD7WJOAAIoNnLbrLc379.png-wh_500x0-wm_3-wmp_4-s_941230149.png



页: [1]
查看完整版本: Nagios服务端安装