寫給本身 :linux運維,本身動手趟一遍php
目前愈來愈多的人都開始使用centos7了,就像win7超越xp同樣,新技術永遠是愈來愈讓人慢慢接受的。爲了快速布暑,所有使用yum安裝。mysql
環境linux
監控服務器:192.168.88.21ios
被監控客戶端:192.168.88.22sql
關閉防火牆(所有服務器)數據庫
#systemctl stop firewalld #systemctl disable firewalld #setenforce 0 #sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
更新時間同步(所有服務器)apache
#yum install ntpdate #ntpdate cn.pool.ntp.org #echo "*/5 * * * * /usr/sbin/ntpdate cn.pool.ntp.org" >>/var/spool/cron/root
安裝epel源(所有服務器)centos
#yum install epel-release
-----------------------------------------------------------------------
瀏覽器
服務器端安裝(192.168.88.21)bash
#yum install mariadb-server mariadb //默認數據庫 #yum install httpd php php-gd //apache+php環境 #yum install nagios nagios-plugins-all nagios-plugins-nrpe nrpe #systemctl start mariadb #mysql_secure_installation //初始化數據庫
設置nagios訪問用戶名和密碼,使用默認nagiosadmin和默認保存位置,省心
#htpasswd -c /etc/nagios/passwd nagiosadmin 回車,設置密碼
#systemctl start mariadb #systemctl start httpd #systemctl start nagios
登錄http://192.168.88.21/nagios/ 輸入以前設置的用戶名 nagiosadmin 及密碼,就能夠登入了。
----------------------------------------------------------------------
監控服務器端(192.168.88.21) 配置
添加nrpe的定義
#vi /etc/nagios/objects/commands.cfg
# 'check_nrpe' command definition define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ } # 'check_nrpe_memory' command definition define command{ command_name check_nrpe_memory command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_mem }
新建監控主機配置文件
#vi /etc/nagios/objects/hosts.cfg define host{ use linux-server host_name 192.168.88.22 alias 192.168.88.22 address 192.168.88.22 }
新建監控服務配置文件
#vi /etc/nagios/objects/services.cfg define service { use local-service host_name 192.168.88.22 service_description check-host-alive check_command check-host-alive } define service { use generic-service host_name 192.168.88.22 service_description Disk Partition check_command check_nrpe!check_disk } define service { use generic-service host_name 192.168.88.22 service_description load check_command check_nrpe!check_load } define service { use generic-service host_name 192.168.88.22 service_description memory check_command check_nrpe_memory } define service { use generic-service host_name 192.168.88.22 service_description swap check_command check_nrpe!check_swap }
#nagios -v /etc/nagios/nagios.cfg 檢測配置文件是否正確 #systemctl restart nagios 重啓一下 nagios
----------------------------------------------------------------------
監控客戶端安裝(192.168.88.22):
安裝被監控的插件及nrpe
#yum install nagios-plugins-nrpe nrpe nagios-plugins-all
配置nrpe
#vi /etc/nagios/nrpe.cfg allowed_hosts=127.0.0.1,192.168.88.21 #容許被服務器監控 command[check_disk]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% command[check_swap]=/usr/lib64/nagios/plugins/check_swap -w 20% -c 10% command[check_iostat]=/usr/lib64/nagios/plugins/check_iostat -d sda -w 1000 -c 2000 command[check_mem]=/usr/lib64/nagios/plugins/check_mem -w 80 -c 70 #echo 'nrpe:192.168.88.21' >>/etc/hosts.allow
check_iostat所須要命令
#yum install sysstat bc
check_mem和check_iostat這二個檢測插件,
請看附件下載,並解壓到/usr/lib64/nagios/plugins 目錄下
記得加執行權限
#chmod +x check_iostat check_mem
啓動nrpe
#systemctl start nrpe
---------------------------------------------------
打開瀏覽器,查看一下,是否能正常監控到數據了: