第一章 網站可用性
所謂網站可用性(availability)也即網站正常運行時間的百分比,業界用N個9來量化可用性,最常說的就是類似4個9(也就是99.99%)的可用性。
描述 | 通俗叫法 | 可用性級別 | 年度停機時間 |
---|---|---|---|
基本可用性 | 2個9 | 99% | 87.6小時 |
較高可用性 | 3個9 | 99.9% | 8.8小時 |
具有故障自動回覆能力的可用性 | 4個9 | 99.99% | 53分鐘 |
極高可用性 | 5個9 | 99.999% | 5分鐘 |
第二章 服務器的硬件監控
- 【溫度】
- 【風扇轉速】
- 【電壓電流】
- 【遠程管理卡】
- 【ipmitools】命令監控
yum -y install OpenIPMI ipmitool
[root@KVM ~]# ipmitool sdr type Temperature
Temp | 01h | ns | 3.1 | Disabled
Temp | 02h | ns | 3.2 | Disabled
Temp | 05h | ns | 10.1 | Disabled
Temp | 06h | ns | 10.2 | Disabled
Ambient Temp | 0Eh | ok | 7.1 | 22 degrees C
Planar Temp | 0Fh | ns | 7.1 | Disabled
IOH THERMTRIP | 5Dh | ns | 7.1 | Disabled
CPU Temp Interf | 76h | ns | 7.1 | Disabled
Temp | 0Ah | ns | 8.1 | Disabled
Temp | 0Bh | ns | 8.1 | Disabled
Temp | 0Ch | ns | 8.1 | Disabled
第三章 系統監控
1. CPU監控
【lscpu】查看cpu信息
[root@ansible01-61 ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
【uptime】查看系統負載
[root@m01 ~]# uptime
09:23:50 up 33 min, 1 user, load average: 0.00, 0.01, 0.03
【top】查看系統運行情況
top - 19:21:07 up 36 min, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 92 total, 1 running, 91 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 999936 total, 588488 free, 98748 used, 312700 buff/cache
KiB Swap: 1048572 total, 1048572 free, 0 used. 731792 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 125396 3960 2408 S 0.0 0.4 0:01.41 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.10 ksoftirqd/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0
6 root 20 0 0 0 0 S 0.0 0.0 0:00.13 kworker/u256:0
7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root 20 0 0 0 0 S 0.0 0.0 0:00.30 rcu_sched
10 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/0
12 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 khelper
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
14 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khungtaskd
16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback
【htop】top升級版
[root@ansible01-61 ~]# htop
CPU[|| 1.2%] Tasks: 28, 35 thr; 1 running
Mem[||||||||||||||||||||||||||||||||||||||||| 127M/976M] Load average: 0.00 0.01 0.05
Swp[ 0K/1024M] Uptime: 00:47:36
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
1415 root 20 0 540M 16436 5784 S 0.0 1.6 0:00.00 /usr/bin/python -Es /usr/sbin/tuned -l -P
1418 root 20 0 540M 16436 5784 S 0.0 1.6 0:00.00 /usr/bin/python -Es /usr/sbin/tuned -l -P
1420 root 20 0 540M 16436 5784 S 0.0 1.6 0:00.34 /usr/bin/python -Es /usr/sbin/tuned -l -P
1425 root 20 0 540M 16436 5784 S 0.0 1.6 0:00.00 /usr/bin/python -Es /usr/sbin/tuned -l -P
1215 root 20 0 540M 16436 5784 S 0.0 1.6 0:00.51 /usr/bin/python -Es /usr/sbin/tuned -l -P
2. 內存監控
【free -h】
[root@ansible01-61 ~]# free -h
total used free shared buff/cache available
Mem: 976M 96M 574M 6.7M 305M 714M
Swap: 1.0G 0B 1.0G
3. 磁盤監控
【df -h】
[root@ansible01-61 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 48G 1.8G 47G 4% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 133M 882M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
【dd】測試寫速度
[root@m01 ~]# dd if=/dev/zero of=test.data bs=100M count=2
2+0 records in
2+0 records out
209715200 bytes (210 MB) copied, 0.99772 s, 210 MB/s
【hdparm -t /dev/sda】測試讀速度
[root@ansible01-61 ~]# hdparm -t /dev/sda1
/dev/sda1:
Timing buffered disk reads: 1024 MB in 1.44 seconds = 710.31 MB/sec
【iotop】
[root@ansible01-61 ~]# iotop
Total DISK READ : 0.00 B/s | Total DISK WRITE : 0.00 B/s
Actual DISK READ: 0.00 B/s | Actual DISK WRITE: 0.00 B/s
TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND
1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd --switched-root --system --deserialize 21
2 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthreadd]
3 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksoftirqd/0]
4 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/0:0]
6 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/u256:0]
5. 網絡監控
【iftop】實時顯示網卡流量
[root@m01 ~]# iftop -i eth0
【nethogs】
[root@m01 ~]# yum -y install iftop nethogs
6. TCP監控
【ss/netstat】
[root@ansible01-61 ~]# ss -ant
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
【lsof】
7. 進程監控
[root@ansible01-61 ~]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 18:44 ? 00:00:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
root 2 0 0 18:44 ? 00:00:00 [kthreadd]
root 3 2 0 18:44 ? 00:00:00 [ksoftirqd/0]
root 4 2 0 18:44 ? 00:00:00 [kworker/0:0]
8. 服務監控
第四章 一切皆可監控
監控項 | 說明 |
---|---|
硬件監控: | 1通過遠程控制卡:DEll的IDRAC,HP的ILO和IBM的IMM等。2使用IPMI來完成物理設備的監控工作。通長必須要監控的就是溫度、硬盤故障等。3路由器,交換機(端口,日誌),打印機,windows等 |
系統監控: | cpu,內存,硬盤使用率,硬盤IO,系統負載,進程數 |
服務監控: | apache,nginx,php-fpm,MySQL,memcache,redis,Tomcat,JVM,TCP連接數 |
性能監控: | 網站性能,服務器性能,數據庫性能,存儲性能 |
日誌監控: | 系統會產生系統日誌,應用程序會有應用的訪問日誌、錯誤日誌,服務有運行日誌等,可以使用ELK來進行日誌監控 |
安全監控: | 1nginx+Lua編寫了一個WAF通過kibana可以圖形化的展示不同的攻擊類型的統計。2用戶登錄數,passwd文件變化,本地所有文件改動 |
網絡監控: | 端口,web(URL),DB,ping包,IDC帶寬網絡流量,網絡流出流出速率,網絡入流量,網絡出流量,網絡使用率,SMTP |
業務監控: | 用戶登錄失敗次數,用戶登錄網站次數,輸入驗證碼失敗次數,網絡連接數,電商網站訂單,支付交易的數量,總訂單數,平均訂單數 |
流量分析: | pv,uv,併發連接數,獨立IP 數 |
第五章 zabbix監控工具服務端安裝
1. 安裝zabbix源和依賴包
axel http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-agent-3.2.1-1.el7.x86_64.rpm
axel http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-get-3.2.1-1.el7.x86_64.rpm
axel http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-java-gateway-3.2.1-1.el7.x86_64.rpm
axel http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-proxy-mysql-3.2.1-1.el7.x86_64.rpm
axel http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-proxy-pgsql-3.2.1-1.el7.x86_64.rpm
axel http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-sender-3.2.1-1.el7.x86_64.rpm
axel http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-server-mysql-3.2.1-1.el7.x86_64.rpm
axel http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-web-3.2.1-1.el7.noarch.rpm
axel http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-web-japanese-3.2.1-1.el7.noarch.rpm
axel http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-web-mysql-3.2.1-1.el7.noarch.rpm
axel http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-web-pgsql-3.2.1-1.el7.noarch.rpm
yum install zabbix-agent-3.2.1-1.el7.x86_64.rpm zabbix-get-3.2.1-1.el7.x86_64.rpm zabbix-java-gateway-3.2.1-1.el7.x86_64.rpm zabbix-proxy-mysql-3.2.1-1.el7.x86_64.rpm zabbix-sender-3.2.1-1.el7.x86_64.rpm zabbix-server-mysql-3.2.1-1.el7.x86_64.rpm zabbix-web-3.2.1-1.el7.noarch.rpm zabbix-web-japanese-3.2.1-1.el7.noarch.rpm zabbix-web-mysql-3.2.1-1.el7.noarch.rpm
yum install -y httpd mariadb
編譯安裝(可忽略)
編譯安裝zabbix
同時安裝server和agent,並支持將數據放入mysql數據中,可使用類似如下配置命令:
./configure –enable-server –enable-agent –with-mysql –enable-ipv6 –with-net-snmp –with-libcurl –with-ssh2如果僅安裝server,並支持將數據放入MySQL數據中,可使用類似如下配置命令;
./configure –enable-server –with-mysql –with-net-snmp –with-libcurl如果僅安裝proxy,並支持將數據放入MySQL數據中,可使用類似如下配置命令;
./configure –prefix=/usr –enable-proxy –with-net-snmp –with-mysql –with-ssh2如果僅安裝agent,可使用類似如下配置命令;
./configure –enable-agent而後編譯安裝zabbix即可;
#make && make install
2. 配置MySQL
/etc/init.d/mysqld start
mysql -uroot -e"create database zabbix character set utf8 collate utf8_bin;"
mysql -e "grant all on zabbix.* to 'zbxuser'@'localhost' identified by 'zbxpass';"
mysql -e "flush privileges;"
3. 導入數據到MySQL
zcat create.sql.gz |mysql -uzbxuser -pzbxpass zabbix
4. 配置PHP修改PHP最大配置
sed -i 's#max_execution_time = 30#max_execution_time = 300#;s#max_input_time = 60#max_input_time = 300#;s#post_max_size = 8M#post_max_size = 16M#;910a date.timezone = Asia/Shanghai' /etc/php.ini
5. 配置zabbix配置文件數據庫用戶密碼
sed -i '/DBUser=/cDBUser=zbxuser' /etc/zabbix/zabbix_server.conf
sed -i '115a DBPassword=zbxpass' /etc/zabbix/zabbix_server.conf
6. 配置zabbix網頁配置
cp -R /usr/share/zabbix/ /var/www/html/
chmod -R 755 /etc/zabbix/web
chown -R apache.apache /etc/zabbix/web
echo "ServerName 127.0.0.1:80">>/etc/httpd/conf/httpd.conf
7. 服務啓動順序
/etc/init.d/mysqld start
systemctl start httpd.service
systemctl start zabbix-server.service
8. 查看網頁
10.0.0.61/zabbix #這裏你的服務器IP地址
第六章 zabbix客戶端安裝
1. 下載zabbix-agent包
rsync -avP root@172.16.1.61:/root/zabbix-agent-3.2.6-1.el7.x86_64.rpm /root/
yum localinstall zabbix-agent-3.2.6-1.el7.x86_64.rpm
2. 修改服務端IP地址
sed -i 's#Server=127.0.0.1#Server=172.16.1.61#' /etc/zabbix/zabbix_agentd.conf
sed -i '/serverActive/cServerActive=172.16.1.61' /etc/zabbix/zabbix_agentd.conf
3. 啓動agent
systemctl start zabbix-agent.service
systemctl status zabbix-agent.service
第七章 解決網頁顯示中文亂碼問題
yum install -y wqy-microhei-fonts
\cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
第八章 自定義監控修改配置文件
1. 客戶端執行
sed -i '294a UserParameter=login_user,who|wc -l' /etc/zabbix/zabbix_agentd.conf
systemctl restart zabbix-agent
2. 服務端執行
zabbix_get -s 172.16.1.7 -p 10050 -k "login_user"
3. 示例自定義監控
[root@web01 zabbix_agentd.d]# pwd
/etc/zabbix/zabbix_agentd.d
[root@web01 zabbix_agentd.d]# cat userparameter_nginx.conf
UserParameter=nginx_active,curl -s 127.0.0.1/nginx_status|awk '/Active/ {print $NF}'
UserParameter=nginx_accepts,curl -s 127.0.0.1/nginx_status|awk 'NR==3 {print $1}'
UserParameter=nginx_handled,curl -s 127.0.0.1/nginx_status|awk 'NR==3 {print $2}'
UserParameter=nginx_requests,curl -s 127.0.0.1/nginx_status|awk 'NR==3 {print $3}'
UserParameter=nginx_reading,curl -s 127.0.0.1/nginx_status|awk 'NR==4 {print $2}'
UserParameter=nginx_writing,curl -s 127.0.0.1/nginx_status|awk 'NR==4 {print $4}'
UserParameter=nginx_waiting,curl -s 127.0.0.1/nginx_status|awk 'NR==4 {print $6}'
[root@web01 zabbix_agentd.d]# /etc/init.d/zabbix-agent restart
######status#########
server {
listen 127.0.0.1:80;
stub_status on;
access_log off;
}
第九章 web頁面配置