Linux監控

第三十次課 Linux監控

目錄php

1、 Linux監控平臺介紹
2、 zabbix監控介紹
3、 安裝zabbix
4、 忘記Admin密碼如何作
5、 主動模式和被動模式
6、 添加監控主機
7、 添加自定義模板
8、 處理圖形中的亂碼
9、 自動發現
10、 添加自定義監控項目
11、 配置郵件告警
12、 測試告警
十3、 不發郵件的問題處理
十4、 擴展前端


1、 Linux監控平臺介紹

常見開源監控方案有cacti、nagios、zabbix、smokeping、open-falcon等python

cacti、smokeping偏向於基礎監控,成圖很是漂亮mysql

cacti、nagios、zabbix服務端監控中心,須要php環境支持,其中zabbix和cacti都須要mysql做爲數據存儲,nagios不用存儲歷史數據,注重服務或者監控項的狀態,zabbix會獲取服務或者監控項目的數據,會把數據記錄到數據庫裏,從而能夠成圖.linux

open-falcon爲小米公司開發,開源後受到諸多大公司和運維工程師的追捧,適合大企業,滴滴、360、新浪微博、京東等大公司在使用這款監控軟件,值得研究ios


2、 zabbix監控介紹

Zabbix 是一個企業級的分佈式開源監控方案。git

Zabbix是一款可以監控各類網絡參數以及服務器健康性和完整性的軟件。Zabbix使用靈活的通知機制,容許用戶爲幾乎任何事件配置基於郵件的告警。這樣能夠快速反饋服務器的問題。基於已存儲的數據,Zabbix提供了出色的報告和數據可視化功能。這些功能使得Zabbix成爲容量規劃的理想方案。web

Zabbix支持主動輪詢和被動捕獲。Zabbix全部的報告、統計信息和配置參數均可以經過基於Web的前端頁面進行訪問。基於Web的前端頁面能夠確保您從任何方面評估您的網絡狀態和服務器的健康性。適當的配置後,Zabbix能夠在IT基礎架構監控方面扮演重要的角色。對於只有少許服務器的小型組織和擁有大量服務器的大型公司也一樣如此。sql

Zabbix是免費的。Zabbix是根據GPL通用公共許可證第2版編寫和發行的。這意味着它的源代碼都是免費發行的,可供公衆任意使用。數據庫

C/S架構,基於C++開發,監控中心支持web界面配置和管理,單server節點能夠支持上萬臺客戶端

最新版本3.4,官方文檔https://www.zabbix.com/documentation/3.4/zh/manual

5個組件

zabbix-server 監控中心,接收客戶端上報信息,負責配置、統計、操做數據

數據庫存儲 存放數據,好比mysql

web界面 也叫web UI,在web界面下操做配置是zabbix簡單易用的主要緣由

zabbix-proxy 可選組件,它能夠代替zabbix-server的功能,減輕server的壓力

zabbix-agent 客戶端軟件,負責採集各個監控服務或項目的數據,並上報

zabbix監控流程


3、 安裝zabbix

1.配置zabbix下載源

進入https://www.zabbix.com/download?zabbix=3.2&os_distribution=centos&os_version=7&db=MySQL

按提示操做

[root@zabbix-server ~]# rpm -i http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.aMjxcE: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
[root@zabbix-server ~]# ls -l /etc/yum.repos.d/zabbix.repo 
-rw-r--r--. 1 root root 410 Sep 14  2016 /etc/yum.repos.d/zabbix.repo

2.安裝mysql數據庫,步驟略。

3.安裝zabbix、httpd和php

