目录
一、zabbix简介
1.zabbix 是什么
2.zabbix 能干什么
指标收集:从任何设备、系统、应用程序上进行指标采集
- 多平台Zabbix代理
- SNMP和IPMI代理
- 用户服务无代理监控
- 自定义方法
- 计算和聚合
- 终端用户Web监控
问题检测:定义智能阈值
- 高度灵活的自定义选项
- 独立的问题条件和解决条件
- 多个严重等级
- 根故障分析
- 异常检测
- 趋势预测
可视化:单一界面管理平台
- 仪表盘小部件
- 图表组件
- 网络拓扑图
- 幻灯片展示
- Drill-down报表
告警和修复:确保及时、有效的告警
- 发送信息
- 让Zabbix自动修复问题
- 根据用户自定义的服务级别,阶梯式发送告警,灵活可控
- 根据收件人的角色自定义邮件
- 基于运行时间和资产信息自定义消息
安全和认证:保护您所有层级的数据
- 所有Zabbix组件之间强加密
- 多种验证方法:Open LDAP, 活动目录
- 灵活的用户权限架构
- Zabbix代码公开,可用于安全审核
轻松搭建部署:大批模板,开箱即用,节省您宝贵的时间
- 几分钟内即可安装Zabbix
- Zabbix提供适用于大部分平台的模板,开箱即用
- 自定义模板
- 来自Zabbix社区的无数模板
- 申请Zabbix原厂模板创建服务
- 套用配置模板一次性监控数千个类似设备
自动发现: 自动监控大型动态环境
- 网络发现:定期扫描、发现设备类型,IP,状态,运行时间/停机时间等,并采取预定义的操作
- 低级别发现(LLD):自动为设备上不同元素创建监控项,触发器和图形
- 主动agent自动注册 使用Zabbix agent自动开始监控新设备
分布式监控:无限制扩展
- 从数千个被监控的设备中采集数据
- 防火墙,DMZ后监控
- 即使网络异常,也可以持续采集数据
- 在受监控的主机上远程运行自定义脚本
Zabbix API:将Zabbix集成到您IT环境的其他任何部分
- 通过API自动化Zabbix管理
- 提供200+不同的方法
- 创造全新的Zabbix+应用
- 将Zabbix与第三方软件集成:配置管理,工单系统
- 获取、管理配置和历史数据
二、zabbix-server安装
1. 安装软件
open-vm-tools bash-completion lrzsz tree vim wget
2.设置 hosts
[root@zabbix ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.153 zabbix
3.关闭防火墙
[root@zabbix ~]# systemctl stop firewalld
[root@zabbix ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Thu 2021-04-08 22:50:47 EDT; 10s ago
Docs: man:firewalld(1)
Process: 5795 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 5795 (code=exited, status=0/SUCCESS)
Apr 08 16:27:52 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 08 16:27:52 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Apr 08 22:50:46 zabbix systemd[1]: Stopping firewalld - dynamic firewall daemon...
Apr 08 22:50:47 zabbix systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@zabbix ~]# systemctl disable firewalld ### 永久关闭
4.关闭seLinux
[root@zabbix ~]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
5.下载zabbix的软件仓库和 安装 zabbix
[root@zabbix software]# wget https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
[root@zabbix zabbix]# rpm -ivh zabbix-release-4.0-2.el7.noarch.rpm
warning: zabbix-release-4.0-2.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-4.0-2.el7 ################################# [100%]
[root@zabbix yum.repos.d]# yum clean all # =====》 可能 rpm 依赖报错,执行 clean all
[root@zabbix zabbix]# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-get
6.安装MySQL数据库
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> CREATE USER 'zabbix'@'%' IDENTIFIED BY 'winner001';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@'%' identified by 'winner001';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
7.将表导入到 zabbix
[root@zabbix zabbix]# zcat /usr/share/doc/zabbix-server-mysql-4.0.30/create.sql.gz | mysql -uzabbix -pwinner001 -Dzabbix
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zabbix zabbix]# mysql -uzabbix -pwinner001 -Dzabbix
mysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
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> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
8.设置配置文件
vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
9.zabbix.conf 配置文件
两个时区都要设置
vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
[root@zabbix zabbix]# vim /etc/php.ini
date.timezone=Asia/Shanghai
10.启动服务
[root@zabbix zabbix]# systemctl status httpd
[root@zabbix zabbix]# systemctl enable httpd
[root@zabbix zabbix]# systemctl restart zabbix-server
[root@zabbix zabbix]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@zabbix zabbix]# systemctl status zabbix-server
[root@zabbix zabbix]#
11.zabbix 初始化设置
12.Check of pre-requisites
13.MySQL zabbix库连接
如果连接信息不对或者数据库连接不上,会报错
14. 配置 安装信息总览
15.使用默认的账号密码登录
账号:Admin
密码:zabbix
16.设置语言
三、zabbix-agent 安装
1.三台机器
2.下载RPM包并安装
[root@hdp105 ~]# wget https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
--2021-04-10 01:06:30-- https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
Resolving repo.zabbix.com (repo.zabbix.com)... 178.128.6.101, 2604:a880:2:d0::2062:d001
Connecting to repo.zabbix.com (repo.zabbix.com)|178.128.6.101|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13800 (13K) [application/x-redhat-package-manager]
Saving to: ‘zabbix-release-4.0-2.el7.noarch.rpm’
100%[=========================================================================================================>] 13,800 --.-K/s in 0s
2021-04-10 01:06:36 (408 MB/s) - ‘zabbix-release-4.0-2.el7.noarch.rpm’ saved [13800/13800]
[root@hdp105 ~]# rpm -ivh zabbix-release-4.0-2.el7.noarch.rpm
warning: zabbix-release-4.0-2.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-4.0-2.el7 ################################# [100%]
[root@hdp105 ~]# yum -y install zabbix-agent
3.修改配置文件
- Server是指被动监测,服务器主动的向被监控主机查询数据
- ServerActive是主动监测,服务器被动的接收数据,被监控主机主动向服务器提供数据
- Hostname是制定被监控主机的名字,服务器将以这个名字作为唯一标识
[root@hdp105 ~]# vim /etc/zabbix/zabbix_agentd.conf
### Option: Hostname
# Value is acquired from HostnameItem if undefined.
# Hostname=
Server=192.168.2.153
### Option: HostnameItem
# Item used for generating Hostname if it is undefined. Ignored if Hostname is defined.
# HostnameItem=system.hostname
# Aliases can be used in HostMetadataItem but not in HostnameItem parameters.
# Hostname=
Hostname=hdp105
[root@hdp105 ~]#
4.启动服务
[root@hdp105 ~]# systemctl restart zabbix-agent.service
[root@hdp105 ~]# systemctl enable zabbix-agent.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@hdp105 ~]# systemctl status zabbix-agent.service
5.查看10050端口是否开启
6.在zabbix服务器上测试客户端是否正常运行
# hdp104 为 zabbix server
[root@hdp104 ~]# zabbix_get -s 192.168.2.154 -k agent.hostname
hdp105
7.在服务器上添加被监控主机
8.查看被监控主机
9.创建监控项
10.随便启动一个进程
[root@hdp105 ~]# cat helloSleep.sh
echo "haha"
sleep 3h
echo "呵呵呵"
[root@hdp105 ~]# ps -ef | grep helloSleep
root 3029 6618 0 02:41 pts/0 00:00:00 grep --color=auto helloSleep
root 15808 12565 0 01:48 pts/1 00:00:00 sh helloSleep.sh
11.zabbbix-server 查看进程状态是否可以获取
[root@hdp104 ~]# zabbix_get -s 192.168.2.154 -p 10050 -k "proc.num[,,,helloSleep]"
1
[root@hdp104 ~]#
12.web 中查看
下篇有 钉钉告警案例:钉钉告警传送门
欢迎大家点赞和关注!