zabbix监控

zabbix自定义监控进程

//在客户端安装zabbix-agent
[root@client ~]# tar xf zabbix-3.4.15.tar.gz
[root@client zabbix-3.4.15]# ./configure --enable-agent
[root@client zabbix-3.4.15]# make install
[root@client ~]# useradd zabbix
//进入客户端zabbix配置文件
[root@client ~]# vim /usr/local/etc/zabbix_agentd.conf
//修改以下配置
Server=192.168.129.135(zabbix监控服务器IP地址)
ServerActive=192.168.129.135(zabbix监控服务器IP地址)
Hostname=192.168.129.136(客户端zabbixIP地址)
UnsafeUserParameters=1
//编写监控脚本
#!/bin/bash 


status=$(ps -ef |egrep -v "grep|$0"| grep -w "$1"|wc -l)

if [ $status -eq 0 ];then
    echo "0"
else
    echo "1"
fi
[root@client scripts]# chmod +x check_process.sh 
[root@client scripts]# ll
总用量 4
-rwxr-xr-x. 1 root root 130 12月 25 10:19 check_process.sh

//在客户端zabbix配置文件中加入一下行
UserParameter=check_process[*],/bin/bash /scripts/check_process.sh $1
//重启客户端zabbix
[root@client ~]# pkill zabbix
[root@client ~]# zabbix_agentd 
[root@client ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128               *:80                            *:*                  
LISTEN      0      128               *:22                            *:*                  
LISTEN      0      100       127.0.0.1:25                            *:*                  
LISTEN      0      128               *:10050                         *:*                  
LISTEN      0      128              :::22                           :::*                  
LISTEN      0      100             ::1:25                           :::* 
//在服务端zabbix监控页面中添加客户机
1.  点击configuration
2.  点击hosts
3.  点击右上角Create host
4.  hostname 填入 客户机主机ip  Group 填入 linux server  Agent 填入 客户机主机ip 
5.  在界面中点击ltems
6.  右上角Create ltems
7.  Name上填入监控名称(要见名知意) key上填入check_proess[httpd](填入想要监控的服务名称]
8.  点击add创建完成

zabbix监控主从

//两个客户端服务器安装好mysql
[root@client1 ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128               *:22                            *:*                  
LISTEN      0      100       127.0.0.1:25                            *:*                  
LISTEN      0      128              :::22                           :::*                  
LISTEN      0      100             ::1:25                           :::*                  
LISTEN      0      80               :::3306                         :::* 
[root@client2 ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128               *:22                            *:*                  
LISTEN      0      100       127.0.0.1:25                            *:*                  
LISTEN      0      128              :::22                           :::*                  
LISTEN      0      100             ::1:25                           :::*                  
LISTEN      0      80               :::3306                         :::*  
//配置两个客户端mysql主从 client2为主  client1为从
//主服务器设置一个给从使用的账号
[root@client2 ~]# mysql -uroot -p123456

mysql> CREATE USER 'repl'@'192.168.129.136' IDENTIFIED BY 'repl123';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.129.136';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.07 sec)

//主服务器mysql配置文件加入下方选项
log-bin=mysql-bin
server-id=1
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
//重启
[root@client2 ~]# /etc/init.d/mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL........... SUCCESS! 
//登录数据库查看主库状态
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql=bin.000001 |      154 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.06 sec)
//配置从数据库状态
[root@client1 ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
relay-log=mysql-relay-bin
server-id=2
symbolic-links=0
log-error=/var/log/mysql.log
//配置并开启主从复制
mysql> CHANGE MASTER TO
    -> MASTER_HOST='192.168.129.137',
    -> MASTER_USER='repl',
    -> MASTER_PASSWORD='repl123',
    -> MASTER_LOG_FILE='mysql-bin.000001',
    -> MASTER_LOG_POS=154;
Query OK, 0 rows affected, 2 warnings (0.08 sec)
mysql> start slave;
Query OK, 0 rows affected (0.06 sec)
mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.129.137
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 154
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 320
        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: 154
              Relay_Log_Space: 527
              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: 1
                  Master_UUID: 557ffd3d-26ca-11ea-97ee-000c2928ba61
             Master_Info_File: /opt/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)
//在从服务器上搭建zabbix-agent
//在从服务器上编写监控脚本
[root@client1 srcipts]# cat mysql.repl.sh 
#!/bin/bash

status=$(mysql -uroot -p123456 -e 'show slave status\G' 2>/dev/null |egrep 'Slave_IO_Running|Slave_SQL_Running:'|grep -c 'Yes')

if [ $status -ne 2 ];then
    echo '1'
else
    echo '0'
fi
[root@client1 srcipts]# chmod +x mysql.repl.sh 
//在配置文件添加一下行
UserParameter=check_mr,/bin/bash /scripts/mysql_repl.sh
//重启zabbix-agent 如同自定义中的网页步骤添加即可完成监控主从

日志监控


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值