Centos 7 minimizes deployment of zabbix

Keywords: PHP Zabbix MySQL RPM Database

Preface

The content of the article is written by the author himself. It has been put in the word document before. Suddenly, the leisure has shifted to the blog. Follow-up viewers are welcome to have questions to discuss with me.~~~

Don't talk too much nonsense. Let's talk about the principle first.

 

Summary

Working principle

Collecting data through c/s mode, analyzing and displaying data based on b/s mode

Agent Configuration Data Acquisition Item
Server collects and analyses data, and finally displays data through web gui
Storage of Historical Data in Database
Proxy Distributed Monitor, which receives data from agent and forwards it to Server
Web gui data display, usually on the same machine as Server
Tools introduced after Java gateway 2.0 are similar to agent d, but only for Java.
Sender actively sends data to Server, which is usually configured on the agent side.
Get actively collects data, usually with server or proxy, triggered manually

 

Common processes

The daemon on the zabbix_agent D agent side, responsible for collecting data
Zabbix_server ZABBIX server daemon, receiving and analyzing data
zabbix_get, a manual data acquisition tool, is commonly used for server-to-agent testing
Zabbix_sender ZABBIX tool for sending data to server or proxy
Zabbix_proxy ZABBIX proxy daemon. It's like a server, it's just a transit station.
Zabbix_java_gateway Java gateway, similar to agent D

 

Working mode

Active mode: agent side actively returns data according to specific requests of server side
Passive mode: server side collects data from agent according to monitoring list item

 

Common nouns

Host requires monitored devices such as hosts, routers, printers, etc.
Logical grouping of monitored hosts, configurable templates
Items monitoring items
Application application group, a collection of monitoring items
Keys specific monitoring values
Trigger threshold, which mainly evaluates monitoring items
Event events, descriptions of a thing, such as state changes, host listing, login
Action action to implement defined operations, such as scripts, mail
Escalation executes customized scenarios for operations in action; a series of notifications, remote commands
Media Media, the Way to Deliver Information
Notification sends event information to users through media
Remote commend remote command
Template template, itmes, application, action, etc. defined for implementation

 

Deployment details

Deployment of network environment

Server       192.168.2.111
Database     192.168.2.111
Agent        192.168.2.112

 

Service End Deployment

Unload the firewall and close selinux

rpm -qa | grep "iptables" | xargs rpm -e --nodeps
rpm -qa | grep "firewall" | xargs rpm -e --nodeps
sed -i 's/enforcing/disabled/g' /etc/selinux/config

 

Mount iso, configure local yum source

mount -t iso9660 -o loop /opt/CentOS-7-x86_64-Everything-1708.iso /mnt/
echo '[ever]' > /etc/yum.repos.d/local.repo
sed -i '$a name=ever' /etc/yum.repos.d/local.repo 
sed -i '$a baseurl=file:///mnt' /etc/yum.repos.d/local.repo 
sed -i '$a gpgcheck=0' /etc/yum.repos.d/local.repo 
sed -i '$a enable=1' /etc/yum.repos.d/local.repo
rm -rf /etc/yum.repos.d/CentOS-*
yum makecache

 

Install http, php and related plug-ins

Install httpd and php

yum -y install httpd php gcc gcc-c++ ncurses ncurses-devel autoconf

 

Installation of zabbix and related programs

ls /opt                            #Here are the packages you need to download from zabbix.com
fping-3.10-1.el7.x86_64.rpm
iksemel-1.4-2.el7.centos.x86_64.rpm
iksemel-devel-1.4-2.el7.centos.x86_64.rpm
iksemel-utils-1.4-2.el7.centos.x86_64.rpm
zabbix-server-mysql-3.4.10-1.el7.x86_64.rpm
zabbix-web-3.4.10-1.el7.noarch.rpm
zabbix-web-mysql-3.4.10-1.el7.noarch.rpm

