监控服务zabbix部署

监控服务zabbix部署


1. zabbix介绍

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。

zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。

zabbix由2部分构成,zabbix server与可选组件zabbix agent

zabbix server可以通过SNMPzabbix agentping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在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)等配合使用。

2. zabbix特点

zabbix的主要特点:

  • 安装与配置简单,学习成本低
  • 支持多语言(包括中文)
  • 免费开源
  • 自动发现服务器与网络设备
  • 分布式监视以及WEB集中管理功能
  • 可以无agent监视
  • 用户安全认证和柔软的授权方式
  • 通过WEB界面设置或查看监视结果
  • email等通知功能

Zabbix主要功能:

  • CPU负荷
  • 内存使用
  • 磁盘使用
  • 网络状况
  • 端口监视
  • 日志监视

3. 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设置客户端日志文件存放路径

4. 部署zabbix

环境说明:

环境IP要安装的应用
服务器192.168.159.141lamp架构 zabbix server zabbix agent
客户端192.168.159.147zabbix agent

因为zabbix是用php语言开发的,所以必须先部署lamp架构,使其能够支持运行php网页(安装过程详细见文章LAMP编译安装

部署zabbix

服务端部署zabbix

安装依赖包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel

下载zabbix安装包
[root@localhost ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.10.tar.gz
--2024-01-04 21:56:15--  https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.10.tar.gz
Resolving cdn.zabbix.com (cdn.zabbix.com)... 104.26.6.148, 172.67.69.4, 104.26.7.148
Connecting to cdn.zabbix.com (cdn.zabbix.com)|104.26.6.148|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 45608366 (43M) [application/octet-stream]
Saving to: ‘zabbix-6.4.10.tar.gz’

zabbix-6.4.10.tar.gz   100%[=========================>]  43.50M  3.54MB/s    in 18s     

2024-01-04 21:56:34 (2.45 MB/s) - ‘zabbix-6.4.10.tar.gz’ saved [45608366/45608366]

解压zabbix安装包
[root@localhost ~]# tar xf zabbix-6.4.10.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg  apr-util-1.6.3  php-8.3.0      zabbix-6.4.10.tar.gz
apr-1.7.4        httpd-2.4.58    zabbix-6.4.10

创建zabbix用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin zabbix

配置zabbix数据库
[root@localhost ~]# mysql -uroot -pPassw0rd@_
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 10
Server version: 8.0.35 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.00 sec)

mysql> create user 'zabbix'@'localhost' identified by 'zabbix@123';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> SET GLOBAL log_bin_trust_function_creators = 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

将数据导入数据库
[root@localhost ~]# hostnamectl set-hostname zabbix-server
[root@zabbix-server ~]# cd zabbix-6.4.10/
[root@zabbix-server zabbix-6.4.10]# ls
aclocal.m4  ChangeLog     config.sub    database  install-sh   man      README
AUTHORS     compile       configure     depcomp   m4           misc     sass
bin         conf          configure.ac  include   Makefile.am  missing  src
build       config.guess  COPYING       INSTALL   Makefile.in  NEWS     ui
[root@zabbix-server zabbix-6.4.10]# cd database/mysql/
[root@zabbix-server mysql]# ls
data.sql  images.sql  Makefile.am  Makefile.in  option-patches  schema.sql
[root@zabbix-server mysql]# mysql -uroot -pPassw0rd@_ zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zabbix-server mysql]# mysql -uroot -pPassw0rd@_ zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@zabbix-server mysql]# mysql -uroot -pPassw0rd@_ --default-character-set=utf8mb4 zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.

将此项值改为0
[root@zabbix-server ~]# mysql -uroot -pPassw0rd@_
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 14
Server version: 8.0.35 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> SET GLOBAL log_bin_trust_function_creators = 0;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye

设置gnu扩展
[root@zabbix-server ~]# cd zabbix-6.4.10/
[root@zabbix-server zabbix-6.4.10]# cd database/mysql/
[root@zabbix-server mysql]# export CFLAGS="-std=gnu99"

编译安装zabbix
[root@zabbix-server zabbix-6.4.10]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
......................................................
  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!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

[root@zabbix-server zabbix-6.4.10]# make install

编辑zabbix服务端配置文件
[root@zabbix-server ~]# cd /usr/local/etc/
[root@zabbix-server etc]# ls
zabbix_agentd.conf  zabbix_agentd.conf.d  zabbix_server.conf  zabbix_server.conf.d
[root@zabbix-server etc]# vim zabbix_server.conf
DBPassword=zabbix@123
DBSocket=/tmp/mysql.sock

启动zabbix
[root@zabbix-server etc]# zabbix_server
[root@zabbix-server etc]# zabbix_agentd
[root@zabbix-server etc]# 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         4096               0.0.0.0:10050            0.0.0.0:*  
LISTEN    0         4096               0.0.0.0:10051            0.0.0.0:*  
LISTEN    0         4096             127.0.0.1:9000             0.0.0.0:*                
LISTEN    0         511                      *:80                     *:*                
LISTEN    0         128                   [::]:22                  [::]:*                
LISTEN    0         70                       *:33060                  *:*                
LISTEN    0         151                      *:3306                   *:*          

设置zabbix的web页面
[root@zabbix-server ~]# cd zabbix-6.4.10/
[root@zabbix-server zabbix-6.4.10]# ls
aclocal.m4 compile config.sub depcomp Makefile missing
ui
AUTHORS conf configure include Makefile.am NEWS
bin config.guess configure.ac INSTALL Makefile.in README
build config.log COPYING install-sh man sass
ChangeLog config.status database m4 misc src
[root@zabbix-server zabbix-6.4.10]# cp -a ui/*
/usr/local/nginx/html
cp: overwrite '/usr/local/nginx/html/index.php'? y
[root@zabbix-server zabbix-6.4.10]# ls /usr/local/apache/htdocs/test/
api_jsonrpc.php conf include
report4.php
api_scim.php data index.html
robots.txt
app disc_prototypes.php index_http.php setup.php
assets favicon.ico index.php
sysmap.php
audio graphs.php index_sso.php
sysmaps.php
browserwarning.php history.php items.php
templates.php
chart2.php host_discovery.php js test
chart3.php hostinventoriesoverview.php jsLoader.php
toptriggers.php
chart4.php hostinventories.php jsrpc.php
tr_events.php
chart6.php host_prototypes.php local
trigger_prototypes.php
chart7.php httpconf.php locale
triggers.php
chart.php httpdetails.php map.php vendor
composer.json image.php modules widgets
composer.lock imgstore.php report2.php
zabbix.php
[root@localhost zabbix-6.4.10]# chown -R nginx.nginx /usr/local/nginx
[root@localhost zabbix-6.4.10]# chmod 777 /usr/local/nginx
[root@localhost zabbix-6.4.10]# ll /usr/local/apache/
total 40
drwxr-xr-x.  2 apache apache 4096 Jan  5 08:44 bin
drwxr-xr-x.  2 apache apache  167 Jan  5 08:44 build
drwxr-xr-x.  2 apache apache   78 Jan  5 08:44 cgi-bin
drwxr-xr-x.  4 apache apache   84 Jan  5 10:12 conf
drwxr-xr-x.  3 apache apache 4096 Jan  5 08:44 error
drwxr-xr-x.  3 apache apache   36 Jan  5 10:09 htdocs
drwxr-xr-x.  3 apache apache 8192 Jan  5 08:44 icons
drwxr-xr-x.  2 apache apache 4096 Jan  5 08:44 include
drwxr-xr-x.  2 apache apache   58 Jan  5 10:12 logs
drwxr-xr-x.  4 apache apache   30 Jan  5 08:44 man
drwxr-xr-x. 14 apache apache 8192 Jan  5 08:44 manual
drwxr-xr-x.  2 apache apache 4096 Jan  5 08:44 modules


重启apache
[root@zabbix-server zabbix-6.4.10]# systemctl restart httpd

访问web界面
在这里插入图片描述
在这里插入图片描述
设置web界面安装配置

[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# systemctl restart php-fpm

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

登录zabbix (账号:Admin 密码:zabbix)
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值