Deployment zabbix 4.0 + grafana

Incomplete, for reference only

Zabbix + grafana monitoring deployment

Basic environment

System: CentOS Linux release 7.3.1611

Zabbix—server: 

Zabbix_agent:  

Nginx version number: 1.62

Mysql Version: 5.7.27

Zabbix Version Number: 4.0

Grafana Version Number: 6.0

1: basic environment configuration (turn off the firewall and selinux)

systemctl stop firewalld

systemctl disable firewalld

setenforce 0

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

 

2: Installation zabbix

  2.1 to deploy install nginx

yum -y install gcc pcre-devel openssl-devel wget

wget http://nginx.org/download/nginx-1.6.2.tar.gz

tar -xf nginx-1.6.2.tar.gz

cd nginx-1.6.2/

./configure --user=nginx --group=nginx --prefix=/opt/nginx/  --with-file-aio  --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module  --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module  --with-mail --with-mail_ssl_module     --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-http_stub_status_module

make  && make install

useradd -s /sbin/nologin nginx

ln -s /opt/nginx/sbin/nginx  /bin

nginx

 

vim /opt/nginx/conf/nginx.conf

  3 worker_processes  auto;

  13     worker_connections  30000;

  45             index index.php  index.html index.htm;

65         location ~ \.php$ {

 66             root           html;

 67             fastcgi_pass   127.0.0.1:9000;

 68             fastcgi_index  index.php;

 69         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

 70             include        fastcgi.conf;

 71         }

 

nginx -s reload

   2.2 to deploy install mysql

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

yum -y install mysql57-community-release-el7-10.noarch.rpm

yum -y install mysql-community-server

systemctl  start  mysqld;systemctl  enable mysqld

grep password /var/log/mysqld.log

mysql -uroot -p '' // according to the initial password database

mysql> set global validate_password_policy=0;

mysql> set global validate_password_length=5;

mysql> alter user root@localhost identified by '密码';

mysql> create database zabbix default character set utf8;

mysql>  create user 'zabbix'@'localhost' identified with mysql_native_password by '密码';

mysql> create user 'zabbix'@'127.0.0.1' identified with mysql_native_password by '密码';

mysql> create user 'zabbix'@'%' identified with mysql_native_password by '密码';

mysql>  grant all privileges on zabbix.* to "zabbix"@"localhost";

mysql> grant all privileges on zabbix.* to "zabbix"@"127.0.0.1";

mysql> grant all privileges on zabbix.* to "zabbix"@"%";

mysql> flush privileges;

 

  2.3 to deploy install PHP

wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm

yum install -y remi-release-7.rpm

yum install -y php72-php-devel php72-php-fpm php72-php-mbstring php72-php-memcache php72-php-redis php72-php-mysqli php72-php-mysqlnd php72-php-pdo php72-php-bcmath php72-php-dom php72-php-gd php72-php-gmp php72-php-igbinary php72-php-imagick php72-php-mcrypt php72-php-pdo_mysql php72-php-posix php72-php-simplexml php72-php-opcache php72-php-xsl php72-php-xmlwriter php72-php-xmlreader php72-php-xml php72-php-swoole php72-php-zip php72-php-fileinfo  systemc

 

vim  /etc/opt/remi/php72/php.ini

385 max_execution_time = 300

395 max_input_time = 300

674 post_max_size = 16M

827 upload_max_filesize = 8M

904 date.timezone = "Asia/Shanghai"

1326 always_populate_raw_post_data= -1

1583 mbstring.func_overload = 0

 

systemctl restart php72-php-fpm && systemctl enable php72-php-fpm

 

  2.4 Deployment mounting zabbix-server

cd /root/ && wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.12/zabbix-4.0.12.tar.gz

yum  -y install  java* mysql-devel net-snmp-devel libevent-devel mysql-devel curl-devel

useradd zabbix

tar  -xf zabbix-4.0.12.tar.gz

cd zabbix-4.0.12/

./configure --prefix=/opt/zabbix --enable-server --enable-agent --with-net-snmp --enable-java --with-libxml2 --with-libcurl --with-libxml2 --with-mysql=/usr/bin/mysql_config  --enable-proxy

make && make install

cd database/mysql/

mysql -uzabbix -p密码 zabbix < schema.sql

mysql -uzabbix -p密码 zabbix < images.sql

mysql -uzabbix -p密码 zabbix < data.sql

