CentOS 7.3安裝Zabbix 3.2

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

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

2.軟件:Zabbix 3.2

主機(jī) 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

二、安裝前的準(zhǔn)備

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

1.安裝所需的軟件包

yum groupinstall "Development Tools"

yum -y install vim lrzsz tree wget ntp mlocate

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

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

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

systemctl stop firewalld.service        #停止firewall
systemctl disable firewalld.service     #禁止firewall開機(jī)啟動(dòng)
firewall-cmd --state          #查看默認(rèn)防火墻狀態(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

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

[root@localhost ~]# getenforce
Enforcing

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

不關(guān)機(jī)情況下關(guān)閉SElinux,這個(gè)在重啟之后會(huì)失效,臨時(shí)關(guān)閉

[root@localhost ~]# setenforce 0

三、安裝Zabbix3.2

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

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

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

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

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

  • 查看MariaDB數(shù)據(jù)庫在進(jìn)程的狀態(tài)
[root@localhost ~]# ss -tulnp | grep mysqld
tcp    LISTEN     0      50        *:3306     *:*   users:(("mysqld",pid=2674,fd=14))
  • 初始化mysql數(shù)據(jù)庫,并配置root用戶密碼(默認(rèn)為空密碼)
    • mysql_secure_installation會(huì)執(zhí)行以下幾個(gè)設(shè)置:
    • a)為root用戶設(shè)置密碼
    • b)刪除匿名賬號
    • c)取消root用戶遠(yuǎn)程登錄
    • 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
  • 啟動(dòng)Zabbix-Server,設(shè)置為開機(jī)自啟動(dòng)
[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,進(jìn)一步安裝Zabbix

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


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


      Zabbix_DB_cnt

      Zabbix_Name

      Zabbix_Summary
    • 完成安裝


      Zabbix_Install
    • 默認(rèn)登錄賬戶密碼: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打開運(yùn)行,輸入fonts,回車進(jìn)入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這個(gè)文件

    大約在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客戶端計(jì)算機(jī)名:Hostname=Zabbix server
  • 設(shè)置為0 僅為主動(dòng)模式,如果需要發(fā)送數(shù)據(jù)等 可以不修改此項(xiàng):StartAgents=0
    (4). 啟動(dòng)zabbix-agent,并配置開機(jī)啟動(dòng)
systemctl enable zabbix-agent
systemctl start zabbix-agent

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

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

zabbix_add_host

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


Zabbix_host_cfg

然后再添加模板


Zabbix_Templates

然后勾選剛剛添加的主機(jī),點(diǎn)擊"啟用"


Zabbix_Ava

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


Zabbix_Linux_Gra

添加網(wǎng)絡(luò)拓?fù)鋱D --> 更新


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命令行運(yùn)行安裝Zabbix Agent服務(wù)注冊,啟動(dòng)一下

# 安裝注冊服務(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ù)端"配置" --> "主機(jī)" --> "創(chuàng)建主機(jī)"


Zabbix_add_Win
Zabbix_Win_Tem

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

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


Zabbix_

添加網(wǎng)絡(luò)拓?fù)鋱D --> 更新

Zabbix_Win_Gra

五、安裝圖形展示

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

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

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

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

(2).安裝好后,會(huì)在主頁顯示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>運(yùn)維方案解決專家</p>
 67             </li>
 68             <li class="business">
 69                 <p>Zabbix監(jiān)控項(xiàng)目承接</p>
 70                 <p>運(yùn)維解決方案咨詢</p>
 71                 <p>運(yùn)維產(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實(shí)現(xiàn)可視化圖形監(jiān)控

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

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

多個(gè)數(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).啟動(dòng)Grafana并設(shè)置開機(jī)啟動(dòng)

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

默認(rèn)登錄用戶名密碼: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插件項(xiàng)目
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插件

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


Plugin_enable
Zabbix_plugin

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

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

默認(rèn)的接口地址: 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
  • 點(diǎn)擊"Sava & Test"保存并測試,測試API配置是否正確。配置成功會(huì)出現(xiàn):Success Zabbix API version: 3.2.7

自定義儀表板

1.Grafana儀表板配置

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

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

新添加一個(gè)"Graph"面板


New_Dashboards
Dashboard_sava

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

(1).Graph

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

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

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

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

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

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

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

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

2.配置Graph Panel

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

graph_config

修改標(biāo)題


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

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

Add_Query

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

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

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

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

Graph_Show

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

3.配置Singlestat Panel

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

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

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

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

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

disk_space_/

:測試實(shí)時(shí)響應(yīng)情況,我們將手動(dò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)建一個(gè)大的臨時(shí)文件:

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

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

4.配置Zabbix Triggers

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

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

Zabbix Triggers_Show

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

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

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

Zabbix Triggers_Show

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

Zabbix_Panorama

Grafana-zabbix模板配置

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

模板

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

創(chuàng)建變量

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

變量(Variable)

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

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

其中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

選擇選項(xiàng)(Selection Options)
多值:啟用,如果你想在同一時(shí)間選擇多個(gè)值

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

開始創(chuàng)建模板

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

Grafana_Templating
Add_templating
Grafana_Template

依次添加host、application、item變量

Templating_host
Templating_application
Templating_item
Zabbix_Templating
Templating_show

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

頁面自動(dòng)刷新

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

總結(jié)

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

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

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

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