部署Zabbix
Posted 映辉博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了部署Zabbix相关的知识,希望对你有一定的参考价值。
https://blog.csdn.net/qq_57414752/article/details/125819822
监控服务zabbix部署
文章目录
监控服务zabbix部署
zabbix介绍
zabbix
是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix
能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
zabbix
由2部分构成,zabbix server
与可选组件zabbix agent
。
zabbix server
可以通过SNMP
,zabbix agent
,ping
,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Ubuntu,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
zabbix agent
需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。
zabbix server
可以单独监视远程服务器的服务状态;同时也可以与zabbix agent
配合,可以轮询zabbix agent
主动接收监视数据(agent方式),同时还可被动接收zabbix agent
发送的数据(trapping方式)。
另外zabbix server
还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。
zabbix特点
zabbix的主要特点:
- 安装与配置简单,学习成本低
- 支持多语言(包括中文)
- 免费开源
- 自动发现服务器与网络设备
- 分布式监视以及WEB集中管理功能
- 可以无agent监视
- 用户安全认证和柔软的授权方式
- 通过WEB界面设置或查看监视结果
- email等通知功能
Zabbix主要功能:
- CPU负荷
- 内存使用
- 磁盘使用
- 网络状况
- 端口监视
- 日志监视
zabbix配置文件
zabbix配置文件有两种:
- 服务器端配置文件(/usr/local/etc/zabbix_server.conf)
- 客户端配置文件(/usr/local/etc/zabbix_agentd.conf)
- zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)
服务器端配置文件zabbix_server.conf常用配置参数:
参数 | 作用 |
---|---|
LogFile | 设置服务端日志文件存放路径 |
ListenIP | 设置服务端监听IP |
ListenPort | 设置服务端监听的端口号 |
PidFile | 设置服务端进程号文件存放路径 |
DBHost | 指定zabbix的数据库服务器IP |
DBName | 指定zabbix使用的数据库库名 |
DBUser | 指定zabbix数据库登录用户 |
DBPassword | 指定zabbix数据库登录密码 |
DBPort | 指定zabbix数据库端口号 |
User | 设置zabbix以什么用户的身份运行 |
AlertScriptsPath | 设置告警脚本存放路径 |
ExternalScripts | 外部脚本存放路径 |
客户端配置文件zabbix_agentd.conf常用配置参数:
参数 | 作用 |
---|---|
Server | 指定zabbix服务器的IP或域名 |
ServerActive | 指定zabbix服务器的IP或域名 |
Hostname | 指定本机的主机名,此项必须与web界面配置项一致 |
UnsafeUserParameters | 是否启用自定义监控项,可选值为{1 | 0} |
UserParameter | 指定自定义监控脚本参数 |
LogFile | 设置客户端日志文件存放路径 |
部署zabbix
环境说明:
环境 | IP | 要安装的应用 |
---|---|---|
服务器 | 192.168.96.129 | lamp架构 zabbix server zabbix agent |
因为zabbix是用php语言开发的,所以必须先部署lamp架构,使其能够支持运行php网页
我这里提前把lamp部署好了,lamp部署请参考lamp部署
zabbix服务端安装
#安装依赖包
[root@localhost ~]# dnf -y install net-snmp-devel libevent-devel
#安装过程省略
下载zabbix
官网https://www.zabbix.com/
下载好了然后通过xftp传过来
[root@localhost ~]# ls
anaconda-ks.cfg apr-util-1.6.1 pass
apr-1.7.0 httpd-2.4.43 zabbix-5.2.6.tar.gz
#解压
[root@localhost ~]# tar xf zabbix-5.2.6.tar.gz
ls[root@localhost ~]# ls
anaconda-ks.cfg apr-util-1.6.1 pass zabbix-5.2.6.tar.gz
apr-1.7.0 httpd-2.4.43 zabbix-5.2.6
#创建系统用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin zabbix
[root@localhost ~]# id zabbix
uid=991(zabbix) gid=989(zabbix) groups=989(zabbix)
配置zabbix数据库
[root@localhost ~]# mysql -uroot -pbwxh
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 2
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 'zabbix123';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' identifiedd by 'zabbix123';
Query OK, 0 rows affected, 2 warnings (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)
mysql> show tables from zabbix;
Empty set (0.00 sec)
mysql> quit
Bye
导入数据库
[root@localhost ~]# cd zabbix-5.2.6
[root@localhost zabbix-5.2.6]# ls
aclocal.m4 compile configure.ac INSTALL man sass
AUTHORS conf COPYING install-sh misc src
bin config.guess database m4 missing ui
build config.sub depcomp Makefile.am NEWS
ChangeLog configure include Makefile.in README
[root@localhost zabbix-5.2.6]# cd database/
[root@localhost database]# ls
elasticsearch Makefile.in oracle sqlite3
Makefile.am mysql postgresql
[root@localhost database]# cd mysql/
[root@localhost mysql]# ls
data.sql double.sql images.sql Makefile.am Makefile.in schema.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix123 zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123 zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123 zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123 -e'show tables from zabbix'
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
|............... |
+----------------------------+
#就会看到以上数据
编译安装zabbix
[root@localhost ~]# ls
anaconda-ks.cfg apr-util-1.6.1 pass zabbix-5.2.6.tar.gz
apr-1.7.0 httpd-2.4.43 zabbix-5.2.6
[root@localhost ~]# cd zabbix-5.2.6
[root@localhost zabbix-5.2.6]#
[root@localhost zabbix-5.2.6]# ./configure --enable-server \\
> --enable-agent \\
> --with-mysql \\
> --with-net-snmp \\
> --with-libcurl \\
> --with-libxml2
#配置过程省略
[root@localhost zabbix-5.2.6]# make install
#安装过程省略
zabbix服务端配置
[root@localhost zabbix-5.2.6]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_server.conf
zabbix_agentd.conf.d zabbix_server.conf.d
#修改服务端配置文件,设置数据库信息
[root@localhost etc]# vim zabbix_server.conf
#找到118行设置zabbix数据库连接密码
118 DBPassword=zabbix123
启动启动zabbix_server和zabbix_agentd
[root@localhost etc]# zabbix_server
[root@localhost etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost etc]# zabbix_agentd
[root@localhost etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
zabbix服务端web界面安装与配置
zabbix web界面安装前配置
修改/etc/php.ini的配置并重启php-fpm
[root@localhost zabbix-5.2.6]# sed -ri 's/(post_max_size =).*/\\1 16M/g' /etc/php.ini
[root@localhost zabbix-5.2.6]# sed -ri 's/(max_execution_time =).*/\\1 300/g' /etc/php.ini
[root@localhost zabbix-5.2.6]# sed -ri 's/(max_input_time =).*/\\1 300/g' /etc/php.ini
[root@localhost zabbix-5.2.6]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost zabbix-5.2.6]# service php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service
[root@localhost apache]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# ls
bwxh index.html
[root@localhost htdocs]# mv bwxh zabbix
[root@localhost htdocs]# ls
index.html zabbix
[root@localhost htdocs]# cd zabbix/
[root@localhost zabbix]# ls
index.php
[root@localhost zabbix]# rm -f index.php
[root@localhost zabbix]# ll
total 0
#把安装目录里面的ui cp到/usr/local/apache/htdocs/zabbix/
[root@localhost zabbix]# cd ~
[root@localhost ~]# cd zabbix-5.2.6
[root@localhost zabbix-5.2.6]# ls
aclocal.m4 conf configure.ac install-sh misc ui
AUTHORS config.guess COPYING m4 missing
bin config.log database Makefile NEWS
build config.status depcomp Makefile.am README
ChangeLog config.sub include Makefile.in sass
compile configure INSTALL man src
[root@localhost zabbix-5.2.6]# ls ui
actionconf.php host_discovery.php overview.php
api_jsonrpc.php hostgroups.php queue.php
app hostinventoriesoverview.php report2.php
assets hostinventories.php report4.php
audio host_prototypes.php robots.txt
auditacts.php hosts.php screenconf.php
browserwarning.php httpconf.php screenedit.php
chart2.php httpdetails.php screen.import.php
chart3.php image.php screens.php
chart4.php imgstore.php services.php
chart5.php include setup.php
chart6.php index_http.php slideconf.php
chart7.php index.php slides.php
chart.php index_sso.php srv_status.php
composer.json items.php sysmap.php
composer.lock js sysmaps.php
conf jsLoader.php templates.php
conf.import.php jsrpc.php toptriggers.php
correlation.php local tr_events.php
discoveryconf.php locale trigger_prototypes.php
disc_prototypes.php maintenance.php triggers.php
favicon.ico map.import.php vendor
graphs.php map.php zabbix.php
history.php modules
[root@localhost zabbix-5.2.6]# cp -r ui/* /usr/local/apache/htdocs/zabbix/
[root@localhost zabbix-5.2.6]# ll /usr/local/apache/htdocs/zabbix/
total 948
-rw-r--r-- 1 root root 22808 May 13 18:43 actionconf.php
-rw-r--r-- 1 root root 2350 May 13 18:43 api_jsonrpc.php
drwxr-xr-x 5 root root 71 May 13 18:43 app
drwxr-xr-x 5 root root 44 May 13 18:43 assets
drwxr-xr-x 2 root root 173 May 13 18:43 audio
-rw-r--r-- 1 root root 5081 May 13 18:43 auditacts.php
-rw-r--r-- 1 root root 1419 May 13 18:43 browserwarning.php
-rw-r--r-- 1 root root 5095 May 13 18:43 chart2.php
-rw-r--r-- 1 root root 6986 May 13 18:43 chart3.php
-rw-r--r-- 1 root root 5593 May 13 18:43 chart4.php
-rw-r--r-- 1 root root 5711 May 13 18:43 chart5.php
-rw-r--r-- 1 root root 3596 May 13 18:43 chart6.php
-rw-r--r-- 1 root root 3901 May 13 18:43 chart7.php
-rw-r--r-- 1 root root 4505 May 13 18:43 chart.php
-rw-r--r-- 1 root root 48 May 13 18:43 composer.json
-rw-r--r-- 1 root root 8010 May 13 18:43 composer.lock
drwxr-xr-x 3 root root 94 May 13 18:43 conf
-rw-r--r-- 1 root root 7330 May 13 18:43 conf.import.php
-rw-r--r-- 1 root root 16645 May 13 18:43 correlation.php
-rw-r--r-- 1 root root 13872 May 13 18:43 discoveryconf.php
-rw-r--r-- 1 root root 57032 May 13 18:43 disc_prototypes.php
-rw-r--r-- 1 root root 32988 May 13 18:43 favicon.ico
-rw-r--r-- 1 root root 25580 May 13 18:43 graphs.php
-rw-r--r-- 1 root root 4453 May 13 18:43 history.php
-rw-r--r-- 1 root root 35772 May 13 18:43 host_discovery.php
-rw-r--r-- 1 root root 9707 May 13 18:43 hostgroups.php
-rw-r--r-- 1 root root 6445 May 13 18:43 hostinventoriesoverview.php
-rw-r--r-- 1 root root 9291 May 13 18:43 hostinventories.php
-rw-r--r-- 1 root root 22008 May 13 18:43 host_prototypes.php
-rw-r--r-- 1 root root 51467 May 13 18:43 hosts.php
-rw-r--r-- 1 root root 29471 May 13 18:43 httpconf.php
-rw-r--r-- 1 root root 6514 May 13 18:43 httpdetails.php
-rw-r--r-- 1 root root 1856 May 13 18:43 image.php
-rw-r--r-- 1 root root 3576 May 13 18:43 imgstore.php
drwxr-xr-x 4 root root 4096 May 13 18:43 include
-rw-r--r-- 1 root root 3201 May 13 18:43 index_http.php
-rw-r--r-- 1 root root 4136 May 13 18:43 index.php
-rw-r--r-- 1 root root 8951 May 13 18:43 index_sso.php
-rw-r--r-- 1 root root 78615 May 13 18:43 items.php
drwxr-xr-x 5 root root 4096 May 13 18:43 js
-rw-r--r-- 1 root root 16046 May 13 18:43 jsLoader.php
-rw-r--r-- 1 root root 19490 May 13 18:43 jsrpc.php
drwxr-xr-x 4 root root 60 May 13 18:43 local
drwxr-xr-x 35 root root 4096 May 13 18:43 locale
-rw-r--r-- 1 root root 14295 May 13 18:43 maintenance.php
-rw-r--r-- 1 root root 4188 May 13 18:43 map.import.php
-rw-r--r-- 1 root root 2136 May 13 18:43 map.php
drwxr-xr-x 2 root root 6 May 13 18:43 modules
-rw-r--r-- 1 root root 10770 May 13 18:43 overview.php
-rw-r--r-- 1 root root 8633 May 13 18:43 queue.php
-rw-r--r-- 1 root root 18738 May 13 18:43 report2.php
-rw-r--r-- 1 root root 7284 May 13 18:43 report4.php
-rw-r--r-- 1 root root 974 May 13 18:43 robots.txt
-rw-r--r-- 1 root root 11970 May 13 18:43 screenconf.php
-rw-r--r-- 1 root root 10235 May 13 18:43 screenedit.php
-rw-r--r-- 1 root root 4210 May 13 18:43 screen.import.php
-rw-r--r-- 1 root root 4943 May 13 18:43 screens.php
-rw-r--r-- 1 root root 12254 May 13 18:43 services.php
-rw-r--r-- 1 root root 7052 May 13 18:43 setup.php
-rw-r--r-- 1 root root 13338 May 13 18:43 slideconf.php
-rw-r--r-- 1 root root 6663 May 13 18:43 slides.php
-rw-r--r-- 1 root root 5419 May 13 18:43 srv_status.php
-rw-r--r-- 1 root root 9870 May 13 18:43 sysmap.php
-rw-r--r-- 1 root root 16711 May 13 18:43 sysmaps.php
-rw-r--r-- 1 root root 35618 May 13 18:43 templates.php
-rw-r--r-- 1 root root 6341 May 13 18:43 toptriggers.php
-rw-r--r-- 1 root root 6931 May 13 18:43 tr_events.php
-rw-r--r-- 1 root root 26508 May 13 18:43 trigger_prototypes.php
-rw-r--r-- 1 root root 38231 May 13 18:43 triggers.php
drwxr-xr-x 7 root root 102 May 13 18:43 vendor
-rw-r--r-- 1 root root 842 May 13 18:43 zabbix.php
#修改属主属组
[root@localhost zabbix-5.2.6]# chown -R apache.apache /usr/local/apache/htdocs/
配置apache虚拟主机
[root@localhost zabbix-5.2.6]# vim /etc/httpd24/extra/vhosts.conf
#修改如下
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName www.hyh.com
ProxyRequests Off
ProxyPassMatch ^/(.*\\.php)$ fcgi://0.0.0.0: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-5.2.6]# apachectl restart
[root@localhost zabbix-5.2.6]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@localhost zabbix-5.2.6]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@localhost zabbix-5.2.6]# ll -d /usr/local/apache/htdocs/zabbix/confdrwxrwxrwx 3 apache apache 94 May 13 18:43 /usr/local/apache/htdocs/zabbix/conf
数据库授权zabbix用户使用本地IP地址登录
[root@localhost zabbix-5.2.6]# mysql -uroot -pbwxh
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 73
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> grant all on *.* to zabbix@'192.168.96.129' identified by 'zabbix123';
Query OK, 0 rows affected, 1 warning (0.00 sec)
[root@localhost zabbix-5.2.6]# apachectl restart
安装zabbix web界面
恢复zabbix/conf目录的权限为755:
[root@localhost zabbix-5.2.6]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@localhost zabbix-5.2.6]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxr-xr-x 3 apache apache 117 May 13 19:05 /usr/local/apache/htdocs/zabbix/conf
登录zabbix
zabbix默认登录用户名和密码:
用户名 | 密码 |
---|---|
Admin | zabbix |
以上是关于部署Zabbix的主要内容,如果未能解决你的问题,请参考以下文章