您好,登錄后才能下訂單哦!
linux下有2大監控神器cacti+nagios,下面我把我自己搭建nagios的步驟記錄下來,以便以后需要的時候看。
首先安裝依賴包
#yum install -y httpd mysql mysql-devel mysql-server php php-mysql gcc gcc-c++ gblic gblic-devel gd gd-devel openssl-devel
添加nagios用戶,用戶組
#groupadd nagcmd
#useradd nagios
#usermod -a -G nagcmd nagios
#usermod -a -G nagcmd daemon(http的user)
下載nagios安裝包,解壓
開始編譯
#./configure --prefix=/etc/nagios \
>--with-nagios-user=nagios \
>--with-nagios-group=nagios \
>--enable-event-broker
#make all
#make install
#make install-init
#make install-commandmode
#make install-config
#make install-webconf(編譯安裝的httpd會出現錯誤)
安裝nagios-plugins
#./configure --with-nagios-user=nagios \
>--with-nagios-group=nagios \
>--with-mysql=/path/to/mysql(監控mysql必須添加此選項)
#make && make install
下面開始安裝nrpe
首先確定開發環境
#yum grouplist
確定有Development tools和Development Libraries
如果沒有就安裝
#yum groupinstall -y "Development tools" "Development Libraries"
開始安裝nrpe
#./configure --with-nagios-user=nagios \
>--with-nagios-group=nagios \
>--with-nrpe-user=nagios \
>--with-nrpe-group=nagios \
>--enable-command-args \
>--enable-ssl
#make all
#make install-plugin
服務器端不需要開始nrpe服務
下面開始配置客戶端
nrpe依賴于nagios-plugins,首先安裝nagios-plugins
#./configure --with-nagios-user=nagios \
>--with-nagios-group=nagios \
>--with-mysql=/path/to/mysql(監控mysql必須添加此選項)
#make && make instal
下面開始安裝nrpe
#./configure --with-nagios-user=nagios \
>--with-nagios-group=nagios \
>--with-nrpe-user=nagios \
>--with-nrpe-group=nagios \
>--enable-command-args \
>--enable-ssl
#make all
#make install-plugin
#make install-daemon(安裝守護進程)
#make install-daemon-config(安裝守護進程配置文件)
修改nrpe.cfg文件
找到allowed_hosts添加你的服務器的IP
啟動nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
下面就可以在服務器端定義主機,定義命令開始監控
定義命令
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$(-c表示在遠程執行命令)
}
定義主機
define host {
use linux-server
host_name webserver
alias web-server
address 192.168.0.4
}
定義服務
define service {
use linux-service
host_name webserver
service_description PING
check_command check_nrpe!check_ping
}
想要監控什么就在客戶端上定義命令,在服務器上填寫檢測內容就可以了
下面附上nrpe的啟動腳本
#!/bin/sh
#
# Source function library
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
elif [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/functions ]; then
. /etc/rc.d/functions
fi
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
NrpeBin=/usr/local/nagios/bin/nrpe
NrpeCfg=/usr/local/nagios/etc/nrpe.cfg
LockFile=/var/lock/subsys/nrpe
# See how we were called.
case "$1" in
start)
# Start daemons.
echo -n "Starting nrpe: "
daemon $NrpeBin -c $NrpeCfg -d
echo
touch $LockFile
;;
stop)
# Stop daemons.
echo -n "Shutting down nrpe: "
killproc nrpe
echo
rm -f $LockFile
;;
restart)
$0 stop
$0 start
;;
status)
status nrpe
;;
*)
echo "Usage: nrpe {start|stop|restart|status}"
exit 1
esac
exit 0
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。