依据前文:Linux下Zabbix5.0 LTS监控基础原理及安装部署(图文教程) 环境,继续添加MySQL应用集。

第一部分:添加Zabbix自带的MySQL应用集。

在ZabbixClient-01上操作。【官方rpm下载

# 检查是否已安装MySQL,反之下载安装
[root@ZabbixClient-01 ~]# rpm -qa | grep mysql
[root@ZabbixClient-01 ~]# wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
[root@ZabbixClient-01 ~]# rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
[root@ZabbixClient-01 ~]# yum list all | grep mysql-community
[root@ZabbixClient-01 ~]# yum install mysql-community-server mysql-community-client -y
[root@ZabbixClient-01 ~]# mysql -V
mysql Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using EditLine wrapper # 检查是否正常启动
[root@ZabbixClient-01 ~]# systemctl start mysqld && systemctl enable mysqld
[root@ZabbixClient-01 ~]# netstat -nutpl | grep mysql
tcp6 0 0 :::3306 :::* LISTEN 7350/mysqld [root@ZabbixClient-01 ~]# ps -ef | grep mysql
mysql 7350 1 0 14:43 ? 00:00:03 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid # MySQL安全初始化
[root@Mysql-Master01 ~]# grep 'temporary password' /var/log/mysqld.log
2021-08-19T04:08:59.720748Z 1 [Note] A temporary password is generated for root@localhost: .!aTlyih4r2y [root@Mysql-Master01 ~]# mysql_secure_installation Securing the MySQL server deployment. Enter password for user root:  # 输入MySQL初始密码 .!aTlyih4r2y The existing password for the user account root has expired. Please set a new password. New password:    # 输入符合复杂密码策略的新密码 Client@01 Re-enter new password:  # 再次输入 Client@01
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root. Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n    # 上面以已经修改了,无需再修改 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y    # 是否删除匿名用户
Success. Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y  # 是否禁用root远程登录
Success. By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  # 是否删除test库和对test库的访问权限
- Dropping test database...
Success. - Removing privileges on test database...
Success. Reloading the privilege tables will ensure that all changes
made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y   # 是否刷新授权表使修改生效
Success. All done! # root测试登录MySQL,并创建监控用户
[root@ZabbixClient-01 ~]# mysql -u root -p
Enter password:  # 输入上面刚更改的密码 Client@01
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 113
Server version: 5.7.36 MySQL Community Server (GPL) Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# 创建用户zbx_monitor 密码ZabbixClient@01
mysql> create user 'zbx_monitor'@'localhost' identified by 'ZabbixClient@01';
Query OK, 0 rows affected (0.00 sec) # 授予zbx_monitor权限
mysql> grant usage,replication client,process,show databases,show view on *.* to 'zbx_monitor'@'localhost';
Query OK, 0 rows affected (0.00 sec)
  或
mysql> grant all privileges on *.* to 'zbx_monitor'@'localhost';
Query OK, 0 rows affected (0.00 sec) # 刷新授权,使其立即生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> select user,host from mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
| zbx_monitor | localhost |
+---------------+-----------+
4 rows in set (0.00 sec) mysql> show grants for 'zbx_monitor'@'localhost';
+----------------------------------------------------------+
| Grants for zbx_monitor@localhost |
+----------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'zbx_monitor'@'localhost' |
+----------------------------------------------------------+
1 row in set (0.00 sec) # zbx_monitor用户测试登录,并查看已有权限
[root@ZabbixClient-01 ~]# mysql -u zbx_monitor -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.36 MySQL Community Server (GPL) Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show grants for current_user();
+----------------------------------------------------------+
| Grants for zbx_monitor@localhost |
+----------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'zbx_monitor'@'localhost' |
+----------------------------------------------------------+
1 row in set (0.00 sec) # /etc/zabbix下新增一个文件 .my.cnf
[root@ZabbixClient-01 ~]# vim /etc/zabbix/.my.cnf
[mysql]
user=zbx_monitor
password=ZabbixClient@01 [mysqladmin]
user=zbx_monitor
password=ZabbixClient@01 # 搜索zabbix-agent自带的MySQL Key配置文件
[root@ZabbixClient-01 ~]# find / -iname userparameter_mysql*
/usr/share/doc/zabbix-agent-5.0.17/userparameter_mysql.conf
[root@ZabbixClient-01 ~]# cp /usr/share/doc/zabbix-agent-5.0.17/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/ # 修改userparameter_mysql.conf配置文件(其实只多了一个 HOME=/etc/zabbix)
[root@ZabbixClient-01 ~]# sed -i_bak$(date +%Y%m%d) -e 's#],#], HOME=/etc/zabbix#g' /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
[root@ZabbixClient-01 ~]# systemctl restart zabbix-agent && systemctl restart mysqld