cd && cp -r zabbix-4.0.12/frontends/php/* /opt/nginx/html/

chmod -R 777 /opt/nginx/html/*

cp zabbix-4.0.12/misc/init.d/fedora/core/zabbix_agentd  /etc/init.d/

cp zabbix-4.0.12/misc/init.d/fedora/core/zabbix_server  /etc/init.d/

chmod +x /etc/init.d/zabbix_agentd

chmod +x /etc/init.d/zabbix_server

sed -i "s/#PidFile=\/tmp\/zabbix_server.pid/PidFile=\/tmp\/zabbix_server.pid/g" /opt/zabbix/etc/zabbix_server.conf

sed -i "s/# DBHost=localhost/DBHost=localhost/g" /opt/zabbix/etc/zabbix_server.conf

sed -i "s/# DBPassword=/DBPassword=密码/g" /opt/zabbix/etc/zabbix_server.conf

sed -i "s/# DBSocket=/DBSocket=\/var\/lib\/mysql\/mysql.sock/g" /opt/zabbix/etc/zabbix_server.conf

sed -i "s / # JavaGateway = / JavaGateway = 127.0.0.1/g" /opt/zabbix/etc/zabbix_server.conf

sed -i "s/Timeout=4/Timeout=30/g" /opt/zabbix/etc/zabbix_server.conf

sed -i "s/^# AlertScriptsPath=/AlertScriptsPath=\/opt\/zabbix\/scripts" /opt/zabbix/etc/zabbix_server.conf

mkdir -p /opt/zabbix/scripts

cp /opt/nginx/html/conf/zabbix.conf.php.example   /opt/nginx/html/zabbix.conf.php

 

vim /opt/nginx/html/zabbix.conf.php

$ DB [ 'PASSWORD'] = 'password';

 

sed -i "s/BASEDIR=\/usr\/local/BASEDIR=\/opt\/zabbix/g" /etc/init.d/zabbix_server

sed -i "s/BASEDIR=\/usr\/local/BASEDIR=\/opt\/zabbix/g" /etc/init.d/zabbix_agentd

systemctl daemon-reload

systemctl start zabbix_server

systemctl start zabbix_agentd

netstat  -utnlp |grep zabbix

Tip: If you can not view 1005010051 ports, you can view the error message by cat /tmp/zabbix_server.log and systemctl status zabbix_server. Here zabbix-server has been deployed.

Case solve the case zabbix server Chinese garbled, the document ukai.ttf file into the file / opt / nginx / html / assets / fonts directory

cd /opt/nginx/html/assets/fonts

vim  /opt/nginx/html/include/defines.inc.php

70 define('ZBX_GRAPH_FONT_NAME',           'ukai'); // font file name

111 define('ZBX_FONT_NAME', 'ukai');

 

2.5 Deployment mounting zabbix-agentd

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

firewall-cmd --reload

yum  -y install  java* mysql-devel net-snmp-devel libevent-devel mysql-devel curl-devel gcc wget

wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.12/zabbix-4.0.12.tar.gz

setenforce 0

useradd -s  /sbin/nologin  zabbix

tar -xf zabbix-4.0.12.tar.gz

cd zabbix-4.0.12/

./configure --enable-agent --prefix=/opt/zabbix

make && make install

mkdir -p /opt/zabbix/logs

chown zabbix /opt/zabbix/logs

sed -i 's#^LogFile.*$#LogFile=/opt/zabbix/logs/zabbix_agentd.log#'   /opt/zabbix/etc/zabbix_agentd.conf

sed -i 's # ^ Server =. * $ # Server = 127.0.0.1, the server IP #' /opt/zabbix/etc/zabbix_agentd.conf

sed -i 's # ^ ServerActive. * $ # ServerActive = server IP #' /opt/zabbix/etc/zabbix_agentd.conf

sed -i '103aListenPort=10050' /opt/zabbix/etc/zabbix_agentd.conf

cp /root/zabbix-4.0.12/misc/init.d/fedora/core/zabbix_agentd  /etc/init.d/

sed -i 's#BASEDIR=.*$#BASEDIR=/opt/zabbix#' /etc/init.d/zabbix_agentd

/etc/init.d/zabbix_agentd start

systemctl daemon-reload

systemctl start zabbix_agentd

systemctl status zabbix_agentd

 

3. To deploy the installation grafana 6.0

wget https://dl.grafana.com/oss/release/grafana-6.0.0-1.x86_64.rpm

yum -y install grafana-6.0.0-1.x86_64.rpm

Installation zabbix and graphic style plug-ins

grafana-cli plugins install alexanderzobnin-zabbix-app

grafana-cli plugins install grafana-clock-panel

grafana-cli plugins install grafana-piechart-panel

systemctl galluogi grafana-server

systemctl start grafana-server

vim /etc/sysconfig/iptables

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3000 -j ACCEPT

 

Login Address: HTTP: // server IP: 3000 / login    login account: admin initial login password: admin Change Password:

 

4 : Configure zabbix interface and alarm

   4.1 Initial login settings

The initial login screen: HTTP: // server IP / index.php   , only need to fill out to set a good database password in the password field of the database, you can click Next.

Initial login account: admin initial password login: zabbix

1: The interface settings display Chinese

Click on the upper right corner of the image of people in the Language column, click and choose "Chinese" to save the update.

2: Disable guest user

Click interface "management" --- "User Groups" --- "Guests" - When checked, click "Disable."

3: Modify the admin password

Click interface "management" --- "user" - "Admin" --- "Password" Enter the password --- "" --- click "Update."

4: new users, and is set to administrator

Click interface "management" --- "user" --- "Create User" ---- Groups "Zabbix administrator" - password "" --- "add."

Click interface "management" --- "user" --- "permission" --- user type "super administrator" --- "Update"

   4.2 host group

Click on "Configuration" --- "host group" --- "Create Host Group" --- group name "PPOVD" --- add

Click on "Manage" --- "User Groups" --- "Zabbix administrators" --- permissions (read-write) --- --- select user group input to the host group --- click "Add"

   4.3 Add Host

Click on "Configuration" --- "host" --- "Create Host" --- Host Name "PPOVD04" --- group "PPOVD" --- IP address "" - Add

Tip: add the same type of host, directly under the host originally created, click the "clone", modify the IP and name.

   4.4 Add Monitoring Project

Click on "Configuration" --- "host" --- "Monitoring item" --- "to create a monitoring item" --- Name "Enter the name" - Type "zabbix client" --- key "according to the monitoring item selection "---Add to

Click on "Configuration" --- "template" --- "Create a template" template name --- (based on business input template name) --- Group "select" --- "Add"

   4.5 add a graphic or flip-flop according to the project

Click on "Configuration" --- "host" --- "trigger" --- Creating triggers "" --- the name "disk not enough" ---

 

   4.6 custom macros and monitoring and alarm

1 : monitoring the disk size, upon reaching / home alarm less than 20G

In the host creates the need to monitor the required set of macros, click "Configuration" - "Host" - click on the selected host - Click on "macro" -

{$FS.FREE.HIGH}    20G

HOST.DIR $ {} / home

2 : Create a corresponding monitored item,

Click on "Configuration" --- "host" --- "Monitoring item" --- Name (Free disk space on {$ HOST.DIR}) ---

Key (vfs.fs.size [{$ HOST.DIR}, free]) --- Click Update

3 : Create a corresponding alarm

Click on "Configuration" --- "host" --- "trigger" --- "Create Trigger" --- the name "Free disk space is less than {$ FS.FREE.HIGH} on" --- expression formula "{PPOVD04: vfs.fs.size [{$ HOST.DIR}, free] .last (0)} <{$ FS.FREE.HIGH}"

4 : monitoring service is functioning properly by monitoring the presence or absence of the port to determine whether the service is operating normally.

Click on "Configuration" --- Host --- "Monitoring item" --- "to create a monitoring item" --- the name "nginx status" --- key (net.tcp.listen [80]) --- Click "update"

Click on "Configuration" trigger --- --- --- Host "Creating triggers" --- the name "nginx is down" --- --- severity of expression ({PPOVD04: net.tcp.listen [ 80] .last ()} = 0) ---- update

 

 

   4.7 Adding monitoring alarm

Click on "Manage" --- "Alarm media types" media type --- --- Creating name "telegram" --- type (script) --- script name "telegram.py" --- script parameters {ALERT. SENDTO} {ALERT.SUBJECT} {ALERT.MESSAGE} ---- Add

Click on "Manage" --- "user" media --- --- alarm type "telegram" --- recipient "telegram account" --- click Update

Click on "Configuration" --- "Create action" --- "name" --- the new trigger conditions (trigger warning of severe or greater) --- operation --- the default title ( {}} {{{Fire fire}} {{fire}} : alarm node: {} TRIGGER.NAME )

--- message content

Issue Details: {ITEM.NAME}: {ITEM.VALUE}

Alarm Host: {HOST.NAME}

Alarm Time: {EVENT.DATE} {EVENT.TIME}

Alarm level: {TRIGGER.SEVERITY}

Alarms: {TRIGGER.NAME}

Alarm items: {TRIGGER.KEY1}

Current status:. {TRIGGER.STATUS} {ITEM.VALUE}

Event ID: {EVENT.ID}

zbxtg:graphs

zbxtg:graphs_period=10800

zbxtq:itemid:{ITEM.ID1}

zbxtg:title:{HOST.HOST} - {TRIGGER.NAME}

--- Click --- sent to the new user group ( of ZABBIX of the Administrators ) --- sent to the user (harry) --- sent only to (telegram) --- operating conditions ((Event acknowledged equal unacknowledged) - --Add to

--- restore the default title --- ({{OK}} {{ OK}} {{OK}}: restoration nodes: {TRIGGER.NAME}) --- message content

Issue Details: {ITEM.NAME}: {ITEM.VALUE}

Recovery host: {HOST.NAME}

Recovery time: {EVENT.DATE} {EVENT.TIME}

Event class: {TRIGGER.SEVERITY}

Restoration projects: {TRIGGER.KEY1}

Current status:. {TRIGGER.STATUS} {ITEM.VALUE}

Event ID: {EVENT.ID}

zbxtg:graphs

zbxtg:graphs_period=10800

zbxtq:itemid:{ITEM.ID1}

zbxtg:title:{HOST.HOST} - {TRIGGER.NAME}

--- Click --- sent to the new user group ( of ZABBIX of the Administrators ) --- sent to the user (harry) --- sent only to (telegram) --- add

--- add

 

# Server configuration script file, the plug-in installed telegram zabbix server

wget https://bootstrap.pypa.io/get-pip.py

python get-pip.py

pip install telegram

pip install python-telegram-bot

pip install pyTelegramBotAPI

 

# In the / opt / Zabbix / scripts, put the script file telegram.py, and give execute permissions

cd /opt/zabbix/scripts/

 

#!usr/bin/env python

# pip install pyTelegramBotAPI

import sys

 

import telebot

 

contact = sys.argv[1]

subject = sys.argv[2]

content = sys.argv[3]

# subject = 'test'

# content = 'test'

TEST = telebot.TeleBot(token='811992293:AAEElXmUbdRpijLrPkLqN3sjetx-EDPrB9Y')

chat_id = int(contact)

TEST.send_message(chat_id=chat_id, text=subject + '\n' + content)

 

# To increase the file execute permissions

chmod +x /opt/zabbix/scripts/telegram.py

chown zabbix.zabbix /opt/zabbix/scripts/telegram.py

 

# Ensure python version on the server is zabbix 2.7 and above can, centos can use the default version

[root@localhost scripts]# python

 

# Manual test script using a script to send information, test examples:

python telegram.py "-355170319" Subject: Testing Information $ 'first line \ nsecond line \ nthird line'

NOTE: If the test group was seen in the telegram alarm, indicating that the entire script is correct, and if the other error, a lot of try.

 

Added: Robot use telegram alarm

1 : Open the telegram robot

   Step 1: Enter "@BotFather" the telegram inside the search bar inside the open and official telegram robot dialog

   Step 2: Send / start

   The third step: to own robot a name (required ending _bot, the front can be customized)

   Step four: receive official sent me a token

   Step 5: Add the robot telegram to the personal account need to receive the message, while establishing a group, add the robot to the group.

use

   Use get the official telegram sent me a token corresponding chat_id, if the machine is sent to the individual, chat is a string of pure numbers, if it is sent to the group, with a front of the data -

https://api.telegram.org/bot811992293:AAEElXmUbdRpijLrPkLqN3sjetx-EDPrB9Y/getUpdates

   (Personal id: 865969417 group ID: -355170319)

 

5 : Configure display zabbix grafana

  5.1 : Creating a Dashboard

Click on the right side of the interface of the second graph Dashboard --- --- Click Save name (zabbix) ---- Click on "save"

Click on the configuration interface plugins --- --- Click Click "zabbix" --- "enable" ---

configuration --- click on the data sources --- click on any screen "add data source" --- displayed zabbix indicates completion.

  5.2 Configuration grafana display data zabbix

Click interface configuration --- click on the "add data source" --- click "zabbix" ---

Enter the URL ( HTTP: // server Ip / api_jsonrpc.php) ---

Select zabbix version 4.x in the

Enter Admin ------ password input zabbix password username () --- click "save & Test"

  5.3grafana create graphics

Click "create" --- click "add query" --- Queries to (zabbix) ---- group (Enter the host group) --- host (hostname) --- click on the "general" -title ()

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/will--1213/p/11824550.html