CentOS 7.3安裝Zabbix 3.2

一、準備搭建環(huán)境

1.系統(tǒng):CentOS 7.3

2.軟件:Zabbix 3.2

主機 IP地址 系統(tǒng)
Zabbix Server 10.10.1.113 CentOS 7.3
Linux-Agent 10.10.10.114 CentOS 7.3
Windows-Agent 10.10.10.110 Windows Server 2008 R2

二、安裝前的準備

最小化安裝CentOS 7系統(tǒng)時,需要做一下設(shè)置:

1.安裝所需的軟件包

yum groupinstall "Development Tools"

yum -y install vim lrzsz tree wget ntp mlocate

ntpdate time.nist.gov   #與時間同步服務(wù)器同步

2.關(guān)閉firewalld和iptables防火墻服務(wù)

centos從7開始默認用的是firewalld,這個是基于iptables的,雖然有iptables的核心,但是iptables的服務(wù)是沒安裝的。所以你只要停止firewalld服務(wù)即可:

systemctl stop firewalld.service        #停止firewall
systemctl disable firewalld.service     #禁止firewall開機啟動
firewall-cmd --state          #查看默認防火墻狀態(tài)(關(guān)閉后顯示notrunning,開啟后顯示running)

如果你要改用iptables的話,需要安裝iptables服務(wù):

yum install iptables-services
systemctl enable iptables 
systemctl enable ip6tables
systemctl start iptables 
systemctl start ip6tables

3.關(guān)閉SElinux

使用這個命令查看SElinux狀態(tài)

[root@localhost ~]# getenforce
Enforcing

[root@localhost ~]# vim /etc/selinux/config
#在文件中找到這一行
SELINUX=enforcing
#把后面的參數(shù)修改為disabled
SELinux=disabled
  • enforcing:開啟防火墻
  • permissive:關(guān)閉防火墻,但是會產(chǎn)生相應(yīng)的日志
  • disabled:徹底關(guān)閉防火墻,沒日志產(chǎn)生

不關(guān)機情況下關(guān)閉SElinux,這個在重啟之后會失效,臨時關(guān)閉

[root@localhost ~]# setenforce 0

三、安裝Zabbix3.2

1)安裝LAMP環(huán)境

yum -y install mariadb mariadb-server php php-mysql httpd

#配置數(shù)據(jù)庫開機啟動
systemctl enable mariadb
systemctl start mariadb

#配置Apache服務(wù)開機自啟
systemctl enable httpd
systemctl start httpd

2) 配置數(shù)據(jù)庫

  • 查看MariaDB數(shù)據(jù)庫在進程的狀態(tài)
[root@localhost ~]# ss -tulnp | grep mysqld
tcp    LISTEN     0      50        *:3306     *:*   users:(("mysqld",pid=2674,fd=14))
  • 初始化mysql數(shù)據(jù)庫,并配置root用戶密碼(默認為空密碼)
    • mysql_secure_installation會執(zhí)行以下幾個設(shè)置:
    • a)為root用戶設(shè)置密碼
    • b)刪除匿名賬號
    • c)取消root用戶遠程登錄
    • d)刪除test庫和對test庫的訪問權(quán)限
    • e)刷新授權(quán)表使修改生效
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

MariaDB_initialization
  • 創(chuàng)建zabbix數(shù)據(jù)庫及訪問用戶
mysql -uroot -proot -e "create database zabbix default character set utf8 collate utf8_bin;"

mysql -uroot -proot -e "grant all on zabbix.* to 'zabbix'@'%' identified by 'zabbix';"
  • 測試剛創(chuàng)建的數(shù)據(jù)庫及用戶
mysql -uzabbix -pzabbix

show databases;

exit;

3)安裝Zabbix Server端

  • 導(dǎo)入yum源
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
  • 安裝Zabbix
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
  • 導(dǎo)入zabbix數(shù)據(jù)結(jié)構(gòu)
