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

ps:大家反饋以下部署步驟並不夠快,所以重新修正標題。

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

一、安裝zabbix軟件包

確保防火牆、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

EOF

安裝zabbix yum源

# rpm -Uvh https://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


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


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


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


Zabbix 服務名是可選設置

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


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


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


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


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


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


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

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

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


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


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


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


六、安裝zabbix-agent

# rpm -Uvh https://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之部署Zabbix數據源(第二篇)


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

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

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

"


分享到:


相關文章: