5.1~5.9 監控 Linux 系統狀態
監控 CPU 的命令
w 查看系統負載
[root@arslinux-01 ~]# w 20:13:49 up 1 min, 1 user, load average: 1.26, 0.80, 0.31 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 192.168.194.1 20:13 5.00s 0.09s 0.01s w
1分鐘內,5分鐘內,15分鐘內
負載值:平均時間內,有多少個活動的進程。數字越大越忙。
正在使用 CPU 或等待 CPU 都屬於活動的進程,無論在排隊還是正在使用都屬於活動進程
uptime 查看系統負載
[root@arslinux-01 ~]# uptime 20:25:29 up 2 min, 1 user, load average: 0.82, 0.67, 0.27
top 動態查看系統狀態
可以讓進程按從高到低順序自動排列,默認按 CPU 使用率排列,同樣可以顯示系統負載
[root@arslinux-01 ~]# top top - 20:28:40 up 5 min, 1 user, load average: 0.05, 0.37, 0.23 Tasks: 142 total, 2 running, 140 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 995896 total, 257656 free, 569336 used, 168904 buff/cache KiB Swap: 1999868 total, 1999868 free, 0 used. 254360 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 25 root 20 0 0 0 0 S 0.3 0.0 0:00.76 kworker/0:1 2947 root 20 0 0 0 0 S 0.3 0.0 0:00.05 xfsaild/sda3 1 root 20 0 125448 3896 2568 S 0.0 0.4 0:02.93 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.29 ksoftirqd/0 4 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 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 R 0.0 0.0 0:01.32 rcu_sched 10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain 11 root rt 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0 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
CPU 使用率 = 100% - id值
RES 進程佔用物理內存的大小
top 命令不僅要關注 Tasks 、%CPU 列,同樣要關注下方 %CPU、%MEM、RES 列
-- 每 3 秒刷新一次
-- 按 M 鍵更改未按內存使用率大小排列
-- 按數字 1 可以查看所有 CPU 的使用率詳情(多核)
[root@arslinux-01 ~]# top top - 20:33:42 up 10 min, 1 user, load average: 0.00, 0.14, 0.17 Tasks: 142 total, 1 running, 141 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.3 us, 0.7 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 995896 total, 255580 free, 571348 used, 168968 buff/cache KiB Swap: 1999868 total, 1999868 free, 0 used. 252320 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 7479 mysql 20 0 1302780 454812 6204 S 0.3 45.7 0:05.31 mysqld 7148 root 20 0 573920 17084 6008 S 0.0 1.7 0:00.57 tuned 5983 polkitd 20 0 612228 14172 4680 S 0.0 1.4 0:00.10 polkitd 5974 root 20 0 474244 8900 6660 S 0.0 0.9 0:00.40 NetworkManager 6000 root 20 0 301040 6480 5108 S 0.0 0.7 0:01.36 vmtoolsd 5995 root 20 0 99668 6104 4496 S 0.0 0.6 0:00.05 VGAuthService 7687 root 20 0 158864 5548 4212 S 0.0 0.6 0:00.19 sshd 7273 root 20 0 229608 4976 1232 S 0.0 0.5 0:00.25 php-fpm 7319 php-fpm 20 0 229548 4752 1008 S 0.0 0.5 0:00.00 php-fpm 7320 php-fpm 20 0 229548 4752 1008 S 0.0 0.5 0:00.00 php-fpm 7282 php-fpm 20 0 229548 4748 1008 S 0.0 0.5 0:00.00 php-fpm 7283 php-fpm 20 0 229548 4748 1008 S 0.0 0.5 0:00.00 php-fpm 7284 php-fpm 20 0 229548 4748 1008 S 0.0 0.5 0:00.00 php-fpm 7286 php-fpm 20 0 229548 4748 1008 S 0.0 0.5 0:00.00 php-fpm 7289 php-fpm 20 0 229548 4748 1008 S 0.0 0.5 0:00.00 php-fpm 7291 php-fpm 20 0 229548 4748 1008 S 0.0 0.5 0:00.00 php-fpm
按 q 退出
top -bn1靜態顯示所有進程情況,也是按 CPU 百分比排序
[root@arslinux-01 ~]# top -bn1 top - 20:36:02 up 12 min, 1 user, load average: 0.00, 0.09, 0.15 Tasks: 142 total, 1 running, 141 sleeping, 0 stopped, 0 zombie %Cpu(s): 5.9 us, 5.9 sy, 0.0 ni, 88.2 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 995896 total, 256044 free, 570848 used, 169004 buff/cache KiB Swap: 1999868 total, 1999868 free, 0 used. 252804 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 7745 root 20 0 161880 2164 1552 R 6.2 0.2 0:00.02 top 1 root 20 0 125448 3896 2568 S 0.0 0.4 0:02.94 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.36 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 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:01.45 rcu_sched 10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain 11 root rt 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0 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
(內容過多不全顯示)
-- 靜態顯示進程信息方便與在腳本里使用
cat /proc/cpuinfo 查看機器有幾個CPU
[root@arslinux-01 ~]# cat /proc/cpuinfo processor: 0 vendor_id: GenuineIntel cpu family: 6 model: 78 model name: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz stepping: 3 microcode: 0xc6 cpu MHz: 2399.999 cache size: 3072 KB physical id: 0 siblings: 1 core id: 0 cpu cores: 1 apicid: 0 initial apicid: 0 fpu: yes fpu_exception: yes cpuid level: 22 wp: yes flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt dtherm arat pln pts hwp hwp_notify hwp_act_window hwp_epp spec_ctrl intel_stibp bogomips: 4799.99 clflush size: 64 cache_alignment: 64 address sizes: 42 bits physical, 48 bits virtual power management:
lscpu查看CPU的信息
[root@arslinux-01 ~]# 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 座: 1 NUMA 節點: 1 廠商 ID: GenuineIntel CPU 系列: 6 型號: 78 型號名稱: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz 步進: 3 CPU MHz: 2399.999 CPU max MHz: 0.0000 CPU min MHz: 0.0000 BogoMIPS: 4799.99 超管理器廠商: VMware 虛擬化類型: 完全 L1d 緩存: 32K L1i 緩存: 32K L2 緩存: 256K L3 緩存: 3072K NUMA 節點0 CPU: 0 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt dtherm arat pln pts hwp hwp_notify hwp_act_window hwp_epp spec_ctrl intel_stibp
監控內存的命令
free 查看內存和 swap 使用情況(默認以 kb 爲單位)
[root@arslinux-01 ~]# free total used free shared buff/cache available Mem: 995896 570492 256152 7864 169252 253164 Swap: 1999868 0 1999868
free -m 按 M 爲單位查看系統內存相關信息
[root@arslinux-01 ~]# free -m total used free shared buff/cache available Mem: 972 557 250 7 165 247 Swap: 1952 0 1952
free -h 自動以單位顯示內存信息
[root@arslinux-01 ~]# free -h total used free shared buff/cache available Mem: 972M 557M 250M 7.7M 165M 247M Swap: 1.9G 0B 1.9G
free -b 以 B 爲單位顯示內存信息
[root@arslinux-01 ~]# free -b total used free shared buff/cache available Mem: 1019797504 584146944 262340608 8052736 173309952 259309568 Swap: 2047864832 0 2047864832
只需關注 available,available = free + buff/cache未使用的部分
內存不夠用時,swap 會將內存裏的內容交換到磁盤分區裏
buffer:從 CPU 產生,即將寫入到磁盤裏去的那部分數據
cached:先從磁盤裏讀出來,然後臨時存到內存裏的那部分數據
手動增加 swap
磁盤上模擬出 1G 空間
dd if=/dev/zero of=/bigfile bs=100M count=10
of 目標文件,bs 單個塊大小,count 塊數量
[root@arslinux-01 ~]# dd if=/dev/zero of=/bigfile bs=100M count=10 記錄了10+0 的讀入 記錄了10+0 的寫出 1048576000字節(1.0 GB)已複製,7.92899 秒,132 MB/秒
[root@arslinux-01 ~]# du -sh /bigfile 1000M/bigfile
[root@arslinux-01 ~]# mkswap /bigfile 正在設置交換空間版本 1,大小 = 1023996 KiB 無標籤,UUID=0f334ed6-5c2b-49e6-a226-8afd4989123b [root@arslinux-01 ~]# chmod 600 /bigfile [root@arslinux-01 ~]# swapon /bigfile [root@arslinux-01 ~]# free total used free shared buff/cache available Mem: 995896 571836 167716 7896 256344 249096 Swap: 3023864 0 3023864
監控磁盤的命令
iostat 監控磁盤(需要安裝 sysstat )
[root@arslinux-01 ~]# iostat Linux 3.10.0-957.el7.x86_64 (arslinux-01) 2019年06月10日 _x86_64_(1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 0.39 0.00 1.23 0.02 0.00 98.36 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 1.79 43.21 294.17 151445 1031077 sdb 0.07 2.63 0.00 9212 0 scd0 0.01 0.29 0.00 1028 0 dm-0 0.02 0.59 0.00 2072 0
iostat 1 每隔1秒查詢一次
[root@arslinux-01 ~]# iostat 1 Linux 3.10.0-957.el7.x86_64 (arslinux-01) 2019年06月10日 _x86_64_(1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 0.38 0.00 1.21 0.02 0.00 98.39 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 1.75 42.07 286.38 151481 1031133 sdb 0.07 2.56 0.00 9212 0 scd0 0.00 0.29 0.00 1028 0 dm-0 0.02 0.58 0.00 2072 0 avg-cpu: %user %nice %system %iowait %steal %idle 0.00 0.00 0.00 0.00 0.00 100.00 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 0.00 0.00 0.00 0 0 sdb 0.00 0.00 0.00 0 0 scd0 0.00 0.00 0.00 0 0 dm-0 0.00 0.00 0.00 0 0 avg-cpu: %user %nice %system %iowait %steal %idle 1.00 0.00 1.00 0.00 0.00 98.00 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 0.00 0.00 0.00 0 0 sdb 0.00 0.00 0.00 0 0 scd0 0.00 0.00 0.00 0 0 dm-0 0.00 0.00 0.00 0
iostat -d 只查看 device 相關信息
[root@arslinux-01 ~]# iostat -d 1 Linux 3.10.0-957.el7.x86_64 (arslinux-01) 2019年06月10日 _x86_64_(1 CPU) Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 1.69 40.65 276.72 151481 1031220 sdb 0.07 2.47 0.00 9212 0 scd0 0.00 0.28 0.00 1028 0 dm-0 0.02 0.56 0.00 2072 0 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 0.00 0.00 0.00 0 0 sdb 0.00 0.00 0.00 0 0 scd0 0.00 0.00 0.00 0 0 dm-0 0.00 0.00 0.00 0 0 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 0.00 0.00 0.00 0 0 sdb 0.00 0.00 0.00 0 0 scd0 0.00 0.00 0.00 0 0 dm-0 0.00 0.00 0.00 0 0
iostat -dx 1 加上 x 查看到的信息更全
[root@arslinux-01 ~]# iostat -dx 1 Linux 3.10.0-957.el7.x86_64 (arslinux-01) 2019年06月10日 _x86_64_(1 CPU) Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda 0.00 0.01 0.96 0.70 39.75 270.58 375.46 0.02 11.54 0.82 26.21 1.13 0.19 sdb 0.00 0.00 0.07 0.00 2.42 0.00 70.59 0.00 0.51 0.51 0.00 0.37 0.00 scd0 0.00 0.00 0.00 0.00 0.27 0.00 114.22 0.00 1.56 1.56 0.00 1.22 0.00 dm-0 0.00 0.00 0.02 0.00 0.54 0.00 48.19 0.00 0.50 0.50 0.00 0.35 0.00 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 sdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 scd0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 dm-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 sdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 scd0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 dm-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
關注 %util,磁盤的使用率
iostat -d 1 2 顯示 2 次
[root@arslinux-01 ~]# iostat -d 1 2 Linux 3.10.0-957.el7.x86_64 (arslinux-01) 2019年06月10日 _x86_64_(1 CPU) Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 1.58 38.07 259.16 151481 1031222 sdb 0.07 2.32 0.00 9212 0 scd0 0.00 0.26 0.00 1028 0 dm-0 0.02 0.52 0.00 2072 0 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 0.00 0.00 0.00 0 0 sdb 0.00 0.00 0.00 0 0 scd0 0.00 0.00 0.00 0 0 dm-0 0.00 0.00 0.00 0 0
iotop 查看進程使用磁盤的信息,動態顯示,按IO使用率大小排序(安裝 iotop)
vmstat 綜合顯示 CPU、內存、磁盤的信息(用法和 iostat 類似)
[root@arslinux-01 ~]# vmstat 1 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 2 0 0 146048 116 273320 0 0 40 237 63 148 1 1 98 0 0 0 0 0 146048 116 273320 0 0 0 0 35 79 0 1 99 0 0 0 0 0 146048 116 273320 0 0 0 0 50 90 0 0 100 0 0 1 0 0 146048 116 273320 0 0 0 0 33 73 0 0 100 0 0 0 0 0 146048 116 273320 0 0 0 0 43 78 0 1 98 1 0 ^C [root@arslinux-01 ~]# vmstat 1 3 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 2 0 0 146196 116 273320 0 0 40 236 63 148 1 1 98 0 0 0 0 0 146164 116 273320 0 0 0 0 38 84 0 0 100 0 0 0 0 0 146164 116 273320 0 0 0 0 50 91 0 1 99 0 0
CPU ——> id
memory——>swpd 非零 或 si so 非零(si = swap in從swap進到內存,so = swap out)
bi 磁盤讀,bo 磁盤寫
r = run,b =block
wa =wait 等待 CPU 的百分比
關注:r、b、si、so、bi、bo、id、wa
監控網卡的命令
sar 監控網卡流量(同樣由 sysstat 包安裝)
[root@arslinux-01 ~]# sar -n DEV 1 3 Linux 3.10.0-957.el7.x86_64 (arslinux-01) 2019年06月10日 _x86_64_(1 CPU) 22時31分30秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22時31分31秒 ens37 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時31分31秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時31分31秒 ens33 1.01 0.00 0.06 0.00 0.00 0.00 0.00 22時31分31秒 ens38 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時31分31秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22時31分32秒 ens37 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時31分32秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時31分32秒 ens33 1.01 1.01 0.06 0.57 0.00 0.00 0.00 22時31分32秒 ens38 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時31分32秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 22時31分33秒 ens37 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時31分33秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 22時31分33秒 ens33 1.00 1.00 0.06 0.56 0.00 0.00 0.00 22時31分33秒 ens38 0.00 0.00 0.00 0.00 0.00 0.00 0.00 平均時間: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 平均時間: ens37 0.00 0.00 0.00 0.00 0.00 0.00 0.00 平均時間: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 平均時間: ens33 1.01 0.67 0.06 0.38 0.00 0.00 0.00 平均時間: ens38 0.00 0.00 0.00 0.00 0.00 0.00 0.00
小常識:
bit 比特(帶寬單位)
Byte 字節(速度傳輸單位)
8bit = 1Byte
/var/log/sa/saxx xx爲日期
sar -f /var/log/sa/saxx 查看歷史 sar 記錄
[root@arslinux-01 ~]# sar -f /var/log/sa/sa14 Linux 3.10.0-957.el7.x86_64 (arslinux-01) 2019年05月14日 _x86_64_(1 CPU) 20時44分23秒 LINUX RESTART 20時50分01秒 CPU %user %nice %system %iowait %steal %idle 21時00分01秒 all 5.29 0.00 2.01 0.02 0.00 92.68 21時10分01秒 all 0.08 0.00 0.23 0.01 0.00 99.68 21時20分01秒 all 0.11 0.00 0.28 0.00 0.00 99.60 21時30分01秒 all 0.08 0.00 0.22 0.00 0.00 99.70 21時40分01秒 all 0.04 0.00 0.15 0.00 0.00 99.80 21時50分01秒 all 0.05 0.11 0.56 0.02 0.00 99.26 22時00分01秒 all 0.06 0.00 0.19 0.00 0.00 99.74 22時10分01秒 all 0.09 0.00 0.23 0.01 0.00 99.68 平均時間: all 0.72 0.01 0.48 0.01 0.00 98.77
-- sar -n DEV -f /var/log/sa/sa14 只看具體日期的網卡流量
sar 查看 CPU
[root@arslinux-01 ~]# sar Linux 3.10.0-957.el7.x86_64 (arslinux-01) 2019年06月10日 _x86_64_(1 CPU) 20時12分31秒 LINUX RESTART 20時23分48秒 LINUX RESTART 20時30分01秒 CPU %user %nice %system %iowait %steal %idle 20時40分01秒 all 0.15 0.00 0.45 0.00 0.00 99.40 20時50分01秒 all 0.08 0.00 0.28 0.00 0.00 99.63 21時00分01秒 all 0.07 0.00 0.26 0.00 0.00 99.67 21時10分01秒 all 0.07 0.00 1.13 0.05 0.00 98.75 21時20分01秒 all 0.02 0.00 0.17 0.00 0.00 99.81 21時30分01秒 all 0.08 0.00 0.27 0.01 0.00 99.65 21時40分01秒 all 1.35 0.02 0.76 0.01 0.00 97.85 21時50分01秒 all 0.08 0.00 0.26 0.00 0.00 99.66 22時00分01秒 all 0.02 0.00 0.17 0.00 0.00 99.81 22時10分01秒 all 0.02 0.00 0.17 0.00 0.00 99.81 22時20分01秒 all 0.01 0.00 0.17 0.00 0.00 99.82 22時30分01秒 all 0.04 0.00 0.20 0.00 0.00 99.76 22時40分01秒 all 0.11 0.00 0.35 0.01 0.00 99.53 平均時間: all 0.16 0.00 0.36 0.01 0.00 99.47
sar -b 查看磁盤io
[root@arslinux-01 ~]# sar -b Linux 3.10.0-957.el7.x86_64 (arslinux-01) 2019年06月10日 _x86_64_(1 CPU) 20時12分31秒 LINUX RESTART 20時23分48秒 LINUX RESTART 20時30分01秒 tps rtps wtps bread/s bwrtn/s 20時40分01秒 0.05 0.00 0.05 0.07 0.56 20時50分01秒 0.06 0.01 0.05 0.89 0.53 21時00分01秒 0.05 0.00 0.05 0.00 0.49 21時10分01秒 3.81 0.31 3.50 29.38 3451.05 21時20分01秒 0.05 0.00 0.05 0.12 0.46 21時30分01秒 0.07 0.01 0.06 0.40 0.81 21時40分01秒 1.57 1.04 0.54 47.96 16.79 21時50分01秒 0.05 0.00 0.05 0.00 0.51 22時00分01秒 0.06 0.00 0.06 0.01 0.74 22時10分01秒 0.16 0.11 0.06 21.74 0.63 22時20分01秒 0.03 0.00 0.03 0.00 0.33 22時30分01秒 0.09 0.01 0.08 0.55 1.00 22時40分01秒 0.13 0.04 0.09 3.18 24.33 平均時間: 0.47 0.12 0.36 8.01 267.86
sar -q 查看系統負載
[root@arslinux-01 ~]# sar -q Linux 3.10.0-957.el7.x86_64 (arslinux-01) 2019年06月10日 _x86_64_(1 CPU) 20時12分31秒 LINUX RESTART 20時23分48秒 LINUX RESTART 20時30分01秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked 20時40分01秒 0 185 0.00 0.04 0.12 0 20時50分01秒 1 184 0.07 0.03 0.07 0 21時00分01秒 1 184 0.00 0.01 0.05 0 21時10分01秒 1 185 0.00 0.02 0.05 0 21時20分01秒 2 185 0.00 0.01 0.05 0 21時30分01秒 1 185 0.00 0.01 0.05 0 21時40分01秒 0 186 0.00 0.02 0.05 0 21時50分01秒 1 185 0.00 0.01 0.05 0 22時00分01秒 1 184 0.00 0.03 0.05 0 22時10分01秒 1 184 0.00 0.01 0.05 0 22時20分01秒 1 184 0.01 0.02 0.05 0 22時30分01秒 1 184 0.00 0.01 0.05 0 22時40分01秒 1 184 0.00 0.01 0.05 0 平均時間: 1 185 0.01 0.02 0.06 0
nload 查看網卡流量(安裝 nload 包,先要安裝 epel-release 包)
按左右方向鍵切換不同的網卡
ethtool 網卡名 查看網卡信息
[root@arslinux-01 ~]# ethtool ens33 Settings for ens33: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on MDI-X: off (auto) Supports Wake-on: d Wake-on: d Current message level: 0x00000007 (7) drv probe link Link detected: yes
mii-tool 網卡名 查看網卡是否連接
[root@arslinux-01 ~]# mii-tool ens33 ens33: negotiated 1000baseT-FD flow-control, link ok
查看進程相關的命令
ps aux 查看系統所有用戶前臺後臺用戶級別的所有進程
ps elf 同上類似
ll /proc/進程id 查看未知進程的情況(是由哪個命令起來的)
ps eLf 查看進程的線程
[root@arslinux-01 ~]# ps -eLf | grep mysql root 7203 1 7203 0 1 20:23 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/datamysql --pid-file=/data/mysql/arslinux-01.pid mysql 7479 7203 7479 0 21 20:23 ? 00:00:04 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7691 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7692 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7693 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7694 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7695 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7696 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7697 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7698 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7699 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7700 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7702 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7703 0 21 20:24 ? 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7704 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7705 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7706 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7707 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7708 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7709 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7710 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock mysql 7479 7203 7711 0 21 20:24 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=arslinux-01.err --pid-file=/datamysql/arslinux-01.pid --socket=/tmp/mysql.sock root 7987 7714 7987 0 1 23:03 pts/0 00:00:00 grep --color=auto mysql
狀態:
S 處於休眠狀態
R 正在運行中
s 父進程(有子進程)
l 多線程
< 優先級高
N 優先級低
+ 前臺的進程(不帶+就是後臺進程)
Z 殭屍進程
關注點:
%CPU、%MEM、RSS(進程佔用的固定內存量)、STAT
擴展連接:https://www.cnblogs.com/huangmr0811/p/5570999.html
查看網絡連接狀況的命令
netstat 查看網絡連接狀況
[root@arslinux-01 ~]# netstat -lnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:38825 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7174/nginx: master tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 7177/rpc.mountd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7150/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7557/master tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 7174/nginx: master tcp 0 0 0.0.0.0:44352 0.0.0.0:* LISTEN 7159/rpc.statd tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN - tcp6 0 0 :::3306 :::* LISTEN 7479/mysqld tcp6 0 0 :::38639 :::* LISTEN - tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::20048 :::* LISTEN 7177/rpc.mountd tcp6 0 0 :::22 :::* LISTEN 7150/sshd tcp6 0 0 ::1:25 :::* LISTEN 7557/master tcp6 0 0 :::2049 :::* LISTEN - tcp6 0 0 :::48737 :::* LISTEN 7159/rpc.statd udp 0 0 127.0.0.1:975 0.0.0.0:* 7159/rpc.statd udp 0 0 0.0.0.0:2049 0.0.0.0:* - udp 0 0 0.0.0.0:60468 0.0.0.0:* 7159/rpc.statd udp 0 0 0.0.0.0:20048 0.0.0.0:* 7177/rpc.mountd udp 0 0 0.0.0.0:111 0.0.0.0:* 1/systemd udp 0 0 127.0.0.1:323 0.0.0.0:* 6039/chronyd udp 0 0 0.0.0.0:58247 0.0.0.0:* - udp 0 0 0.0.0.0:930 0.0.0.0:* 5894/rpcbind udp6 0 0 :::2049 :::* - udp6 0 0 :::20048 :::* 7177/rpc.mountd udp6 0 0 :::111 :::* 1/systemd udp6 0 0 :::48248 :::* 7159/rpc.statd udp6 0 0 :::36657 :::* - udp6 0 0 ::1:323 :::* 6039/chronyd udp6 0 0 :::930 :::* 5894/rpcbind raw6 0 0 :::58 :::* 7 5974/NetworkManager raw6 0 0 :::58 :::* 7 5974/NetworkManager raw6 0 0 :::58 :::* 7 5974/NetworkManager Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node PID/Program name Path unix 2 [ ACC ] STREAM LISTENING 41459 7557/master public/pickup unix 2 [ ACC ] STREAM LISTENING 40742 7243/gssproxy /run/gssproxy.sock unix 2 [ ACC ] STREAM LISTENING 41463 7557/master public/cleanup unix 2 [ ACC ] STREAM LISTENING 41466 7557/master public/qmgr unix 2 [ ACC ] STREAM LISTENING 41488 7557/master public/flush unix 2 [ ACC ] STREAM LISTENING 41503 7557/master public/showq unix 2 [ ACC ] STREAM LISTENING 41470 7557/master private/tlsmgr unix 2 [ ACC ] STREAM LISTENING 21315 1/systemd /run/lvm/lvmetad.socket unix 2 [ ACC ] STREAM LISTENING 41797 7479/mysqld /tmp/mysql.sock unix 2 [ ACC ] STREAM LISTENING 41473 7557/master private/rewrite unix 2 [ ACC ] STREAM LISTENING 41476 7557/master private/bounce unix 2 [ ACC ] STREAM LISTENING 41479 7557/master private/defer unix 2 [ ACC ] STREAM LISTENING 41482 7557/master private/trace unix 2 [ ACC ] STREAM LISTENING 40741 7243/gssproxy /var/lib/gssproxy/default.sock unix 2 [ ACC ] STREAM LISTENING 32898 1/systemd /run/dbus/system_bus_socket unix 2 [ ACC ] STREAM LISTENING 32901 1/systemd /var/run/rpcbind.sock unix 2 [ ACC ] STREAM LISTENING 21410 1/systemd /run/lvm/lvmpolld.socket unix 2 [ ACC ] STREAM LISTENING 41485 7557/master private/verify unix 2 [ ACC ] STREAM LISTENING 41491 7557/master private/proxymap unix 2 [ ACC ] STREAM LISTENING 41494 7557/master private/proxywrite unix 2 [ ACC ] STREAM LISTENING 41497 7557/master private/smtp unix 2 [ ACC ] STREAM LISTENING 41500 7557/master private/relay unix 2 [ ACC ] STREAM LISTENING 41506 7557/master private/error unix 2 [ ACC ] STREAM LISTENING 41509 7557/master private/retry unix 2 [ ACC ] STREAM LISTENING 41512 7557/master private/discard unix 2 [ ACC ] STREAM LISTENING 41515 7557/master private/local unix 2 [ ACC ] STREAM LISTENING 40908 7273/php-fpm: maste /tmp/arslinux.sock unix 2 [ ACC ] STREAM LISTENING 41518 7557/master private/virtual unix 2 [ ACC ] STREAM LISTENING 41521 7557/master private/lmtp unix 2 [ ACC ] STREAM LISTENING 41524 7557/master private/anvil unix 2 [ ACC ] STREAM LISTENING 40911 7273/php-fpm: maste /tmp/php-fcgi.sock unix 2 [ ACC ] STREAM LISTENING 41527 7557/master private/scache unix 2 [ ACC ] SEQPACKET LISTENING 21461 1/systemd /run/udev/control unix 2 [ ACC ] STREAM LISTENING 35295 5995/VGAuthService /var/run/vmware/guestServicePipe unix 2 [ ACC ] STREAM LISTENING 8946 1/systemd /run/systemd/journal/stdout unix 2 [ ACC ] STREAM LISTENING 21239 1/systemd /run/systemd/private
netstat -lntp 只查看 tcp 監聽的連接狀態
[root@arslinux-01 ~]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:38825 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7174/nginx: master tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 7177/rpc.mountd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7150/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7557/master tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 7174/nginx: master tcp 0 0 0.0.0.0:44352 0.0.0.0:* LISTEN 7159/rpc.statd tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN - tcp6 0 0 :::3306 :::* LISTEN 7479/mysqld tcp6 0 0 :::38639 :::* LISTEN - tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::20048 :::* LISTEN 7177/rpc.mountd tcp6 0 0 :::22 :::* LISTEN 7150/sshd tcp6 0 0 ::1:25 :::* LISTEN 7557/master tcp6 0 0 :::2049 :::* LISTEN - tcp6 0 0 :::48737 :::* LISTEN 7159/rpc.statd
netstat -lnup 只查看 udp 監聽的連接狀態
netstat -lntup 查看 tcp 和 udp 監聽的連接狀態
netstat -an 查看所有的網絡連接,包括監聽的,包括已連接的
ss -an 類似於 netstat -an,顯示更快,如果 netstat -an 比較慢,可以嘗試 ss -an
ESTABLISHED 建立連接
TIME_WAIT 要斷還沒斷開就是
擴展連接:https://blog.csdn.net/m0_37556444/article/details/83000553
網卡流量異常,通過抓包來分析
tcpdump 抓包工具(安裝 tcpdump)
-nn 數字的形式顯示 ip 和 port
-i 指定端口
port 指定端口號
-c 指定抓多少包
-w 指定寫入到哪個文件裏去
not port 不要某個端口,多個端口可以 not port and not port
not host 不要某個 ip 的
[root@arslinux-01 ~]# tcpdump -nn -i ens33 port 80
tcpdump -r 讀取 .cap 文件
可以用windows上 wireshark 分析 .cap 文件
tshark 抓包工具(需要安裝 wireshark 包)和 tcpdump 用法類似
[root@arslinux-01 ~]# tshark -nn -i ens33 Running as user "root" and group "root". This could be dangerous. Capturing on 'ens33' 1 0.000000000 192.168.194.1 -> 239.255.255.250 SSDP 216 M-SEARCH * HTTP/1.1 2 0.506531192 192.168.194.130 -> 192.168.194.1 SSH 170 Encrypted response packet len=116 3 0.555192741 192.168.194.1 -> 192.168.194.130 TCP 60 4518 > 22 [ACK] Seq=1 Ack=117 Win=2048 Len=0 4 1.000574486 192.168.194.1 -> 239.255.255.250 SSDP 216 M-SEARCH * HTTP/1.1 5 1.253766432 192.168.194.130 -> 192.168.194.1 SSH 362 Encrypted response packet len=308 6 1.295522376 192.168.194.1 -> 192.168.194.130 TCP 60 4518 > 22 [ACK] Seq=1 Ack=425 Win=2047 Len=0 7 1.797154561 192.168.194.130 -> 192.168.194.1 SSH 282 Encrypted response packet len=228 8 1.838083781 192.168.194.1 -> 192.168.194.130 TCP 60 4518 > 22 [ACK] Seq=1 Ack=653 Win=2053 Len=0 9 2.003689876 192.168.194.1 -> 239.255.255.250 SSDP 216 M-SEARCH * HTTP/1.1 10 2.506430635 192.168.194.130 -> 192.168.194.1 SSH 362 Encrypted response packet len=308 11 2.547345210 192.168.194.1 -> 192.168.194.130 TCP 60 4518 > 22 [ACK] Seq=1 Ack=961 Win=2051 Len=0 12 3.005064119 192.168.194.1 -> 239.255.255.250 SSDP 216 M-SEARCH * HTTP/1.1 1 packet dropped 12 packets captured
tshark -i 端口號 -n -t a -R http.request -T fields -e "frame.time" -e "ip.src" -e "http.host" -e "http.request.method" -e "http.request.uri"
結果和訪問日誌一樣
5.10 監控介紹
爲什麼要做監控?
可以提前發現故障隱患,第一時間解決掉,把影響降低。
常見的監控軟件:
cacti(專業網絡設備監控軟件)、nagios、zabbix、open-falcon、prometheus、grafana
zabbix 操作方便,在瀏覽器操作;可以自定定義監控腳本;可以方便查看趨勢圖形圖像;可以查看歷史區間內的各項指標
5.11~5.12 安裝zabbix4.0
zabbix 官網:www.zabbix.com
前期準備
1、安裝 zabbix 的 yum 源
[root@arslinux-01 ~]# rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
2、查看可用的 yum 源
[root@arslinux-01 ~]# yum list|grep zabbix zabbix-release.noarch 4.0-1.el7 installed iksemel.x86_64 1.4-2.el7.centos zabbix-non-supported iksemel-devel.x86_64 1.4-2.el7.centos zabbix-non-supported iksemel-utils.x86_64 1.4-2.el7.centos zabbix-non-supported pcp-export-pcp2zabbix.x86_64 4.1.0-5.el7_6 updates pcp-export-zabbix-agent.x86_64 4.1.0-5.el7_6 updates python-pyzabbix.noarch 0.7.3-2.el7 epel python2-zabbix-api-erigones.noarch 1.2.4-3.el7 epel python36-zabbix-api-erigones.noarch 1.2.4-3.el7 epel uwsgi-stats-pusher-zabbix.x86_64 2.0.17.1-2.el7 epel zabbix-agent.x86_64 4.0.9-3.el7 zabbix zabbix-get.x86_64 4.0.9-3.el7 zabbix zabbix-java-gateway.x86_64 4.0.9-3.el7 zabbix zabbix-proxy-mysql.x86_64 4.0.9-3.el7 zabbix zabbix-proxy-pgsql.x86_64 4.0.9-3.el7 zabbix zabbix-proxy-sqlite3.x86_64 4.0.9-3.el7 zabbix zabbix-sender.x86_64 4.0.9-3.el7 zabbix zabbix-server-mysql.x86_64 4.0.9-3.el7 zabbix zabbix-server-pgsql.x86_64 4.0.9-3.el7 zabbix zabbix-web.noarch 4.0.9-3.el7 zabbix zabbix-web-japanese.noarch 4.0.9-3.el7 zabbix zabbix-web-mysql.noarch 4.0.9-3.el7 zabbix zabbix-web-pgsql.noarch 4.0.9-3.el7 zabbix zabbix22.x86_64 2.2.23-1.el7 epel zabbix22-agent.x86_64 2.2.23-1.el7 epel zabbix22-dbfiles-mysql.noarch 2.2.23-1.el7 epel zabbix22-dbfiles-pgsql.noarch 2.2.23-1.el7 epel zabbix22-dbfiles-sqlite3.noarch 2.2.23-1.el7 epel zabbix22-proxy.noarch 2.2.23-1.el7 epel zabbix22-proxy-mysql.x86_64 2.2.23-1.el7 epel zabbix22-proxy-pgsql.x86_64 2.2.23-1.el7 epel zabbix22-proxy-sqlite3.x86_64 2.2.23-1.el7 epel zabbix22-server.noarch 2.2.23-1.el7 epel zabbix22-server-mysql.x86_64 2.2.23-1.el7 epel zabbix22-server-pgsql.x86_64 2.2.23-1.el7 epel zabbix22-web.noarch 2.2.23-1.el7 epel zabbix22-web-mysql.noarch 2.2.23-1.el7 epel zabbix22-web-pgsql.noarch 2.2.23-1.el7 epel zabbix30.x86_64 3.0.22-2.el7 epel zabbix30-agent.x86_64 3.0.22-2.el7 epel zabbix30-dbfiles-mysql.noarch 3.0.22-2.el7 epel zabbix30-dbfiles-pgsql.noarch 3.0.22-2.el7 epel zabbix30-dbfiles-sqlite3.noarch 3.0.22-2.el7 epel zabbix30-proxy.noarch 3.0.22-2.el7 epel zabbix30-proxy-mysql.x86_64 3.0.22-2.el7 epel zabbix30-proxy-pgsql.x86_64 3.0.22-2.el7 epel zabbix30-proxy-sqlite3.x86_64 3.0.22-2.el7 epel zabbix30-server.noarch 3.0.22-2.el7 epel zabbix30-server-mysql.x86_64 3.0.22-2.el7 epel zabbix30-server-pgsql.x86_64 3.0.22-2.el7 epel zabbix30-web.noarch 3.0.22-2.el7 epel zabbix30-web-mysql.noarch 3.0.22-2.el7 epel zabbix30-web-pgsql.noarch 3.0.22-2.el7 epel zabbix40.x86_64 4.0.6-1.el7 epel zabbix40-agent.x86_64 4.0.6-1.el7 epel zabbix40-dbfiles-mysql.noarch 4.0.6-1.el7 epel zabbix40-dbfiles-pgsql.noarch 4.0.6-1.el7 epel zabbix40-dbfiles-sqlite3.noarch 4.0.6-1.el7 epel zabbix40-proxy.noarch 4.0.6-1.el7 epel zabbix40-proxy-mysql.x86_64 4.0.6-1.el7 epel zabbix40-proxy-pgsql.x86_64 4.0.6-1.el7 epel zabbix40-proxy-sqlite3.x86_64 4.0.6-1.el7 epel zabbix40-server.noarch 4.0.6-1.el7 epel zabbix40-server-mysql.x86_64 4.0.6-1.el7 epel zabbix40-server-pgsql.x86_64 4.0.6-1.el7 epel zabbix40-web.noarch 4.0.6-1.el7 epel zabbix40-web-mysql.noarch 4.0.6-1.el7 epel zabbix40-web-pgsql.noarch 4.0.6-1.el7 epel
3、需要安裝的包如下:
zabbix-agent、zabbix-get、zabbix-server-mysql、zabbix-web、zabbix-web-mysql
4、安裝需要裝的所有包
[root@arslinux-01 ~]# yum install zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
5、查看端口
[root@arslinux-01 ~]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:40647 0.0.0.0:* LISTEN 7181/rpc.statd tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7201/nginx: master tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 7199/rpc.mountd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7173/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7584/master tcp 0 0 0.0.0.0:45177 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 7201/nginx: master tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN - tcp6 0 0 :::3306 :::* LISTEN 7516/mysqld tcp6 0 0 :::46092 :::* LISTEN 7181/rpc.statd tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::20048 :::* LISTEN 7199/rpc.mountd tcp6 0 0 :::22 :::* LISTEN 7173/sshd tcp6 0 0 ::1:25 :::* LISTEN 7584/master tcp6 0 0 :::2049 :::* LISTEN - tcp6 0 0 :::38661 :::* LISTEN
6、創建數據庫 zabbix 並配置
[root@arslinux-01 ~]# mysql -uroot -parslinux Warning: Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.43-log MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database zabbix; Query OK, 1 row affected (0.00 sec) mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye
7、編輯 zabbix server 配置文件
[root@arslinux-01 ~]# vim /etc/zabbix/zabbix_server.conf
DBHost=127.0.0.1
DBName=zabbix
DBPassword=123456
8、啓動 zabbix-server
[root@arslinux-01 ~]# systemctl start zabbix-server [root@arslinux-01 ~]# ps aux|grep zabbix root 8078 0.0 0.0 112724 984 pts/0 R+ 12:49 0:00 grep --color=auto zabbix
9、程序未啓動,查看日誌文件 /var/log/zabbix/zabbix_server.log
[root@arslinux-01 ~]# cat /var/log/zabbix/zabbix_server.log 8156:20190611:125125.104 [Z3005] query failed: [1146] Table 'zabbix.users' doesn't exist [select userid from users limit 1]
庫裏沒有表,所以無法啓動
10、安裝的 RPM 包中帶有 sql 文件(create.sql),將其導入數據庫
[root@arslinux-01 ~]# ls /usr/share/doc/zabbix-server-mysql-4.0.9/ AUTHORS ChangeLog COPYING create.sql.gz NEWS README [root@arslinux-01 ~]# gzip -d !$ gzip -d /usr/share/doc/zabbix-server-mysql-4.0.9/create.sql.gz [root@arslinux-01 ~]# ls /usr/share/doc/zabbix-server-mysql-4.0.9/ AUTHORS ChangeLog COPYING create.sql NEWS README [root@arslinux-01 ~]# mysql -uroot -parslinux zabbix < /usr/share/doc/zabbix-server-mysql-4.0.9/create.sql Warning: Using a password on the command line interface can be insecure.
11、啓動 zabbix-server
[root@arslinux-01 ~]# systemctl start zabbix-server [root@arslinux-01 ~]# ps aux|grep zabbix
12、zabbix-server 監聽 10051 端口
[root@arslinux-01 ~]# netstat -lntp|grep zabbix tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 7820/zabbix_server tcp6 0 0 :::10051 :::* LISTEN 7820/zabbix_server
13、編輯 zabbix-agent 的配置文件
[root@arslinux-01 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=127.0.0.1 //server 去取
ServerActive=127.0.0.1 //機器量多的話,線程就太多,那麼客戶端上報更好
14、啓動 zabbix-agent
[root@arslinux-01 ~]# systemctl start zabbix-agent [root@arslinux-01 ~]# ps aux|grep zabbix_agent
15、安裝 web ui,需要啓動 httpd 服務,首先關閉 nginx 服務
[root@arslinux-01 ~]# systemctl stop nginx [root@arslinux-01 ~]# systemctl start httpd [root@arslinux-01 ~]# netstat -lntp|grep httpd
開始安裝 web ui
1、訪問 http://192.168.194.130/zabbix/setup.php,可以安裝 zabbix 了
2、在下一步裏,會有紅色的標註 FAIL 的選項,需要修改參數
此處,我們需要找到 php 的配置文件去更改
3、更改php.ini 參數(httpd 是之前 yum 安裝的) /etc/php.ini 中的 date.timezone
[root@arslinux-01 ~]# vi /etc/php.ini date.timezone = Asia/Shanghai
4、重啓 httpd
[root@arslinux-01 ~]# systemctl restart httpd
5、到瀏覽器中,刷新一下,可以看到,參數已經全部正常了
6、定義數據庫相關信息
7、自定義服務器信息
根據提示,默認安裝完即可
8、到登陸頁面,默認初始用戶名和密碼是 admin 和 zabbix
9、然後可以到個人管理中更改密碼和語言
往後再訪問時就在瀏覽器輸入 ip/zabbix 即可
10、總結:
1)安裝 zabbix yum 源
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
2)yum 安裝
yum install zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
3)數據庫操作
create database zabbix;
grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by '密碼'
4)導入數據
/usr/share/doc/zabbix-server-mysql-4.0.3/create.sql.gz
gzid -d /usr/share/doc/zabbix-server-mysql-4.0.3/create.sql.gz
mysql -uroot -p密碼 zabbix < /usr/share/doc/zabbix-server-mysql-4.0.3/create.sql.gz
5)編輯 zabbix_server.conf
vim /etc/zabbix/zabbix_server.conf #定義數據庫相關的參數
systemctl start zabbix-server
systemctl enable zabbix-server
6)編輯 zabbix_agent.conf
vim /etc/zabbix/zabbix_agent.conf #定義Server 和 ServerActive=127.0.0.1
systemctl start zabbix-agent
systemctl enable zabbix-agent
7)httpd
systemctl start httpd #如果已經啓動了 nginx,需要先把 nginx 關閉,然後啓動 httpd;如果 nginx 不能停止,那麼需要更改 nginx 監聽端口爲非 80 端口,比如 8080 /8000
8)web ui 配置
http://ip/zabbix 訪問,解決 php 的問題 (date.timezone = Asia/Shanghai)
/etc/php.ini (httpd 是 yum 安裝)
默認用戶名密碼:admin,zabbix
5.13 監控客戶機-添加主機
1、安裝 zabbix 的 yum 源
[root@arslinux-02 ~]# rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
2、yum 安裝 zabbix-agent
[root@arslinux-02 ~]# yum install -y zabbix-agent
3、編輯配置文件 /etc/zabbix/zabbix_agentd.conf
[root@arslinux-02 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.194.130 //zabbix-server 的 ip
ServerActive=192.168.194.130
4、啓動 zabbix-agent
[root@arslinux-02 ~]# systemctl start zabbix-agent [root@arslinux-02 ~]# ps aux|grep zabbix zabbix 7272 0.0 0.1 80720 1268 ? S 21:20 0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbi_agentd.conf zabbix 7273 0.0 0.1 80720 1312 ? S 21:20 0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec] zabbix 7274 0.0 0.1 80720 1836 ? S 21:20 0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection] zabbix 7275 0.0 0.1 80720 1836 ? S 21:20 0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection] zabbix 7276 0.0 0.1 80720 1836 ? S 21:20 0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection] zabbix 7277 0.0 0.2 80852 2224 ? S 21:20 0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec] root 7279 0.0 0.0 112724 988 pts/0 R+ 21:20 0:00 grep --color=auto zabbix
5、查看 zabbix-agentd 監聽的端口
[root@arslinux-02 ~]# netstat -lntp|grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 7272/zabbix_agentd tcp6 0 0 :::10050 :::* LISTEN 7272/zabbix_agentd
zabbix-agentd 監聽 10050 端口,會和 server 端的 10051 端口通信
5.14 監控客戶機-管理模板
1、創建新主機
配置——主機——創建主機
主機已經添加完成
2、創建模板
配置——模板——創建模板
3、拷貝某個模板裏的應用集 CPU 中的監控項到自定義的模板中
配置——模板——Template OS Linux——應用集——CPU
4、將監控項拷貝到 test 模板中去
5、同樣的方法拷貝其他參數的監控項到 test 模板中
6、自動發現(Discovery)是無法使用複製來添加到自定義模板中的
我們可以將“自動發現”規則一樣的模板克隆到一個新的自定義模板中
配置——模板——模板名稱——全克隆(Full Clone)
添加名稱和羣組信息
7、進入新建的模板 ars4life ,在“連接的宏模板”中取消連接,並更新
8、根據需要刪除模板中的監控項、觸發器、圖形
刪除順序:圖形——觸發器——監控項——應用集(刪除空白項)
9、將模板鏈接到自定義創建的主機上去
配置——主機——具體主機——模板——選擇鏈接模板——添加——更新
10、添加完成
11、查看監控項。監測——最新數據
12、命令行查看相關信息
[root@arslinux-01 ~]# zabbix_get -s 192.168.194.132 -p 10050 -k "system.cpu.load[all,avg1]" 0.100000
5.15 監控客戶機-管理圖形和窗口
監測——聚合圖形——創建聚合圖形
儀表板中也可以自定義新的監測模塊
在圖形中,將常用的類型圖標收藏,點星星變×××
點進去就能查看
5.16 監控客戶機-配置觸發器
自定義網卡流量觸發器
5.17 解決中文名稱不能寫數據庫的問題
字符集的問題:
/etc/my.cnf 將以下幾個參數全改爲 utf8,再去導入數據庫、表,就沒有這個問題了
也可以將所有數據導出,改字符集後再將講數據導入
導出表:
mysqldump -uroot -parslinux --default-character-set=utf8 zabbix > zabbix.sql
vim zabbix.sql
:1,$s/latin1/utf8/g
導入表:
mysql -uroot -parslinux --default-character-set=utf8 zabbix < zabbix.sql
進入數據庫查看:
show create table items\G 字符集變成了 utf8
screen改中文:screen——Properites——Name 改成中文——Update
主機名不可以改成中文,和字符集無關
5.18 解決圖形中文亂碼
原因:沒有支持中文文字的字體
zabbix 使用的字體:
/usr/share/zabbix/include/defines.inc.php 中
查看 ZBX_FONTPATH ,找到路徑和名字
方法:
在/usr/share/zabbix/fonts/graphfont.ttf,graphfont.ttf 是 /etc/alternatives/zabbix-web-font 的軟鏈接
可以直接在 windows 中找到 c-windows-fonts 中找一箇中文字體拷到虛擬機中
將原 graphfont.ttf 改名,再將拷貝過來的字體做軟鏈接改名成 graphfont.ttf
在網頁中,亂碼已經解決
5.19~5.21 zabbix郵件告警
1、雲——產品與服務——雲通信——郵件推送——立即開通
2、郵件設置——發信域名——新建域名——配置
到DNSPOD 中——域名解析——找到域名中——添加記錄——根據雲中主機記錄、類型、記錄值去配置,以此類推
如果雲中沒有記錄,那麼就在 DNSPOD 中寫 @
添加所有需要驗證的,等待一會兒就可以了,改完確認修改
再點擊驗證,狀態變爲可使用-未備案
新建發信地址:
郵件設置——發信地址——新建發信地址——發信域名、賬號(自定義)、發信類型爲觸發郵件——設置SMTP密碼(可以用keepass生成隨機字符串,也可以用mkpasswd)
創建發郵件 python 腳本:
vi mail.py #!/usr/bin/python #coding:utf-8 import smtplib from email.mime.text import MIMEText import sys mail_user = '[email protected]' mail_pass = 'xxxxxxxx' def send_mail(to_list,subject,content): me = "zabbix 監控告警平臺"+"<"+mail_user+">" msg = MIMEText(content, 'plain', 'utf-8') msg['Subject'] = subject msg['From'] = me msg['to'] = to_list try: s = smtplib.SMTP("smtpdm.aliyun.com", 25) s.login(mail_user,mail_pass) s.sendmail(me,to_list,msg.as_string()) s.close() return True except Exception,e: print str(e) return False if __name__ == "__main__": send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
郵件用戶名、密碼,SMTP服務器根據情況更改爲實際的參數
改 mail.py 權限爲 755
測試: python mail.py [email protected] "測試郵件" "cececececece"
再到郵箱中查看是否有測試郵件
設置zabbix_server配置文件
vim /etc/zabbix/zabbix_server.conf
找到:報警腳本路徑 AlertScriptsPath=/usr/lib/zabbix/alertscripts
cd /usr/lib/zabbix/alertscripts
把mail.py 挪到這個目錄下來,發郵件時是zabbix用戶執行的,而不是root用戶
給它一個755權限 chmod 755 mail.py
設置zabbixWEB UI
1) 設置報警媒介
Administration -> Media types -> 右上角(Create Media type)
Name: baojing
Type: Script
Script name: mail.py
Script parameters -> Add {ALERT.SENDTO}/ Add {ALERT.SUBJECT}/Add {ALERT.MESSAGE}
Add
2)設置接收郵件地址
Administration -> Users -> Admin(或者新建用戶)
Media -> Add
Type: baojing
Send to: 郵箱地址,如 [email protected]
Add(可以添加多個)
Permissions 檢查下是不是 All groups 都要 Read-write 權限,如果沒有權限,可以更改user type
Update
3)配置動作
可以直接在actions中點右側,將disable 改爲 enable
Configuration -> Actions -> Create action
Name: 發郵件
Operations
New
Send to Users -> Admin
Send only to -> baojing
Conditions -> new -> Add
Add
Recovery operations
New
Send to Users -> Admin
Send only to -> baojing
Add
Add
測試報警
Configuration -> Hosts -> Triggers
故意調整一個trigger
Monitoring -> Problems
5.22/5.23 zabbix監控Nginx
在aminglinux02上安裝Nginx
編輯yum倉庫: vi /etc/yum.repos.d/nginx.repo 粘貼: [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 安裝: yum install -y nginx
配置Nginx狀態信息
vi /etc/nginx/conf.d/default.conf #增加 location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; }
測試
curl http://127.0.0.1/nginx_status
說明:
字段 | 含義 |
---|---|
Active Connections | 當前活動連接數,其中也包括了等待狀態的連接 |
accepts | 接收到的連接數 |
handled | 已經處理完的連接數,該數字一般和accepts一致,如果不一致那麼說明Nginx出錯了 |
requests | 總共處理的請求數,一個連接可以有多個請求,所以該值比accpets要大 |
Reading | 正在讀取請求頭信息的連接數 |
Writing | 正在發送響應報文的連接數 |
Waiting | 處於閒置狀態,等待客戶端發送請求的連接數 |
編寫監控腳本
vi /usr/local/sbin/ngx_status.sh #內容如下 #!/bin/bash url="http://127.0.0.1/nginx_status" curl=/usr/bin/curl # 檢測nginx進程是否存在 function ping { /sbin/pidof nginx | wc -l } # 檢測nginx性能 function active { $curl $url 2>/dev/null| grep 'Active' | awk '{print $NF}' } function reading { $curl $url 2>/dev/null| grep 'Reading' | awk '{print $2}' } function writing { $curl $url 2>/dev/null| grep 'Writing' | awk '{print $4}' } function waiting { $curl $url 2>/dev/null| grep 'Waiting' | awk '{print $6}' } function accepts { $curl $url 2>/dev/null| awk NR==3 | awk '{print $1}' } function handled { $curl $url 2>/dev/null| awk NR==3 | awk '{print $2}' } function requests { $curl $url 2>/dev/null| awk NR==3 | awk '{print $3}' } $1 chmod 755 /usr/local/sbin/ngx_status.sh
編輯zabbix_agent.conf
vi /etc/zabbix/zabbix_agentd.conf # 增加 UserParameter=nginx.status[*],/usr/local/sbin/ngx_status.sh $1
重啓服務
systemctl restart zabbix-agent
zabbix_get 測試
在服務端執行 zabbix_get -s 192.168.222.129 -k 'nginx.status[accepts]
導入nginx模板
下載模板 https://github.com/aminglinux/linux2019/blob/master/zabbix_nginx_template/zbx_export_templates.xml Configuration -> Templates -> 右上角Import
鏈接模板
Configuration -> Hosts -> aminglinux02 -> Templates -> Select -> Add -> Update
5.24 zabbix監控Tomcat
監控流程:
1)安裝zabbix_java_gateway 2)配置zabbix_java_gateway配置文件和zabbix_server配置文件,指定監聽端口,啓動進程數 3)編輯Tomcat配置文件,開啓JMX 4)添加host,指定JMX interface 5)鏈接TOMCAT模板
安裝zabbix_java_gateway
yum install -y zabbix-java-gateway
修改配置文件
vi /etc/zabbix/zabbix_java_gateway.conf 定義 LISTEN_PORT 和 START_POLLERS vi /etc/zabbix/zabbix_server.conf 定義 JavaGateway 和 JavaGatewayPort 和 StartJavaPollers 啓動zabbix-java-gateway服務 systemctl start zabbix-java-gateway 重啓zabbix-server服務 systemctl restart zabbix-server
開啓JMX
vi /usr/local/tomcat/bin/catalina.sh #在#!/bin/sh下增加 export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.222.128 -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false" 重啓tomcat /usr/local/tomcat/bin/shutdown.sh /usr/local/tomcat/bin/startup.sh
添加Host鏈接模板
Configuration -> Hosts -> Create host Agent interfaces -> remove JMX interfaces -> Add -> 192.168.222.128 9999 Templates -> Select -> Template App Apache Tomcat JMX -> select -> Add Add
5.25 zabbix監控MySQL
授權一個監控用戶
> grant usage, process, replication client on *.* to 'mon'@'localhost' identified by 'x2ay9xodTvyM';
編輯配置文件
vi /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf mkdir /var/lib/zabbix vi /var/lib/zabbix/.my.cnf #如下內容 [mysql] host=localhost user=mon password='x2ay9xodTvyM' socket=/tmp/mysql.sock [mysqladmin] host=localhost user=mon password='x2ay9xodTvyM' socket=/tmp/mysql.sock
重啓zabbix-agent服務
systemctl restart zabbix-agent
測試
zabbix_get -s 127.0.0.1 -p 10050 -k mysql.ping 若提示:sh: mysqladmin: 未找到命令 需要: ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/ zabbix_get -s 127.0.0.1 -p 10050 -k mysql.version zabbix_get -s 127.0.0.1 -p 10050 -k mysql.size
添加主機和模板
Configuration -> Hosts -> Create host Agent interfaces -> 127.0.0.1 10050 Templates -> Select -> Template DB MySQL -> select -> Add Add
課堂筆記
1、監控重要性
2、主流監控:zabbix、open-falcon、Prometheus、grafana
鏈路監控:apm、pinport
3、學習監控需要把握的幾點:監控項目如何配置、自定義監控如何配置、如何成圖、如何告警