zabbix介绍
- zabbix是由Alexei Vladishev 开发的一种网络监视、管理系统,基于Server-Client架构。可用于监视各种网络服务、服务器和网络机器等状态。
- 使用各种Database-end 如 MysqL,Postgresql,sqlite,Oracle 或IBMDB2储存资料。Server端基于C语言、Web管理端frontend则是基于PHP所制作的。
- zabbix可以使用多种方式监视。可以只使用Simple Check不需要安装
Client端,亦可基于SMTP或HTTP… 各种协议定制监视。 - 在客户端如UNIX,Windows 中安装zabbix Agent之后,可监视cpuLoad、网络使用状况、硬盘容量等各种状态。而就算没有安装Agent 在监视对象中,zabbix 也可以经由SNMP、TCP、ICMP、利用IPMI、SSH、telnet 对目标进行监视。
- zabbbix自带的Item足够满足普通小公司的监控需求,对于大公司也可以设定自定义的Item,自动生成报表,也有API可以和其他系统集成。
- zabbix由2部分构成,zabbix server与可选组件zabbix agent。
zabbix特点
zabbix的主要特点:
安装与配置简单,学习成本低
支持多语言(包括中文)
免费开源
自动发现服务器与网络设备
分布式监视以及WEB集中管理功能
可以无agent监视
用户安全认证和柔软的授权方式
通过WEB界面设置或查看监视结果
email等通知功能
zabbix主要功能:
cpu负荷
内存使用
磁盘使用
网络状况
端口监视
日志监视
为何是zabbix不是其他监控
zabbix就是可以满足理想化的监控系统需求
支持自定义监控脚本,提供需要输出的值即可
zabbix存储的数据库表结构稍有复杂但是逻辑清晰
zabbix存在模板的概念,可以方便的将一组监控项进行部署
zabbix每一个item也就是监控项,都可以看到历史记录,且web界面友好
zabbix有强大的Trigger(触发器)定义规则,可以定义复杂的报警逻辑
zabbix提供了ack报警确认机制
zabbix支持邮件,短信,微信等告警
zabbix在触发告警后,可以远程执行系统命令
zabbix有原生的PHP绘图模块
部署zabbix时为什么服务端也要安装部署zabbix
因为服务端在监控其他主机的时候,如果自己出了啥子问题是无法进行自我反应的,所以在监控其他主机的时候,也要进行自我监控,及时反应问题。
zabbix程序组件
zabbix_server,服务端守护进程
zabbix_agentd,agent守护进程
zabbix_proxy,代理服务器
zabbix_database,存储系统,MysqL,pgsql
zabbix_web,web GUI图形化界面
zabbix_ get,命令行工具,测试向agent发起数据采集请求
zabbix_sender,命令行工具,测试向server发送数据
zabbix_ java_ gateway,java网关
zabbix配置文件
zabbix配置文件有两种:
服务器端配置文件(/usr/local/etc/zabbix_server.conf)
客户端配置文件(/usr/local/etc/zabbix_agentd.conf)
zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)
部署zabbix
因为zabbix是用PHP语言开发的,所以必须先部署lamp架构,使其能够支持运行PHP网页
需要提前搭建好lamp架构,可以查看 下面的搭建方法
[lamp架构的搭建](部署LAMP - 姜翎 - 博客园 (cnblogs.com))
mysql官网
此处需要使用的MysqL8mysql源码包
php官网
此处需要使用的php源码包
zabbix官网
zabbix源码包
zabbix服务端安装
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.2.tar.gz
//下载源码包
--2022-09-01 22:12:50-- https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.2.tar.gz
Resolving cdn.zabbix.com (cdn.zabbix.com)... 172.67.69.4, 104.26.6.148, 104.26.7.148, ...
...
[root@localhost src]# ls
debug kernels zabbix-6.2.2.tar.gz
[root@localhost src]# tar xf zabbix-6.2.2.tar.gz //解压
[root@localhost src]# cd zabbix-6.2.2/
[root@localhost zabbix-6.2.2]# dnf -y install net-snmp-devel libevent-devel //安装依赖包
....
tpm2-tss-2.3.2-4.el8.x86_64
unzip-6.0-45.el8_4.x86_64
zip-3.0-23.el8.x86_64
Complete!
[root@localhost zabbix-6.2.2]# useradd -r -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
//创建zabbix系统用户
[root@localhost zabbix-6.2.2]# mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix
//创建zabbix用户的家目录
[root@localhost zabbix-6.2.2]# chown -R zabbix.zabbix /usr/lib/zabbix/
//使其属主属组都是zabbix
[root@localhost zabbix-6.2.2]# MysqL -uroot -p'lnh123' //登录数据库,配置数据库
MysqL: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 13
Server version: 8.0.28 MysqL Community Server - GPL
copyright (c) 2000, 2022, 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 utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.02 sec)
MysqL> create user 'zabbix'@'localhost' identified by 'zabbix123!';
Query OK, 0 rows affected (0.03 sec)
MysqL> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected, 1 warning (0.01 sec)
MysqL> SET GLOBAL log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.00 sec)
MysqL> quit
Bye
[root@localhost zabbix-6.2.2]# cd /usr/src/zabbix-6.2.2/database/MysqL/
[root@localhost MysqL]# ls
Makefile.am Makefile.in data.sql double.sql history_pk_prepare.sql images.sql schema.sql
//将此处数据进行导入
[root@localhost MysqL]# MysqL -uroot -p'lnh123' zabbix < schema.sql
MysqL: [Warning] Using a password on the command line interface can be insecure.
[root@localhost MysqL]# MysqL -uroot -p'lnh123' zabbix < images.sql
MysqL: [Warning] Using a password on the command line interface can be insecure.
[root@localhost MysqL]# MysqL -uroot -p'lnh123' zabbix < data.sql
MysqL: [Warning] Using a password on the command line interface can be insecure.
[root@localhost MysqL]# MysqL -uroot -p'lnh123'
MysqL: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 18
Server version: 8.0.28 MysqL Community Server - GPL
copyright (c) 2000, 2022, 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> show tables from zabbix;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| ackNowledges |
| actions |
....
| widget_field |
+----------------------------+
176 rows in set (0.03 sec)
//查看zabbix数据库下有哪些表,没有问题的话是176张表
[root@localhost MysqL]# cd /usr/src/zabbix-6.2.2/
[root@localhost zabbix-6.2.2]# ./configure --enable-server --enable-agent --with-MysqL --with-net-snmp --with-libcurl --with-libxml2
//编译zabbix
...
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
[root@localhost zabbix-6.2.2]# make install
zabbix服务端配置
[root@localhost zabbix-6.2.2]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
[root@localhost etc]# vim zabbix_server.conf.d/
# DBPassword= //在这行下面添加前面设置的MysqL里面用户密码
DBPassword=zabbix123! //添加
zabbix配置web界面
[root@localhost etc]# cd
[root@localhost ~]# cd /usr/src/zabbix-6.2.2/
[root@localhost zabbix-6.2.2]# ls
AUTHORS Makefile README compile config.status database m4 sass
copYING Makefile.am aclocal.m4 conf config.sub depcomp man src
ChangeLog Makefile.in bin config.guess configure include misc ui
INSTALL NEWS build config.log configure.ac install-sh missing
[root@localhost zabbix-6.2.2]# vim /usr/local/apache/conf/extra/httpd-vhosts.conf
//配置apache虚拟主机,可以注释之前的配置
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName zabbix.example.com
ErrorLog "logs/zabbix.example.com-error_log"
CustomLog "logs/zabbix.example.com-access_log" common
ProxyRequests Off
ProxyPassMatch ^/(.*\.PHP)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
<Directory "/usr/local/apache/htdocs/zabbix">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
[root@localhost zabbix-6.2.2]# cd /usr/src/zabbix-6.2.2/
[root@localhost zabbix-6.2.2]# ls
AUTHORS Makefile README compile config.status database m4 sass
copYING Makefile.am aclocal.m4 conf config.sub depcomp man src
ChangeLog Makefile.in bin config.guess configure include misc ui
INSTALL NEWS build config.log configure.ac install-sh missing
[root@localhost zabbix-6.2.2]# cd ui/
[root@localhost ui]# ls //此处是PHP代码
actionconf.PHP composer.lock imgstore.PHP report2.PHP
api_jsonrpc.PHP conf include report4.PHP
app data index.PHP robots.txt
assets disc_prototypes.PHP index_http.PHP setup.PHP
audio favicon.ico index_sso.PHP sysmap.PHP
auditacts.PHP graphs.PHP items.PHP sysmaps.PHP
browserwarning.PHP history.PHP js templates.PHP
chart.PHP host_discovery.PHP jsLoader.PHP toptriggers.PHP
chart2.PHP host_prototypes.PHP jsrpc.PHP tr_events.PHP
chart3.PHP hostinventories.PHP local trigger_prototypes.PHP
chart4.PHP hostinventoriesoverview.PHP locale triggers.PHP
chart6.PHP httpconf.PHP maintenance.PHP vendor
chart7.PHP httpdetails.PHP map.PHP zabbix.PHP
composer.json image.PHP modules
[root@localhost ui]# cd -
/usr/src/zabbix-6.2.2
[root@localhost zabbix-6.2.2]# cd
[root@localhost ~]# cd /usr/src/zabbix-6.2.2/
[root@localhost zabbix-6.2.2]# mkdir /usr/local/apache/htdocs/zabbix //创建zabbix的web站点目录
[root@localhost zabbix-6.2.2]# cp -a /usr/src/zabbix-6.2.2/ui/* /usr/local/apache/htdocs/zabbix/
//将zabbix的web界面PHP代码复制到站点目录
[root@localhost zabbix-6.2.2]# chown -R apache.apache /usr/local/apache/htdocs/
//使其属主属组是apache
[root@localhost zabbix-6.2.2]# ll /usr/local/apache/htdocs/
total 8
-rw-r--r--. 1 apache apache 45 Jun 12 2007 index.html
drwxr-xr-x. 2 apache apache 23 Sep 1 21:29 runtime
drwxr-xr-x. 13 apache apache 4096 Sep 1 23:19 zabbix
[root@localhost zabbix-6.2.2]# chmod 777 /usr/local/apache/htdocs/zabbix/conf/
//设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.PHP
[root@localhost zabbix-6.2.2]# ll -d /usr/local/apache/htdocs/zabbix/conf/
drwxrwxrwx. 3 apache apache 94 Aug 29 15:05 /usr/local/apache/htdocs/zabbix/conf/
[root@localhost zabbix-6.2.2]# httpd -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'ServerName' directive globally to suppress this message
Syntax OK
[root@localhost zabbix-6.2.2]# systemctl restart httpd.service
//重启httpd
[root@localhost zabbix-6.2.2]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/PHP.ini
[root@localhost zabbix-6.2.2]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/PHP.ini
[root@localhost zabbix-6.2.2]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/PHP.ini
[root@localhost zabbix-6.2.2]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/PHP.ini
//修改/etc/PHP.ini的配置
[root@localhost zabbix-6.2.2]# service PHP-fpm restart
Gracefully shutting down PHP-fpm . done
Starting PHP-fpm done
//重启PHP-fpm
[root@localhost ~]# zabbix_server
[root@localhost ~]# zabbix_agentd
//启动zabbix_server和zabbix_agentd
在物理机上做hosts域名映射
在我的电脑里面进行映射(C:\Windows\System32\drivers\etc)
去浏览器访问,输入zabbix.example.com,看到如下页面,然后点击next step
部署完成
[root@localhost ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf/
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf/
drwxr-xr-x. 3 apache apache 117 Sep 1 23:41 /usr/local/apache/htdocs/zabbix/conf/
//恢复zabbix/conf目录的权限为755
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。