Zabbix Web设置,添加MySQL监控集。

第二部分: 动作触发实现163.com邮箱报警功能。

发送手机短信获取163邮箱授权码。

Zabbix Web设置。

qq邮箱,已收到测试邮件。

创建二级管理员用户群组。

创建二级管理员用户。

创建动作触发。

ZabbixClient-01测试停用MySQL服务,验证结果 。

[root@ZabbixClient-01 ~]# systemctl stop mysqld
[root@ZabbixClient-01 ~]# ps -ef | grep mysqld
root 71766 1141 0 11:30 pts/0 00:00:00 grep --color=auto mysqld

ZabbixClient-01测试启用MySQL服务,验证结果。

[root@ZabbixClient-01 ~]# systemctl start mysqld
[root@ZabbixClient-01 ~]# ps -ef | grep mysqld
mysql 96660 1 0 11:58 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 96816 1141 0 12:06 pts/0 00:00:00 grep --color=auto mysqld

第三部分:执行预处理操作。

设置MySQL告警停用后,自动执行重启MySQL操作。

# 增加远程执行命令操作配置
[root@ZabbixClient-01 ~]# sed -i -e '$a\EnableRemoteCommands=1\nLogRemoteCommands=1' /etc/zabbix/zabbix_agentd.conf
解析:EnableRemoteCommands=1 #允许远程执行命令
   LogRemoteCommands=1 #开启远程执行命令操作日志 # 配置zabbix客户端的sudo权限
[root@ZabbixClient-01 ~]# visudo
#....
# 末行添加以下两行内容
# allows 'zabbix' user to restart mysqld without password.
zabbix ALL=NOPASSWD:/usr/bin/systemctl restart mysqld

至此,已完成所有部署设置。

Linux下Zabbix5.0 LTS添加MySQL监控,实现邮件报警并执行预处理操作的更多相关文章

  1. Linux下Zabbix5.0 LTS添加自定义监控项

    自定义监控项 zabbix本身提供了很多可选的监控项,可以满足绝大部分的监控需求.有时候由于业务需求,需要自定义监控项. 下面以创建mysql自定义监控项为例,分享如何创建zabbix自定义监控项. ...

  2. Linux下Zabbix5.0 LTS监控基础原理及安装部署(图文教程)

    Zabbix 是什么? zabbix 是一个基于 Web 界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.通过 C/S 模式采集数据,通过 B/S 模式在 Web 端展示和配置,能监视 ...

  3. Linux下Zabbix5.0 LTS + Grafana8.2.2图形可视化

    Grafana是一款开源的可视化软件,可以搭配数据源实现一个数据的展示和分析:Grafana功能强大,有着丰富的插件,但Grafana默认没有zabbix作为数据源,需要手动给zabbix安装一个插件 ...

  4. 分布式监控系统Zabbix-3.0.3-完整安装记录(2)-添加mysql监控

    Zabbix3.0 Server以后就自带了MySQL插件来监控mysql数据库的模板,只需要配置好agent客户端,然后在web端给主机增加模板就行了. 以下是公司线上的zabbix3.0环境下添加 ...

  5. linux下使用crontab定时备份MYSQL数据库的方法:

    摘要 linux下使用crontab定时备份MYSQL数据库的方法: 只需按照下面3步做,一切都在你的掌控之下: 第一步:在服务器上配置备份目录代码: ------------------------ ...

  6. Linux下安装配置与使用MySQL数据库

    Linux下安装配置与使用MySQL数据库 在Linux下安装做开发时往往少不了要使用到MySQL数据库,下面就Linux系统为例讲解一下,如何安装MySQL数据库,如何启用/停.止MySQL服务,如 ...

  7. Linux下tomcat6.0与jdk安装

    Linux下tomcat6.0与jdk安装 步骤如下: 1. 上传apache-tomcat-6.0.37.tar.gz和jdk-6u13-linux-i586.bin至/usr/local 给这两个 ...

  8. LoadRunner添加Weblogic监控的注意事项(非单纯的操作步骤)

    LoadRunner添加Weblogic监控的注意事项(非单纯的操作步骤)   关于LR如何监控Weblogic(JMX方式)的操作就不在这里多说了,帮助文件和网上的介绍已经非常多了,关键是对各操作步 ...

  9. linux下安装jdk+tomcat+eclipse+mysql

    我的环境:主机是win7的,虚拟机是VWare  Workstation 6.0   ,linux系统为Red Hat Enterprise  Linux 5 64位 各软件版本:jdk是jdk-6u ...

