ubuntu16.04安裝配置nagios
參考博文:https://www.howtoing.com/ubuntu-nagios/
該博文真實有效可供參考,按照步驟,基本可以成功
一.安裝的先決條件
sudo apt-get install wget build-essential apache2 php apache2-mod-php7.0 php-gd libgd-dev sendmail unzip
二.用戶和組配置
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagios,nagcmd www-data
三.安裝nagios
1.下載提取Nagios核心
cd ~
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.0.tar.gz
tar -xzf nagios*.tar.gz
cd nagios-4.2.0
2.編譯nagios
./configure --with-nagios-group=nagios --with-command-group=nagcmd
make all
sudo make install
sudo make install-commandmode
sudo make install-init
sudo make install-config
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
並將evenhandler目錄復制到nagios目錄中:
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
3.安裝Nagios插件
下載提取nagios插件:
cd ~
wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
tar -xzf nagios-plugins*.tar.gz
cd nagios-plugin-2.1.2/
以下命令安裝nagios插件:
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make
make install
4.配置nagios
安裝階段完成後,您可以在/ usr / local / nagios /中找到Nagios的默認配置。
我們將配置Nagios和Nagios聯系人。
使用vim編輯默認的nagios配置:
vim /usr/local/nagios/etc/nagios.cfg
取消註釋線路51為主機監視器配置。
cfg_dir=/usr/local/nagios/etc/servers
保存並退出。
添加名為servers的新文件夾:
mkdir -p /usr/local/nagios/etc/servers
可以在contact.cfg文件中配置Nagios聯系人。 打開它使用:
vim /usr/local/nagios/etc/objects/contacts.cfg
然後用您自己的電子郵件替換默認電子郵件。
四、配置Apache
1. 啟用Apache模塊
sudo a2enmod rewrite
sudo a2enmod cgi
您可以使用htpasswd命令為nagios Web界面配置用戶nagiosadmin:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
並輸入密碼
2. 啟用Nagios虛擬主機
sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/
3.啟動Apache和Nagios
service apache2 restart
service nagios start
當Nagios啟動時,您可能會看到以下錯誤:
Starting nagios (via systemctl): nagios.serviceFailed
cd /etc/init.d/
cp /etc/init.d/skeleton /etc/init.d/nagios
vim /etc/init.d/nagios
並添加以下代碼:
DESC="Nagios"
NAME=nagios
DAEMON=/usr/local/nagios/bin/$NAME
DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg"
PIDFILE=/usr/local/nagios/var/$NAME.lock
使其可執行並啟動Nagios:
chmod +x /etc/init.d/nagios
service apache2 restart
servuce nagios start
五、測試Nagios服務器
在我的情況下,請打開瀏覽器並訪問Nagios服務器ip: http : //192.168.126.130/nagios 。
Nagios用apache htpasswd登錄
用戶名默認為nagiosadmin
密碼就是你之前通過執行該 sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin 命令輸入的密碼
六、添加主機監控
在我的另外IP:192.168.126.128
連接我的另外主機
1. 連接到ubuntu主機
ssh [email protected]
2.安裝NRPE服務
sudo apt-get install nagios-nrpe-server nagios-plugins
3.配置NRPE
vim /etc/nagios/nrpe.cfg
並將nagios server IP 192.168.126.130添加到server_aaddress
server_address = 192.168.126.130
4.重新啟動NRPE
service nagios-nrpe-server restart
5.將Ubuntu主機添加到Nagios服務器
請連接到Nagios服務器:
ssh [email protected]
然後為/ usr / local / nagios / etc / servers /中的主機配置創建一個新文件。
vim /usr/local/nagios/etc/servers/ubuntu_host.cfg
添加如下內容:
# Ubuntu Host configuration file
define host {
use linux-server
host_name ubuntu_host
alias Ubuntu Host
address 192.168.1.10
register 1
}
define service {
host_name ubuntu_host
service_description PING
check_command check_ping!100.0,20%!500.0,60%
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
define service {
host_name ubuntu_host
service_description Check Users
check_command check_local_users!20!50
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
define service {
host_name ubuntu_host
service_description Local Disk
check_command check_local_disk!20%!10%!/
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
define service {
host_name ubuntu_host
service_description Check SSH
check_command check_ssh
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
define service {
host_name ubuntu_host
service_description Total Process
check_command check_local_procs!250!400!RSZDT
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
您可以在/usr/local/nagios/etc/objects/commands.cfg文件中找到許多check_command 。 如果您想添加更多的服務,如DHCP,POP等,請參閱
現在檢查配置:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
6.重新啟動所有服務
在Ubuntu主機上啟動NRPE服務:
service nagios-nrpe-server restart
...在Nagios服務器上,啟動Apache和Nagios:
service apache2 restart
service nagios restart
7.測試Ubuntu主機
從瀏覽器打開Nagios服務器,並查看受監控的ubuntu_host。
Ubuntu主機在受監控的主機上可用。
ubuntu16.04安裝配置nagios