zabbix 4.0 theory + operation - 02 (zabbix deployment + email alarm)

Keywords: Zabbix PHP MariaDB MySQL

zabbix theory + operation-02 (zabbix deployment + email alarm)

Experimental environment

Monitoring end:
Monitored end:

Install LAMP

yum install -y \
httpd \
mariadb-server mariadb \
php \
php-mysql \
php-gd \
libjpeg* \
php-ldap \
php-odbc \
php-pear \
php-xml \
php-xmlrpc \
vim /etc/httpd/conf/httpd.conf
DirectoryIndex index.html index.php

vi /etc/php.ini
date.timezone = PRC    //Set China time zone

systemctl stop firewalld.service
setenforce 0

systemctl start httpd.service
systemctl start mariadb.service

netstat -ntap | egrep '(80|3306)'


vi /var/www/html/index.php


mysql -u root -p

#Set up a database for zabbix and a user to manage it
CREATE DATABASE zabbix character set utf8 collate utf8_bin;
GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';
flush privileges;

#Write a test Homepage
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# vim index.php

#Verify zabbix can connect to the database
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";

---------Solve the problem of local login failure (can be ignored)---------------

[root@localhost html]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select user,host from mysql.user;  //There is an empty user name occupation, which results in local failure to log in and remote login
| user   | host                  |
| zabbix | %                     |
| root   |             |
| root   | ::1                   |
|        | localhost             |
| root   | localhost             |
|        | localhost.localdomain |
6 rows in set (0.01 sec)

drop user ''@localhost;

drop user ''@cacti;

flush privileges;

----------------Start to deploy zabbix Server-------

yum install php-bcmath php-mbstring -y

rpm -ivh http://Repo. ZABBIX. COM / ZABBIX / 3.5 / RHEL / 7 / x86 ʄ / zabbix-release-3.5-1.el7. Noarch. RPM / / will automatically generate the yum source file to ensure that the system can access the Internet
yum install zabbix-server-mysql zabbix-web-mysql -y

zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p  zabbix //Generate the database file, pay attention not to enter the password as root

grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf 

125:DBPassword=admin123 //Revise our bank

vim /etc/httpd/conf.d/zabbix.conf //Modify time zone

php_value date.timezone Asia/Shanghai

vim /usr/share/zabbix/include/ //Correction of Chinese characters in charts
:%s /graphfont/kaiti/g  //Copy the corresponding font file from Microsoft system to / usr/share/zabbix/fonts directory. Note that the font name should correspond to the configuration file, and pay attention to case
cp STKAITI.TTF /usr/share/zabbix/fonts/

systemctl enable zabbix-server
systemctl start zabbix-server
netstat -anpt | grep zabbix  //Listening on port 10051

systemctl restart httpd.service //Login user name after installation Admin Password: zabbix

Set up Chinese environment

Administrator users click user settings in language

-----------Configure the proxy - the server under control - and install the ZABBIX agent if the server needs to be monitored by itself--

rpm -ivh

yum install -y zabbix-agent

grep -n '^'[a-Z] /etc/zabbix/zabbix_agentd.conf


service firewalld stop
setenforce 0
systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service

netstat -anpt | grep zabbix  //Listening on port 10050

---------------Add controlled host--stay WEB Doing on the platform-----
//Configuration host create host:

//Host page is configured according to requirements
//Template page needs to link template, and link corresponding template as required

--------Configure mail alarm function---Configuration on server---------
yum install mailx

vi /etc/mail.rc //Note that Netease email needs to open client authorization code for third-party login

----Add at the end of the file---
set smtp-auth-password=Mailbox password
set smtp-auth=login

echo "hello world" | mail -s "testmail" //Normal test sending

cd /usr/lib/zabbix/alertscripts

vi //Script outgoing messages
#send mail

messages=`echo $3 | tr '\r\n' '\n'`
subject=`echo $2 | tr '\r\n' '\n'`
echo "${messages}" | mail -s "${subject}" $1 >>/tmp/mailx.log 2>&1

touch /tmp/mailx.log 
chown -R zabbix.zabbix  /tmp/mailx.log 
chmod +x /usr/lib/zabbix/alertscripts/
chown -R zabbix.zabbix /usr/lib/zabbix/

./ "theme" "content"   //Test whether the sending script works properly

-----Configure on server WEB----

Management > alarm media type > create media type

Name: mail test
 Type: Script
 Script name:
 Script parameters: / / add the following three parameters


Admin user click admin alarm media:

Type: mail test / / call the above script
 Other defaults - save

Configuration action create action delete default label modify trigger condition
 Name: Mailx
 Condition A host group = Linux servers

Operation - "configuration as follows

Default operation step duration 60
 Default recipient: {TRIGGER.STATUS}:{TRIGGER.NAME}
Default information:

Alarm host: {HOST.NAME}
Alarm IP: {HOST.IP}
Alarm information: {TRIGGER.NAME}:{ITEM.VALUE}
Event ID: {EVENT.ID}

Operation details: --

Action type: send message
 Send to user: Admin (Zabbix Administrator) 
Send only to: mail test / / be sure to configure or the mail will not be sent successfully

Recovery operation: {TRIGGER.STATUS}:{TRIGGER.NAME}
Recovery information:

Recovery host: {HOST.NAME}
Recovery IP: {HOST.IP}
Recovery time: {EVENT.DATE}-{EVENT.TIME}
Recovery level: {TRIGGER.SEVERITY}
Recovery information: {TRIGGER.NAME}:{ITEM.VALUE}
Recovery ID: {EVENT.ID}

Operation details: --
Action type: send message
 Send to user: Admin (Zabbix Administrator) 
Send only to: mail test / / be sure to configure or the mail will not be sent successfully

systemctl restart zabbix-server
systemctl restart zabbix-agent.service

------The following are test alarms-----

It can simulate that the relevant parameters, such as disk space, exceed the threshold value on the controlled host. Then verify the email.

systemctl stop zabbix-agent.service / / turn off test alarm email reception on the monitored host

Posted by DeathfireD on Mon, 10 Feb 2020 03:12:52 -0800