Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Zabbix monitoring and email alarm

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. installation of zabbix client

Since we want to monitor, we need to add the host to be monitored. Before adding the host, we need to install it on the host to be detected.

Agent, install agent is relatively simple, we also follow the process of installing server, download the software package, when compiling

Wait, we only choose agent.

192.168.1.20, as the monitored end of zabbix, provides web and mysql applications

1. Install Zabbix and configure Zabbix agent:

21 rz (upload zabbix-3.2.1.tar.gz) 22 ls 23 tar zxf zabbix-3.2.1.tar.gz (decompression) 24 cd zabbix-3.2.1/ 25. / configure-- prefix=/usr/local/zabbix-- enable-agent & & make & & make install (compilation and installation) 2. Optimize zabbix 23 cp misc/init.d/fedora/core/zabbix_agentd / etc/init.d/ (copy startup file) 24 vim / etc/init.d/zabbix_agentd (modify startup file) BASEDIR=/usr/local/Zabbix # 22 PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid # 31 25 cd / usr/local/zabbix/etc/ 26 vim zabbix_agentd.conf (modify zabbix configuration File) 28 grep-v "^ #" / usr/local/zabbix/etc/zabbix_agentd.conf | grep-v "^ $" PidFile=/usr/local/zabbix/logs/zabbix_agentd.pid # 11LogFile=/usr/local/zabbix/logs/zabbix_agentd.log # 30Server=192.168.1.10 # 91 server IPListenPort=10050 # 99 to comment ListenIP=0.0.0.0 # to comment ServerActive=192.168.1.10 # 132 server IPHostname=192.168.1.30 # IP Then Timeout=3 # to comment on Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/ # 262

29 mkdir / usr/local/zabbix/logs (create required directory) 30 useradd zabbix-s / sbin/nologin-M (create required user) 33 chown-R zabbix:zabbix / usr/local/zabbix/ (make user executable / usr/local/zabbix) 34 ll / usr/local/zabbix/ (check out the group and owner of / usr/local/zabbix)

3. Self-booting

36 chkconfig-add zabbix_agentd (add Startup) 37 chkconfig zabbix_agentd on (Boot on) 38 / etc/init.d/zabbix_agentd start (enable zabbix) 40 netstat-anpt | grep 10050 (View Port)

At this point, the basic environment of the zabbix3.2.1 monitoring system has been installed.

4. Implement zabbix to add monitoring items

Add monitoring of Linux hosts

Open in browser: http://192.168.31.225/zabbix

Log in to zabbix, first add host monitoring in "configuration"-"Host" to monitor os resources: memory, cpu, io, load, bandwidth, etc. Log in to zabbix and click "create Host" in "configuration"-"Host".

Note: the "host name" in the following figure should be the name after "Hostname" set in the zabbix_agentd.conf file.

To!

Host name: 192.168.1.30

Group: Linux servers

Agent Agent Program Interface

Ip: 192.168.1.10

Enabled: check

Other options are available by default

Switch to template

Choice

Select: Template OS Linux

Point add

Add

At this point, the Zabbix monitoring Linux host setting is complete.

After configuring for a period of time, check to see if the effect of the monitoring chart has come out.

Zabbix3.0 server already has its own mysql template, just configure the agent client, and then add a template to the host on the web side.

II. Zabbix_agent client operation

Install MySQL using a script

43 rz upload mysql installation package and script 44 sh mysql.sh 45 history 46 netstat-anpt | grep 3306 View IP

Mysql.sh script content

#! / bin/bashtar-zxf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz# move the binary package to / usr/local/mysqlmv mysql-5.7.22-linux-glibc2.12-x86_64 / usr/local/mysql# create the data directory mkdir / usr/local/mysql/data# create users and groups and grant folder permissions groupadd-r mysqluseradd-r-g mysql- M-s / bin/false mysqlchown-R mysql:mysql / usr/local/mysql# removes mariadb-libsrpm-e mariadb-libs included in centos7-- nodeps# settings my.cnf configuration file cat > / etc/my.cnf start_SSL ($SERVER)) {# 1906 modification

Continue to execute

SendEmail-f 123456@qq.com-t 123456om-s smtp.qq.com-u "hello"-o message-content-type=html-o message-charset=utf8-xu 123456@qq.com-xp twjlhxzhsykjddcb-m "123"

The email has now been sent successfully

(3) create a mail.sh mail script

55 cd 56 vim mail.sh (create email script) #! / bin/bashto=$1subject=$2body=$3/usr/local/bin/sendEmail-o tls=auto-f 123456@qq.com-t "$to"-s smtp.qq.com-u "$subject"-o message-content-type=html-o message-charset=utf8-xu 123546@qq.com-xp twjlhxzhsykjddcb-m "$body"

Execute a script test to send an email

57 sh mail.sh223456@qq.com test 123 (execute script to send email)

Sent successfully

(4) move the script to enter / usr/local/zabbix/share/zabbix/alertscripts/

Mv mail.sh / usr/local/zabbix/share/zabbix/alertscripts/

Chown + x mail.sh

Zabbix web side configuration

After the above email script is configured, you need to add alarm media on the web side. On the web page Management, alarm Media types page, click create Media Type on the right.

Go to the creation page, enter the name "email alarm script", select the type script, select the name mail.sh, click the add button, and add three script parameters, namely {ALERT.SENDTO}, {ALERT.SUBJECT}, {ALERT.MESSAGE}, for to, subject and body in mail.sh. After adding, click the add button below, and our alarm medium will be created.

After creating the alarm media, we need to associate the alarm media with our users. Click manage, user, and then select our user admin can also create a new user, click the user name to enter the user configuration interface. Click the alarm media, then click add, select the email alarm script we created in the previous step, enter the recipient, select the alarm time and type, and then click add to associate the created alarm media with our users.

What we need to do now is to create a trigger action, that is, if the system fails, trigger this action, and then send an alarm email to our mailbox. Click configure, select actions, and then click create Action on the right.

Write the action name and trigger condition we defined in the name of the action page.

Configure trigger

Alarm test

Shut down the zabbix_agent process on the 192.168.1.20 server.

It is found that the fault alarm email can be received normally.

/ etc/init.d/zabbix_agentd stop

You can see that it has been successfully sent

QQ Mail received an error message.

The whole experiment is over.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report