zabbix監控流程圖php
準備兩臺主機:python
zabbix服務端:192.168.133.88mysql
zabbix客戶端:192.168.133.66nginx
咱們epl的yum倉庫裏存放的zabbix的版本較低,因此咱們先搭建一個zabbix的yum倉庫,服務端和客戶端上都要作這個步驟。web
1.下載zabbix yum包地址https://www.zabbix.com/download?zabbix=3.2&os_distribution=centos&os_version=7&db=MySQLsql
2.安裝完zabbix發現就是多了一個zabbix yum源數據庫
[root@centos-03 ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
獲取http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
警告:/var/tmp/rpm-tmp.OiXov8: 頭V4 RSA/SHA512 Signature, 密鑰 ID a14fe591: NOKEY
準備中... ################################# [100%]
正在升級/安裝...
1:zabbix-release-3.2-1.el7 ################################# [100%]
[root@centos-03 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel-testing.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo epel.repo zabbix.repo
[root@centos-03 ~]# ls /etc/yum.repos.d/
3.有了這個源以後就能夠安裝zabbix了express
服務端apache
[root@centos-02 ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
zabbix-agent:zabbix客戶端軟件 zabbix-get:服務端的一個應用工具,經過命令行的形式,得到客戶端的某些監控項目數據 zabbix-server-mysql:一些和mysql相關的文件 zabbix-web:web界面 zabbix-web-mysql:web還要和mysql打交道,一些MySQL和web的文件
客戶端vim
[root@centos-03 /]# yum install -y zabbix-agent
客戶端只須要安裝zabbix-agent就能夠了
兩臺機子若是MySQL沒有安裝,參照以前lamp章節的安裝
啓動mysql若是失敗查看mysql錯誤日誌文件提示不能read-write多是由於數據庫文件目錄/data/mysql的權限是root須要改爲mysql
chown -R mysql:mysql /data/mysql/
安裝前看是否安裝過mysql,
yum list installed mysql*
若是有就用yum remove卸載mysql
查看yum庫下是否有mysql-server
yum list | grep mysql 或 yum -y list mysql*
若是沒有(通常在centos7下沒有)
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
而後安裝mysql
yum install mysql-server
yum install mysql-devel
若是有mysql-server,則按下面步驟
安裝mysql客戶端:
[root@centos-03 /]# rpm -ivh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 獲取http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 準備中... ################################# [100%] 正在升級/安裝... 1:mysql-community-release-el7-5 ################################# [100%] [root@centos-03 /]# yum install -y mysql-server [root@centos-03 /]# yum install -y mysql-devel [root@centos-03 /]# service mysqld start Redirecting to /bin/systemctl start mysqld.service [root@centos-03 /]# mysql -uroot -p Enter password: 直接回車
[root@centos-02 mysql]# ps aux|grep mysqld mysql 3276 0.0 0.1 113256 1556 ? Ss 16:44 0:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr mysql 3443 0.7 11.9 961120 119848 ? Sl 16:44 0:11 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock root 3515 0.0 0.0 112664 932 pts/0 S+ 17:09 0:00 grep --color=auto mysqld [root@centos-02 mysql]#
1.編輯mysql的配置文件設置默認字符集
[root@centos-02 mysql]# vim /etc/my.cnf [root@centos-02 mysql]# character_set_server = utf8 (設置字符級,不設置的話,web界面設置中文可能會出現亂碼)
2.重啓mysql,建立zabbix庫在服務端的MySQL上建立zabbix的庫和用戶,用戶是須要php代碼鏈接mysql,zabbix-server也是須要連接的
[root@centos-02 mysql]# service mysqld restart Redirecting to /bin/systemctl restart mysqld.service [root@centos-02 mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.39 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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>
mysql> create database zabbix character set utf8; Query OK, 1 row affected (0.01 sec) mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'zabbix'; Query OK, 0 rows affected (0.10 sec) mysql> quit; Bye [root@centos-02 mysql]#
3.導入一些原始的數據,沒有這些數據,zabbix沒辦法工做
[root@centos-02 mysql]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/ [root@centos-02 mysql]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/ [root@centos-02 zabbix-server-mysql-3.2.11]# ls AUTHORS ChangeLog COPYING create.sql.gz NEWS README [root@centos-02 zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz [root@centos-02 zabbix-server-mysql-3.2.11]# ls AUTHORS ChangeLog COPYING create.sql NEWS README [root@centos-02 zabbix-server-mysql-3.2.11]# mysql -uroot -p zabbix < create.sql Enter password: [root@centos-02 zabbix-server-mysql-3.2.11]#
4.啓動zabbix和httpd服務,再啓動httpd前,先看一下有沒有啓動nginx服務,若是有的話須要停掉
[root@centos-02 zabbix-server-mysql-3.2.11]# systemctl start zabbix-server [root@centos-02 zabbix-server-mysql-3.2.11]#
[root@centos-02 zabbix-server-mysql-3.2.11]# ps aux|grep nginx root 3793 4.0 0.0 112664 932 pts/0 S+ 17:43 0:00 grep --color=auto nginx [root@centos-02 zabbix-server-mysql-3.2.11]# /etc/init.d/nginx stop
[root@centos-02 zabbix-server-mysql-3.2.11]# 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:22 0.0.0.0:* LISTEN 871/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1320/master tcp6 0 0 :::3306 :::* LISTEN 3734/mysqld tcp6 0 0 :::22 :::* LISTEN 871/sshd tcp6 0 0 ::1:25 :::* LISTEN 1320/master [root@centos-02 zabbix-server-mysql-3.2.11]#
5.啓動http服務
[root@centos-02 zabbix-server-mysql-3.2.11]# systemctl start httpd [root@centos-02 zabbix-server-mysql-3.2.11]# 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:22 0.0.0.0:* LISTEN 871/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1320/master tcp6 0 0 :::3306 :::* LISTEN 3734/mysqld tcp6 0 0 :::80 :::* LISTEN 3817/httpd tcp6 0 0 :::22 :::* LISTEN 871/sshd tcp6 0 0 ::1:25 :::* LISTEN 1320/master [root@centos-02 zabbix-server-mysql-3.2.11]#
6.若是要開啓啓動,須要添加到服務的啓動列表裏
[root@centos-02 zabbix-server-mysql-3.2.11]# systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. [root@centos-02 zabbix-server-mysql-3.2.11]# systemctl enable zabbix-server Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service. [root@centos-02 zabbix-server-mysql-3.2.11]# systemctl disable nginx^C [root@centos-02 zabbix-server-mysql-3.2.11]# chkconfig nginx off^C [root@centos-02 zabbix-server-mysql-3.2.11]# ps aux|grep zabbix zabbix 4039 1.0 0.0 0 0 ? Zs 18:14 0:00 [zabbix_server] <defunct> zabbix 4040 2.0 0.0 0 0 ? Z 18:14 0:00 [zabbix_server] <defunct> root 4042 1.0 0.0 112664 932 pts/0 R+ 18:14 0:00 grep --color=auto zabbix
7.沒有zabbix的服務
[root@centos-02 ~]# netstat -nvlt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp6 0 0 :::3306 :::* LISTEN tcp6 0 0 :::80 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN [root@centos-02 ~]#
8.咱們啓動了zabbix,用ps發現進程在,可是用natstat查看,沒有zabbix的端口,是由於沒有鏈接MySQL,須要配置zabbix的配置文件
[root@centos-02 ~]# less /var/log/zabbix/zabbix_server.log (這是zabbix的日誌文件)
9.編輯配置文件
[root@centos-02 ~]# vim /etc/zabbix/zabbix_server.conf DBHost=127.0.0.1 (搜索DBHost,指定數據庫所在機器的IP,不是建立用戶時的來源ip)
默認DBname=zabbix (數據庫名字)
DBuser=zabbix (登陸數據庫的用戶名)
DBPassword=zabbix (這個密碼是受權時候設置的密碼,登陸數據庫的密碼)
10.重啓zabbix_server服務,查看zabbix服務
[root@centos-02 ~]# systemctl restart zabbix-server [root@centos-02 ~]# ps aux|grep zabbix zabbix 6430 0.1 0.3 183380 3916 ? S 21:52 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf zabbix 6432 0.2 0.3 183388 3244 ? S 21:52 0:01 /usr/sbin/zabbix_server: configuration syncer [synced configuration in 0.090700 sec, idle 60 sec] zabbix 6433 0.0 0.2 183380 2992 ? S 21:52 0:00 /usr/sbin/zabbix_server: db watchdog [synced alerts config in 0.092265 sec, idle 60 sec] zabbix 6434 0.0 0.5 290300 5348 ? S 21:52 0:00 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000040 sec, idle 5 sec] zabbix 6435 0.1 0.5 290300 5348 ? S 21:52 0:00 /usr/sbin/zabbix_server: poller #2 [got 0 values in 0.000094 sec, idle 5 sec] zabbix 6436 0.1 0.5 290300 5348 ? S 21:52 0:00 /usr/sbin/zabbix_server: poller #3 [got 0 values in 0.000038 sec, idle 5 sec] zabbix 6437 0.1 0.5 290300 5348 ? S 21:52 0:00 /usr/sbin/zabbix_server: poller #4 [got 0 values in 0.000040 sec, idle 5 sec]
[root@centos-02 ~]# 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:22 0.0.0.0:* LISTEN 871/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1320/master tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 6430/zabbix_server tcp6 0 0 :::3306 :::* LISTEN 3734/mysqld tcp6 0 0 :::80 :::* LISTEN 3817/httpd tcp6 0 0 :::22 :::* LISTEN 871/sshd tcp6 0 0 ::1:25 :::* LISTEN 1320/master tcp6 0 0 :::10051 :::* LISTEN 6430/zabbix_server [root@centos-02 ~]#
11.配置web界面,直接訪問服務端主機名加zabbix。例如(192.168.133.88/zabbix),若是不能訪問多是iptables防火牆沒關閉
12.點next step 咱們發現只有這一行是錯誤的
PHP option "date.timezone"unknown
Fail
13.編輯php配置文件設置時區爲Asia/Shanghai,重啓httpd服務
[root@centos-02 ~]# vim /etc/php.ini [root@centos-02 ~]# date.timezone = Asia/Shanghai [root@centos-02 ~]# systemctl restart httpd
14.刷新頁面,變成ok了
15.繼續web界面的下一步(也就是MySQL的界面了)
port端口號:3360
密碼寫在數據庫中建立用戶的密碼。
若是顯示sock文件不存在,則把用戶改爲127.0.0.1
16.定義zabbix server的界面
自定義Name
17.繼續下一步
1八、登陸zabbix
(一)默認用戶爲admin
默認登錄密碼爲zabbix
19.修改密碼,設置語言
[root@centos-02 ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 696 Server version: 5.6.39 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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>
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.01 sec) mysql> desc users -> ; +----------------+---------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+---------------------+------+-----+---------+-------+ | userid | bigint(20) unsigned | NO | PRI | NULL | | | alias | varchar(100) | NO | UNI | | | | name | varchar(100) | NO | | | | | surname | varchar(100) | NO | | | | | passwd | char(32) | NO | | | | | url | varchar(255) | NO | | | | | autologin | int(11) | NO | | 0 | | | autologout | int(11) | NO | | 900 | | | lang | varchar(5) | NO | | en_GB | | | refresh | int(11) | NO | | 30 | | | type | int(11) | NO | | 1 | | | theme | varchar(128) | NO | | default | | | attempt_failed | int(11) | NO | | 0 | | | attempt_ip | varchar(39) | NO | | | | | attempt_clock | int(11) | NO | | 0 | | | rows_per_page | int(11) | NO | | 50 | | +----------------+---------------------+------+-----+---------+-------+ 16 rows in set (0.26 sec) mysql>
mysql> update users set passwd=md5('admin888') where alias='admin'; Query OK, 0 rows affected (0.25 sec) Rows matched: 1 Changed: 0 Warnings: 0 mysql> select * from users; +--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+------------+---------------+---------------+ | userid | alias | name | surname | passwd | url | autologin | autologout | lang | refresh | type | theme | attempt_failed | attempt_ip | attempt_clock | rows_per_page | +--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+------------+---------------+---------------+ | 1 | Admin | Zabbix | Administrator | 7fef6171469e80d32c0559f88b377245 | | 1 | 0 | zh_CN | 30 | 3 | default | 0 | | 0 | 50 | | 2 | guest | | | d41d8cd98f00b204e9800998ecf8427e | | 0 | 900 | en_GB | 30 | 1 | default | 0 | | 0 | 50 | +--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+------------+---------------+---------------+ 2 rows in set (0.00 sec) mysql>
1.
1.安裝yum源
[root@centos-03 ~]# rpm -ivh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
[root@centos-03 ~]# yum install -y zabbix-agent
2.編輯配置文件,在客戶端上須要指定服務端的ip,(主動被動一塊兒開啓會比較好)
[root@centos-03 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.133.88 (被動模式):等待服務端來取數據
ServerActive=192.168.133.88 (主動模式):主動上報數據
Hostname=centos-03 (不能隨便寫,要寫可以識別的主機名)
[root@centos-03 ~]# systemctl start zabbix-agent [root@centos-03 ~]# ps aux|grep zabbix zabbix 3377 0.9 0.1 80592 1276 ? S 23:29 0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf zabbix 3378 0.1 0.1 80592 1284 ? S 23:29 0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec] zabbix 3379 0.0 0.1 80592 1840 ? S 23:29 0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection] zabbix 3380 0.0 0.1 80592 1840 ? S 23:29 0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection] zabbix 3381 0.0 0.1 80592 1840 ? S 23:29 0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection] zabbix 3382 0.1 0.2 80592 2124 ? S 23:29 0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec] root 3384 0.0 0.0 112664 932 pts/0 R+ 23:29 0:00 grep --color=auto zabbix [root@centos-03 ~]#
[root@centos-03 ~]# 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:22 0.0.0.0:* LISTEN 965/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1402/master tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 3377/zabbix_agentd tcp6 0 0 :::3306 :::* LISTEN 3038/mysqld tcp6 0 0 :::22 :::* LISTEN 965/sshd tcp6 0 0 ::1:25 :::* LISTEN 1402/master tcp6 0 0 :::10050 :::* LISTEN 3377/zabbix_agentd [root@centos-03 ~]#
3.加入到開機啓動列表
[root@centos-03 ~]# systemctl enable zabbix-agent
1.添加主機:在添加主機以前,咱們要先添加一個主機羣組,在配置中主機羣組的右上角有一個建立主機羣組,組名命名爲zabbix,添加
2.而後再點主機,建立主機。
3.點擊添加
應用集;應用集就是監控項的集合,更加方便的管理監控項
監控項:每一項都是監控的數據
觸發器:針對某一個監控項設置一個告警規則
圖形:每個數據zabbix都有記錄,會造成一個圖表
自動發現規則:自動發現的項目
web場景:監控一個網站或者一個網址。
1.能夠自定義一個經常使用模板,方便給新增主機添加監控項目
2.把其餘自帶模板裏面的某些監控項目(好比cpu,內存等)複製到zabbix模板裏
3.相同方法添加自動發現並無複製按鈕。
4.解決方法有兩個:
一個是導出模板,生成了一個xml文件,將不須要的都刪除,修改模板名,保留自動發現,而後導入。
二是用連接模板方式,詳情見下文
5.刪除剛剛導入的6項監控項,
6.選擇連接的模板,點擊添加,而後點更新
7.如圖發現選項有點多,能夠刪除些選項
8.當咱們要刪除監控項時,提示沒法刪除,由於監控項在連接的模板裏,沒法刪除
9.咱們能夠點擊取消連接,更新,而後再刪除就能夠了
10.刪除的話要先取消鏈接,更新後先刪監控項(監控項保留下面的,其餘的都刪除),再刪應用集。
11.應用集保留監控項後面有數字的
12.圖形刪除
13.這樣模板就建成功了
1.將模板和主機相連
2.更新
3.圖形預覽發現有亂碼,這是由於在zabbix字體庫中沒有中文字體。須要從windows上借用一個過來。
4.查看字體存放路徑
[root@centos-02 ~]# vim /usr/share/zabbix/include/defines.inc.php [root@centos-02 ~]# ls /usr/share/zabbix/fonts/ graphfont.ttf [root@centos-02 ~]# ls -l !$ ls -l /usr/share/zabbix/fonts/ 總用量 0 lrwxrwxrwx 1 root root 33 3月 10 15:53 graphfont.ttf -> /etc/alternatives/zabbix-web-font [root@centos-02 ~]# ls -l /etc/alternatives/zabbix-web-font lrwxrwxrwx 1 root root 38 3月 10 15:53 /etc/alternatives/zabbix-web-font -> /usr/share/fonts/dejavu/DejaVuSans.ttf
5.從Windows上覆制一個字體放到桌面,而後上傳到centos-02服務器上的src目錄
C:\Windows\Fonts
[root@centos-02 src]# rz [root@centos-02 src]# ls SIMLI.TTF [root@centos-02 src]#
[root@centos-02 src]# mv SIMLI.TTF /usr/share/zabbix/fonts/ [root@centos-02 src]# cd !$ cd /usr/share/zabbix/fonts/ [root@centos-02 fonts]# ls graphfont.ttf SIMLI.TTF [root@centos-02 fonts]# mv graphfont.ttf graphfont.ttf.bak; ln SIMLI.TTF graphfont.ttf [root@centos-02 fonts]# ls -l 總用量 18016 -rw-r--r-- 2 root root 9223160 11月 5 2003 graphfont.ttf lrwxrwxrwx 1 root root 33 3月 10 15:53 graphfont.ttf.bak -> /etc/alternatives/zabbix-web-font -rw-r--r-- 2 root root 9223160 11月 5 2003 SIMLI.TTF [root@centos-02 fonts]# rm -f graphfont.ttf [root@centos-02 fonts]# ln -s SIMLI.TTF graphfont.ttf [root@centos-02 fonts]# ls -l 總用量 9008 lrwxrwxrwx 1 root root 9 3月 11 23:29 graphfont.ttf -> SIMLI.TTF lrwxrwxrwx 1 root root 33 3月 10 15:53 graphfont.ttf.bak -> /etc/alternatives/zabbix-web-font -rw-r--r-- 1 root root 9223160 11月 5 2003 SIMLI.TTF [root@centos-02 fonts]#
6.刷新網頁,中文顯示正常了
5、zabbix遠程執行命令
監控,有的人只把他當作報警使用,出現問題以後打開跑回家打開電腦處理掉,大多數時候都是一些已知問題,爲什麼不讓zabbix幫你把這些事情處理掉呢?
Zabbix遠程執行命令能夠作些什麼:
1)重啓應用(apache/nginx/mysql)。
2)自定義執行腳本。
3)使用IPMI接口重啓服務器。
4)自動釋放磁盤空間(刪除老文件,清除/tmp目錄等等)。
5)CPU過載時將一個虛擬機遷移到另一個物理服務器。
6)雲環境下,一臺服務器CPU\硬盤\內存\其餘硬件資源不足的狀況下,能夠自動添加過去。
Zabbix遠程執行命令注意事項:
1)遠程執行命令是server端向agent端執行,不支持主動模式的agent;
2)不支持代理模式;
3)zabbix用戶必須對命令具備執行權限,可使用sudo賦予root權限(配置sudo無密碼方式);
4)遠程命令只是執行,執行成功與否並不檢測並確認,可在」 Monitoring–>Events」中查看action執行時,或在」Reports–>Action log」中查看遠程命令是否執行成功(成功爲」 Executed」)。
建立一個報警,記得使用郵件報警嗎?實際上,咱們把發送郵件的操做改爲執行遠程命令就好了。
Zabbix agent不支持遠程命令,遠程命令最大長度爲255字符,同時支持多個遠程命令,如須要執行多條命令,只須要另起一行寫命令便可,但最好自定在agent端定義一個腳本,直接讓zabbix執行腳本便可。還有,遠程命令可使用宏變量。
1)配置zabbix-agent端
首先咱們須要在zabbix agent端開啓對遠程命令的支持,修改配置文件zabbix_agentd.conf中的參數,而後重啓客戶端:
1 |
EnableRemoteCommands = 1 |
另外,在執行命令時確保你的zabbix用戶有執行權限,若是某些命令須要root權限,那麼請使用sudo。編輯sudoer文件,zabbix用戶即可以執行nginx -s reload命令了。
1 2 |
zabbix ALL=NOPASSWD: ALL zabbix ALL=NOPASSWD: /etc/init.d/nginx stop,/etc/init.d/nginx start |
2)配置zabbix-server端
ConfigurationàActionsà Operation,其中operation type改爲Remote Command,而後寫上要在zabbix-agent執行的命令便可。以下圖:
Type:IPMI、custom script、ssh、telnet、global script。
若是你要執行自定義的腳本,以下操做:
直接執行腳本便可。
1.修改自動發現間隔時間爲60秒
SHA
2.刷新頁面圖形變爲3個了
3.重啓下zabbix服務器和客戶端,讓效果更快顯示
[root@centos-02 ~]# systemctl restart zabbix-server [root@centos-02 ~]# ^C [root@centos-02 ~]# [root@centos-03 ~]# systemctl restart zabbix-agent [root@centos-03 ~]#
4.sar命令監測網卡流量
sar -n DEV 1 100
1.監控某臺web的80端口鏈接數,並出圖。
2.查看80端口的網絡鏈接數
[root@centos-03 ~]# netstat -ant |grep ':80' |grep -c ESTABLISHED 0 [root@centos-03 ~]#
步驟:
1):zabbix監控中心建立監控項目
2):針對該監控項目以圖形展示
3.編寫腳本
[root@centos-02 ~]# vim /usr/local/sbin/estab.sh [root@centos-02 ~]# #!/bin/bash ##獲取80端口併發鏈接數 netstat -ant |grep ':80 ' |grep -c ESTABLISHED
[root@centos-03 ~]# chmod 755 /usr/local/sbin/estab.sh
[root@centos-03 ~]# vim /etc/zabbix/zabbix_agentd.conf [root@centos-03 ~]# UnsafeUserParameters=1 去掉#號,並修改成1,表示開啓使用自定義腳本
UserParameter=my.estab.count[*],/usr/local/sbin/estab.sh 自定義監控項的key爲my.estab.count,後面的{*}裏面寫腳本的參數,若是沒有參數能夠省略,腳本爲/usr/local/sbin/estab.sh
4.重啓zabbix-agent服務
[root@centos-03 ~]# systemctl restart zabbix-agent [root@centos-03 ~]#
5.驗證
[root@centos-02 ~]# zabbix_get -s 192.168.133.66 -p 10050 -k 'my.estab.count' 到服務端驗證,執行命令,結果返回爲0,表示腳本定義成功 0 [root@centos-02 ~]#
6.在zabbix監控中心(瀏覽器)配置增長監控項目
名稱自定義
鍵值填寫my.estab.count
歷史數據保留時長 (數據存儲多長時間)
趨勢數據存儲週期
7.還須要作一個圖形
8.觸發器-->建立觸發器
使用163或者qq郵箱發告警郵箱
由於qq郵箱有時候會收不到告警,因此咱們選用163郵箱來作實驗,勾選pop3設置受權碼
1.在監控中心設置郵件告警
管理--> 報警沒接類型-->建立媒體類型
(雖然zabbix給了咱們email的模板,可是咱們用python寫一個腳本,用腳本的形式來實現)
腳本的參數分別表明了
{ALERT.SENDTO} 收件人
{ALERT.SUBJECT} 主題
{ALERT.MESSAGE} 內容
1.建立報警腳本mail.py
首先咱們要知道配置文件裏,把自定義腳本放在哪一個目錄下。
[root@centos-02~]# vim /etc/zabbix/zabbix_server.conf //搜索alert
咱們發現路徑是
AlertScriptsPath=/usr/lib/zabbix/alertscripts
[root@centos-02 ~]# cd /usr/lib/zabbix/alertscripts/ [root@centos-02 alertscripts]# vi mail.py [root@centos-02 alertscripts]# #!/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.163.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('sunyu***_de@163.com', 'sunyujun163','sunyu***_de@163.com',to,subject,content) if __name__ == "__main__": main()
[root@centos-02 alertscripts]# chmod 755 mail.py [root@centos-02 alertscripts]# python mail.py sunyujun_de@163.com "title" "content" [root@centos-02 alertscripts]#
2.成功
3.建立用戶
4.設置報警媒介
5.權限這裏要注意了,如今全部組權限爲無,須要修改組的權限
6.用戶配置完了,還須要配置動做(觸發器觸發後我要作的事情)
爲了讓zabbix報警,咱們建立一個錯誤,建立一個觸發器
最近20個問題列表下出現了
修改監控項
再查看郵件ok了