zabbix配置环境及使用

zabbix安装部署及使用

安装zabbix

1. 准备一台全新虚拟机

     重命名 - -好区分主机

        [root@localhost ~]# hostname zabbix-server
        [root@localhost ~]# su - root
        上一次登录:二 3月 16 16:32:19 CST 2021从 192.168.186.1pts/5 上
        [root@zabbix-server ~]#
2. 安装zabbix-release包

目的:得到/etc/yum.repos.d/里面的zabbix.repo源

根据自己的系统选择zabbix源

[root@zabbix-server ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
  • 安装包下载到本地进行安装

下载安装包
centos7-software-zabbix
centos8-software-zabbix

官网下载
Zabbix官方资料库

下载后需要在windows上解压后传到虚拟机上

进入centos8-software-zabbix/目录,进行安装zabbix-release包

[root@zabbix-server ~]# cd centos8-software-zabbix/
[root@zabbix-server centos8-software-zabbix]# ls
zabbix-agent-4.4.6-1.el8.x86_64.rpm         zabbix-js-4.4.6-1.el8.x86_64.rpm            zabbix-web-4.4.6-1.el8.noarch.rpm
zabbix-apache-conf-4.4.6-1.el8.noarch.rpm   zabbix-nginx-conf-4.4.6-1.el8.noarch.rpm    zabbix-web-japanese-4.4.6-1.el8.noarch.rpm
zabbix-get-4.4.6-1.el8.x86_64.rpm           zabbix-sender-4.4.6-1.el8.x86_64.rpm        zabbix-web-mysql-4.4.6-1.el8.noarch.rpm
zabbix-java-gateway-4.4.6-1.el8.x86_64.rpm  zabbix-server-mysql-4.4.6-1.el8.x86_64.rpm       zabbix-web-mysql-4.4.6-1.el8.noarch.r
[root@zabbix centos8-software-zabbix]# rpm -ivh zabbix-release-4.4-1.el8.noarch.rpm 
警告:zabbix-release-4.4-1.el8.noarch.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:zabbix-release-4.4-1.el8         ################################# [100%]
  • 在线下载方式安装
        [root@zabbix-server lianxi]# rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/8/x86_64/zabbix-release-4.4-1.el8.noarch.rpm
        获取https://repo.zabbix.com/zabbix/4.4/rhel/8/x86_64/zabbix-release-4.4-1.el8.noarch.rpm
        警告:/var/tmp/rpm-tmp.Zoovz8: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
        Verifying...                          ################################# [100%]
        准备中...                          ################################# [100%]
        正在升级/安装...
           1:zabbix-release-4.4-1.el8         ################################# [100%]

检查/etc/yum.repos.d/是否有zabbix.repo源

[root@zabbix-server centos8-software-zabbix]# cd /etc/yum.repos.d/
[root@zabbix-server yum.repos.d]# ls
CentOS-AppStream.repo   CentOS-CR.repo         CentOS-Extras.repo     CentOS-Media.repo       CentOS-Vault.repo
CentOS-Base.repo        CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-PowerTools.repo  zabbix.repo
CentOS-centosplus.repo  CentOS-Devel.repo      CentOS-HA.repo         CentOS-Sources.repo

centos7里需要安装epel-release包,需要用的epel源,在安装zabbix-nginx-conf的时候,需要nginx软件
centos8里不需要安装epel源

3. 安装centos8-software-zabbix文件夹下的所有安装包
[root@zabbix-server ~]# cd centos8-software-zabbix/
[root@zabbix-server centos8-software-zabbix]# yum install zabbix-* -y 

    注意需要在上传rpm包的目录下开始安装zabbix

开启mysql服务,导入初始数据

我使用的是mariadb,其他数据库均可

1. 安装mariadb
安装mariadb库
[root@zabbix centos8-software-zabbix]# yum install mariadb mariadb-server -y

mariadb-server是服务机的数据库
mariadb是客户端的数据库

开启mariadb
  1. 临时启动mariadb

    [root@zabbix-client-1 centos8-software-zabbix]# systemctl start mariadb
    
     [root@zabbix-client-1 centos8-software-zabbix]# service  mariadb   start
     Redirecting to /bin/systemctl start mariadb.service
    
  2. 设置开机自启动mariadb

      [root@zabbix centos8-software-zabbix]# systemctl enable mariadb.service
      Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
      Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
      Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
    
检查mysql服务是否启动
[root@zabbix php-fpm.d]# ps aux|grep mysql
mysql      17470  0.3 12.8 1300264 104472 ?      Ssl  19:19   0:00 /usr/libexec/mysqld --basedir=/usr
root       17537  0.0  0.1  12324  1060 pts/5    S+   19:23   0:00 grep --color=auto mysql
2. 关闭防火墙和selinux

防火墙关闭

  • 临时关闭防火墙
    [root@zabbix php-fpm.d]# service firewalld stop
    Redirecting to /bin/systemctl stop firewalld.service
  • 自启动关闭防火墙
[root@zabbix php-fpm.d]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

检查防火墙是否关闭

[root@zabbix zabbix-server-mysql]# iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
```

selinux关闭

  • 临时关闭selinux

     [root@zabbix php-fpm.d]# getenforce
     Permissive
     [root@zabbix php-fpm.d]# setenforce 0
    

永久禁用selinux

①. 可靠一些

/etc/sysconfig/selinux是/etc/selinux/config的一个软件连接 (soft link) /etc/selinux/config才是原文件.修改etc/sysconfig/selinux导致软链接关系破裂,变为普通文件且不再被系统作为selinux的配置文件

    vim /etc/selinux/config

在这里插入图片描述

②.

vim /etc/sysconfig/selinux

`
在这里插入图片描述

登录数据库,进行设置

登录
[root@zabbix php-fpm.d]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 146
Server version: 10.3.27-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初次登录,默认密码为空密码,回车可以直接进入

查看数据库
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.119 sec)

