当前位置: 移动技术网 > IT编程>数据库>Redis > Zabbix监控

Zabbix监控

2020年07月23日  | 移动技术网IT编程  | 我要评论

1.zabbix监控日志文件配置

[root@localhost ~]# mkdir /scripts/
[root@localhost ~]# mv log.py /scripts/
mv: 无法获取"log.py" 的文件状态(stat): 没有那个文件或目录
[root@localhost ~]# cd pyscripts-master/
[root@localhost pyscripts-master]# mv log.py /scripts/
[root@localhost pyscripts-master]# ls
[root@localhost pyscripts-master]# cd
[root@localhost ~]# ls
anaconda-ks.cfg   pyscripts-master.zip  zabbix-5.0.2.tar.gz
pyscripts-master  zabbix-5.0.2
[root@localhost ~]# cd /scripts/
[root@localhost scripts]# ls
log.py
[root@localhost scripts]# pwd
/scripts
[root@localhost scripts]# vim /usr/local/etc/zabbix_agentd.conf
[root@localhost scripts]# tail /usr/local/etc/zabbix_agentd.conf
#       Override the default ciphersuite selection criteria for certificate- and PSK-based encryption.
#       Example for GnuTLS:
#               NONE:+VERS-TLS1.2:+ECDHE-RSA:+RSA:+ECDHE-PSK:+PSK:+AES-128-GCM:+AES-128-CBC:+AEAD:+SHA256:+SHA1:+CURVE-ALL:+COMP-NULL:+SIGN-ALL:+CTYPE-X.509
#       Example for OpenSSL:
#               EECDH+aRSA+AES128:RSA+aRSA+AES128:kECDHEPSK+AES128:kPSK+AES128
#
# Mandatory: no
# Default:
# TLSCipherAll=
UserParameter=zzl[*],/usr/bin/python /scripts/log.py
[root@localhost scripts]# 

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

2.mysql主从监控

2.1配置主库
[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-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)]> CREATE USER 'repl'@'192.168.20.100' IDENTIFIED BY 'zzl123';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>  GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.20.100';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> 

//编辑配置文件
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
log-bin=mysql_bin        //添加这2行
server-id=10

[root@localhost ~]# systemctl restart mariadb

[root@localhost ~]# mysql -uroot -pzzl123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.65-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)]> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql_bin.000001 |      245 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> 
2.2配置从库
[root@localhost ~]# yum -y install mariadb*

[root@localhost ~]# vim /etc/my.cnf

[mtysqld]
server-id=20                      //添加这2行
relay-log=mysql_relay_bin

[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.65-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)]> change master to
    -> master_host='192.168.20.120',
    -> master_user='repl',
    -> master_password='zzl123',
    -> master_log_file='mysql_bin.000001',
    -> master_log_pos=245;
Query OK, 0 rows affected (0.10 sec)

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show slave status \G*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.20.120
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql_bin.000001
          Read_Master_Log_Pos: 245
               Relay_Log_File: mysql_relay_bin.000002
                Relay_Log_Pos: 529
        Relay_Master_Log_File: mysql_bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 245
              Relay_Log_Space: 823
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 10
1 row in set (0.00 sec)

MariaDB [(none)]> 

[root@localhost scripts]# vim mysql.sh    //编写脚本

#!/bin/bash

mysql=$(mysql -e 'show slave status \G'| grep Slave.*Running: | grep -co 'Yes')

if [ $mysql -eq 2 ];then
    echo '0'
else
    echo '1'
fi

[root@localhost scripts]# chmod +x mysql.sh 
[root@localhost scripts]# vim /usr/local/etc/zabbix_agentd.conf
UserParameter=lzlz[*],/bin/bash /scripts/mysql.sh

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3.监控数据库主从延迟

[root@localhost scripts]# vim mysql_delayed.sh 
[root@localhost scripts]# bash mysql_delayed.sh 
0
[root@localhost scripts]# cat mysql_delayed.sh 
#!/bin/bash

delay_value=$(mysql -e 'show slave status\G' 2>/dev/null|grep 'Seconds_Behind_Master' | awk -F'[: ]+' '{print $3}')

if [ $delay_value -eq 0 ];then
    echo '0'
else 
    echo '1'
fi

[root@localhost scripts]# vim /usr/local/etc/zabbix_agentd.conf  

UserParameter=mysql_delayed,/bin/bash /scripts/mysql_delayed.sh   //添加这一行

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

4.监控时可以加声音

在这里插入图片描述

本文地址:https://blog.csdn.net/qq_44784155/article/details/107470366

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网