监控服务zabbix部署
常用的监控软件:
nagios 擅长报警,配置麻烦
cacti 擅长画图,流量图
zabbix 结合nagios+cacti的优点+grafana
prometheus 普罗米修斯 >>监控容器 需要用到agent(代理):负责收集情报(奸细)
//常见的监控软件及其特点
Nagios:Nagios是一款开源的网络监控工具,可用于监控网络设备、服务器、应用程序等。它具有强大的插件系统,支持自定义监控指标和报警方式,可以实时监控系统状态并发送警报。
Zabbix:Zabbix是一款功能丰富的企业级监控软件,支持多种监控方式,包括网络、服务器、数据库等。它提供了灵活的报警机制和可视化的监控界面,可以帮助管理员实时监控和管理系统。
Prometheus:Prometheus是一款开源的监控和警报工具,特别适用于容器化环境。它支持多种数据源,包括服务发现、指标收集和存储等,可以进行多维度的数据查询和报警。
Grafana:Grafana是一款开源的数据可视化工具,可以与多种监控软件集成,如Prometheus、Zabbix等。它提供了丰富的图表和仪表盘功能,可以将监控数据可视化展示,帮助用户更直观地了解系统状态。
Datadog:Datadog是一款云端监控和分析平台,支持监控云服务、应用程序、网络设备等。它提供了强大的数据收集和分析功能,可以实时监控系统性能,并提供可视化的报表和警报功能。
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 server 不能在windows上使用 ,agent可以
zabbix agent
需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。
监控指标:
硬件(IPMI): 电源 温度
软件:系统 <内存使用率 cpu使用率 磁盘使用率> 网络<网卡流量> 业务<进程 日志>
zabbix server
可以单独监视远程服务器的服务状态;同时也可以与zabbix agent
配合,可以轮询zabbix agent
主动接收监视数据(agent方式),同时还可被动接收zabbix agent
发送的数据(trapping方式)。
另外zabbix server
还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。
zabbix的主要特点:
- 安装与配置简单,学习成本低
- 支持多语言(包括中文)
- 免费开源
- 自动发现服务器与网络设备
- 分布式监视以及WEB集中管理功能
- 可以无agent监视
- 用户安全认证和柔软的授权方式
- 通过WEB界面设置或查看监视结果
- email等通知功能
Zabbix主要功能:
- CPU负荷
- 内存使用
- 磁盘使用
- 网络状况
- 端口监视
- 日志监视
部署zabbix
准备环境:
lamp源码部署: https://blog.csdn.net/2203_75303999/article/details/133161637?spm=1001.2014.3001.5502
环境说明:
环境 | IP | 要安装的应用 |
---|---|---|
服务器 | 192.168.134.148 | lamp架构 zabbix server zabbix agent |
客户端 | 192.168.134.151 | zabbix agent |
//首先:部署好lamp
先删除之前在lamp中部署的mysql
[root@localhost ~]# rm -rf /etc/my.cnf
[root@localhost ~]# cd /usr/local
[root@localhost local]# rm -rf mysql-5.7.39-linux-glibc2.12-x86_64/
[root@localhost local]# rm -rf mysql
[root@localhost local]# cd
[root@localhost ~]# rm -rf /opt/data
//其次:
在本地上传一个Mariadb的包,并解压
进入到该目录里面,然后执行这个脚本
[root@localhost mariadb-10.5.22-rhel-8-x86_64-rpms]# ./setup_repository
[root@localhost mariadb-10.5.22-rhel-8-x86_64-rpms]# yum install MariaDB-server -y
//设置Mariadb为开机自启
[root@localhost mariadb-10.5.22-rhel-8-x86_64-rpms]# systemctl enable --now mariadb
//查看一下版本是否为最新版本
[root@localhost mariadb-10.5.22-rhel-8-x86_64-rpms]# mariadb-server -v
因为zabbix是用php语言开发的,所以必须先部署lamp架构,使其能够支持运行php网页**
部署
准备工作
//先执行lamp脚本 然后关闭防火墙 关闭selinux
[root@localhost ~]# systemctl disabled --now firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /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
访问php页面发现可以访问
//首先在zabbix.com里面查看帮助文档并下载zabbix包
[root@localhost ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.6.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg lamp zabbix-6.4.6.tar.gz
//安装依赖包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel mysql-devel OpenIPMI-libs
//创建用户账号
[root@localhost ~]# useradd -r -M -s /sbin/nologin zabbix
//解压
[root@localhost ~]# tar xf zabbix-6.4.6.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg lamp mariadb-10.5.22-rhel-8-x86_64-rpms mariadb-10.5.22-rhel-8-x86_64-rpms.tar zabbix-6.4.6 zabbix-6.4.6.tar.gz
[root@localhost ~]# cd zabbix-6.4.6
[root@localhost zabbix-6.4.6]# ls
aclocal.m4 bin ChangeLog conf config.sub configure.ac database include install-sh Makefile.am man missing README src
AUTHORS build compile config.guess configure COPYING depcomp INSTALL m4 Makefile.in misc NEWS sass ui
//此处有INSTALL/README帮助文档可以查看
//登录mysql服务
[root@localhost zabbix-6.4.6]# mysql -uroot -pLuchengyang111_
//授权
MariaDB [(none)]> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> create user 'zabbix'@'localhost' identified by 'zabbix123!';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> SET GLOBAL log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> quit
Bye
[root@localhost ~]# cd zabbix-6.4.6
[root@localhost zabbix-6.4.6]# ls
aclocal.m4 bin ChangeLog conf config.sub configure.ac database include install-sh Makefile.am man missing README src
AUTHORS build compile config.guess configure COPYING depcomp INSTALL m4 Makefile.in misc NEWS sass ui
[root@localhost zabbix-6.4.6]# cd database/
[root@localhost database]# ls
elasticsearch Makefile.am Makefile.in mysql oracle postgresql sqlite3
[root@localhost database]# cd mysql/
[root@localhost mysql]# ls
data.sql double.sql history_pk_prepare.sql images.sql Makefile.am Makefile.in schema.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix123! --default-character-set=utf8mb4 zabbix < data.sql
[root@localhost mysql]# mysql -uroot -pLuchengyang111_
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.5.22-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> SET GLOBAL log_bin_trust_function_creators = 0;
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> show tables from zabbix;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| auditlog |
| autoreg_host |
| changelog |
| conditions |
| config |
| config_autoreg_tls |
| connector |
| connector_tag |
| corr_condition |
| corr_condition_group |
| corr_condition_tag |
| corr_condition_tagpair |
| corr_condition_tagvalue |
| corr_operation |
| correlation |
| dashboard |
| dashboard_page |
| dashboard_user |
| dashboard_usrgrp |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| event_recovery |
| event_suppress |
| event_symptom |
| event_tag |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| ha_node |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| host_rtdata |
| host_tag |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| hstgrp |
| httpstep |
| httpstep_field |
| httpstepitem |
| httptest |
| httptest_field |
| httptest_tag |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| interface_snmp |
| item_condition |
| item_discovery |
| item_parameter |
| item_preproc |
| item_rtdata |
| item_tag |
| items |
| lld_macro_path |
| lld_override |
| lld_override_condition |
| lld_override_opdiscover |
| lld_override_operation |
| lld_override_ophistory |
| lld_override_opinventory |
| lld_override_opperiod |
| lld_override_opseverity |
| lld_override_opstatus |
| lld_override_optag |
| lld_override_optemplate |
| lld_override_optrends |
| maintenance_tag |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| media |
| media_type |
| media_type_message |
| media_type_param |
| module |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| problem |
| problem_tag |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| report |
| report_param |
| report_user |
| report_usrgrp |
| rights |
| role |
| role_rule |
| scim_group |
| script_param |
| scripts |
| service_alarms |
| service_problem |
| service_problem_tag |
| service_status_rule |
| service_tag |
| services |
| services_links |
| sessions |
| sla |
| sla_excluded_downtime |
| sla_schedule |
| sla_service_tag |
| sysmap_element_trigger |
| sysmap_element_url |
| sysmap_shape |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_element_tag |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| tag_filter |
| task |
| task_acknowledge |
| task_check_now |
| task_close_problem |
| task_data |
| task_remote_command |
| task_remote_command_result |
| task_result |
| timeperiods |
| token |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| trigger_queue |
| trigger_tag |
| triggers |
| user_scim_group |
| userdirectory |
| userdirectory_idpgroup |
| userdirectory_ldap |
| userdirectory_media |
| userdirectory_saml |
| userdirectory_usrgrp |
| users |
| users_groups |
| usrgrp |
| valuemap |
| valuemap_mapping |
| widget |
| widget_field |
+----------------------------+
186 rows in set (0.001 sec)
MariaDB [(none)]> quit
Bye
[root@localhost mysql]# pwd
/root/zabbix-6.4.6/database/mysql
[root@localhost mysql]# export CFLAGS="-std=gnu99"
[root@localhost ~]# cd zabbix-6.4.6
[root@localhost zabbix-6.4.6]# ls
aclocal.m4 bin ChangeLog conf config.sub configure.ac database include install-sh Makefile.am man missing README src
AUTHORS build compile config.guess configure COPYING depcomp INSTALL m4 Makefile.in misc NEWS sass ui
//报错
configure: error: MySQL library not found
解决
[root@localhost ~]# yum -y install mysql-devel
报错
configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
解决
[root@localhost ~]# yum -y install OpenIPMI-libs http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/OpenIPMI-devel-2.0.31-3.el8.x86_64.rpm
报错
configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
解决
[root@localhost ~]# yum -y install net-snmp-devel
//编译安装
[root@localhost zabbix-6.4.6]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi
[root@localhost zabbix-6.4.6]# make install
此处编译如果出现:
1、
config.status: error: in `/usr/src/zabbix-6.4.6':
config.status: error: Something went wrong bootstrapping makefile fragments
for automatic dependency tracking. If GNU make was not used, consider
re-running the configure script with MAKE="gmake" (or whatever is
necessary). You can also try re-running configure with the
'--disable-dependency-tracking' option to at least be able to build
the package (albeit without support for automatic dependency tracking).
See `config.log' for more details
解决:
[root@c8-3 zabbix-6.4.6]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --disable-dependency-tracking
2、configure: error: Not found libxml2 library
解决:yum install curl-devel -y
3、config.status: error: in `/root/zabbix-6.4.6':
config.status: error: Something went wrong bootstrapping makefile fragments
for automatic dependency tracking. If GNU make was not used, consider
re-running the configure script with MAKE="gmake" (or whatever is
necessary). You can also try re-running configure with the
'--disable-dependency-tracking' option to at least be able to build
the package (albeit without support for automatic dependency tracking).
See `config.log' for more details
解决:重新编译: ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --disable-dependency-tracking
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
部署成功
[root@c8-3 zabbix-6.4.6]# make install
[root@localhost~ zabbix-6.4.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
....
DBPassword=zabbix123! //设置zabbix数据库连接密码
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
[root@localhost ~]# zabbix_server
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
[root@localhost ~]# zabbix_agentd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
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 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
[root@localhost ~ zabbix-6.4.6]\cp -a ui/* /usr/local/apache/htdocs/lcy.com
//此处的\表示:覆盖
[root@localhost ~ zabbix-6.4.6]# chown -R apache.apache /usr/local/apache/htdocs
[root@localhost ~ zabbix-6.4.6]# cd /usr/local/apache/htdocs/lcy.com
//查看权限
[root@localhost ~ lcy.com]# ll -d conf/
drwxr-xr-x. 3 apache apache 94 Aug 22 16:10 conf/
//修改权限
[root@RHEL8 lcy.com]# chmod 777 conf
//再次查看权限
[root@RHEL8 lcy.com]# ll -d conf
drwxrwxrwx. 3 apache apache 94 Aug 22 16:10 conf
[root@localhost ~ lcy.com]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~ lcy.com]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~ lcy.com]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~ lcy.com]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~ lcy.com]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
ip访问zabbix并登录数据库
127.0.0.1
端口3306
//将权限改回
[root@localhost ~ lcy.com]# cd conf/
[root@localhost ~ conf]# ls
certs maintenance.inc.php zabbix.conf.php zabbix.conf.php.example
[root@localhost ~ conf]# cd ..
[root@localhost ~ lcy.com]# chmod 755 conf
登录zabbix
zabbix默认登录用户名和密码:
用户名 密码
Admin zabbix
部署成功
注:在添加监控端时:
被监控端的zabbix_agentd.conf文件中的ip(server端ip)和名字(在zabbix网页设置的名字)必须更改