Nagios怎么安裝和配置

小億
75
2023-10-22 10:55:37

以下是安裝和配置Nagios的步驟:

  1. 安裝必要的軟件包:

    • 在Debian/Ubuntu上運(yùn)行以下命令:
      sudo apt-get update
      sudo apt-get install build-essential libgd2-xpm-dev openssl libssl-dev xinetd apache2 php libapache2-mod-php php-gd
      
    • 在CentOS/RHEL上運(yùn)行以下命令:
      sudo yum install gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix
      
  2. 創(chuàng)建Nagios用戶:

    • 在Debian/Ubuntu上運(yùn)行以下命令:
      sudo useradd nagios
      sudo groupadd nagcmd
      sudo usermod -a -G nagcmd nagios
      
    • 在CentOS/RHEL上運(yùn)行以下命令:
      sudo useradd nagios
      sudo groupadd nagcmd
      sudo usermod -a -G nagcmd nagios
      sudo usermod -a -G nagios apache
      
  3. 下載Nagios核心軟件包:

    • 訪問Nagios官方網(wǎng)站(https://www.nagios.org/downloads/core-releases/)下載最新的Nagios核心軟件包。
  4. 解壓和編譯Nagios軟件包:

    tar -xzf nagios-x.x.x.tar.gz
    cd nagios-x.x.x
    ./configure --with-command-group=nagcmd
    make all
    sudo make install
    sudo make install-init
    sudo make install-config
    sudo make install-commandmode
    sudo make install-webconf
    
  5. 創(chuàng)建Nagios管理員賬戶:

    sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
    
  6. 安裝并配置Nagios插件:

    • 訪問Nagios插件官方網(wǎng)站(https://www.nagios.org/downloads/nagios-plugins/)下載最新的Nagios插件軟件包。
    • 解壓和編譯插件軟件包:
      tar -xzf nagios-plugins-x.x.x.tar.gz
      cd nagios-plugins-x.x.x
      ./configure --with-nagios-user=nagios --with-nagios-group=nagios
      make
      sudo make install
      
  7. 配置Nagios:

    • 打開Nagios配置文件:
      sudo vi /usr/local/nagios/etc/nagios.cfg
      
    • 使Nagios能夠訪問外部命令:
      • 在配置文件中找到以下行并取消注釋:
        #cfg_dir=/usr/local/nagios/etc/servers
        
    • 配置Nagios對(duì)象:
      • 創(chuàng)建主機(jī)配置文件夾:
        sudo mkdir /usr/local/nagios/etc/servers
        
      • 在主機(jī)配置文件夾中創(chuàng)建主機(jī)配置文件(例如,localhost.cfg)并添加以下內(nèi)容:
        define host {
            use                     linux-server
            host_name               localhost
            alias                   My localhost server
            address                 127.0.0.1
            max_check_attempts      5
            check_period            24x7
            notification_interval   30
            notification_period     24x7
        }
        
    • 驗(yàn)證Nagios配置文件的正確性:
      sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
      
  8. 啟動(dòng)Nagios服務(wù):

    • 在Debian/Ubuntu上運(yùn)行以下命令:
      sudo service nagios start
      
    • 在CentOS/RHEL上運(yùn)行以下命令:
      sudo systemctl start nagios
      
  9. 配置Nagios Web界面:

    • 在Debian/Ubuntu上運(yùn)行以下命令:
      sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/
      sudo systemctl restart apache2
      
    • 在CentOS/RHEL上運(yùn)行以下命令:
      sudo ln -s /etc/httpd/conf.d/nagios.conf /etc/httpd/conf.d/nagios.conf
      sudo systemctl restart httpd
      
  10. 訪問Nagios Web界面:

    • 在Web瀏覽器中訪

0