Grafana之部署Zabbix數據源(第二篇)

Zabbix是當前主流開源的企業級分布式監控系統。Zabbix特點是:安裝部署較簡單,且默認自帶了多種監控告警模板。也具備較強的儀表盤展示功能;提供API接口,支持腳本調用;支持自定義編寫插件以及監控模板。

一、安裝zabbix軟件包

環境說明:

# cat /etc/redhat-release

CentOS Linux release 7.7.1908 (Core)

uname -a

Linux monitor01 3.10.0-1062.18.1.el7.x86_64 #1 SMP Tue Mar 17 23:49:17 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

確保防火墻、selinux已經關閉

# systemctl stop Firewalld

# systemctl disable Firewalld

# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# setenforce 0


修改用戶資源限制

# cat /etc/security/limits.conf

root soft nofile 65535

root hard nofile 65535

* soft nproc 65535

* hard nproc 65535

* soft nofile 65535

* hard nofile 65535

* hard core unlimited

* soft core unlimited


安裝zabbix yum源

# rpm -Uvhhttps://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm

安裝epel源,用于支持nginx

# yum install epel-release

安裝zabbix相關軟件包

# yum search zabbix

# yum -y install zabbix-*

或者只安裝以下組件

# for pkgs in ?zabbix-server-mysql zabbix-web-mysql zabbix-web-mysql zabbix-agent zabbix-get zabbix-web zabbix-sender zabbix-nginx-conf ;do yum -y install $pkgs;done


zabbix-agent-4.4.7-1.el7.x86_64

zabbix-get-4.4.7-1.el7.x86_64

zabbix-release-4.4-1.el7.noarch

zabbix-server-mysql-4.4.7-1.el7.x86_64

zabbix-web-4.4.7-1.el7.noarch

zabbix-sender-4.4.7-1.el7.x86_64

zabbix-nginx-conf-4.4.7-1.el7.noarch

zabbix-web-mysql-4.4.7-1.el7.noarch

?

二、安裝mariadb并初始化導入zabbix表結構數據

安裝mariadb數據庫并啟動

# yum -y install mariadb-*

# systemctl enable mariadb

# systemctl start mariadb


創建zabbix數據庫

create database zabbix character set utf8 collate utf8_bin;

grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix@123';

flush privileges;

quit;


導入數據

# zcat /usr/share/doc/zabbix-server-mysql-*/create.sql.gz |mysql -uzabbix -p'zabbix@123' -b zabbix


三、修改zabbix_server.conf并啟動zabbix_server

# cat /etc/zabbix/zabbix_server.conf |grep -v "^#" |grep -v "^$" |grep -v grep ?

LogFile=/var/log/zabbix/zabbix_server.log

LogFileSize=0

DebugLevel=3

PidFile=/var/run/zabbix/zabbix_server.pid

SocketDir=/var/run/zabbix

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix@123

StartPollers=16

StartPollersUnreachable=4

StartTrappers=10

StartPingers=8

SNMPTrapperFile=/var/log/snmptrap/snmptrap.log

CacheSize=1024M

StartDBSyncers=8

HistoryCacheSize=1024M

HistoryIndexCacheSize=256M

TrendCacheSize=1024M

Timeout=4

AlertScriptsPath=/usr/lib/zabbix/alertscripts

ExternalScripts=/usr/lib/zabbix/externalscripts

LogSlowQueries=3000

StatsAllowedIP=127.0.0.1


# systemctl enable zabbix-server

# systemctl start zabbix-server


四、修改nginx/php-fpm配置,將server端口配置為8080,端口配置沒有特殊要求,只要未被占用都可配置。若想使用80端口,則需要注釋或修改nginx.conf的server {}段配置

# vi /etc/nginx/conf.d/zabbix.conf


listen ? ? ? ? ?8080;

server_name ? ? monitor.com;



修改php時區

# vi /etc/php-fpm.d/zabbix.conf

php_value[date.timezone] = Asia/Shanghai



# systemctl enable php-fpm

# systemctl restart php-fpm


# systemctl enable nginx

# systemctl start nginx


五、設置并登錄zabbix系統

訪問http://IP:port/setup.php






Zabbix 服務名是可選設置







配置action,實現使安裝有Zabbix Agent的Linux自動注冊到Zabbix Server端。

步驟:configuration>>action>>Event source(選擇Auto registration)>>Create Action,我們按如下步驟來定義個action





六、安裝zabbix-agent

# rpm -Uvhhttps://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm

# yum -y install zabbix-agent

修改zabbix-agent配置,monitor01為Zabbix Server主機的hostname,所有Zabbix agent主機上都要添加Zabbix Server主機的hostname。

# sed -i "s/Server=127.0.0.1/Server=monitor01/g" /etc/zabbix/zabbix_agentd.conf

# sed -i "s/ServerActive=127.0.0.1/ServerActive=monitor01/g" /etc/zabbix/zabbix_agentd.conf

# sed -i "s#Hostname=Zabbix server#Hostname=$(hostname)#g" /etc/zabbix/zabbix_agentd.conf

# sed -i "s#\# HostMetadataItem=#HostMetadataItem=system.uname#g" /etc/zabbix/zabbix_agentd.conf ?

啟動zabbix-agent

# systemctl enable zabbix-agent

# systemctl restart zabbix-agent

如果有幾十上百個節點,我們就需要借助Ansible或SaltStack等批量部署工具來快速部署了。


安裝Zabbix Agent后的主機會自動注冊到Zabbix Server上,并且Availability狀態顯示為綠色

就表示添加成功了。


由于本系列教程講述的重點是Grafana的使用,Zabbix僅是為Grafana提供要展示數據的接口,所以不再重點講述,后續在講解Grafana使用時會再穿插講解一些Zabbix使用技巧。

總結:對Linux較熟悉的同學部署上述環境應該so easy。當然部署方法多種多樣,想挑戰又有時間可以全部用源碼來編譯安裝,能更體驗過程;想更簡單一點的話,可以嘗試用zabbix官方提供的docker鏡像,但前提得會用docker。

寫給自己:世上無難事,只怕有心人。

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。