cd /opt/ 
yum -y install ./*.rpm

 

Install mysql

Unload the default database

rpm -qa | grep "mysql" | xargs rpm -e --nodeps
rpm -qa | grep "mariadb*" | xargs rpm -e --nodeps

 

Install cmake and related plug-ins

wget https://cmake.org/files/v3.10/cmake-3.10.1.tar.gz
tar -zxf cmake-3.10.1.tar.gz -C /usr/local/
cd /usr/local/cmake-3.10.1
./bootstrap
make && make install

 

Create mysql daemon user

groupadd -g 306 mysql
useradd -g mysql -s /sbin/nologin -M mysql

 

Installation of Mysql

cd mysql-5.6.26
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DWITH_DEBUG=0
make -j `grep "processor" /proc/cpuinfo | wc -l`
make install

 

Configuration of Mysql

cp support-files/my-default.cnf /etc/my.cnf
sed -i '$a basedir=/usr/local/mysql' /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
sed -i '$a PATH=$PATH:/usr/local/mysql/bin' /etc/profile
sed -i '$a export PATH' /etc/profile
source /etc/profile

 

Initialize and start

cd /usr/local/mysql
chown -R mysql:mysql *
./scripts/mysql_install_db  --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
chown -R root *
chown -R mysql data
service mysqld start

 

Creating zabbix database and data import

Log in to the database

mysql -uroot -p

 

Create a database and authorize users

CREATE DATABASE IF NOT EXISTS zabbix DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
grant all privileges on zabbix.* to 'zabbix'@'%' identified by 'zabbix';
flush privileges;

 

Import of Zabbix Data Information

cd /usr/share/doc/zabbix-server-mysql-3.4.10/
gunzip -d create.sql.gz
mysql -uzabbix -pzabbix -h192.168.2.111 zabbix < create.sql

 

Configure zabbix server

vi /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=192.168.2.111                            Appoint zabbix Database Storage Location
DBName=zabbix                                Appoint zabbix Database name
DBUser=zabbix                                    Appoint zabbix Database login user
DBPassword=zabbix                                Specify database remote connection password
#DBSocket=/var/lib/mysql/mysql.sock                Appoint sock Connection file
SNMPTrapperFile=/var/log/snmptt/snmptt.log        
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts

 

Configuration Startup Service

Modify the php default time zone

vim /etc/php.ini
date.timezone = Asia/Shanghai

 

Start http and zabbix

systemctl start httpd.service
systemctl start zabbix-server
systemctl enable httpd.service
systemctl enable zabbix-server

 

Configuration of Web Interface

 

Changing Chinese

Find a font you like under the windows directory C:WindowsFonts and upload it to Server's zabbix font directory

The original link file under this directory is destroyed, and the file uploaded by oneself can be changed to the original file. Other versions may need to change only fonts configuration file to support Chinese.

So far, the server end has been deployed.

 

Agent End Deployment

Install agent program

Agent installation does not depend on any plug-ins, it can be installed directly.

wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.10-1.el7.x86_64.rpm
wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-sender-3.4.10-1.el7.x86_64.rpm
rpm -ivh zabbix-sender-3.4.10-1.el7.x86_64.rpm
rpm -ivh zabbix-agent-3.4.10-1.el7.x86_64.rpm

 

Configuration agent

vim zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid     # Setting the pid file location of the agent
LogFile=/var/log/zabbix/zabbix_agentd.log     # Setting the log file location of the agent
LogFileSize=0                                 # Set the log file size of the agent
Server=192.168.2.111                          # Setting the address of zabbix server
ServerActive=192.168.2.111                    # Set active mode and fill in server address
Hostname=192.168.2.112                        # Setting server resolves agent hostname or IP
Include=/etc/zabbix/zabbix_agentd.d/*.conf    # Setting up Extended Configuration Directory

 

Start agent

systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service
systemctl is-enabled zabbix-agent.service

 

Create Host

Login Server's web Management Interface

Configure >> Hosts >> create host

Configuration agent information

Now that the host has been added, it should be noted that zabbix has just joined the monitored host and it will take some time to activate the host.

 

Create monitoring items

Configure >> Hosts >> Items >> Create item

Customize keys to add monitoring items manually

Switch the extended configuration directory of zabbix

cd /etc/zabbix/zabbix_agentd.d

 

Generate network card traffic monitoring script network.sh

#!/bin/bash
usage() {
        echo "Useage : $0"
        echo "eg. sh $0 eth0"
        exit 1
}
if [ $# -lt 1 ]
then
        usage
fi
eth=$1
timer=1
in_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $1 }')
out_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $9 }')
x=1
while [ $x -le 2 ]
do
        sleep ${timer}
        in=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $1 }')
        out=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $9 }')
        dif_in=$(((in-in_old)/timer))
        dif_in=$((dif_in/1024))
        dif_out=$(((out-out_old)/timer))
        dif_out=$((dif_out/1024))
        ct=$(date +"%F %H:%M:%S")
        echo "${ct} -- IN: ${dif_in} KByte/s     OUT: ${dif_out} KByte/s"
        in_old=${in}
        out_old=${out}
        x=3
done
exit 0

 

Add scripts to Items custom files

UserParameter=Network_in,bash /etc/zabbix/zabbix_agentd.d/network.sh eth0| awk '{print $5}'
UserParameter=Network_out,bash /etc/zabbix/zabbix_agentd.d/network.sh eth0| awk '{print $8}'

 

Restart agent, server test Keys

systemctl restart zabbix-agent            
#agent side

zabbix_get -s 192.168.2.112 -p 10050 -k "Network_out"        
#server side

 

Add item to web interface

So far, custom keys have been created

 

Create monitoring images

Configure >> Hosts >> Graphs >> Create graph

After adding a single graph, we will introduce the creation of integrated graphics.

 

Monitoring >> Screens >> Edit screen

So far, the aggregate graph has been created.

 

Create triggers

Triggers are used to define thresholds. Here's how to create triggers

Configure >> Hosts >> Triggers >> create trigger

Trigger is created

 

Create alerts

Alerts can use commands or mail or scripts, etc. I'll show you here using remote commands only.

The following demonstrates the creation of actions: Configure > Actions > Creation action

The main purpose of a general trigger is to define these things.

 

Zabbix monitoring case

agent protocol

Custom monitoring disk usage

Custom monitoring disk IO

Custom monitoring CPU load

Custom Monitoring Memory

Custom Monitoring Network Card Flow

# cat /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf | tail -n2
UserParameter=Network_in,bash /etc/zabbix/zabbix_agentd.d/network.sh eth0| awk '{print $5}'
UserParameter=Network_out,bash /etc/zabbix/zabbix_agentd.d/network.sh eth0| awk '{print $8}'

 

Attach the content of the network.sh script below

#!/bin/bash
usage() {
        echo "Useage : $0"
        echo "eg. sh $0 eth0"
        exit 1
}
if [ $# -lt 1 ]
then
        usage
fi
eth=$1
timer=1
in_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $1 }')
out_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $9 }')
x=1
while [ $x -le 2 ]
do
        sleep ${timer}
        in=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $1 }')
        out=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk '{print $9 }')
        dif_in=$(((in-in_old)/timer))
        dif_in=$((dif_in/1024))
        dif_out=$(((out-out_old)/timer))
        dif_out=$((dif_out/1024))
        ct=$(date +"%F %H:%M:%S")
        echo "${ct} -- IN: ${dif_in} KByte/s     OUT: ${dif_out} KByte/s"
        in_old=${in}
        out_old=${out}
        x=3
done
exit 0

 

Custom monitoring port

Custom monitoring user file usage

Custom monitoring log file

Custom monitoring URL

 

Documents have been uploaded to the storage of the blog park, in fact, it is better to see that, because the picture is clearer than the blog, but I am afraid that next time I forget where to put the document, I will write it on the blog first....

Posted by Hiro on Fri, 02 Aug 2019 04:19:21 -0700