zabbix监控安装

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配置文件有两种:

  • 服务器端配置文件(/usr/local/etc/zabbix_server.conf)
  • 客户端配置文件(/usr/local/etc/zabbix_agentd.conf)
  • zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)
  • 服务器端配置文件zabbix_server.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

环境准备:

因为zabbix是用php语言开发的,所以部署zabbix前必须先部署lamp架构,使其能够支持运行php网页
环境IP要安装的应用
服务器192.168.10.131lamp架构、zabbix server 、zabbix agent
客户端192.168.10.132zabbix agent

zabbix服务端安装

关闭防火墙、SELINUX

[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled 

安装mariadb

1.安装依赖
[root@c83 ~]# 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
 
[root@c83 ~]# yum -y install http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/mariadb-connector-c-3.1.11-2.el8_3.x86_64.rpm
 
[root@c83 ~]# yum -y install 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
 
2.部署mariadb
[root@c83 ~]# wget 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@c83 ~]# rpm -ivh mariadb-10.5.9-1.module_el8.5.0+732+7afc82e7.x86_64.rpm
[root@c83 ~]# 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


3.启动服务,并查看服务状态已启动
systemctl enable --now mariadb
systemctl status mariadb

安装依赖包

yum -y install net-snmp-devel mysql-devel libevent-devel --allowerasing
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

下载zabbix至/usr/src目录并解压

官网地址:zabbix.com

wget https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.6.tar.gz
tar xf zabbix-6.4.6.tar.gz

创建账户

useradd -r -M -s /sbin/nologin zabbix

配置mysql,创建zabbix库,创建zabbix用户并自定义密码,授权用户权限,设置全局变量,刷新权限表

mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user 'zabbix'@'localhost' identified by '123456';
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
mysql> SET GLOBAL log_bin_trust_function_creators = 1;
mysql> flush privileges;
mysql> quit;

进入zabbix-6.4.6/database/mysql/这个目录

[root@localhost mysql]# pwd
/usr/src/zabbix-6.4.6/database/mysql
[root@localhost mysql]# ls  #在这里可以看到以下创建数据库后产生的文件
data.sql  double.sql  history_pk_prepare.sql  images.sql  Makefile.am  Makefile.in  schema.sql

配置导入表到zabbix的数据库中

[root@localhost mysql]# mysql -uzabbix -p123456 zabbix < schema.sql
[root@localhost mysql]# mysql -uzabbix -p123456 zabbix < images.sql
[root@localhost mysql]# mysql -uzabbix -p123456 --default-character-set=utf8mb4 zabbix < data.sql

进入mariadb

#查看zabbix数据库的表
MariaDB [(none)]> show tables from zabbix;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| auditlog                   |
| autoreg_host               |
| changelog                  |
| conditions                 |
| config                     |
| config_autoreg_tls         |
| connector                  |
......
| widget                     |
| widget_field               |
+----------------------------+
186 rows in set (0.001 sec)
#再把1改为0
MariaDB [(none)]> SET GLOBAL log_bin_trust_function_creators = 0;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> quit
Bye

导出环境变量

[root@localhost ~]# export CFLAGS="-std=gnu99"
开始编译安装zabbix
[root@localhost ~]# cd /usr/src/zabbix-6.4.6/
[root@localhost zabbix-6.4.6]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************
[root@localhost zabbix-6.4.6]# make install

安装完成后看到一些新的目录和文件

[root@localhost zabbix-6.4.6]# 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]# 

在zabbix服务的主配置文件中添加zabbix数据库中zabbix用户的密码

[root@localhost etc]# vim zabbix_server.conf
/DBUser
#
# Mandatory: no
# Default:
# DBUser=

DBUser=zabbix

### Option: DBPassword
#       Database password.
#       Comment this line if no password is used.
#
# Mandatory: no
# Default:
# DBPassword=
DBPassword=123456   #添加这一行密码是zabbix用户的密码

启动服务查看端口号

10051是服务端zabbix_server,10050是客户端zabbix_agent

[root@localhost etc]# zabbix_server
[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                    127.0.0.1:9000                   0.0.0.0:*                      
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            80                             *:3306                         *:*                      
LISTEN      0            128                            *:80                           *:*                      
LISTEN      0            128                         [::]:22                        [::]:*                      
LISTEN      0            128                         [::]:10050                     [::]:*                      
LISTEN      0            128                         [::]:10051                     [::]:*                      

将zabbix的网页文件复制到虚拟主机下

[root@localhost zabbix-6.4.6]# cp -a ui/* /usr/local/apache/htdocs/huangtianen.com/
cp: overwrite '/usr/local/httpd/htdocs/www.pupu.com/index.php'? y  #询问是否覆盖,y确认覆盖

将htdocs目录及以下的目录或文件的属主和属组设为apache用户

[root@localhost zabbix-6.4.6]# chown -R apache.apache /usr/local/apache/htdocs/

给予conf文件全部权限

[root@localhost zabbix-6.4.6]# chmod 777 /usr/local/apache/htdocs/huangtianen.com/conf

重启httpd

[root@localhost ~]# systemctl restart httpd

通过域名访问zabbix页面

在这里插入图片描述

此时只能显示页面但不能实现功能,继续下一步操作

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

然后重启php服务

[root@localhost zabbix-6.4.6]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

再次查看

要求全部ok,如果要求不满足需要到

在这里插入图片描述

下一步

在这里插入图片描述### 核对安装信息,下一步
在这里插入图片描述

安装成功

在这里插入图片描述

恢复之前的文件权限

[root@localhost zabbix-6.4.6]# chmod 755 /usr/local/apache/htdocs/huangtianen.com/conf

登录

zabbix默认登录用户名和密码:
用户名密码
Adminzabbix
在这里插入图片描述

zabbix监控的页面

在这里插入图片描述

最后设置zabbix的开启自启

首先是设置zabbix.server的文件

[root@localhost ~]# which zabbix_server
/usr/local/sbin/zabbix_server    #查看zabbix_server的环境变量文件

然后复制一份其他的配置文件

[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/zabbix_server.service 
[root@localhost ~]# vim /usr/lib/systemd/system/zabbix_server.service
[root@localhost ~]# cat /usr/lib/systemd/system/zabbix_server.service
[Unit]
Description=zabbix server daemon  #名字
After=network.target

[Service]
Type=forking    #类型
ExecStart=/usr/local/sbin/zabbix_server  #把启动服务的方式改为查看到的环境变量文件的位置,启动直击输入zabbix_server
ExecStop=pkill zabix_server              #停止服务,停止服务直接输入pkill zabix_server
ExecReload=/bin/kill -HUP $MAINPID       #重新加载

[Install]
WantedBy=multi-user.target

再配置zabbix.agent

[root@localhost ~]# cp /usr/lib/systemd/system/zabbix_server.service /usr/lib/systemd/system/zabbix_agentd.service   #直接复制zabbix_server.service文件

[root@localhost ~]# vim /usr/lib/systemd/system/zabbix_agentd.service
[root@localhost ~]# cat /usr/lib/systemd/system/zabbix_agentd.service
[Unit]
Description=zabbix agentd  #改描述
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/sbin/zabbix_agentd   #启动服务直接输入zabbix_agentd
ExecStop=pkill zabbix_agentd              #停止服务直接输入pkill zabbix_agentd
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

查看端口

[root@localhost ~]# ss -antl
State       Recv-Q       Send-Q             Local Address:Port             Peer Address:Port      Process      
LISTEN      0            128                    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            128                            *:80                          *:*                      
LISTEN      0            128                         [::]:22                       [::]:*                      

启动服务

[root@localhost etc]# zabbix_server 
[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                    127.0.0.1:9000                   0.0.0.0:*                      
LISTEN      0           128                      0.0.0.0:22                     0.0.0.0:*                      
LISTEN      0           128                         [::]:10050                     [::]:*                      
LISTEN      0           128                         [::]:10051                     [::]:*                      
LISTEN      0           80                             *:3306                         *:*                      
LISTEN      0           128                            *:80                           *:*                      
LISTEN      0           128                         [::]:22                        [::]:*                      

停止服务

[root@localhost ~]# pkill 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:10050                  0.0.0.0:*                      
LISTEN      0           128                    127.0.0.1:9000                   0.0.0.0:*                      
LISTEN      0           128                      0.0.0.0:22                     0.0.0.0:*                      
LISTEN      0           128                         [::]:10050                     [::]:*                      
LISTEN      0           80                             *:3306                         *:*                      
LISTEN      0           128                            *:80                           *:*                      
LISTEN      0           128                         [::]:22                        [::]:*                      
[root@localhost ~]# 

开机自启

[root@localhost ~]# systemctl enable --now zabbix_server
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix_server.service → /usr/lib/systemd/system/zabbix_server.service.
[root@localhost ~]# systemctl enable --now zabbix_agentd
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix_agentd.service → /usr/lib/systemd/system/zabbix_agentd.service.

查看

[root@localhost ~]# systemctl status zabbix_server
[root@localhost ~]# systemctl status zabbix_agentd

Created symlink /etc/systemd/system/multi-user.target.wants/zabbix_server.service → /usr/lib/systemd/system/zabbix_server.service.
[root@localhost ~]# systemctl enable --now zabbix_agentd
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix_agentd.service → /usr/lib/systemd/system/zabbix_agentd.service.


### 查看

[root@localhost ~]# systemctl status zabbix_server
[root@localhost ~]# systemctl status zabbix_agentd


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值