抓包: 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
在宿主打開浏覽器通路 網頁檔案
<a href="http://192.168.4.56/test.php">http://192.168.4.56/test.php</a>
二、安裝Nagios軟體(源碼包)
2.1 安裝準備
]# rpm -q gcc gcc-c++ || yum -y install gcc gcc-c++
[root@mon56 ~]# useradd nagios
[root@mon56 ~]# groupadd nagcmd
[root@mon56 ~]# usermod -G nagcmd nagios
2.2 安裝軟體包
#tar -zxf nagios-4.2.4.tar.gz
#cd nagios-4.2.4
[root@mon56 nagios-4.2.4]# ./configure \
--with-nagios-user=nagios --with-nagios-group=nagcmd \ --with-command-user=nagios --with-command-group=nagcmd [root@mon56 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 //使用者認證
[root@mon56 libexec]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
[root@mon56 libexec]#
[root@mon56 libexec]# cat /usr/local/nagios/etc/htpasswd.users
nagiosadmin:$apr1$Qa.IkjEz$PXVWVX9efnwhnCyA4aqeH.
[root@mon56 libexec]#
五、用戶端254主機 通路監控伺服器檢視監控資訊
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
templates.cfg //定義監控模闆配置檔案
timeperiods.cfg //定義監控時間模闆配置檔案
contacts.cfg //定義接收報警郵件的配置檔案
34: email nagios@localhost
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'
2 監控插件的使用
#cd /usr/local/nagios/libexec/
./插件名 --help //檢視插件的幫助資訊
根分區空閑空間 check_disk (監控磁盤的空閑空間)
]# ./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 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
command_name check_51_mysqld
command_line $USER1$/check_tcp -H 192.168.4.51 -p 3306
#monitor httpd
command_name check_51_httpd
command_line $USER1$/check_http -H 192.168.4.51 -p 8090
#monitor sshd
command_name check_51_sshd
command_line $USER1$/check_ssh -H 192.168.4.51
[root@mon56 objects]#
[root@mon56 objects]# cat ser51.cfg
define host{
use linux-server
host_name ser51
address 192.168.4.51
define service{
use local-service
service_description httpd
check_command check_51_httpd
service_description mysqld
check_command check_51_mysqld
service_description sshd
check_command check_51_sshd
[root@mon56 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/
]# ./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-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服務配置
[root@PC51 ~]# /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
[root@PC51 ~]#
[root@PC51 ~]# /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;
B、配置監控伺服器:192.168.4.56
1、安裝連接配接nrpe服務的插件check_nrpe 并測試
]# make install-plugin
]#ls /usr/local/nagios/libexec/check_nrpe
[root@mon56 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
[root@mon56 nrpe-3.0.1]#
2、定義監控遠端主機私有資源的監控指令
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
use local-service
service_description users
check_command check_51_user
4、配置nagios服務運作時,加載監控遠端主機的配置檔案
s]# grep ser51.cfg /usr/local/nagios/etc/nagios.cfg
5、檢查配置并重新開機nagios服務
#systemctl restart nagios
6、登入監控頁面檢視監控資訊
4 配置監控報警(當被監控資源顯示的狀态是warning 或 critical 時,nagios服務會給指定的郵箱發郵件)
]# grep email /usr/local/nagios/etc/objects/contacts.cfg
email nagios@localhost
[root@mon56 ~]# hostname
mon56
[root@mon56 ~]#
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
templates.cfg 監控主機 linux-server 監控資源 local-service
timeperiods.cfg 24x7
contacts.cfg email nagios@localhost
commands.cfg
define command {
command_name 指令名
command_line 插件名 選項 參數
localhost.cfg
define host { }
define service { }
檢查配置檔案是否與文法錯誤:
++++++++++++++++++++++++++++++
擴充知識:
配置nagios服務使用短信的方式接收報警消息。
配置nagios主機依賴監控
配置nagios服務依賴監控
配置nagios繪制監控圖像
本文轉自sweak_h 51CTO部落格,原文連結:http://blog.51cto.com/13478354/2067898,如需轉載請自行聯系原作者