3、zabbix配置入门

Zabbix模板

zabbix组件:
    zabbix-server
    zabbix-database
    zabbix-web
    zabbix-agent
    zabbix-proxy
zabbix逻辑组件:
    主机组、主机
    item(监控项)、appliction(应用)
    graph(图形)
    trigger(触发器)
        event(事件)
    action
        notice
        command
     media
     users(meida)
监控系统四种功能:
    数据采集、数据存储、报警、数据可视化
zabbix安装过程:
    server端:database(创建zabbix数据库和zbxuser用户) --> zabbix-server (zabbix_server.conf、把数据导入到database) -->  zabbix-web(LAMP平台、启动httpd服务器)

    --> http://zabbix-web-server/zabbix(在浏览器中实现zabbix配置)
    agent端:zabbix-agent (zabbix-agent)

如何不依赖templates手动创建items来实现监控项?

   

  

获取item的key列表:

1、在zabbix官方文档获取

    https://www.zabbix.com/documentation/4.0/manual/config/items/itemtypes/zabbix_agent

2、查询MySQL数据库

# mysql

> use zabbix;

MariaDB [zabbix]> select * from itemsG;   

*************************** 766. row ***************************
itemid: 25430
type: 0
snmp_community:
snmp_oid:
hostid: 10106
name: Used disk space on $1    //key名称
key_: vfs.fs.size[/boot,used]  //key

......

MariaDB [zabbix]> select key_,type from items;  //查找key_名称和key的类型

+---------------------------------------------------------------------------------+------+
| key_                                                                            | type |
+---------------------------------------------------------------------------------+------+
| proc.num[]    //key名称                                                          |    0 |   //key类型,比如0是编号,这个编号对应的有名称,是在另一个表上存储的
| system.cpu.load[percpu,avg1]                                                    |    0 |   //type为0的一般是由zabbix-agent提供的
| zabbix[wcache,history,pfree]                                                    |    5 |
| zabbix[wcache,trend,pfree]                                                      |    5 |
| zabbix[wcache,values]                                                           |    5 |
| hrStorageSizeInBytes[{#SNMPVALUE}]                                              |   15 |
| hrStorageUsedInBytes[{#SNMPVALUE}]                                              |   15 |
| hrStorageSizeInBytes[{#SNMPVALUE}]                                              |   15 |
| hrStorageUsedInBytes[{#SNMPVALUE}]                                              |   15 |
| hrStorageUsed[{#SNMPVALUE}]                                                     |    4 |
| sysContact                                                                      |    4 |
| hrProcessorLoad[{#SNMPINDEX}]                                                   |    4 |
| bb_1.8v_sm                                                                      |   12 |
| bb_3.3v                                                                         |   12 |
| bb_3.3v_stby                                                                    |   12 |

# zabbix_get -h  //以手动的方式用命令向指定的zabbix agent主机获取某一指定key的值

usage:
  zabbix_get -s host-name-or-IP [-p port-number] [-I IP-address] -k item-key
  zabbix_get -s host-name-or-IP [-p port-number] [-I IP-address]
                --tls-connect cert --tls-ca-file CA-file
                [--tls-crl-file CRL-file] [--tls-agent-cert-issuer cert-issuer]
                [--tls-agent-cert-subject cert-subject]
                --tls-cert-file cert-file --tls-key-file key-file -k item-key
  zabbix_get -s host-name-or-IP [-p port-number] [-I IP-address]
                --tls-connect psk --tls-psk-identity PSK-identity
                --tls-psk-file PSK-file -k item-key
  zabbix_get -h
  zabbix_get -V

Example(s):
  zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg1]"

  zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg1]" 
    --tls-connect cert --tls-ca-file /home/zabbix/zabbix_ca_file 
    --tls-agent-cert-issuer 
    "CN=Signing CA,OU=IT operations,O=Example Corp,DC=example,DC=com" 
    --tls-agent-cert-subject 
    "CN=server1,OU=IT operations,O=Example Corp,DC=example,DC=com" 
    --tls-cert-file /home/zabbix/zabbix_get.crt 
    --tls-key-file /home/zabbix/zabbix_get.key

  zabbix_get -s 127.0.0.1 -p 10050 -k "system.cpu.load[all,avg1]" 
    --tls-connect psk --tls-psk-identity "PSK ID Zabbix agentd" 
    --tls-psk-file /home/zabbix/zabbix_agentd.psk

Report bugs to: <https://support.zabbix.com>
Zabbix home page: <http://www.zabbix.com>
Documentation: <https://www.zabbix.com/documentation>

[root@node1 ~]# zabbix_get -s 192.168.128.132 -k "system.uname"   //从server端获取指定IP的agent端的主机名,只要指定IP的主机上安装了                                                                          //zabbix-agent程序包,type为0大多数key都是支持调用的
      Linux node2 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64      //-p指定端口,如果是默认的可以省略

[root@node1 ~]# zabbix_get -s 192.168.128.132 -k "net.if.in[ens33]"    //[]表示传递参数,表示网卡的流出量
     18237565
[root@node1 ~]# zabbix_get -s 192.168.128.132 -k "net.if.out[ens33]"    //表示网卡的流进量
     8821605

在监控定义时每一个key所定义的内容就是一个item,表示这个item是用来监控什么内容的。

创建key的流程:Configuration --> Host --> 对应的host上选择item --> create item  --> 提供参数

从数据库中获取item的name

MariaDB [zabbix]> select key_,type from items where key_ like 'system.cpu%';   //可以获取关于cpu的item名称

MariaDB [zabbix]> show tables;   //定义好items后,可以在mysql中查看表history

MariaDB [zabbix]> select * from history;

创建Trigger

  

  

{wwww.magedu.com:system.cpu.load[all,avg1].last(0)}>3   

//wwww.magedu.com  表主机

//system.cpu.load  表key,key是可以接受参数的,all,avg1表示key的参数

  

   

Trigger名称中可以使用宏:{HOST.HOST},{HOST.NAME},{HOST.CONN},{HOST.DNS}

现在利用hping3工具发包,使cpu中断数增加  

# wget http://www.hping.org/hping3-20051105.tar.gz

或者

# wget https://github.com/antirez/hping/archive/master.zip

# unzip master.zip

# yum install -y gcc libpcap libpcap-devel tcl tcl-devel     参考  https://www.topjishu.com/11392.html

# ln -sf /usr/include/pcap-bpf.h /usr/include/net/bpf.h

# unzip hping-master.zip

cd hping-master/

./configure

make

make install

# hping -h 可以查看使用方法

# hping3 192.168.128.132 --faster

下面定义报警方式action   https://blog.csdn.net/hao134838/article/details/57568332

   

报警信息是发给zabbix用户的,这个用户要事先定义的

  

当zabbix执行报警时,会报警给zbxuser,zbxuser所关联的账号是root@localhost,所以root用户也会收到信息。

下面配置报警功能:

action有两类:

send message

command

  

  

# hping3 192.168.128.132 --faster    //提高中断数

原文地址:https://www.cnblogs.com/hanshanxiaoheshang/p/10304672.html