Grafana接入zabbix部署说明

阿里云ECS部署Grafana接入zabbix

关于zabbix及相关服务软件版本:

Linux: ECS_CentOS 7.2

nginx: 1.9.15

一、购买ECS

购买一台ECS

二、安装nginx

安装依赖包:

yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel

创建nginx用户:

useradd nginx -s /sbin/nologin -M

下载nginx软件包并进入到目录中:

wget http://nginx.org/download/nginx-1.9.15.tar.gz && tar xvf nginx-1.9.15.tar.gz && cd nginx-1.9.15

编译:

./configure –prefix=/usr/local/product/nginx1.9.14 –user=nginx –group=nginx –with-http_ssl_module –with-http_v2_module –with-http_stub_status_module –with-pcre

make && make install

ln -s /usr/local/product/nginx1.9.14 /usr/local/nginx    ==>创建软链接

参数解释:

–with-http_stub_status_module:支持nginx状态查询
–with-http_ssl_module:支持https
–with-http_spdy_module:支持google的spdy,想了解请百度spdy,这个必须有ssl的支持
–with-pcre:为了支持rewrite重写功能,必须制定pcre

三、安装Grafana

mkdir /opt/grafana && cd /opt/grafana
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.3.2.linux-x64.tar.gz
tar -zxvf grafana-4.3.2.linux-x64.tar.gz
mv grafana-4.3.2 grafana
cd grafana/bin/
#查看可以安装的插件
./grafana-cli plugins list-remote
#安装zabbix插件
./grafana-cli plugins install alexanderzobnin-zabbix-app
#安装饼图插件
./grafana-cli plugins install grafana-piechart-panel
#启动,并后台运行
./grafana-server -homepath /opt/grafana/grafana &

四、Grafana管理网站配置(nginx):

编辑nginx虚拟主机:

[root@grafana conf]# mkdir extra
[root@grafana conf]# cd extra/
[root@grafana extra]# vim grafana.conf
server {
listen       80;
server_name  grafana.dtstack.com;
access_log /data/logs/zabbix/grafana.dtstack.com.access.log main;

location / {
index  index.html;
proxy_pass http://127.0.0.1:3000;
proxy_set_header   Host             $host;
proxy_set_header   X-Real-IP        $remote_addr;
proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

}
}

编辑nginx.conf配置文件:

[root@grafana conf]# cat nginx.conf

user  nginx;
worker_processes  1;

#error_log  logs/error.log warning;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {
worker_connections  1024;
}

http {
include       mime.types;
default_type  application/octet-stream;

log_format  main  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;
include extra/*.conf;

}

添加/etc/hosts文件:

192.168.119.140 grafana.dtstack.com

访问Grafana

访问http://grafana.dtstack.com  admin/admin

五、添加数据源:

启用zabbix插件
数据源配置 – 数据源
Name:      zabbix
Default:   ✔️
Type:      Zabbix

Http settings

URL:     http://zabbix.dtstack.com/api_jsonrpc.php
Access:  proxy

Zabbix API details

Username: xxxxxx
Password: xxxxxx