MariaDB [(none)]>

❗注意 show databases 后面要接;

此命令要在mysql内输入

新建zabbix库
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;

建库zabbix,指定字符集为utf8

新建用户,授予权限

1.两条命令搞定- - -优先用这个

 MariaDB [(none)]>create user 'zabbix'@'localhost' identified by 'zabbix123';

'zabbix’是用户名,'localhost’指定只能本地登录,'zabbix123’登录密码

 MariaDB [(none)]>grant all privileges on zabbix.* to 'zabbix'@'localhost';

授权zabbix库里所有的权限给zabbix用户

2.一条命令搞定

centos7和centos8可能出现不能使用的情况

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123';
Query OK, 0 rows affected (2.466 sec)
导入数据到zabbix库

退出数据库,在linux界面导入

MariaDB [(none)]> quit
Bye

1.解压后导入

    [root@zabbix php-fpm.d]# cd /usr/share/doc/zabbix-server-mysql/
    [root@zabbix zabbix-server-mysql]# ls
    [root@zabbix-server-1 zabbix-server-mysql]# gunzip create.sql.gz
    [root@zabbix zabbix-server-mysql]# ls
    AUTHORS  ChangeLog  COPYING  create.sql  NEWS  README

导入方式

在create.sql所在目录下导入

root@zabbix-server-1 zabbix-server-mysql]# mysql -uzabbix -p'zabbix123' zabbix  < create.sql

[root@zabbix zabbix-server-mysql]# cat create.sql |mysql -uzabbix -p zabbix
登录数据库,看是否导入成功
[root@zabbix-server zabbix-server-mysql]# cat create.sql |mysql -uzabbix -p'zabbix123' zabbix
[root@zabbix-server zabbix-server-mysql]# mysql -uzabbix -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.3.27-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 databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| zabbix             |
+--------------------+
2 rows in set (0.001 sec)
MariaDB [(none)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| config_autoreg_tls         |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dashboard                  |
| dashboard_user             |
| dashboard_usrgrp           |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_suppress             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| host_tag                   |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| hstgrp                     |
| httpstep                   |
| httpstep_field             |
| httpstepitem               |
| httptest                   |
| httptest_field             |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| item_preproc               |
| item_rtdata                |
| items                      |
| items_applications         |
| lld_macro_path             |
| maintenance_tag            |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| media_type_param           |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_trigger     |
| sysmap_element_url         |
| sysmap_shape               |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| tag_filter                 |
| task                       |
| task_acknowledge           |
| task_check_now             |
| task_close_problem         |
| task_remote_command        |
| task_remote_command_result |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
| widget                     |
| widget_field               |
+----------------------------+
149 rows in set (0.001 sec)

2.未解压的状态导入

[root@zabbix ~]# zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz |mysql -uzabbix -pzabbix123 zabbix
  • 启动zabbix server进程

    • 编辑数据库配置

      [root@zabbix zabbix-server-mysql]# vim /etc/zabbix/zabbix_server.conf
      

      1.删除注释

      2.填写用户名

      在这里插入图片描述

      4.填写密码

      在这里插入图片描述

    • 启动zabbix server进程

      [root@zabbix zabbix-server-mysql]# service zabbix-server start
      Redirecting to /bin/systemctl start zabbix-server.service
      
    • 查看zabbix服务是否启用

      此为启动了

      [root@zabbix zabbix-server-mysql]# ps aux|grep zabbix
      zabbix     17150  0.0  0.7 195960  5852 ?        S    17:30   0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
      zabbix     17152  0.0  0.2  76532  1912 ?        S    17:30   0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
      zabbix     17153  0.0  0.2  76532  1836 ?        S    17:30   0:02 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
      zabbix     17154  0.0  0.5  76664  4100 ?        S    17:30   0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
      zabbix     17155  0.0  0.5  76664  4100 ?        S    17:30   0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
      zabbix     17156  0.0  0.5  76664  4100 ?        S    17:30   0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
      zabbix     17157  0.0  0.5  76664  4100 ?        S    17:30   0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
      apache     17163  0.0  1.6 262716 13008 ?        S    17:30   0:00 php-fpm: pool zabbix
      apache     17164  0.0  1.6 262716 13008 ?        S    17:30   0:00 php-fpm: pool zabbix
      apache     17165  0.0  1.6 262716 13008 ?        S    17:30   0:00 php-fpm: pool zabbix
      apache     17166  0.0  1.6 262716 13008 ?        S    17:30   0:00 php-fpm: pool zabbix
      apache     17167  0.0  1.6 262716 13008 ?        S    17:30   0:00 php-fpm: pool zabbix
      root       18185  0.0  0.1  12324  1072 pts/5    S+   20:17   0:00 grep --color=auto zabbix
      
    • 查看zabbix占用哪个端口

      [root@zabbix zabbix-server-mysql]# netstat -anplut
      Active Internet connections (servers and established)
      Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
      tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      919/sshd            
      tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      17152/zabbix_agentd 
      tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      14317/nginx: master 
      tcp        0     36 192.168.186.128:22      192.168.186.1:63878     ESTABLISHED 14688/sshd: root [p 
      tcp        0      0 192.168.186.128:22      192.168.186.1:64300     ESTABLISHED 14768/sshd: root [p 
      tcp6       0      0 :::22                   :::*                    LISTEN      919/sshd            
      tcp6       0      0 :::10050                :::*                    LISTEN      17152/zabbix_agentd 
      tcp6       0      0 :::3306                 :::*                    LISTEN      17470/mysqld        
      tcp6       0      0 :::80                   :::*                    LISTEN      14317/nginx: master 
      udp        0      0 192.168.186.128:68      192.168.186.254:67      ESTABLISHED 908/NetworkManager
      

    占用的10050端口

    • 查看端口占用情况
    [root@zabbix php-fpm.d]# lsof -i:10050
    COMMAND     PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    zabbix_ag 17152 zabbix    4u  IPv4 138612      0t0  TCP *:zabbix-agent (LISTEN)
    zabbix_ag 17152 zabbix    5u  IPv6 138613      0t0  TCP *:zabbix-agent (LISTEN)
    zabbix_ag 17153 zabbix    4u  IPv4 138612      0t0  TCP *:zabbix-agent (LISTEN)
    zabbix_ag 17153 zabbix    5u  IPv6 138613      0t0  TCP *:zabbix-agent (LISTEN)
    zabbix_ag 17154 zabbix    4u  IPv4 138612      0t0  TCP *:zabbix-agent (LISTEN)
    zabbix_ag 17154 zabbix    5u  IPv6 138613      0t0  TCP *:zabbix-agent (LISTEN)
    zabbix_ag 17155 zabbix    4u  IPv4 138612      0t0  TCP *:zabbix-agent (LISTEN)
    zabbix_ag 17155 zabbix    5u  IPv6 138613      0t0  TCP *:zabbix-agent (LISTEN)
    zabbix_ag 17156 zabbix    4u  IPv4 138612      0t0  TCP *:zabbix-agent (LISTEN)
    zabbix_ag 17156 zabbix    5u  IPv6 138613      0t0  TCP *:zabbix-agent (LISTEN)
    zabbix_ag 17157 zabbix    4u  IPv4 138612      0t0  TCP *:zabbix-agent (LISTEN)
    zabbix_ag 17157 zabbix    5u  IPv6 138613      0t0  TCP *:zabbix-agent (LISTEN)
    
    • 系统自启动

      [root@zabbix zabbix-server-mysql]# systemctl enable zabbix-server
      Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /usr/lib/systemd/system/zabbix-server.service.
      

zabbix前端配置

  • 修改前端位置
[root@zabbix zabbix-server-mysql]# vim /etc/php-fpm.d/zabbix.conf

在这里插入图片描述

在centos7里还需要修改/etc/php.ini文件,让时区生效

[root@sc-zabbix etc]# vim /etc/php.ini

date.timezone = Asia/Shanghai --》878行,修改**
启动服务

  • 临时开启

    [root@zabbix-server php-fpm.d]# systemctl restart zabbix-server zabbix-agent httpd php-fpm
    
    • 设置开机自启

      [root@zabbix zabbix]#  systemctl enable zabbix-server zabbix-agent httpd php-fpm  mariadb
      Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent.service → /usr/lib/systemd/system/zabbix-agent.service.
      Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
      Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
      

登录web界面

浏览器输入 ip地址/zabbix

如192.168.186.128/zabbix

在这里插入图片描述

在这里插入图片描述

此密码为前面mariadb设置的密码
https://gitee.com/wupei_w/photo/raw/master/wupei_w/photo/20210419105553.png默认登录用户名为Admin 默认登录密码为zabbix
https://gitee.com/wupei_w/photo/raw/master/wupei_w/photo/20210419110301.png
可以登录到zabbix数据库进行查看

MariaDB [(none)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [zabbix]> select userid,alias,name,passwd from users;
+--------+-------+--------+----------------------------------+
| userid | alias | name   | passwd                           |
+--------+-------+--------+----------------------------------+
|      1 | Admin | Zabbix | 5fce1b3e34b520afeffb37ce08c7cd66 |
|      2 | guest |        | d41d8cd98f00b204e9800998ecf8427e |
+--------+-------+--------+----------------------------------+
2 rows in set (0.000 sec)

配置被监控主机

在这里插入图片描述

nginx
安装nginx
  • centos7
[root@localhost ~]# yum install epel-release -y
[root@localhost ~]# yum install nignx -y
  • centos8
[root@localhost ~]# yum install nignx -y
开启nginx
[root@localhost ~]# service nginx start
查看nginx是否启动

lsof -i:80

[root@localhost ~]# lsof -i:80
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   17859  root    6u  IPv4  93406      0t0  TCP *:http (LISTEN)
nginx   17859  root    7u  IPv6  93407      0t0  TCP *:http (LISTEN)
nginx   17860 nginx    6u  IPv4  93406      0t0  TCP *:http (LISTEN)
nginx   17860 nginx    7u  IPv6  93407      0t0  TCP *:http (LISTEN)

关闭防火墙和selinux

防火墙
  • 临时
[root@localhost ~]# service firewalld stop
  • 开机自动关闭
[root@localhost ~]# systemctl disable firewalld
  • 检查防火墙是否被关闭 - - - 使用iptables

    [root@localhost ~]# iptables -L
    Chain INPUT (policy ACCEPT)
    target     prot opt source               destination         
    
    Chain FORWARD (policy ACCEPT)
    target     prot opt source               destination         
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination
    
selinux

临时

[root@zabbix php-fpm.d]# getenforce
Enforcing
[root@zabbix php-fpm.d]# setenforce 0

永久-修改配置文件

vim /etc/selinux/config

查看nignx开启情况

https://gitee.com/wupei_w/photo/raw/master/wupei_w/photo/20210419130255.png

在被监控主机上安装agent

  • 安装

获得安装包

从一台虚拟机传到另一台虚拟机

    [root@localhost centos8-software-zabbix]# scp zabbix-agent-4.4.6-1.el8.x86_64.rpm 192.168.186.132:/root
    The authenticity of host '192.168.186.132 (192.168.186.132)' can't be established.
    ECDSA key fingerprint is SHA256:53gnkAOwz/kyqc2FC2B9qVsqs/1nY6xlh6whkkiQ9/A.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added '192.168.186.132' (ECDSA) to the list of known hosts.
    root@192.168.186.132's password: 
    zabbix-agent-4.4.6-1.el8.x86_64.rpm                                                       100%  440KB  12.1MB/s   00:00                                                                  100%  440KB  19.3MB/s   00:00

192.168.186.129为被监控主机ip地址

  • 安装

      [root@localhost ~]# yum install zabbix-agent-4.4.6-1.el8.x86_64.rpm -y
    
  • 修改配置文件

    [root@localhost ~]# cd /etc/zabbix
    [root@localhost zabbix]# ls
    zabbix_agentd.conf  zabbix_agentd.d
    [root@localhost zabbix]# vim zabbix_agentd.conf
    

Server=(server主机的ip地址)
ServerActive=(server主机的ip地址)

在这里插入图片描述


在这里插入图片描述

  • 启动zabbix-agent服务
[root@localhost zabbix]# service zabbix-agent start
  • 刷新服务 service zabbix-agent restart
service zabbix-agent restart

检查是否已监控 - - -在zabbix-server主机上操作

安装zabbix_get

[root@zabbix-client-nginx ~]# yum install zabbix-get -y 

使用zabbix_get

    [root@zabbix centos8-software-zabbix]# zabbix_get -s 192.168.186.129 -p 10050 -k "system.cpu.load[all,avg1]"
    zabbix_get [22428]: Check access restrictions in Zabbix agent configuration

zabbix_get 是一个server端获取客户端数据的工具
-s 192.168.111.131 指定客户端的ip地址
-p 10050 zabbix-agentd程序默认开发的端口号
-k “system.cpu.load[all,avg1]” 指定获取的值–》key–》系统里的cpu的平均负载

  • 配置和警告

    • 添加监控主机

    在这里插入图片描述

    在这里插入图片描述

    • 添加模板

      在这里插入图片描述

    在这里插入图片描述

    • 图形
      • 模板自动生成图形
      • 手动创建图形

自定义监控项

原因:

zabbix自带的模板不能满足需求

监控nginx

nginx

1.安装nginx服务

2.启动nginx服务

3.修改nginx的参数配置 - - - 开启nginx本身的统计功能

   cd /etc/nginx
        vim nginx.conf
   #添加
   location /nginx_status {
        stub_status on;
           }

4.刷新nginx服务

service nginx restart

5.web访问zabbixserver的ip地址,查看效果

http://host/nginx_status
在这里插入图片描述
连接数:建立三次握手的次数

请求数:请求访问的次数

  • Active connections Nginx正处理的活动链接数个数;重要 acceptsNginx启动到现在共接受了多少个连接。
  • handled Nginx启动到现在共处理了多少个连接。
    requests Nginx总共处理了请求次数。
    Reading Nginx读取到客户端的
    Header 信息数。 读取客户端的
    request Writing Nginx返回给客户端的
    Header
    信息数。 返回给客户端的response Waiting
    Nginx已经处理完正在等候下一次请求指令的驻留链接,开启。
    Keep-alive的情况下,Waiting这个值等于active-(reading + writing)。

zabbix-agent的nginx进行操作

流程

在这里插入图片描述

新建nginx参数配置文件 - - - 在zabbix-agent主机上

 cd /etc/zabbix/zabbix-agentd.d
 vim userparameter_nginx.conf
 UserParameter=nginx.status[*],/etc/zabbix/zabbix_agentd.d/nginx.sh $1

创建监控nginx的脚本 - - - zabbix-agent上操作

在 /etc/zabbix/zabbix_agentd.d此目录下
        # 被监控主机ip地址
        HOST="192.168.186.132"
        # 被监听服务的端口号
        PORT="80"

            case $1 in
                active)
                   /usr/bin/curl --insecure "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
                    ;;
                reading)
                    /usr/bin/curl --insecure "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
                    ;;
                writing)
                    /usr/bin/curl --insecure "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
                    ;;
                waiting)
                     /usr/bin/curl --insecure "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
                    ;;
                accepts)
                    /usr/bin/curl --insecure "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk 'NR==3{print $1}'
                    ;;
                ping)
                     /sbin/pidof nginx | wc -w
                    ;;
                handled)
                    /usr/bin/curl --insecure "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk 'NR==3{print $2}'
                    ;;
                requests)
                     /usr/bin/curl --insecure "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk 'NR==3{print $3}'
                    ;;
        esac

授权可执行权限

[root@localhost zabbix_agentd.d]# chmod +x nginx.sh

刷新zabbix-agent服务

service zabbix-agent restart

在zabbix-server获得数据

zabbix_get
zabbix_get -s 192.168.186.132  -p 10050 -k nginx.status[avtive]
[root@localhost ~]# zabbix_get -s 192.168.186.132 -k nginx.status[active]

在这里插入图片描述

  • 监控ssh服务

    zabbix-agent主机

    • 配置agent的配置文件
    [root@localhost zabbix_agentd.d]# cat userparameter_ssh.conf 
    UserParameter=ssh.status[*],/etc/zabbix/zabbix_agentd.d/ssh.sh $1
    

zabbix-server主机

  • 获取数据

    [root@localhost ~]# zabbix_get -s 192.168.186.132 -k ssh.status[ping]
    2
    
  • 添加模块

    • 创建应用集

      在这里插入图片描述

      在这里插入图片描述

      在这里插入图片描述

    • 添加模板

      在这里插入图片描述

      在这里插入图片描述

      在这里插入图片描述

    • 图形

      在这里插入图片描述

      在这里插入图片描述

      在这里插入图片描述

      在这里插入图片描述

      效果图

      在这里插入图片描述

    • 聚合图形

      在这里插入图片描述

      在这里插入图片描述

      在这里插入图片描述

      在这里插入图片描述

      在这里插入图片描述

      效果如下图

      在这里插入图片描述

  • 触发器

    44

    在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

排错

端口冲突

  • zabbix_get获取错误

      [root@zabbix-client-nginx ~]# zabbix_get -s 192.168.186.129 -p 10050 -k "system.cpu.load[all,avg1]"
      zabbix_get [25506]: Check access restrictions in Zabbix agent configuration
    
    1. agent主机上的防火墙没有关闭
    2. agent、机器没有给server机器获取数据权限

    ②zabbi-server获取时出错

          [root@localhost ~]# zabbix_get -s 192.168.186.132 -k ssh.status[ping]
          (Not all processes could be identified, non-owned process info
           will not be shown, you would have to be root to see it all.)
          0
    

    因为调用的用户为普通用户

    解决办法 - - -授予管理员权限

       [root@localhost zabbix_agentd.d]# chmod +s /usr/bin/netstat
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值