標籤:分區 服務監控 ice 啟動 本地yum mon nrpe command 3.1
抓包: tcpdump 選項 過濾條件
協議分析軟體 : wireshark
搭建CA伺服器: CA
配置CA服務的過程:192.168.4.55 ca.tedu.cn tarena
1 部署認證簽發環境:/etc/pki/tls/openssl.conf
工作目錄
認證存放目錄
私密金鑰檔案名稱
根憑證檔案名稱
認證編號檔案
認證索引檔案
認證識別: 國家 省 城市 公司 部門
匹配策略:
2 建立私密金鑰檔案名稱: 命令 儲存目錄 檔案名稱
3 建立根憑證檔案名稱:命令 儲存目錄 檔案名稱
輸入:國家 省 城市 公司 部門 郵箱 主機名稱
4 共用根憑證檔案 : 使用的服務可以 httpd ftp nfs samba
5 用戶端測試並安裝根憑證檔案
++++++++++++++++++++++++++++++++++++++++++++
給網站伺服器簽發數位憑證檔案 192.168.4.53 www.tedu.cn
網站伺服器的配置:192.168.4.53
1 建立私密金鑰檔案: 命令 儲存目錄 檔案名稱
2 建立認證請求檔案: 命令 儲存目錄 檔案名稱
輸入:國家 省 城市 公司 部門 郵箱 主機名稱
3 提交認證請求檔案給CA伺服器
CA伺服器的配置:192.168.4.55
1 審核認證請求檔案 簽發數位憑證檔案: 命令 儲存目錄 檔案名稱
2 下發數位憑證檔案給網站伺服器
3 在網站伺服器上配置網站服務在運行時載入私密金鑰檔案和數位憑證檔案,並重啟網站服務。
4 在用戶端254 驗證配置。
+++++++++++++++++++++++++++++++++++++++
DBA 營運工程師 IDC監控
一、監控 : 監視 並 控制
二、監控對象:伺服器(網站 和 資料庫)
三、監控哪些資源?
網路流量: ethX (進 出 的流量)
硬體資源的使用方式:cpu 記憶體 儲存
服務運行狀態: 運行 停止 休眠 殭屍
作業系統運行情況: 進程數量 使用者數量
四、監控的手段?
使用命令查看運行情況: ping sar uptime free df
systemctl status 服務名 ps
ps aux | wc -l users
wc -l /etc/passwd
編寫監控指令碼 做監控 : shell python
搭建監控伺服器:對指定的主機做監控
Nagios Cacti Zabbix
++++++++++++++++++++++++++++++++++++++++
準備新伺服器 做監控伺服器:配置要求:
#setenforce 0
#systemctl stop firewalld ; systemctl disable firewalld ;
#配置本地yum源
#ip地址 192.168.4.56
+++++++++++++++++++++++++++++++++++++++++
A、搭建Nagios監控伺服器
一、部署Nagios服務運行環境
#yum -y install httpd php
#systemctl start httpd ; systemctl enable httpd
#vim /var/www/html/test.php
<?php
phpinfo();
?>
:wq
在宿主開啟瀏覽器訪問 網頁檔案
http://192.168.4.56/test.php
二、安裝Nagios軟體(源碼包)
2.1 安裝準備
]# rpm -q gcc gcc-c++ || yum -y install gcc gcc-c++
[[email protected] ~]# useradd nagios
[[email protected] ~]# groupadd nagcmd
[[email protected] ~]# usermod -G nagcmd nagios
2.2 安裝軟體包
#tar -zxf nagios-4.2.4.tar.gz
#cd nagios-4.2.4
[[email protected] nagios-4.2.4]# ./configure \
--with-nagios-user=nagios --with-nagios-group=nagcmd \
--with-command-user=nagios --with-command-group=nagcmd
[[email protected] nagios-4.2.4]# make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
make install-exfoliation
#ls /usr/local/nagios
bin etc libexec sbin share var
三、安裝監控外掛程式 (軟體開發人員編寫好的指令碼)
tar -zxf nagios-plugins-2.1.4.tar.gz
cd nagios-plugins-2.1.4
./configure
make
make install
#ls /usr/local/nagios/libexec/check_*
四、 啟動監控服務
4.1 啟動服務
#/etc/init.d/nagios status | start | stop |restart
#systemctl restart httpd
4.2 設定訪問監控頁面的使用者名稱和密碼
#sed -n ‘39p;52p‘ /etc/httpd/conf.d/nagios.conf
39 Alias /nagios "/usr/local/nagios/share" //定義目錄別名
52 AuthUserFile /usr/local/nagios/etc/htpasswd.users //使用者認證
[[email protected] libexec]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
[[email protected] libexec]#
[[email protected] libexec]# cat /usr/local/nagios/etc/htpasswd.users
nagiosadmin:$apr1$Qa.IkjEz$PXVWVX9efnwhnCyA4aqeH.
[[email protected] libexec]#
五、用戶端254主機 訪問監控伺服器查看監控資訊
URL: http://192.168.4.56/nagios
nagiosadmin
123456
- nagios 服務預設監控本機資源,資源如下:
CPU負載 check_load
系統登入使用者數量 check_users
網站服務運行狀態 check_http
PING check_ping
根分區空閑空間 check_disk
ssh服務 check_ssh
交換分區使用量 check_swap
系統總進程數量 check_procs
監控顯示狀態: ok warning unknown critical pending
正常 警告 監控配置錯誤 報錯 監控中
nagios服務的監控過程?
nagios服務運行時,調用監控外掛程式,並設定監控的閥值,分別是警告值和錯誤值。nagios服務把外掛程式擷取到的資料和設定的閥值比較,然後顯示監控狀態。
監控到的資料 < warning值 顯示 ok 狀態
監控到的資料 > warning值 and < critical值 顯示warning狀態
監控到的資料 > critical值 顯示 critical 狀態
顯示 unknown 狀態 表示nagios服務組態檔有問題。
顯示 pending 狀態 表示正在擷取被監控資源的資料
+++++++++++++++++++++++++++++++++++++++
B、配置Nagios監控伺服器
1 設定檔說明
#cd /usr/local/ngaios/etc
#ls
nagios.cfg 主設定檔 //ngios啟動時載入的檔案
29 cfg_file=/usr/local/nagios/etc/objects/commands.cfg
30 cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
31 cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
32 cfg_file=/usr/local/nagios/etc/objects/templates.cfg
33
34 # Definitions for monitoring the local (Linux) host
35 cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
resource.cfg 宏定義檔案 //設定ngios服務使用的變數
$USER1$=/usr/local/nagios/libexec
cgi.cfg //定義CGI檔案存取權限
#cd object
#ls
templates.cfg //定義監控模板設定檔
timeperiods.cfg //定義監控時間模板設定檔
contacts.cfg //定義接收警示郵件的設定檔
34: email [email protected]
commands.cfg //定義監控命令
define command {
command_name check_local_disk //命令名稱
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$ //監控外掛程式
}
localhost.cfg //監控本機設定檔
define host{ //定義監控主機
use linux-server //定義監控主機使用的模板
host_name localhost //定義主機
alias localhost //定義描述資訊 可選項
address 127.0.0.1 //被監控主機的ip 地址
}
define service { //定義監控主機資源
use local-service //監控資源使用的模板
host_name localhost //主機名稱
service_description root_paticion //設定監控資源顯示名稱
check_command check_local_disk!20%!10%!/ //調用的監控命令
}
如何驗證配置是否有錯誤?
]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
]# alias checknagios=‘/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg‘
vim ~/.bashrc
alias checknagios=‘/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg‘
:wq
2 監控外掛程式的使用
#cd /usr/local/nagios/libexec/
./外掛程式名 --help //查看外掛程式的協助資訊
CPU負載 check_load
系統登入使用者數量 check_users
網站服務運行狀態 check_http
PING check_ping
根分區空閑空間 check_disk (監控磁碟的空閑空間)
ssh服務 check_ssh
交換分區使用量 check_swap
系統總進程數量 check_procs
]# ./check_users -w 1 -c 2
]# ./check_users -w 10 -c 15
]# ./check_http -I 192.168.4.51
]# ./check_http -I 192.168.4.51 -p 8090
]# ./check_ssh -H 192.168.4.51
]# ./check_ssh -H 192.168.4.51 -p 22122
]# df -h
]# ./check_disk -w 50% -c 25% -p /boot
]# dd if=/dev/zero of=/boot/a.txt bs=1M count=250
]# ./check_disk -w 50% -c 25% -p /boot
]# ./check_disk -w 25% -c 10% -p /
]# ./check_procs -w 20 -c 21 -s R
]# ./check_procs -w 10 -c 11 -s Z (pid 0-65535)
]# ./check_procs -w 20 -c 21 -s S
]# ./check_procs -w 100 -c 101
]# ./check_load -w 0.5,1.0,1.5 -c 1.0,2.0,2.5
]# ./check_ping -H 192.168.4.51 -w 10,50% -c 15,75%
]# ./check_swap -w 50% -c 25%
]# ./check_tcp -H 192.168.4.51 -p 80
]# ./check_tcp -H 192.168.4.51 -p 3306
——————————————————————
監控主機的配置步驟:
1 定義監控命令 commands.cfg
2 建立監控主機的設定檔 vim ser51.cfg
3 在服務主機設定檔nagios.cfg 檔案裡 載入監控主機的設定檔ser51.cfg
4 檢查配置是否有錯誤 checknagios
5 重啟nagios監控服務
6 訪問監控頁面查看監控資訊
7 若監控項有警告狀態或嚴重錯誤狀態的 查看是否收到警示郵件
++++++++++++++++++++++++++++++++
監控本機配置?監控本機時,
監控本機引導分區的使用方式:空閑空間小於50% 警告 空閑空間小於25% 報錯,
修改監控本機登入使用者數量 警告值修改成1 錯誤值修改成2 ;
不監控原生交換分區的使用方式。
+++++++++++++++++++++++++++++++++
3 監控遠端主機 192.168.4.51
3.1 監控遠端主機的公有資源(各種服務 httpd mysql ssh )
vim commands.cfg
#monitor mysqld
define command {
command_name check_51_mysqld
command_line $USER1$/check_tcp -H 192.168.4.51 -p 3306
}
#monitor httpd
define command {
command_name check_51_httpd
command_line $USER1$/check_http -H 192.168.4.51 -p 8090
}
#monitor sshd
define command {
command_name check_51_sshd
command_line $USER1$/check_ssh -H 192.168.4.51
}
[[email protected] objects]#
[[email protected] objects]# cat ser51.cfg
define host{
use linux-server
host_name ser51
address 192.168.4.51
}
define service{
use local-service
host_name ser51
service_description httpd
check_command check_51_httpd
}
define service{
use local-service
host_name ser51
service_description mysqld
check_command check_51_mysqld
}
define service{
use local-service
host_name ser51
service_description sshd
check_command check_51_sshd
}
[[email protected] objects]#
[[email protected] etc]# grep ser51.cfg nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/ser51.cfg
#checknagios
#/etc/init.d/nagios restart
++++++++++++++++++++++++++++++++++++++
3.2 監控遠端主機的私人資源(系統運行情況)
磁碟使用量 登入使用者數量 進程數量
A、配置被監控端 51
1、安裝擷取私人資源的外掛程式 ,並使用外掛程式
]# tar -zxf nagios-plugins-2.1.4.tar.gz
]# cd nagios-plugins-2.1.4/
]# rpm -q gcc gcc-c++ || yum -y install gcc gcc-c++
]# ./configure && make && make install
]# ls /usr/local/nagios
/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /boot
/usr/local/nagios/libexec/check_users -w 1 -c 2
/usr/local/nagios/libexec/check_procs -w 10 -c 11 -s R
/usr/local/nagios/libexec/check_procs -w 5 -c 6 -s Z
/usr/local/nagios/libexec/check_procs -w 100 -c 101
2、運行nrpe服務
2.1 裝包
#rpm -q openssl openssl-devel
#yum -y install openssl-devel
#useradd nagios
]# tar -zxf nrpe-3.0.1.tar.gz
]# cd nrpe-3.0.1/
]# ./configure
]# make all
make install-daemon
make install-config
make install-init
make install-plugin
2.2 修改設定檔
]# vim /usr/local/nagios/etc/nrpe.cfg
98 allowed_hosts=127.0.0.1, 192.168.4.56
command[nrpe_51_users]=/usr/local/nagios/libexec/check_users -w 1 -c 2
command[nrpe_51_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[nrpe_51_boot]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /boot
command[nrpe_51_prun]=/usr/local/nagios/libexec/check_procs -w 10 -c 11 -s R
command[nrpe_51_pzbi]=/usr/local/nagios/libexec/check_procs -w 5 -c 6 -s Z
command[nrpe_51_psum]=/usr/local/nagios/libexec/check_procs -w 100 -c 101
2.3 啟動nrpe服務
]# systemctl enable nrpe ; systemctl start nrpe
]#netstat -utnalp | grep :5666
2.4 測試nrep服務配置
[[email protected] ~]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -p 5666 -c nrpe_51_users
USERS OK - 1 users currently logged in |users=1;1;2;0
[[email protected] ~]#
[[email protected] ~]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -p 5666 -c nrpe_51_prun
PROCS OK: 2 processes with STATE = R | procs=2;10;11;0;
[[email protected] ~]#
B、配置監控伺服器:192.168.4.56
1、安裝串連nrpe服務的外掛程式check_nrpe 並測試
#yum -y install openssl-devel
]# tar -zxf nrpe-3.0.1.tar.gz
]# cd nrpe-3.0.1/
]# ./configure
]# make all
]# make install-plugin
]#ls /usr/local/nagios/libexec/check_nrpe
[[email protected] nrpe-3.0.1]# /usr/local/nagios/libexec/check_nrpe -H 192.168.4.51 -p 5666 -c nrpe_51_users
USERS OK - 0 users currently logged in |users=0;1;2;0
[[email protected] nrpe-3.0.1]#
2、定義監控遠端主機私人資源的監控命令
vim commands.cfg
define command {
command_name check_51_user
command_line $USER1$/check_nrpe -H 192.168.4.51 -p 5666 -c nrpe_51_users
}
3、監控遠端主機時,調用定義的監控命令
vim ser51.cfg
define service{
use local-service
host_name ser51
service_description users
check_command check_51_user
}
:wq
4、配置nagios服務運行時,載入監控遠端主機的設定檔
s]# grep ser51.cfg /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/ser51.cfg
5、檢查配置並重啟nagios服務
#checknagios
#systemctl restart nagios
6、登入監控頁面查看監控資訊
+++++++++++++++++++++++++++++++++
4 配置監控警示(當被監控資源顯示的狀態是warning 或 critical 時,nagios服務會給指定的郵箱發郵件)
]# grep email /usr/local/nagios/etc/objects/contacts.cfg
email [email protected]
[[email protected] ~]# hostname
mon56
[[email protected] ~]#
36 vim /etc/hosts
127.0.0.1 mon56
37 systemctl restart postfix
38 grep nagios /etc/passwd
39 echo 123456 | passwd --stdin nagios
40 mail -s "test" nagios < /etc/hosts
41 su - nagios
42 mail
——————————————————————————————
部署nagios監控伺服器的步驟:
1 部署服務運行環境:yum -y install httpd php
2 安裝nagios軟體:安裝準備、 安裝軟體包、查看安裝目錄
/usr/local/nagios
3 安裝監控外掛程式: 解包 配置 編譯 安裝 查看是否安裝成功
/usr/local/nagios/libexec
4 啟動nagios監控服務:
重啟網站務/etc/httpd/conf.d/nagios.conf
設定訪問監控頁面的管理員nagiosadmin 密碼123456 啟動nagios監控服務
5 訪問管理頁面,查看監控資訊
6 設定檔說明:
#cd /usr/local/nagios/etc
#ls
nagios.cfg resource.cfg cgi.cfg
#cd /usr/local/nagios/etc/object
#ls
templates.cfg 監控主機 linux-server 監控資源 local-service
timeperiods.cfg 24x7
contacts.cfg email [email protected]
commands.cfg
define command {
command_name 命令名
command_line 外掛程式名 選項 參數
}
localhost.cfg
define host { }
define service { }
檢查設定檔是否與語法錯誤:
++++++++++++++++++++++++++++++
擴充知識:
配置nagios服務監控時,調用自訂監控指令碼(shell指令碼)
配置nagios服務使用簡訊的方式接收警示訊息。
配置nagios主機依賴監控
配置nagios服務依賴監控
配置nagios繪製監控映像
SECURITY 04: Nagios監控實戰 、 監控概述 、 Nagios監控服務