CentOS7下部署Zabbix4+Grafana5详细过程

系统基本配置

Zabbix基于LAMP/LNMP环境,本教程选的是LAMP,详细介绍在CentOS7下如何部署Zabbix4和Grafana5。Zabbix的数据展示功能简直弱爆了,Grafana作为一款可视化工具,正好弥补了这一缺陷。

配置防火墙

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=10050/tcp --permanent
firewall-cmd --zone=public --add-port=10051/tcp --permanent
firewall-cmd --reload

部署 Zabbix Server

安装依赖包

yum -y install gcc gcc-c++ expat-devel zlib-devel openssl curl curl-devel net-snmp net-snmp-devel perl-DBI libxml2 libxml2-devel

安装 Mariadb

yum -y install mariadb mariadb-server mariadb-devel

systemctl enable mariadb && systemctl start mariadb

mysqladmin -uroot password 'Mariadb@123'

也可以安装Mysql,具体方法略。

配置 MariaDB

一般情况下无需对数据库做太多配置,不过因公司主机数量和业务量都比较多,因此对数据库做了主从同步,所有参数配置如下,大家可根据实际需求进行优化。

[mysqld]
init_connect = 'SET collation_connection = utf8_unicode_ci' 
init_connect = 'SET NAMES utf8' 
character-set-server = utf8 
collation-server = utf8_unicode_ci 
skip-character-set-client-handshake
datadir = /data/mysql
socket = /var/lib/mysql/mysql.sock
skip-external-locking
explicit_defaults_for_timestamp = TRUE
lower_case_table_names = 1
key_buffer_size = 512M
table_open_cache = 512
max_allowed_packet = 32M
open_files_limit = 4096
back_log = 1024
max_connections = 4000
max_connect_errors = 1024
wait_timeout = 7200 
interactive_timeout = 7200
read_rnd_buffer_size = 4M
read_buffer_size = 4M
join_buffer_size = 4M
sort_buffer_size = 2M
query_cache_type = 1
query_cache_limit = 2M
query_cache_size = 256M
query_cache_min_res_unit = 2k
thread_cache_size = 300
thread_stack = 256K
tmp_table_size = 256M
max_tmp_tables = 256
bulk_insert_buffer_size = 16M
binlog_cache_size = 2M
max_binlog_size = 128M
max_binlog_cache_size = 512M
innodb_buffer_pool_size = 10G
innodb_log_file_size = 256M
innodb_log_buffer_size = 64M
innodb_lock_wait_timeout = 100
innodb_flush_log_at_trx_commit = 2
bulk_insert_buffer_size = 4M
long_query_time=5
log-queries-not-using-indexes
binlog_format = row
slow_query_log = 1
net_buffer_length = 2K
binlog-format = mixed
replicate_wild_ignore_table=information_schema.%
replicate_wild_ignore_table=performance_schema.%
server_id=110
log_bin = /data/mysql/bin-log/master-bin
innodb_flush_log_at_trx_commit = 2
sync_binlog = 1

配置 Zabbix 用户

mysql -uroot -pMariadb@123

create database zabbix character set utf8 collate utf8_bin;

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

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

flush privileges;

安装 httpd / php

实际上,在安装zabbix-web-mysql里会自动依赖安装http,因此本步骤可以省略。

yum -y install httpd php php-devel php-pdo php-gd php-mysql php-common php-mbstring php-odbc php-xml php-bcmath php-pear

安装 zabbix

官网下载页面:https://www.zabbix.com/download,请根据操作系统版本下载相应的Zabbix安装包。

rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum clean all

yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent

附:源码安装方法简述(请先下载解压)

./configure --sysconfdir=/opt/zabbix --enable-server --enable-agent --with-net-snmp --enable-java --with-libxml2 --with-libcurl --with-mysql

make && make install

cp /opt/zabbix/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/

cp /opt/zabbix/misc/init.d/fedora/core/zabbix_server /etc/init.d/

/etc/init.d/zabbix_server start

/etc/init.d/zabbix_agentd start

配置 zabbix-server

vi /etc/zabbix/zabbix_server.conf

LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=zabbix-server
DBName=zabbix
DBUser=zabbix
DBPassword=Zabbix@123
DBSocket=/var/lib/mysql/mysql.sock
DBPort=3306
#以下是常用的参数,请根据实际需求进行优化
StartPollers=64
StartPollersUnreachable=8
StartTrappers=64
StartPingers=8
StartHTTPPollers=8
StartTimers=4
StartEscalators=4
StartAlerters=8
JavaGateway=172.17.110.104,172.16.19.100
JavaGatewayPort=10052
StartJavaPollers=2
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
ListenIP=0.0.0.0
MaxHousekeeperDelete=10000
CacheSize=2048M
CacheUpdateFrequency=60
StartDBSyncers=32
HistoryCacheSize=256M
HistoryIndexCacheSize=32M
TrendCacheSize=512M
ValueCacheSize=1024M
Timeout=15
UnreachablePeriod=60
UnreachableDelay=60
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=1000
StartProxyPollers=2

部署 httpd

vi /etc/httpd/conf.d/zabbix.conf

php_value date.timezone Asia/Shanghai

视实际情况修改以下参数:

vi /etc/httpd/conf/httpd.conf

ServerName localhost
DocumentRoot "/opt/zabbix/html"

导入 Zabbix 数据

zcat /usr/share/doc/zabbix-server-mysql-*/create.sql.gz | mysql zabbix -uzabbix -pZabbix@123

拷贝 zabbix web

Zabbix web 的默认目录在 /var/www/html,具体方法请自行百度,通过rpm安装不需要此步骤,故本文略。

启动 httpd

systemctl start httpd

systemctl enable httpd

部署 Zabbix Agent

所有被监控主机都需要安装zabbix-agent,请根据操作系统版本安装相应的zabbix-agent,本文以CentOS为例。

安装 zabbix-agent

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

yum -y install zabbix-agent

配置 zabbix-agent

vi /etc/zabbix/zabbix_agentd.conf

修改如下内容:

Server=zabbix-server[,zabbix-server2,zabbix-server3]
#ServerActive=zabbix-server1[,zabbix-server2,zabbix-server3]
Hostname=zagent01

注意:需要做域名解析,或者写 Zabbix Server 的服务器IP。

至此,已经完成Zabbix全套部署,现在可以登录 http://10.10.200.20/zabbix/ 进行监控管理,当然,最好由 Grafana 来负责前端展示,如果有时间再讲。

部署 Grafana

Grafana的Linux版本的官方下载地址是:https://grafana.com/grafana/download?platform=linux

安装Grafana

cd /opt

wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.3.1-1.x86_64.rpm

yum -y localinstall grafana-5.3.1-1.x86_64.rpm

systemctl start grafana-server

访问grafana

默认的URL地址:http://10.10.200.248:3000

默认的账号密码:admin / admin

安装zabbix插件

也可以登录http://10.10.200.248:3000/plugins查找各种插件。

grafana-cli plugins list-remote | grep zabbix

grafana-cli plugins install alexanderzobnin-zabbix-app

安装常用插件

grafana-cli plugins install grafana-piechart-panel #圆饼形

grafana-cli plugins install grafana-clock-panel #钟表形

grafana-cli plugins install briangann-gauge-panel

grafana-cli plugins install vonage-status-panel

重启grafana

service grafana-server restart

#systemctl restart grafana-server

配置grafana

zabbix的api地址为:http://10.10.200.248/zabbix/api_jsonrpc.php

赞 (0) 打赏

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

感谢您的支持与帮助

支付宝扫一扫打赏

微信扫一扫打赏