常见的监控软件:
nagios : 擅长报警,配置比较麻烦
cacti: 擅长画图,流量图
zabbix : 结合nagios和cacti的优点 + grafana
prometheus 普罗米修斯 监控容器
监控指标:
硬件: IPMI 、电源、温度
软件:系统(内存使用率,cpu使用率,磁盘使用率)、网络(网卡流量)、业务(进程、日志)
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主要功能:
zabbix配置文件有两种:
服务器端配置文件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 | 设置客户端日志文件存放路径 |
ip | 环境版本 |
---|---|
192.168.136.140 | centos8 |
因为zabbix
是用php
语言开发的,所以必须先部署lamp
架构,使其能够支持运行php
网页
安装条件:
是在lamp的基础上面部署的
要求:
mariadb 10.9.5
apache 和php 8.2.9
如果有mariadb 先卸载
yum remove mariadb
pkill mariadb
# 下载zabbix
[root@server ~]wget https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.6.tar.gz
-2023-09-22 10:15:04-- https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.6.tar.gz
Resolving cdn.zabbix.com (cdn.zabbix.com)... 172.67.69.4, 104.26.6.148, 104.26.7.148, ...
Connecting to cdn.zabbix.com (cdn.zabbix.com)|172.67.69.4|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 43744978 (42M) [application/octet-stream]
Saving to: ‘zabbix-6.4.6.tar.gz’
zabbix-6.4.6.tar.gz 100%[===================================================>] 41.72M 887KB/s in 67s
2023-09-22 10:16:23 (642 KB/s) - ‘zabbix-6.4.6.tar.gz’ saved [43744978/43744978]
# 解压zabbix
[root@server ~]# tar xf zabbix-6.4.6.tar.gz
[root@server ~]# ll
total 42728
-rw-------. 1 root root 1246 Jul 27 10:00 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Sep 22 08:09 {changed:
drwxr-xr-x 13 tq tq 4096 Aug 22 04:11 zabbix-6.4.6
-rw-r--r-- 1 root root 43744978 Aug 22 05:58 zabbix-6.4.6.tar.gz
[root@server ~]#
# 关闭防火墙和selinux
[root@server ~] systemctl disable --now firewalld
[root@server ~] setenforce 0
[root@server ~] vim /etc/selinux/config
[root@server ~]# cat /etc/selinux/config
# 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 these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
# 安装依赖包
[root@server ~]# yum -y install net-snmp-devel libevent-devel mysql-devel
Last metadata expiration check: 0:01:56 ago on Tue 19 Sep 2023 02:38:21 AM EDT.
Dependencies resolved.
=========================================================================================
Package Arch Version Repo Size
=========================================================================================
Installing:
libevent-devel x86_64 2.1.8-5.el8 appstream 104 k
net-snmp-devel x86_64 1:5.8-28.el8 appstream 275 k
Installing dependencies:
annobin x86_64 11.13-2.el8 baseos 972 k
binutils x86_64 2.30-123.el8 baseos 5.8 M
cpp x86_64 8.5.0-20.el8 baseos 10 M
dwz x86_64 0.12-10.el8
........................................
.......................................
# 创建zabbix用户和组
[root@server ~]# groupadd -r zabbix
[root@server ~]# useradd -r -g zabbix -M -s /sbin/nologin zabbix
[root@server ~] cd zabbix-6.4.6
[root@server zabbix-6.4.6]# ls
aclocal.m4 build conf configure database INSTALL Makefile.am misc README ui
AUTHORS ChangeLog config.guess configure.ac depcomp install-sh Makefile.in missing sass
bin compile config.sub COPYING include m4 man NEWS src
[root@server zabbix-6.4.6]#
下载数据mariadb10.9.5
[root@server ~] yum -y install http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/mariadb-common-10.5.9-1.module_el8.5.0+732+7afc82e7.x86_64.rpm http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/mariadb-errmsg-10.5.9-1.module_el8.5.0+732+7afc82e7.x86_64.rpm
[root@server ~] yum -y install mysql-selinux psmisc
[root@server ~] yum -y install http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/mariadb-10.5.9-1.module_el8.5.0+732+7afc82e7.x86_64.rpm
[root@server ~] yum -y install http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/mariadb-server-10.5.9-1.module_el8.5.0+732+7afc82e7.x86_64.rpm
![在这里插入图片描述](https://img-blog.csdnimg.cn/2531b15e72614ccd82bd371b1a562fcd.png#pic_center)
# 下载依赖包
[root@server ~] yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/OpenIPMI-devel-2.0.31-3.el8.x86_64.rpm
//启动mariadb,并设置开机自启
[root@server ~] systemctl start mariadb
[root@server ~] systemctl enable mariadb
# 配置zabbix数据库
[root@server local]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.42 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, 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.04 sec)
mysql> create user 'zabbix'@'localhost' identified by 'zabbix123';
Query OK, 0 rows affected (0.04 sec)
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> SET GLOBAL log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
mysql> quit
Bye
# 编译安装zabbix
[root@server ~]# cd zabbix-6.4.6
[root@server zabbix-6.4.6] cd database/
[root@server database] ls
[root@server database] cd database/mysql
[root@server mysql]# ll
total 39248
-rw-r--r--. 1 tq tq 37989703 Aug 22 04:11 data.sql
-rw-r--r--. 1 tq tq 282 Aug 22 04:10 double.sql
-rw-r--r--. 1 tq tq 1527 Aug 22 04:11 history_pk_prepare.sql
-rw-r--r--. 1 tq tq 1978341 Aug 22 04:10 images.sql
-rw-r--r--. 1 tq tq 749 Aug 22 04:10 Makefile.am
-rw-r--r--. 1 tq tq 16863 Aug 22 04:10 Makefile.in
-rw-r--r--. 1 tq tq 188015 Aug 22 04:11 schema.sql
#导入表和数据到zabbix库里面
[root@server mysql] mysql -uzabbix -pzabbix123 zabbix < schema.sql
[root@server mysql] mysql -uzabbix -pzabbix123 zabbix < images.sql
[root@server mysql] mysql -uzabbix -pzabbix123 --default-character-set=utf8mb4 zabbix < data.sql
[root@server mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.42 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+--------------------+
5 rows in set (0.01 sec)
mysql> 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
mysql> show tables;(查看是否有186个表)
[root@server ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.42 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, 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.
# 再次登录到数据库,禁用log_bin_trust_function_creators
mysql> SET GLOBAL log_bin_trust_function_creators = 0;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
#设置一个环境变量
[root@server mysql]# export CFLAGS="-std=gnu99"
[root@server mysql]# echo $CFLAGS
-std=gnu99
#开始编译安装
[root@server zabbix-6.4.6]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi
................................................
................................................过程省略
Enable agent: yes
Agent details:
TLS: no
Modbus: no
Linker flags: -rdynamic
Libraries: -lz -lpthread -lcurl -lpthread -lm -ldl -lresolv -lpcre
Configuration file: /usr/local/etc/zabbix_agentd.conf
Modules: /usr/local/lib/modules
Enable agent 2: no
Enable web service: no
Enable Java gateway: no
LDAP support: no
IPv6 support: no
cmocka support: no
yaml support: no
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* *
***********************************************************
[root@server zabbix-6.4.6]# make install
Making install in include
make[1]: Entering directory '/root/zabbix-6.4.6/include'
make[2]: Entering directory '/root/zabbix-6.4.6/include'
make[2]: Nothing to be done for 'install-exec-am'.
..............................................
..............................................
make[1]: Entering directory '/root/zabbix-6.4.6/misc'
make[2]: Entering directory '/root/zabbix-6.4.6/misc'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/root/zabbix-6.4.6/misc'
make[1]: Leaving directory '/root/zabbix-6.4.6/misc'
make[1]: Entering directory '/root/zabbix-6.4.6'
make[2]: Entering directory '/root/zabbix-6.4.6'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/root/zabbix-6.4.6'
make[1]: Leaving directory '/root/zabbix-6.4.6'
# 查看以下服务的配置文件
[root@server zabbix-6.4.6]# cd /usr/local/etc/
[root@server etc]# ll
total 48
-rw-r--r--. 1 root root 17025 Sep 23 00:45 zabbix_agentd.conf
drwxr-xr-x. 2 root root 6 Sep 23 00:45 zabbix_agentd.conf.d
-rw-r--r--. 1 root root 27216 Sep 23 00:45 zabbix_server.conf
drwxr-xr-x. 2 root root 6 Sep 23 00:45 zabbix_server.conf.d
# 修改服务端配置文件和数据库信息
[root@server etc]# vim zabbix_server.conf
# Mandatory: no
122 # Default:
123 # DBPassword=
124 DBPassword=zabbix123 # 添加这行
125 ### Option: DBSocket
126 # Path to MySQL socket.
127 #
128 # Mandatory: no
129 # Default:
# 启动服务端和客户端
[root@server etc]# zabbix_server //启动服务端
[root@server etc]# zabbix_agentd //启动客户端
#查看端口号。10051是服务端,10050是客户端
[root@server 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 2048 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 511 *:80 *:*
LISTEN 0 128 [::]:22 [::
设置zabbix开机自启
[root@server system]# pwd
/usr/lib/systemd/system
# 服务端
[root@server system]# cat zabbix_server.service
[Unit]
Description=zabbix server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/sbin/zabbix_server
ExecStop=pkill zabbix_server
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
# agent端
[root@server system]# cat zabbix_agentd.service
[Unit]
Description=zabbix agentd
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/sbin/zabbix_agentd
ExecStop=pkill zabbix_agentd
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
# 查看
[root@server ~]# pkill zabbix
[root@server ~]# ps -ef | grep zabbix
root 245001 219324 0 02:07 pts/0 00:00:00 ping zabbix.tq.com
root 245644 219324 0 03:35 pts/0 00:00:00 grep --color=auto zabbix
[root@server ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 2048 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:
# 启动zabbix
[root@server ~]# systemctl daemon-reload
[root@server ~]# systemctl enable --now zabbix_server.service
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix_server.service → /usr/lib/systemd/system/zabbix_server.service.
启动agentd
[root@server ~]# systemctl enable --now zabbix_agentd.service
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix_agentd.service → /usr/lib/systemd/system/zabbix_agentd.service.
[root@server ~]# 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 2048 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@server ~]#
# 修改 /etc/php.ini的配置并重启php-fpm
[root@server ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@server ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@server ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@server ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@server ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
#给zabbix的网页文件创建一个家目录
[root@server ~]# cd zabbix-6.4.6
[root@server zabbix-6.4.6]# mkdir /usr/local/apache/htdocs/zabbix
#进入到解压后的源码包目录,把zabbix的网页文件全部复制到刚刚创建的目录里面去
[root@server zabbix-6.4.6]# cp -a ui/* /usr/local/apache/htdocs/zabbix/
#修改属主
[root@server zabbix-6.4.6]# chown -R apache.apache /usr/local/apache/htdocs
[root@server zabbix-6.4.6]# ls /usr/local/apache/htdocs/zabbix/
api_jsonrpc.php chart6.php graphs.php imgstore.php local sysmaps.php
api_scim.php chart7.php history.php include locale templates.php
app chart.php host_discovery.php index_http.php map.php toptriggers.php
assets composer.json hostinventoriesoverview.php index.php modules tr_events.php
audio composer.lock hostinventories.php index_sso.php report2.php trigger_prototypes.php
browserwarning.php conf host_prototypes.php items.php report4.php triggers.php
chart2.php data httpconf.php js robots.txt vendor
chart3.php disc_prototypes.php httpdetails.php jsLoader.php setup.php widgets
chart4.php favicon.ico image.php jsrpc.php sysmap.php zabbix.php
[root@server zabbix-6.4.6]#
# 配置apache虚拟主机
[root@server ~]# vim /etc/httpd24/httpd.conf
#添加下面内容
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName zabbix.tq.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
Options none
AllowOverride none
Require all granted
# 设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@server ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf/
[root@server ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx. 3 apache apache 94 Aug 22 04:10 /usr/local/apache/htdocs/zabbix/conf
# 重启apache
[root@server ~]# apachectl stop
[root@server ~]# apachectl start
[root@server ~]# 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 2048 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 511 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@server ~]#
# 在虚拟机中看域名是否可以ping通
[root@server ~]# ping zabbix.tq.com
PING zabbix.tq.com.localdomain (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.570 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.058 ms
这里默认的:
用户名:Admin
密码: zabbix
恢复zabbix/conf目录的权限为755
[root@server ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf