(高可用)六、Zabbix

zabbix

一、基础

  • 部署教程地址:https://www.zabbix.com/download?zabbix=5.0&os_distribution=centos&os_version=7&components=server_frontend_agent&db=mysql&ws=apache

请添加图片描述

######  配置yum源
[root@localhost ~]# rpm -Uvh centos-release-scl-*
warning: centos-release-scl-2-3.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:centos-release-scl-rh-2-3.el7.cen################################# [ 50%]
   2:centos-release-scl-2-3.el7.centos################################# [100%]
[root@localhost ~]# ll /etc/yum.repos.d/
total 20
-rw-r--r--. 1 root root 998 Dec 11  2018 CentOS-SCLo-scl.repo
-rw-r--r--. 1 root root 971 Oct 29  2018 CentOS-SCLo-scl-rh.repo
-rw-r--r--. 1 root root 358 Jan 13 03:37 redhat.repo
-rw-r--r--. 1 root root  60 Jan 13 03:37 rhel7.repo
-rw-r--r--. 1 root root 853 May 10  2020 zabbix.repo
[root@localhost ~]# yum clean all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Cleaning repos: rhel7 zabbix zabbix-non-supported
Other repos take up 1.6 k of disk space (use --verbose for details)

#####  安装软件包
[root@localhost ~]# yum install zabbix-server-mysql zabbix-agent


##### 再配置yum源,下载地址https://developer.aliyun.com/packageSearch?word=centos-release-scl
[root@localhost ~]# rpm -Uvh centos-release-scl-*
warning: centos-release-scl-2-3.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:centos-release-scl-rh-2-3.el7.cen################################# [ 50%]
   2:centos-release-scl-2-3.el7.centos################################# [100%]
[root@localhost ~]# ll /etc/yum.repos.d/
total 20
-rw-r--r--. 1 root root 998 Dec 11  2018 CentOS-SCLo-scl.repo
-rw-r--r--. 1 root root 971 Oct 29  2018 CentOS-SCLo-scl-rh.repo
-rw-r--r--. 1 root root 358 Jan 13 03:37 redhat.repo
-rw-r--r--. 1 root root  60 Jan 13 03:37 rhel7.repo
-rw-r--r--. 1 root root 853 May 10  2020 zabbix.repo
[root@localhost ~]# vim /etc/yum.repos.d/zabbix.repo

###########  安装软件包
[root@localhost ~]# yum install zabbix-web-mysql-scl zabbix-apache-conf-scl


###########  从rpm包安装mysql5.7,下载地址:https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.33-1.el7.x86_64.rpm-bundle.tar
[root@localhost ~]# yum install -y mysql-community-client-5.7.33-1.el7.x86_64.rpm mysql-community-common-5.7.33-1.el7.x86_64.rpm mysql-c                                                    ommunity-libs-5.7.33-1.el7.x86_64.rpm mysql-community-libs-compat-5.7.33-1.el7.x86_64.rpm mysql-community-server-5.7.33-1.el7.x86_64.rpm

########## 开启MySQL server
[root@localhost ~]# systemctl enable --now mysqld
[root@localhost ~]# grep 'password' /var/log/mysqld.log
2023-01-15T10:07:10.876920Z 1 [Note] A temporary password is generated for root                                                                                                             @localhost: ::t!=ZVM
[root@localhost ~]# mysql_secure_installation

###############  修改管理员密码进入mysql,按照教程建立zabbix数据库及用户
[root@localhost ~]# mysql -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.33 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> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

mysql> create user zabbix@localhost identified by 'xxxxxx';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> set global log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye


#########  导入官方提供的SQL语句
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | my                                                                                                             sql -uzabbix -p zabbix
Enter password:


##########  关闭log_bin_trust_function_creators
[root@localhost ~]# mysql -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.33 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> set global log_bin_trust_function_creators = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

############  按照教程修改配置
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
[root@localhost ~]# vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

############  启动zabbix服务
[root@localhost ~]# systemctl enable --now zabbix-server zabbix-agent httpd 
  • 访问http://192.168.147.142/zabbix/setup.php,进一步配置
######  这里主要检查依赖是否都通过,给DB的管理密码

二、添加zabbix client

  • 默认ZBX,监控普通应用

  • SNMP监控路由设备

  • JMX监控java应用

  • IPMI监控硬件

  • 安装zabbix-agent

# 修改yum源配置
[root@localhost ~]# vim /etc/yum.repos.d/zabbix.repo

:%s/gpgcheck=1/gpgcheck=0

[root@localhost ~]# yum install -y zabbix-agent

# 修改zabbix_agentd.conf
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf

Server=192.168.147.142  # 指定zabbix server的地址

ServerActive=192.168.147.142

Hostname=server3  # 指定本机的hostname


# 启动zabbix-agent服务
[root@localhost ~]# systemctl enable --now zabbix-agent.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.

1. 手动添加

请添加图片描述
请添加图片描述
请添加图片描述

2. 自动搜索添加

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

3. 触发器自动注册

请添加图片描述
请添加图片描述
请添加图片描述

4. 使用zabbix API批量添加

请添加图片描述

# API登录到管理员账号,获取到token
[root@localhost ~]# curl -X POST http://192.168.147.142/zabbix/api_jsonrpc.php -H 'Content-Type: application/json-rpc' -d '
{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": "Admin",
        "password": "zabbix"
    },
    "id": 1,
    "auth": null
}'
{"jsonrpc":"2.0","result":"c9777c1d30be7277ab6cfa5c8445db59","id":1}[root@localhost ~]#


# 获取主机列表
[root@localhost ~]# curl -X POST http://192.168.147.142/zabbix/api_jsonrpc.php -H 'Content-Type: application/json-rpc' -d '
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": [
            "hostid",
            "host"
        ],
        "selectInterfaces": [
            "interfaceid",
            "ip"
        ]
    },
    "id": 2,
    "auth": "c9777c1d30be7277ab6cfa5c8445db59"
}' | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   514    0   223  100   291   3986   5201 --:--:-- --:--:-- --:--:--  5290
{
    "id": 2,
    "jsonrpc": "2.0",
    "result": [
        {
            "host": "Zabbix server",
            "hostid": "10084",
            "interfaces": [
                {
                    "interfaceid": "1",
                    "ip": "127.0.0.1"
                }
            ]
        },
        {
            "host": "server2",
            "hostid": "10437",
            "interfaces": [
                {
                    "interfaceid": "2",
                    "ip": "192.168.147.138"
                }
            ]
        }
    ]
}


# 发现主机
[root@localhost ~]# curl -X POST http://192.168.147.142/zabbix/api_jsonrpc.php -H 'Content-Type: application/json-rpc' -d '
{
    "jsonrpc": "2.0",
    "method": "dhost.get",
    "params": {
        "output": "extend",
        "selectDServices": "extend",
        "druleids": "2"
    },
    "auth": "c9777c1d30be7277ab6cfa5c8445db59",
    "id": 1
}' | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   928    0   703  100   225  16411   5252 --:--:-- --:--:-- --:--:-- 16738
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": [
        {
            "dhostid": "1",
            "druleid": "2",
            "dservices": [
                {
                    "dcheckid": "2",
                    "dhostid": "1",
                    "dns": "server2",
                    "dserviceid": "1",
                    "ip": "192.168.147.138",
                    "lastdown": "0",
                    "lastup": "1673787802",
                    "port": "10050",
                    "status": "0",
                    "value": "Linux server2 3.10.0-957.el7.x86_64 #1 SMP Thu Oct 4 20:48:51 UTC 2018 x                                        86_64"
                }
            ],
            "lastdown": "0",
            "lastup": "1673787802",
            "status": "0"
        },
        {
            "dhostid": "2",
            "druleid": "2",
            "dservices": [
                {
                    "dcheckid": "2",
                    "dhostid": "2",
                    "dns": "server3",
                    "dserviceid": "2",
                    "ip": "192.168.147.143",
                    "lastdown": "0",
                    "lastup": "1673787811",
                    "port": "10050",
                    "status": "0",
                    "value": "Linux server3 3.10.0-957.el7.x86_64 #1 SMP Thu Oct 4 20:48:51 UTC 2018 x                                        86_64"
                }
            ],
            "lastdown": "0",
            "lastup": "1673787811",
            "status": "0"
        }
    ]
}

三、使用zabbix监控nginx和mysql、percona

  • 在server2上安装nginx
[root@server2 nginx-1.22.1]# ./configure --with-http_ssl_module --with-http_stub_status_module  # 需要添加这个参数

# 修改配置文件,添加一个location
location = /basic_status {
    stub_status;
}
  • 在server3上安装mysql
# 确保同时安装mysql和zabbix-agent
# 拷贝template_db_mysql.conf到/etc/zabbix/zabbix_agentd.d/
[root@server1 ~]# find / -name *mysql.conf
/usr/lib/tmpfiles.d/mysql.conf
/usr/share/doc/zabbix-agent-5.0.30/userparameter_mysql.conf
[root@server1 ~]# cp /usr/share/doc/zabbix-agent-5.0.30/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/


# 进入数据库,创建专用于监控的用户
mysql> CREATE USER 'zbx_monitor'@localhost IDENTIFIED BY 'xxxxxxxxxxxxxxxxx';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@localhost;
Query OK, 0 rows affected (0.00 sec)


# 在zabbix agent的主目录新建.my.cnf写入数据库配置
[root@server1 ~]# mkdir /var/lib/zabbix/
[root@server1 ~]# cd /var/lib/zabbix/
[root@server1 ~]# vim .my.cnf

[client]
user=zbx_monitor
password=xxxxxxxxxxx


# 重启zabbix-agent
systemctl restart zabbix-agentd.service

zabbix监控nginx配置

请添加图片描述
请添加图片描述

zabbix监控mysql配置

请添加图片描述
请添加图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
课程目标     全面理解和掌握 Zabbix 监控系统的架构及运行原理,搭建和管理各种规模的Zabbix监控系统 课程简介         Zabbix是一个开源的企业级的监控解决方案。通过Zabbix可以监控IT基础设施的方方面面,包括硬件、操作系统、网络、虚拟化层、中间件和各种业务应用系统。用Zabbix几乎可以监控你想监控的任意数据。              本课程从Zabbix的介绍、安装开始,一步步带你深入Zabbix,通过学习你会:         1、掌握Zabbix各个组件的配置和管理。         2、掌握不同监控项的类型和配置方法,根据监控需求灵活配置监控项。         3、掌握网络发现、低级发现和主动式agent自动注册,实现自动化监控。         4、掌握模版、宏变量、触发器和告警通知的配置和高级的应用方法。         5、掌握图形、屏幕、拓扑图和仪表盘等数据可视化的方法,利用大屏可以实时的展示监控数据。         6、掌握Zabbix系统自身的维护、备份、升级、排障以及性能优化。         7、掌握Zabbix内部运行机制和Zabbix使用技巧,让zabbix更好的帮助你实现监控目标。                  本课程中还包含很多操作演示,比如像创建主机,创建监控项、触发器、图形、全局事件关联等,也介绍了微信和钉钉告警的配置方法。当你对Zabbix深入了解之后,面对层出不穷的新业务、新应用,你都能轻松自如的制定和提供相应的监控解决方案。 特别提示:官网的中文文档有些地方翻译的有问题,一定要以英文文档为准。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值