[root@localhost ~]# updatedb             #生成查找快照
[root@localhost ~]# locate create.sql    #查找create.sql文件位置
/usr/share/doc/zabbix-server-mysql-3.2.7/create.sql.gz
[root@localhost ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.7
[root@localhost zabbix-server-mysql-3.2.7]# zcat create.sql.gz | mysql -uroot -proot zabbix
  • 修改Zabbix Server配置文件
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf

新增如下內(nèi)容:

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix
  • 修改Zabbix的php配置文件
vim /etc/httpd/conf.d/zabbix.conf

取消內(nèi)容為:php_value date.timezone的注釋,并調(diào)整值為:Asia/Shanghai
  • 啟動Zabbix-Server,設(shè)置為開機自啟動
[root@localhost ~]# systemctl enable zabbix-server
[root@localhost ~]# systemctl start zabbix-server
[root@localhost ~]# systemctl enable zabbix-agent
[root@localhost ~]# systemctl start zabbix-agent
  • 重啟Apache服務(wù)器
[root@localhost ~]# systemctl restart httpd
  • 瀏覽器訪問Zabbix-Server,進一步安裝Zabbix

    • 使用http://IP/zabbix訪問
      Zabbix_index
    • 檢查組件是否所有ok,直接下一步


      Zabbix_Check_pre
    • 創(chuàng)建數(shù)據(jù)庫的連接:輸入端口號和密碼


      Zabbix_DB_cnt

      Zabbix_Name

      Zabbix_Summary
    • 完成安裝


      Zabbix_Install
    • 默認登錄賬戶密碼:Admin/zabbix


      Zabbix_login
    • 設(shè)置語言為中文:Chinese(zh_CN)


      Zabbix_Status

      Zabbix_Language
    • 簡單設(shè)置一下,啟用Zabbix Server的監(jiān)控


      Zabbix_enable
  • 解決亂碼問題

    Zabbix_Garbled

    解決辦法如下:
    在Windows系統(tǒng)下Win+R打開運行,輸入fonts,回車進入Windows字體目錄,找到黑體-常規(guī),復(fù)制出來將文件名修改為simhei.ttf,然后上傳到/usr/share/zabbix/fonts

    Fonts
    [root@localhost  ~]# cd /usr/share/zabbix/fonts
    [root@localhost fonts]# rz     #上傳simheil.ttf字體
    [root@localhost fonts]# ls
    graphfont.ttf  simhei.ttf 
    

    上傳成功后,編輯 /usr/share/zabbix/include/defines.inc.php這個文件

    大約在45行,將'graphfont' 修改為simhei 。

     [root@localhost fonts]# vim /usr/share/zabbix/include/defines.inc.php
     44 define('ZBX_FONTPATH',                          realpath('fonts')); // where to search for font (GD > 2.0.18)
     45 define('ZBX_GRAPH_FONT_NAME',           'simhei'); // font file name
     46 define('ZBX_GRAPH_LEGEND_HEIGHT',    120); // when graph height is less then this value, some legend will not show up
    
Fonts_edit

修改完成后,刷新亂碼就好了。

四、安裝Zabbix-agent

1.監(jiān)控Linux系統(tǒng)配置

客戶端CentOS 7.3系統(tǒng)
(1). 導(dǎo)入yum源

rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm

(2). 安裝zabbix-agent

yum -y install zabbix-agent

(3). 配置zabbix-agent

vim /etc/zabbix/zabbix_agentd.conf

Server=10.10.10.113
ServerActive=10.10.10.113
Hostname=10.10.10.114
  • 修改Server的IP,地址為服務(wù)端地址:Server=ServerIP
  • 修改ServerAcive的IP,地址為服務(wù)端地址:ServerActive=ServerIP
  • Hostname修改為網(wǎng)頁里面添加的Hostname,需要保持一致,zabbix_agentd客戶端計算機名:Hostname=Zabbix server
  • 設(shè)置為0 僅為主動模式,如果需要發(fā)送數(shù)據(jù)等 可以不修改此項:StartAgents=0
    (4). 啟動zabbix-agent,并配置開機啟動
systemctl enable zabbix-agent
systemctl start zabbix-agent

服務(wù)端配置監(jiān)控Linux主機

配置 --> 主機 --> 創(chuàng)建主機

zabbix_add_host

創(chuàng)建主機后,選擇主機選項,然后填寫:主機名稱、可見的名稱、群組、agent代理程序的接口IP,這幾項添寫就OK了


Zabbix_host_cfg

然后再添加模板


Zabbix_Templates

然后勾選剛剛添加的主機,點擊"啟用"


Zabbix_Ava

從拓撲圖里右鍵可以查看主機聚合圖形,具體查看Linux主機監(jiān)控指標(biāo)的圖表


Zabbix_Linux_Gra

添加網(wǎng)絡(luò)拓撲圖 --> 更新


Zabbix_network

2.監(jiān)控Windows系統(tǒng)配置
(1). 下載文件: http://www.zabbix.com/downloads/3.2.0/zabbix_agents_3.2.0.win.zip

(2). 解壓到C盤根目錄,再修改文件:zabbix_agents_3.2.0.win/conf/zabbix_agentd.win.conf

Server=10.10.10.113
ServerActive=10.10.10.113
Hostname=Windows Server

(3).修改完后,"Win+R"打開cmd命令行運行安裝Zabbix Agent服務(wù)注冊,啟動一下

# 安裝注冊服務(wù)
c:\zabbix_agents_3.2.0.win\bin\win64\zabbix_agentd.exe -i  -c c:\zabbix_agents_3.2.0.win\conf\zabbix_agentd.win.conf
# 刪除注冊服務(wù)
c:\zabbix_agents_3.2.0.win\bin\win64\zabbix_agentd.exe  -d  -c  c:\zabbix_agents_3.2.0.win\bin\win64\zabbix_agentd.win.conf
Zabbix_agent_cmd
Zabbix_Agent_Server

(4).在服務(wù)端"配置" --> "主機" --> "創(chuàng)建主機"


Zabbix_add_Win
Zabbix_Win_Tem

最后再"配置" --> "主機"里勾選"[Windows Server測試主機]"啟用,一會就可以看到圖形

從拓撲圖里右鍵可以查看主機聚合圖形,具體查看Windows主機監(jiān)控指標(biāo)的圖表


Zabbix_

添加網(wǎng)絡(luò)拓撲圖 --> 更新

Zabbix_Win_Gra

五、安裝圖形展示

1.趨勢圖集中顯示Graphtree插件

插件地址:https://github.com/OneOaaS/graphtrees

(1).在Server上配置,下載補丁并升級

cd /usr/share/zabbix
wget https://raw.githubusercontent.com/OneOaaS/graphtrees/master/graphtree3.0.4.patch
yum install -y patch        #安裝打補丁path包,安裝過可忽略
patch  -Np0 <graphtree3.0.4.patch
chown -R apache:apache oneoaas/    #設(shè)置權(quán)限,注意此處的權(quán)限,必須和nginx或者apache的用戶一致

(2).安裝好后,會在主頁顯示Graphtree插件


Zabbix_Graphtree
Zabbix_Graphtree

(3).刪除廣告信息
vim /usr/share/zabbix/oneoaas/templates/graphtree/graphtree.tpl
刪除頂部圖片8-12行和66-86底部廣告

 66 <footer id="footer" class="footer navbar-inverse">
 61     <div class="container">
 62         <ul>
 63             <li class="qrcode">
 64                 <img src="../oneoaas/assets/img/qrcode.jpg">
 65                 <p>專業(yè) 合作 開放 </p>
 66                 <p>運維方案解決專家</p>
 67             </li>
 68             <li class="business">
 69                 <p>Zabbix監(jiān)控項目承接</p>
 70                 <p>運維解決方案咨詢</p>
 71                 <p>運維產(chǎn)品咨詢</p>
 72                 <p><a href="[http://www.oneoaas.com](http://www.oneoaas.com/)">[www.oneoaas.com](http://www.oneoaas.com/)</a></p>
 73                 <p>請聯(lián)系 support#[oneoaas.com](http://oneoaas.com/) (#替換為@)
 74             </li>
       ……………

86 </footer>

(4).重新載入Zabbix-web,可以看到Graphtree已出效果;

systemctl restart httpd
Zabbix_Dashboard

2.安裝Grafana 4實現(xiàn)可視化圖形監(jiān)控

Grafana 是 Graphite 和 InfluxDB 儀表盤和圖形編輯器。Grafana 是開源的,功能齊全的度量儀表盤和圖形編輯器,支持 Graphite,InfluxDB 和 OpenTSDB。

Grafana 主要特性:靈活豐富的圖形化選項;可以混合多種風(fēng)格;支持白天和夜間模式;

多個數(shù)據(jù)源;Graphite 和 InfluxDB 查詢編輯器等等。

官網(wǎng):https://grafana.com/

安裝Grafana

(1).安裝服務(wù)端圖形呈現(xiàn)依賴包

yum install fontconfig
yum install freetype*
yum install urw-fonts
yum install initscripts

(2). 在服務(wù)端安裝Grafana 4.4.3

#使用yum源安裝
yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.4.3-1.x86_64.rpm
#使用rpm安裝
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.4.3-1.x86_64.rpm
rpm -Uvh grafana-4.4.3-1.x86_64.rpm

(4).啟動Grafana并設(shè)置開機啟動

systemctl daemon-reload                #重新載入服務(wù)
systemctl start grafana-server 
systemctl status grafana-server
systemctl enable grafana-server.service

(5).查看安裝包位置

[root@localhost ~]# rpm -qc grafana
/etc/init.d/grafana-server
/etc/sysconfig/grafana-server
/usr/lib/systemd/system/grafana-server.service
Zabbix_Grafana_install

(6). 訪問Grafana

地址:http://ServerIP:3000

默認登錄用戶名密碼:admin/admin

Grafana_Login

為Grafana安裝Zabbix插件

(1). grafana-zabbix插件安裝有好幾種方式:

# 第一種:使用grafana-cli工具安裝

獲取可用插件列表命令
grafana-cli plugins list-remote
安裝zabbix插件命令
grafana-cli plugins install alexanderzobnin-zabbix-app

安裝插件完成之后重啟garfana服務(wù)
systemctl restart grafana-server
service grafana-server restart

# 第二種:使用grafana-zabbix-app源,其中包含最新版本的插件

cd /var/lib/grafana/plugins/
克隆grafana-zabbix-app插件項目
git clone https://github.com/alexanderzobnin/grafana-zabbix-app

注:如果沒有g(shù)it,請先安裝git
 yum –y install git

插件安裝完成重啟garfana服務(wù)
systemctl restart grafana-server
 service grafana-server restart

注:通過這種方式,可以很容易升級插件
$ cd /var/lib/grafana/plugins/grafana-zabbix-app
$ git pull
$ service grafana-server restart

# 第三種:使用源碼包安裝(一般沒有必要)
需要安裝NodeJS, npm和Grunt 從源碼構(gòu)建插件,更多安裝方法可以查看Grafana docs.
git clone https://github.com/alexanderzobnin/grafana-zabbix.git
cd grafana-zabbix
npm install
npm install -g grunt-cli
grunt  #插件將建成dist/目錄。然后你可以將它復(fù)制到你的grafana插件目錄或在grafana配置文件中指定編譯插件的路徑
如果需要更新,執(zhí)行下面命令
git pull
Grunt
重啟grafana服務(wù)
systemctl restart grafana-server
service grafana-server restart

這里使用grafana-cli工具安裝的

# 安裝grafana-zabbix插件:
[root@localhost plugins]# grafana-cli plugins install alexanderzobnin-zabbix-app

# 以下插件可以根據(jù)自己所需安裝
# 安裝grafana-clock-panel鐘表形展示
[root@localhost plugins]# grafana-cli plugins install grafana-clock-panel

#安裝briangann-gauge-panel字符型展示
[root@localhost plugins]# grafana-cli plugins install briangann-gauge-panel

#安裝natel-discrete-panel服務(wù)器狀態(tài)
[root@localhost plugins]# grafana-cli plugins install natel-discrete-panel

#安裝grafana-worldmap-panel世界地圖插件
grafana-cli plugins install grafana-worldmap-panel 

[root@localhost plugins]# systemctl restart grafana-server
Grafana_cli

(2).到網(wǎng)站管理控制臺啟用zabbix插件

移動到grafana左側(cè)面板的插件,選擇應(yīng)用程序選項卡,然后選擇"Apps"選項卡,打開Zabbix,啟用插件


Plugin_enable
Zabbix_plugin

(3).添加Zabbix為數(shù)據(jù)源

點擊左側(cè)的"Data Sources" --> "Add data source"

默認的接口地址: http://ip/zabbix3/api_jsonrpc.php

Zabbix_add_datasource
Zabbix_success
  • Name 可以自定義
  • Type下拉框中選擇Zabbix
  • Http setting s --> Url 填入http://zabbix-server-ip/zabbix/api_jsonrpc.php 這里填入的是Zabbix API接口
  • Http settings --> Access 選擇 direct 使用直接訪問的方式
  • Zabbix API details --> User 填入Admin
  • Zabbix API details --> Password 填入 zabbix
  • 點擊"Sava & Test"保存并測試,測試API配置是否正確。配置成功會出現(xiàn):Success Zabbix API version: 3.2.7

自定義儀表板

1.Grafana儀表板配置

配置完Zabbix Source,需要自定義儀表板顯示所需的監(jiān)控項圖形,配置儀表板的步驟如下:

  • 點擊左側(cè)的"Dashboards" --> 在下拉菜單的底部選擇"+ New"。這時新的頁面中默認出現(xiàn)一個空的橫行圖表,左上角有的隱藏的按鈕,鼠標(biāo)放上可以看到,右下角有"+ ADD ROW"
  • 添加"Graph"面板,鼠標(biāo)往下拖,就可以添加一個面板;列出的面板包括"Graph、Singlestat、Table、Text、Heatmap、Alert List、Dashboard list、Clock……"
  • 如需再添加面板,鼠標(biāo)放在左上角處,選擇Add Panel,和上一步一樣;
  • 最后一步點擊"保存"或者使用快捷鍵"Ctrl+s",設(shè)置儀表板的名稱,保存下來;
Grafana-Dashboards

新添加一個"Graph"面板


New_Dashboards
Dashboard_sava

這里介紹以下主要面板:
官網(wǎng)介紹:http://docs.grafana.org/features/panels/

(1).Graph

這個選項是創(chuàng)建一個圖表,類似于Zabbix的監(jiān)控圖表,是最常用的類型之一。

  • General-Title:設(shè)置該圖表的名稱
  • Metrics:在該項的右下角,選擇正確的數(shù)據(jù)源(之前在Data Sources配置的Name)
  • Metrics-Group/Host/Application/Item:這些項目是必填項目,需要依次下拉選擇*如果一張圖需要展現(xiàn)兩條線的數(shù)據(jù),可以在左下角點擊"+ Query"
  • Display Styles-Chart Options:這里可以選擇以豎線展示,以折線展示或以點來展示數(shù)據(jù)

(2).Table
表格展示,類似于Excel表格的展現(xiàn)形式

  • 點擊"- +"號可以調(diào)整該模塊的大小(橫向伸縮)
  • 點擊"Edit"可以重新編輯該模塊的數(shù)據(jù)源

(3).Singlestat
單統(tǒng)計模塊,從字面意思就可以知道,該種模塊僅可以展示一種數(shù)據(jù),統(tǒng)計一種數(shù)據(jù)。這里需要重點說明就是Option
選項下的參數(shù)以統(tǒng)計磁盤使用大小一項來舉例

  • Unit:要選擇data下的bytes單位來統(tǒng)計
  • Decimals:小數(shù)設(shè)置保持默認的auto即可
  • Coloring:這里可以選擇渲染背景色或字體色
    • Colors控制著三個顏色,可以自由發(fā)揮,一般綠色代表正常,黃色代表預(yù)警,紅色代表警告
    • Thresholds可以設(shè)置以逗號分隔的三個數(shù)字,分別表示三個狀態(tài)的閾值
    • Spark lines有兩種顯示模式,Show會在數(shù)據(jù)的下方展示折線;Background mode會在整個模塊的背景展示折線

(4).Text
這個模塊很好理解,就是一個現(xiàn)實文字的模塊,支持markdown語法,可以放在每個頁面的頭部,標(biāo)記當(dāng)前圖表信息的歸類。

(5).Dashboards list
這個模塊是用來展示頁面列表用的。舉個例子,如果一個監(jiān)控系統(tǒng)中,涉及到了多個頁面展示監(jiān)控圖表,就會用到這個功能,這個模塊會列出你需要展示的頁面的列表,方便在當(dāng)前頁面中,快速的切換到其他監(jiān)控頁面。

2.配置Graph Panel

現(xiàn)在開始配置剛剛添加好的"Graph"面板

graph_config

修改標(biāo)題


Graph_article
  • 設(shè)置數(shù)據(jù)源
  • 設(shè)置主機組 Zabbix servers
  • 設(shè)置主機到Zabbix server 。
  • 設(shè)置應(yīng)用程序到CPU
  • 設(shè)置項為Processor load (1 min average per core)
Graph_Metrics
Graph_legend

然后再回到"Metrics",多添加幾個查詢,比如我添加5分鐘、15分鐘的負載

Add_Query

再添加另一個圖表,可以重復(fù)上述步驟或復(fù)制現(xiàn)有圖形。

要復(fù)制現(xiàn)有的圖,選擇面板標(biāo)題,然后單擊duplicate 。 然后選擇新的圖形的標(biāo)題,并選擇Edit選項。然后應(yīng)用以下設(shè)置:

  • 更改標(biāo)題為CPU usage
  • 選擇指標(biāo)選項卡和項目字段更改為/CPU.*/
    可以對主機或度量名稱使用正則表達式模式。只是一定要在包含正斜杠(模式/ )
Graph_copy
Graph_CPU_all

使用快鍵鍵"ESC"退出到主面板,然后"Ctrl+s"保存一下,一會可以看到圖形;

Graph_Show

如需添加其他圖表的應(yīng)用程序展示,可以按照這種方法來配置,大同小異;

3.配置Singlestat Panel

點擊左下角"+ ADD ROW "新添加一行,選擇"Singlestat"向下拖;

add_row
Singlestat_Panel
Singlestat_edit.jpg
  • 設(shè)置 General 選項:
    • 設(shè)置標(biāo)題字段為:Free disk space on /
    • 其他無需設(shè)置
Singlestat_General
  • 設(shè)置Metrics選項如下:

    • 面板數(shù)據(jù)源設(shè)置 Zabbix Server
    • 主機組設(shè)置 Zabbix servers
    • 主機設(shè)置 Zabbix server
    • 應(yīng)用程序設(shè)置 Filesystems
    • 項目設(shè)置為Free disk space on / (percentage)
    Singlestat_Metrics.jpg
  • 設(shè)置Options選項如下:

    • 設(shè)置Valuet的stat為"current"
    • 設(shè)置單元為百分比
    • 設(shè)置Coloring的值,勾選上和閾值設(shè)置為10,20 在測量儀上顯示這些閾值
    • 設(shè)置Gauge(測量)啟用Show選項,勾選閾值便簽和標(biāo)記
Singelestat_Optins

Esc返回到儀表板,調(diào)整到最上面,然后"Ctrl+s"保存,展示數(shù)據(jù)如下:

disk_space_/

:測試實時響應(yīng)情況,我們將手動減少磁盤上的可用空間,并查看儀表板顯示的內(nèi)容。
首先登陸到Linux Agent服務(wù)器,查看"/"目錄的使用情況

[root@localhost ~]# df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/cl-root xfs        17G  1.7G   16G  10% /
devtmpfs            devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs               tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs               tmpfs     1.9G  8.5M  1.9G   1% /run
tmpfs               tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1           xfs      1014M  138M  877M  14% /boot
tmpfs               tmpfs     380M     0  380M   0% /run/user/0

通過查看,有16 GB的可用空間,然后減少對根分區(qū)的20%閾值之下,使用fallocate命令創(chuàng)建一個大的臨時文件:

[root@localhost ~]# fallocate -l 15G /tmp/test.img    #可以根據(jù)服務(wù)器上的可用空間量設(shè)置文件大小
Disk alarm

最后,讓我們在儀表板上顯示活動的Zabbix觸發(fā)器,這里我們引入一個"Zabbix Triggers"面板。

4.配置Zabbix Triggers

  • 設(shè)置 General 選項:
    • 設(shè)置標(biāo)題字段為:Zabbix Alarm
    • 其他無需設(shè)置
Zabbix Triggers_title
  • 設(shè)置Options選項:
    • show fileds 勾選顯示詳細的屬性
Zabbix Triggers_Option

Esc返回到儀表板,調(diào)整到最上面,然后"Ctrl+s"保存,可以看到主動觸發(fā)器通知您服務(wù)器上缺少可用空間顯示的報警:

Zabbix Triggers_Show

最好刪除之前創(chuàng)建的臨時文件以釋放磁盤上的空間,消除告警信息:

[root@localhost ~]# rm -rf /tmp/test.img 

再次查看,已沒有告警信息顯示了

Zabbix Triggers_Show

其他面板可以通過上面的方式自行添加,就不一一介紹了,來一張編輯好的圖形,是不是很漂亮:

Zabbix_Panorama

Grafana-zabbix模板配置

在配置好自定義的儀表板時,展示的效果還是很不錯的,但是有一個缺點,每次只能查看一臺主機的監(jiān)控圖形,如果有多臺很是不方便,所以這時可以引入模板設(shè)置,通過變量的方式去實現(xiàn),根據(jù)選擇顯示不同主機的狀態(tài),比較靈活;需要的設(shè)置的變量包括:group、host、application、item 下面介紹下模板的各種參數(shù);

模板

儀表盤模板可以讓你創(chuàng)建一個交互式和動態(tài)性的儀表板,它是Grafana里面最強大的、最常用的功能之一。創(chuàng)建的儀表盤模板參數(shù),可以在任何一個儀表盤中使用。

創(chuàng)建變量

點擊頂部的設(shè)置按鈕,選擇模板," + New" 創(chuàng)建新的變量,可以看到模板變量編輯器,包含以下參數(shù):

變量(Variable)

命名:變量的名稱。
標(biāo)簽:可見標(biāo)簽變量
類型:查詢類型選擇; 有6種變量類型: query,custom,interval,Data source和Contsta,Ad hoc filters它們都可以用來創(chuàng)建動態(tài)變量,不同之處在于獲得的數(shù)據(jù)值不一樣

查詢選項(Query Options)
數(shù)據(jù)源:用于查詢變量值的數(shù)據(jù)源
刷新:更新此變量的值
查詢:查詢字符串。
正則表達式:如果你需要篩選值或提取值的一部分,那就使用正則表達式

其中query的匹配原則

   *                           returns all groups
   *.*                        returns all hosts (from all groups)
   Servers.*             returns all hosts in group Servers
   Servers.*.*           returns all applications in group Servers
   Servers.*.*.*        returns all items from hosts in group Servers

選擇選項(Selection Options)
多值:啟用,如果你想在同一時間選擇多個值

數(shù)值組/標(biāo)簽(實驗功能)(Value groups/tags (Experimental feature))

開始創(chuàng)建模板

復(fù)制一個面板出來,免得出錯,創(chuàng)建模板

Grafana_Templating
Add_templating
Grafana_Template

依次添加host、application、item變量

Templating_host
Templating_application
Templating_item
Zabbix_Templating
Templating_show

模板適合監(jiān)控單獨一項,不能同時選擇多個item,可以選擇多臺主機顯示在一個監(jiān)控圖形中,形成對比;儀表板上的每個面板都可以顯示不同服務(wù)器的數(shù)據(jù),您可以使用Grafana以許多有用的方式過濾數(shù)據(jù),Grafana很強大,還有很多功能要自己摸索;

頁面自動刷新

點擊右上角Last 30 minutes, 在彈出的下拉框中,選擇Time range下的Refreshing every選項,點擊下拉框按鈕,有off 和其他選項。點擊5s然后Apply設(shè)置。即為每5秒刷新一次數(shù)據(jù)的意思。設(shè)置成功后,在原來Last 30 minutes的后面會出現(xiàn)Refresh every 5s的橙色文字!

總結(jié)

在本教程中,使用yum安裝Zabbix 3.2;以及使用Zabbix監(jiān)控Linux系統(tǒng)主機和Windows系統(tǒng)主機;安裝圖形插件Graphtree;由于圖形顯示不夠好看,學(xué)習(xí)了如何安裝和配置Grafana,創(chuàng)建自定義儀表板、不同插件配置、顯示Zabbix數(shù)據(jù)的面板??梢栽谧烂婊虼笃聊簧巷@示這些儀表板,以便管理員可以查看IT基礎(chǔ)架構(gòu)的狀態(tài),配置模板等。后續(xù)再慢慢補充Zabbix相關(guān)配置,歡迎大家批評指正;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • CentOS 7.3安裝Zabbix 3.2 一、準備搭建環(huán)境 二、安裝前的準備 最小化安裝CentOS 7系統(tǒng)時...
    不知歲月惜閱讀 863評論 0 0
  • Zabbix簡介 Zabbix官方網(wǎng)站Zabbix中文文檔 本文系統(tǒng)環(huán)境是CentOS7x86_64, Zabbi...
    Zhang21閱讀 8,287評論 0 37
  • 1.寫在前面 本文主要介紹的是zabbix的編譯安裝過程,包含它的基礎(chǔ)環(huán)境LNMP,雖然zabbix官方一般推薦的...
    天之藍色閱讀 2,653評論 0 16
  • 又有同事要訂婚了,看著她嬌羞的模樣,我想她是幸福的吧。另一個同事半年前訂的婚,問她你想結(jié)婚嗎現(xiàn)在?她說如果他對我好...
    不小不閱讀 140評論 0 0
  • 前段時間,睿道市場總監(jiān)問了我這樣一個問題?給你一個團隊,應(yīng)該如何管理。當(dāng)時所闡述的答案確實不讓自己滿意,因...
    阿毅閱讀 614評論 0 3

友情鏈接更多精彩內(nèi)容