随机推荐

  1. ajax 中文参数乱码问题不一定是编码格式问题。

    代码要修改用户的信息,写了三个ajax,第一个写完测试没有问题,后面俩逻辑一样的就直接复制粘贴了.到第二个ajax测试的时候发现中文会乱码 如下 $.ajax({//中文参数乱码 url: '/edi ...

  2. 初探区块链数字加密资产标准ERC721

    ERC721介绍 数字加密货币大致可以分为原生币(coin)和代币(token)两大类.前者如BTC.ETH等,拥有自己的区块链.后者如Tether.TRON.ONT等,依附于现有的区块链.市场上流通 ...

  3. 自定义ConditionalOnXX注解

    一.Conditional注解介绍 对SpringBoot有足够了解的小伙伴应该都用过Conditional系列注解,该注解可用在类或者方法上用于控制Bean的初始化. 常用的Conditional注 ...

  4. 力扣 - 剑指 Offer 39. 数组中出现次数超过一半的数字

    题目 剑指 Offer 39. 数组中出现次数超过一半的数字 思路1(排序) 因为题目说一定会存在超过数组长度一半的一个数字,所以我们将数组排序后,位于length/2位置的一定是众数 代码 clas ...

  5. RabbitMQ延时队列应用场景

    应用场景 我们系统未付款的订单,超过一定时间后,需要系统自动取消订单并释放占有物品 常用的方案 就是利用Spring schedule定时任务,轮询检查数据库 但是会消耗系统内存,增加了数据库的压力. ...

  6. 【UE4 调试】C++ 几种编译方法和小技巧

    编译方法 Visual Studio 2019 编译 默认编译 UnrealVS 快速编译 Editor 编译 一般 vs 编译完后,Editor会跟着热编译(有声音) 如果发现编译后代码没更新到Ed ...

  7. 【数据结构与算法Python版学习笔记】树——二叉查找树 Binary Search Tree

    二叉搜索树,它是映射的另一种实现 映射抽象数据类型前面两种实现,它们分别是列表二分搜索和散列表. 操作 Map()新建一个空的映射. put(key, val)往映射中加入一个新的键-值对.如果键已经 ...

  8. 使用cerebro可视化ElasticSearch集群信息

    使用cerebro可视化ElasticSearch集群信息 一.背景 二.安装步骤 1.下载并解压 2.配置cerebro 3.启动 cerebro 4.启动界面 三.注意事项 四.参考文档 一.背景 ...

  9. Noip模拟37 2021.8.12

    T1 数列 真是考场上不是数学的乱推柿子,想定理,是数学的没想出来.. 比较悲伤... 列柿子不用动脑子,就是没有想出来$EXgcd$解不定方程,淦.. 解处一组解后利用比较显然的性质: $x+\fr ...

  10. BOOST内存管理-intrusive_ptr

    参考链接https://blog.csdn.net/harbinzju/article/details/6754646 intrusive_ptr 是shared_ptr的插入式版本.与shared_ ...