ix.com; Unknown error"
[root@zabbix-server ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
Loaded plugins: fastestmirror
base                                                                                                | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                                | 5.6 kB  00:00:00     
epel                                                                                                | 3.2 kB  00:00:00     
extras                                                                                              | 3.4 kB  00:00:00     
updates                                                                                             | 3.4 kB  00:00:00     
zabbix                                                                                              | 2.9 kB  00:00:00     
zabbix-non-supported                                                                                |  951 B  00:00:00     
zabbix/x86_64/primary_db                                                                            |  87 kB  00:00:01     
zabbix-non-supported/x86_64/primary                                                                 | 1.6 kB  00:00:06     
Determining fastest mirrors
 * base: mirrors.cn99.com
 * epel: mirrors.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
zabbix-non-supported      
...中間略...

Installed:
  zabbix-agent.x86_64 0:3.2.11-1.el7   zabbix-get.x86_64 0:3.2.11-1.el7         zabbix-server-mysql.x86_64 0:3.2.11-1.el7  
  zabbix-web.noarch 0:3.2.11-1.el7     zabbix-web-mysql.noarch 0:3.2.11-1.el7  

Dependency Installed:
  OpenIPMI-libs.x86_64 0:2.0.23-2.el7                          OpenIPMI-modalias.x86_64 0:2.0.23-2.el7                    
  dejavu-fonts-common.noarch 0:2.33-6.el7                      dejavu-sans-fonts.noarch 0:2.33-6.el7                      
  fontpackages-filesystem.noarch 0:1.44-8.el7                  fping.x86_64 0:3.10-4.el7                                  
  httpd.x86_64 0:2.4.6-80.el7.centos.1                         httpd-tools.x86_64 0:2.4.6-80.el7.centos.1                 
  iksemel.x86_64 0:1.4-2.el7.centos                            libX11.x86_64 0:1.6.5-1.el7                                
  libX11-common.noarch 0:1.6.5-1.el7                           libXau.x86_64 0:1.0.8-2.1.el7                              
  libXpm.x86_64 0:3.5.12-1.el7                                 libpng.x86_64 2:1.5.13-7.el7_2                             
  libxcb.x86_64 0:1.12-1.el7                                   libzip.x86_64 0:0.10.1-8.el7                               
  mailcap.noarch 0:2.1.41-2.el7                                net-snmp-libs.x86_64 1:5.7.2-33.el7_5.2                    
  php.x86_64 0:5.4.16-45.el7                                   php-bcmath.x86_64 0:5.4.16-45.el7                          
  php-cli.x86_64 0:5.4.16-45.el7                               php-common.x86_64 0:5.4.16-45.el7                          
  php-gd.x86_64 0:5.4.16-45.el7                                php-ldap.x86_64 0:5.4.16-45.el7                            
  php-mbstring.x86_64 0:5.4.16-45.el7                          php-mysql.x86_64 0:5.4.16-45.el7                           
  php-pdo.x86_64 0:5.4.16-45.el7                               php-xml.x86_64 0:5.4.16-45.el7                             
  t1lib.x86_64 0:5.1.2-14.el7                                  unixODBC.x86_64 0:2.3.1-11.el7                             

Complete!

4.在mysql數據庫中新建zabbix庫及執行初始化腳本

//修改/etc/my.cnf,增長以下內容
character_set_server = utf8
//初始化zabbix數據庫
[root@zabbix-server ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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 character set utf8;

Query OK, 1 row affected (0.00 sec)

mysql> grant all on zabbix.* to 'zabbix'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

Bye
[root@zabbix-server ~]# rpm -ql zabbix-server-mysql
/etc/logrotate.d/zabbix-server
/etc/zabbix/zabbix_server.conf
/usr/lib/systemd/system/zabbix-server.service
/usr/lib/tmpfiles.d/zabbix-server.conf
/usr/lib/zabbix/alertscripts
/usr/lib/zabbix/externalscripts
/usr/sbin/zabbix_server_mysql
/usr/share/doc/zabbix-server-mysql-3.2.11
/usr/share/doc/zabbix-server-mysql-3.2.11/AUTHORS
/usr/share/doc/zabbix-server-mysql-3.2.11/COPYING
/usr/share/doc/zabbix-server-mysql-3.2.11/ChangeLog
/usr/share/doc/zabbix-server-mysql-3.2.11/NEWS
/usr/share/doc/zabbix-server-mysql-3.2.11/README
/usr/share/doc/zabbix-server-mysql-3.2.11/create.sql.gz
/usr/share/man/man8/zabbix_server.8.gz
/var/log/zabbix
/var/run/zabbix
[root@zabbix-server ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11
[root@zabbix-server zabbix-server-mysql-3.2.11]# gunzip create.sql.gz 
[root@zabbix-server zabbix-server-mysql-3.2.11]# ls
AUTHORS  ChangeLog  COPYING  create.sql  NEWS  README
[root@zabbix-server zabbix-server-mysql-3.2.11]# mysql -uroot -p zabbix < create.sql 
Enter password: 

[root@zabbix-server zabbix-server-mysql-3.2.11]# 
[root@zabbix-server zabbix-server-mysql-3.2.11]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| groups                     |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| httpstep                   |
| httpstepitem               |
| httptest                   |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| items                      |
| items_applications         |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_url         |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| task                       |
| task_close_problem         |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
+----------------------------+
127 rows in set (0.00 sec)

mysql>

5.啓動http,並設爲自動啓動

[root@zabbix-server ~]# systemctl start httpd.service
[root@zabbix-server ~]# systemctl enable httpd.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@zabbix-server ~]# lsof -i :80
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
httpd   2698   root    4u  IPv6  29556      0t0  TCP *:http (LISTEN)
httpd   2700 apache    4u  IPv6  29556      0t0  TCP *:http (LISTEN)
httpd   2701 apache    4u  IPv6  29556      0t0  TCP *:http (LISTEN)
httpd   2702 apache    4u  IPv6  29556      0t0  TCP *:http (LISTEN)
httpd   2703 apache    4u  IPv6  29556      0t0  TCP *:http (LISTEN)
httpd   2704 apache    4u  IPv6  29556      0t0  TCP *:http (LISTEN)

6.配置zabbix

//只需配置DBPassword便可
[root@zabbix-server ~]# vim /etc/zabbix/zabbix_server.conf 
//修改DBPasssword的值爲以前設定的123456
DBPassword=123456
[root@zabbix-server ~]# systemctl start zabbix-server.service  
//提示沒法啓動
Job for zabbix-server.service failed because a configured resource limit was exceeded. See "systemctl status zabbix-server.service" and "journalctl -xe" for details.
//查看日誌,顯示沒有權限
[root@zabbix-server ~]# cat /var/log/zabbix/zabbix_server.log 
  2831:20180724:220827.653 Starting Zabbix Server. Zabbix 3.2.11 (revision 76339).
  2831:20180724:220827.653 ****** Enabled features ******
  2831:20180724:220827.653 SNMP monitoring:           YES
  2831:20180724:220827.653 IPMI monitoring:           YES
  2831:20180724:220827.653 Web monitoring:            YES
  2831:20180724:220827.653 VMware monitoring:         YES
  2831:20180724:220827.653 SMTP authentication:       YES
  2831:20180724:220827.653 Jabber notifications:      YES
  2831:20180724:220827.653 Ez Texting notifications:  YES
  2831:20180724:220827.653 ODBC:                      YES
  2831:20180724:220827.653 SSH2 support:              YES
  2831:20180724:220827.653 IPv6 support:              YES
  2831:20180724:220827.654 TLS support:               YES
  2831:20180724:220827.654 ******************************
  2831:20180724:220827.654 using configuration file: /etc/zabbix/zabbix_server.conf
  2831:20180724:220827.654 cannot set resource limit: [13] Permission denied
  2831:20180724:220827.654 cannot disable core dump, exiting...
  2837:20180724:220837.804 Starting Zabbix Server. Zabbix 3.2.11 (revision 76339).
  2837:20180724:220837.804 ****** Enabled features ******
  2837:20180724:220837.804 SNMP monitoring:           YES
  2837:20180724:220837.804 IPMI monitoring:           YES
  2837:20180724:220837.804 Web monitoring:            YES
  2837:20180724:220837.804 VMware monitoring:         YES
  2837:20180724:220837.804 SMTP authentication:       YES
  2837:20180724:220837.804 Jabber notifications:      YES
  2837:20180724:220837.804 Ez Texting notifications:  YES
  2837:20180724:220837.804 ODBC:                      YES
  2837:20180724:220837.804 SSH2 support:              YES
  2837:20180724:220837.804 IPv6 support:              YES
  2837:20180724:220837.804 TLS support:               YES
  2837:20180724:220837.804 ******************************
  2837:20180724:220837.804 using configuration file: /etc/zabbix/zabbix_server.conf
  2837:20180724:220837.804 cannot set resource limit: [13] Permission denied
  2837:20180724:220837.804 cannot disable core dump, exiting...
//查看selinux狀態
[root@zabbix-server ~]# getenforce 
Enforcing
//臨時關閉selinux,永久關閉selinux
[root@zabbix-server ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@zabbix-server ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

//再次重啓zabbix-server.service,仍提示錯誤,查看日誌
 3089:20180724:221742.303 using configuration file: /etc/zabbix/zabbix_server.conf
  3089:20180724:221742.307 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  3089:20180724:221742.307 database is down: reconnecting in 10 seconds
  3089:20180724:221752.310 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
  3089:20180724:221752.310 database is down: reconnecting in 10 seconds
  
[root@zabbix-server ~]# mkdir /var/lib/mysql
[root@zabbix-server ~]# chown -R mysql.mysql /var/lib/mysql 
[root@zabbix-server ~]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
[root@zabbix-server ~]# systemctl stop zabbix-server.service 
[root@zabbix-server ~]# systemctl start zabbix-server.service   
[root@zabbix-server ~]# netstat -nltup

[root@zabbix-server ~]# netstat -nltup | grep :10051
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      3316/zabbix_server  
tcp6       0      0 :::10051                :::*                    LISTEN      3316/zabbix_server

7.配置zabbix-web

登陸配置網頁


輸入數據庫鏈接信息




第一次登陸


修改界面語言

修改默認管理員密碼

zabbix客戶端

1.在客戶端配置zabbix源

[root@zabbix-client1 ~]# rpm -i http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.8ox8dZ: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
[root@zabbix-client1 ~]# ls -l /etc/yum.repos.d/zabbix.repo 
-rw-r--r-- 1 root root 410 Sep 14  2016 /etc/yum.repos.d/zabbix.repo

2.安裝zabbix-agent,zabbix-sender

[root@zabbix-client1 ~]# yum -y install zabbix-agent zabbix-sender
Loaded plugins: fastestmirror
base                                                                                                | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                                | 5.6 kB  00:00:00     
epel                                                                                                | 3.2 kB  00:00:00     
extras                                                                                              | 3.4 kB  00:00:00     
updates                                                                                             | 3.4 kB  00:00:00     
zabbix                                                                                              | 2.9 kB  00:00:00     
zabbix-non-supported                                                                                |  951 B  00:00:00     
(1/3): epel/x86_64/updateinfo                                                                       | 930 kB  00:00:00     
(2/3): epel/x86_64/primary                                                                          | 3.5 MB  00:00:00     
(3/3): zabbix/x86_64/primary_db                                                                     |  87 kB  00:00:14     
zabbix-non-supported/x86_64/primary                                                                 | 1.6 kB  00:00:02     
...中間略...
Warning: RPMDB altered outside of yum.
  Installing : zabbix-sender-3.2.11-1.el7.x86_64                                                                       1/2 
  Installing : zabbix-agent-3.2.11-1.el7.x86_64                                                                        2/2 
  Verifying  : zabbix-agent-3.2.11-1.el7.x86_64                                                                        1/2 
  Verifying  : zabbix-sender-3.2.11-1.el7.x86_64                                                                       2/2 

Installed:
  zabbix-agent.x86_64 0:3.2.11-1.el7                          zabbix-sender.x86_64 0:3.2.11-1.el7                         

Complete!

3.編譯zabbix-agent配置文件

[root@zabbix-client1 ~]# vim /etc/zabbix/zabbix_agentd.conf 
//在主動模式和被動模式下配置zabbix-server的地址
##### Passive checks related
Server=10.0.1.60
##### Active checks related
ServerActive=10.0.1.60
//修改
Hostname=Zabbix-client1.local

[root@zabbix-client1 ~]# systemctl status zabbix-agent.service      
● zabbix-agent.service - Zabbix Agent
   Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2018-07-25 11:57:16 CST; 8s ago
  Process: 1865 ExecStart=/usr/sbin/zabbix_agentd -c $CONFFILE (code=exited, status=0/SUCCESS)
 Main PID: 1867 (zabbix_agentd)
   CGroup: /system.slice/zabbix-agent.service
           ├─1867 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
           ├─1868 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
           ├─1869 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
           ├─1870 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
           ├─1871 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
           └─1872 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]

Jul 25 11:57:16 zabbix-client1 systemd[1]: Starting Zabbix Agent...
Jul 25 11:57:16 zabbix-client1 systemd[1]: Started Zabbix Agent.
[root@zabbix-client1 ~]# systemctl enable zabbix-agent.service       
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.


4、 忘記Admin密碼如何作

如遺忘admin用戶密碼,可登陸mysql後臺修改其用戶名密碼

[root@zabbix-server ~]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 304
Server version: 5.6.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select alias,passwd,name from users;
+-------+----------------------------------+--------+
| alias | passwd                           | name   |
+-------+----------------------------------+--------+
| Admin | 3f58ad914e9a289cb81402b47abb4c84 | Zabbix |
| guest | d41d8cd98f00b204e9800998ecf8427e |        |
+-------+----------------------------------+--------+
//newpasswd替換爲新的密碼便可
update users set passwd=md5(‘newpasswd’) where alias=‘Admin’;


5、 主動模式和被動模式

主動或者被動是相對於zabbix-agent來說的

被動模式,服務端會主動鏈接客戶端獲取監控項目數據,客戶端被動地接受鏈接,並把監控信息傳遞給服務端

主動模式,客戶端會主動把監控數據彙報給服務端,服務端只負責接收便可。

當客戶端數量很是多時,建議使用主動模式,這樣能夠下降服務端的壓力。

服務端有公網ip,客戶端只有內網ip,但卻能連外網,這種場景適合主動模式


6、 添加監控主機

1.添加主機羣組zb-test


2.添加主機


幾個概念

應用 (application)

一組監控項組成的邏輯分組

監控項 (item)

你想要接收的主機的特定數據,一個度量數據。

觸發器 (trigger)

一個被用於定義問題閾值和「評估」監控項接收到的數據的邏輯表達式

圖形(graph)

監控數據的圖形化展現

自動發現(auto discovery)

經過預設的規則,zabbix自動添加主機及相關監控內容。


7、 添加自定義模板

添加模板能夠經過複製其餘預設模板中的監控項來生成,可是自動發現沒法複製,須要導出預設模板設置,修改後再導入。比較容易出錯。不推薦。

這裏介紹連接的方式生成自定義模板。

1.配置→模板→建立模板

填入相應的信息,點擊最下方的添加便可添加模板,可是這時候的新添加的模板是空的,沒有監控項,觸發器等內容。

2.給新添加的模板添加連接模板

勾選想要連接的模板,點擊下方的選擇

3.修改,刪除沒必要要的監控項,程序集等內容

取法連接,可是保留以前連接的內容

4.如今能夠在監控項刪除不須要的項,而後能夠刪除不須要的程序集,修改圖形,自動發現等

選中不須要的,點最下方的刪除

刪除無用的應用集

刪除圖形

其餘項的刪除動做相似。至些咱們就獲得了一個咱們想要的模板。

添加好之後,咱們能夠將模板應用到咱們新添加的主機上。


8、 處理圖形中的亂碼

瀏覽圖形時發現中文顯示不了,由於缺乏中文字符

解決辦法

  1. 從windows系統下複製一種中文字體上傳到zabbix-server的/usr/share/zabbix/fonts/目錄下。上傳可用winscp或xftp實現。
[root@zabbix-server fonts]# ls
graphfont.ttf  simsun.ttc

2.修改simsun.ttc爲simsun.ttf

[root@zabbix-server fonts]# ls -l
total 17788
lrwxrwxrwx. 1 root root       33 Jul 25 09:35 graphfont.ttf -> /etc/alternatives/zabbix-web-font
-rw-r--r--  1 root root 18214356 Jul 27 10:10 simsun.ttf

3.修改字體連接

[root@zabbix-server fonts]# mv graphfont.ttf graphfont.ttf.bak
[root@zabbix-server fonts]# ln -s simsun.ttf graphfont.ttf
[root@zabbix-server fonts]# ls -l
total 17788
lrwxrwxrwx  1 root root       10 Jul 27 10:12 graphfont.ttf -> simsun.ttf
lrwxrwxrwx. 1 root root       33 Jul 25 09:35 graphfont.ttf.bak -> /etc/alternatives/zabbix-web-font
-rw-r--r--  1 root root 18214356 Jul 27 10:10 simsun.ttf

4.再查看,已經正常


9、 自動發現

由於默認是1小時的間隔,爲了實驗效果,這裏改爲30秒

此時在圖形裏已經可看到網卡的流量信息

若是須要更改圖形的參數,能夠在模板裏修改


10、 添加自定義監控項目

需求:監控某臺web的80端口鏈接數,並出圖

1.在被監控端新建腳本

[root@zabbix-client1 ~]# vim /usr/local/sbin/estab.sh 
#!/bin/bash

# 獲取80端口併發鏈接數
netstat -ant | grep ':80' | grep -c ESTABLISHED

//賦予755權限
[root@zabbix-client1 ~]# chmod 755 /usr/local/sbin/estab.sh

2.編譯被監控端的配置文件

[root@zabbix-client1 ~]# vim /etc/zabbix/zabbix_agentd.conf 
//增長
//表示使用自定義腳本
UnsafeUserParameters=1  
UserParameter=my.estab.count[*],/usr/local/sbin/estab.sh 
//重啓服務
[root@zabbix-client1 ~]# systemctl restart zabbix-agent.service

3.在服務器上驗證客戶端腳本配置成功

[root@zabbix-server fonts]# zabbix_get -s 10.0.1.61 -p 10050 -k 'my.estab.count'
0

4.服務器端配置

建立監控項

建立圖形

在客戶端進行壓力測試


11、 配置郵件告警及測試

1.使用163郵箱發告警郵件
首先登陸你的163郵箱,設置開啓POP三、IMAP、SMTP服務, 而後開啓並記錄受權碼

2.在監控中心設置郵件告警

3.建立報警腳本mail.py

[root@zabbix-server fonts]# vim vim /usr/lib/zabbix/alertscripts/mail.py
//內容參考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D22Z/mail.py
#!/usr/bin/env python
#-*- coding: UTF-8 -*-
import os,sys
reload(sys)
sys.setdefaultencoding('utf8')
import getopt
import smtplib
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from  subprocess import *

def sendqqmail(username,password,mailfrom,mailto,subject,content):
    gserver = 'smtp.qq.com'
    gport = 25

    try:
        msg = MIMEText(unicode(content).encode('utf-8'))
        msg['from'] = mailfrom
        msg['to'] = mailto
        msg['Reply-To'] = mailfrom
        msg['Subject'] = subject

        smtp = smtplib.SMTP(gserver, gport)
        smtp.set_debuglevel(0)
        smtp.ehlo()
        smtp.login(username,password)

        smtp.sendmail(mailfrom, mailto, msg.as_string())
        smtp.close()
    except Exception,err:
        print "Send mail failed. Error: %s" % err


def main():
    to=sys.argv[1]
    subject=sys.argv[2]
    content=sys.argv[3]
##定義QQ郵箱的帳號和密碼,你須要修改爲你本身的帳號和密碼(請不要把真實的用戶名和密碼放到網上公開,不然你會死的很慘)
    sendqqmail('1234567@qq.com','aaaaaaaaaa','1234567@qq.com',to,subject,content)

if __name__ == "__main__":
    main()

[root@zabbix-server fonts]# chmod 755 !$
chmod 755 /usr/lib/zabbix/alertscripts/mail.py
[root@zabbix-server fonts]# ls -l !$
ls -l /usr/lib/zabbix/alertscripts/mail.py
-rwxr-xr-x 1 root root 1220 Jul 27 11:38 /usr/lib/zabbix/alertscripts/mail.py

4.建立告警用戶

將新添加用戶添加到管理員組,而後設定擁有讀寫權限。權限須要在羣組裏設置

5.設置動做

6.測試報警

根據觸發器的定義來測試達到報警條件

以zabbix-template-test: /etc/passwd has been changed on {HOST.NAME}爲例 ,修改後

郵件系統中正常收到報警郵件

將被監控端斷網1分鐘,根據觸發器定義,產生報警。

郵件web端正常收到報警郵件

恢復被監控端的網絡


12、 不發郵件的問題處理

可能緣由

1.用戶權限
2.用戶媒介有沒有設置郵箱
3.發郵件腳本的權限是否755
4.腳本的位置是否在/usr/lib/zabbix/alertscripts/下
5.發郵件腳本正不正常,最好事先測試一下。格式: mail.py ‘收件人地址’ ‘主題’ ‘內容’
腳本參考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D22Z/mail.py


十3、 擴展

zabbix監控交換機(思科)

http://tryrus.blog.51cto.com/10914693/1789847

zabbix遠程執行命令

http://www.ywnds.com/?p=6610

zabbix分佈式部署

http://sfzhang88.blog.51cto.com/4995876/1364399

zabbix監控tomcat(版本有點老,你們只須要參考步驟,不能照搬)

http://www.fblinux.com/?p=616

相關文章
相關標籤/搜索