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

1587965956095-1d1497fc-23f9-4f6b-b683-b4d3a5a64449.png

1587965956247-994941ae-3b79-4108-bead-7b5380d74da8.png

1587965956427-47951904-b3b4-4896-97aa-339576e720b1.png

Zabbix 服务名是可选设置

1587965956557-fd48878c-13d2-477b-bc39-00b6005a5ffb.png

1587965956691-2d6f1bac-9884-413a-b508-2dd9f35065a1.png

1587965956826-e1568216-05ee-4657-8607-a3ac8d6e3fb0.png

1587965956968-904952e5-5bc4-4b8b-9721-e8a6598baccd.png

1587965957152-eff6d629-2ff4-4ac0-a516-0891de66e26a.png?x-oss-process=image%2Fresize%2Cw_1500

image.png

配置action,实现使安装有Zabbix Agent的Linux自动注册到Zabbix Server端。

步骤:configuration>>action>>Event source(选择Auto registration)>>Create Action,我们按如下步骤来定义个action

1587965957330-1d5788a9-4224-4c85-ac1b-a6adb3a14640.png?x-oss-process=image%2Fresize%2Cw_1500

1587965957524-1f6b83ca-4e84-4e58-adaa-9032c33fe532.png

1587965957715-99599f76-60a1-4276-aede-78565cd8a5b1.png

1587965957871-0a722665-c021-47aa-aa09-43cb173b402e.png?x-oss-process=image%2Fresize%2Cw_1500

六、安装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显示为一绿色的1587965958054-59cfa8fd-6918-49b6-a966-857efd0ecf00.png就表示添加成功了。

1587965958296-64fbac47-c129-431a-93af-4451c057e8db.png?x-oss-process=image%2Fresize%2Cw_1500

由于本系列教程讲述的重点是Grafana的使用,Zabbix仅是为Grafana提供要展示数据的接口,所以不再重点讲述,后续在讲解Grafana使用时会再穿插讲解一些Zabbix使用技巧。

猜你喜欢

转载自blog.51cto.com/firefly222/2492162
今日推荐