欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Linux监控服务之zabbix使用

程序员文章站 2022-03-10 16:16:46
1. zabbix介绍Zabbix 是由 Alexei Vladishev 开发的一种网络监视、管理系统,基于 Server-Client 架构。可用于监视各种网络服务、服务器和网络机器等状态。使用各种Database-end 如 MySQL, PostgreSQL, SQLite, Oracle或IBM DB2储存资料。Server 端基于 C语言、Web 管理端 frontend则是基于 PHP 所制作的。Zabbix可以使用多种方式监视。可以只使用 Simple Check 不需要安装 Clien...

1. zabbix介绍

Zabbix 是由 Alexei Vladishev 开发的一种网络监视、管理系统,基于 Server-Client 架构。可用于监视各种网络服务、服务器和网络机器等状态。

使用各种Database-end 如 MySQL, PostgreSQL, SQLite, OracleIBM DB2储存资料。Server 端基于 C语言、Web 管理端 frontend 则是基于 PHP 所制作的。Zabbix可以使用多种方式监视。可以只使用 Simple Check 不需要安装 Client 端,亦可基于 SMTP 或 HTTP … 各种协定做死活监视。

在客户端如 UNIX, Windows 中安装 Zabbix Agent 之后,可监视 CPU Load、网络使用状况、硬盘容量等各种状态。而就算没有安装 Agent在监视对象中,Zabbix也可以经由 SNMP、TCP、ICMP、利用 IPMI、SSH、telnet 对目标进行监视。

另外,Zabbix 包含 XMPP等各种 Item 警示功能。

2.zabbix特点

zabbix的主要特点:

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

Zabbix主要功能:

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

3.zabbix的架构组成

Linux监控服务之zabbix使用
1)zabbix server:负责接收agent发送的报告信息的核心组件,所有配置、统计数据及操作数据都由它组织进行;

2)database storage:专用于存储所有配置信息,以及由zabbix收集的数据;

3)web interface:zabbix的GUI接口;

4)proxy:可选组件,常用于监控节点很多的分布式环境中,代理server收集部分数据转发到server,可以减轻server的压力;

5)agent:部署在被监控的主机上,负责收集主机本地数据如cpu、内存、数据库等数据发往server端或proxy端;

4.Zabbix 构建监控系统过程

Linux监控服务之zabbix使用
agentd需要安装到被监控的主机上,它负责定期收集各项数据,并发送到zabbix server端,zabbix server将数据存储到数据库中,zabbix web根据数据在前端进行展现和绘图。这里agentd收集数据分为主动和被动两种模式:

主动:agent请求server获取主动的监控项列表,并主动将监控项内需要检测的数据提交给server/proxy

被动:server向agent请求获取监控项的数据,agent返回数据。

5.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
UserParameter 指定自定义监控脚本参数
LogFile 设置客户端日志文件存放路径

6.部署zabbix

环境说明:

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

6.1 zabbix服务端安装

zabbix下载地址

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

//下载zabbix 
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://cdn.zabbix.com/zabbix/sources/stable/4.4/zabbix-4.4.7.tar.gz

//解压
[root@longnian src]# tar xf zabbix-4.4.7.tar.gz

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

//配置zabbix数据库
[root@longnian ~]# mysql -uroot -plongnian123.
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 3
Server version: 5.7.24-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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.05 sec)

mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'longnian123.';
Query OK, 0 rows affected, 2 warnings (0.00 sec)

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

mysql> quit
Bye

[root@longnian ~]# cd /usr/src/zabbix-4.4.7/database/mysql/
[root@longnian mysql]# ls
data.sql  images.sql  Makefile.am  Makefile.in  schema.sql
[root@longnian mysql]# mysql -uzabbix -plongnian123. zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@longnian mysql]# mysql -uzabbix -plongnian123. zabbix < images.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@longnian mysql]# mysql -uzabbix -plongnian123. zabbix < data.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.

//编译安装zabbix
[root@longnian ~]# cd /usr/src/zabbix-4.4.7
[root@longnian zabbix-4.4.7]#  ./configure --enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2

[root@longnian zabbix-4.4.7]#  make install

6.2 zabbix服务端配置

//修改服务端配置文件
//设置数据库信息
[root@longnian ~]# vim /usr/local/etc/zabbix_server.conf

DBPassword=longnian123.       //设置zabbix数据库连接密码

[root@longnian ~]# find / -name libmysqlclient.so.20
/usr/local/mysql-5.7.24-linux-glibc2.12-x86_64/lib/libmysqlclient.so.20
[root@longnian ~]# echo "/usr/local/mysql/lib" >> /etc/ld.so.conf
[root@longnian ~]# ldconfig

//启动zabbix_server和zabbix_agentd
[root@longnian ~]# zabbix_server
[root@longnian ~]# zabbix_agentd 
[root@longnian ~]# ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     127.0.0.1:9000                        *:*                  
LISTEN      0      128             *:111                         *:*                  
LISTEN      0      128             *:20048                       *:*                  
LISTEN      0      128             *:51733                       *:*                  
LISTEN      0      128             *:22                          *:*                  
LISTEN      0      100     127.0.0.1:25                          *:*                  
LISTEN      0      64              *:60377                       *:*                  
LISTEN      0      128             *:3260                        *:*                  
LISTEN      0      64              *:2049                        *:*                  
LISTEN      0      128             *:10050                       *:*                  
LISTEN      0      128             *:10051                       *:*                  
LISTEN      0      80             :::3306                       :::*                  
LISTEN      0      128            :::58251                      :::*                  
LISTEN      0      128            :::111                        :::*                  
LISTEN      0      128            :::80                         :::*                  
LISTEN      0      128            :::20048                      :::*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      100           ::1:25                         :::*                  
LISTEN      0      128            :::3260                       :::*                  
LISTEN      0      64             :::34462                      :::*                  
LISTEN      0      64             :::2049                       :::*

6.3 zabbix客户端配置

//安装同上
//编译
[root@longnian zabbix-4.4.7]#  ./configure --enable-agent
[root@longnian zabbix-4.4.7]#  make install

//修改客户端配置文件
[root@longnian etc]# vim zabbix_agentd.conf
[root@longnian etc]# useradd -r -M -s /sbin/nologin zabbix
[root@longnian etc]# zabbix_agentd
[root@longnian etc]# ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     127.0.0.1:9000                        *:*                  
LISTEN      0      128             *:111                         *:*                  
LISTEN      0      128             *:20048                       *:*                  
LISTEN      0      128             *:40500                       *:*                  
LISTEN      0      128             *:22                          *:*                  
LISTEN      0      100     127.0.0.1:25                          *:*                  
LISTEN      0      64              *:51295                       *:*                  
LISTEN      0      64              *:2049                        *:*                  
LISTEN      0      128             *:10050                       *:*                  
LISTEN      0      128            :::43560                      :::*                  
LISTEN      0      80             :::3306                       :::*                  
LISTEN      0      128            :::111                        :::*                  
LISTEN      0      128            :::80                         :::*                  
LISTEN      0      128            :::20048                      :::*                  
LISTEN      0      64             :::37233                      :::*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      100           ::1:25                         :::*                  
LISTEN      0      64             :::2049                       :::*                  

6.4 zabbix服务端web界面安装与配置

6.4.1zabbix web界面安装前配置

//修改/etc/php.ini的配置并重启php-fpm
[root@longnian ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@longnian ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@longnian ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@longnian ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@longnian ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

[root@longnian ~]# cd /usr/src/zabbix-4.4.7
[root@longnian zabbix-4.4.7]# mkdir /usr/local/apache/htdocs/zabbix
[root@longnian zabbix-4.4.7]# cp -a frontends/php/* /usr/local/apache/htdocs/zabbix/
[root@longnian zabbix-4.4.7]# chown -R apache.apache /usr/local/apache/htdocs

//配置apache虚拟主机
//在配置文件的末尾加如下内容
[root@longnian ~]# vim /etc/httpd24/httpd.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName www.longniand.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
    <Directory "/usr/local/apache/htdocs/zabbix">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

//设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@longnian ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx 2 apache apache 78 3月  23 17:01 /usr/local/apache/htdocs/zabbix/conf

//重启apache
[root@longnian ~]# apachectl stop
[root@longnian ~]# apachectl start
[root@longnian ~]# ss -anlt
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     127.0.0.1:9000                        *:*                  
LISTEN      0      128             *:111                         *:*                  
LISTEN      0      128             *:20048                       *:*                  
LISTEN      0      128             *:51733                       *:*                  
LISTEN      0      128             *:22                          *:*                  
LISTEN      0      100     127.0.0.1:25                          *:*                  
LISTEN      0      64              *:60377                       *:*                  
LISTEN      0      128             *:3260                        *:*                  
LISTEN      0      64              *:2049                        *:*                  
LISTEN      0      128             *:10050                       *:*                  
LISTEN      0      128             *:10051                       *:*                  
LISTEN      0      80             :::3306                       :::*                  
LISTEN      0      128            :::58251                      :::*                  
LISTEN      0      128            :::111                        :::*                  
LISTEN      0      128            :::80                         :::*                  
LISTEN      0      128            :::20048                      :::*                  
LISTEN      0      128            :::22                         :::*                  
LISTEN      0      100           ::1:25                         :::*                  
LISTEN      0      128            :::3260                       :::*                  
LISTEN      0      64             :::34462                      :::*                  
LISTEN      0      64             :::2049                       :::*                  

6.4.2安装zabbix web界面

  • 修改/etc/hosts文件,添加域名与IP的映射
  • 在浏览器*问
  • 恢复zabbix/conf目录的权限为755
    Linux监控服务之zabbix使用
    Linux监控服务之zabbix使用
    Linux监控服务之zabbix使用
    Linux监控服务之zabbix使用
    Linux监控服务之zabbix使用
    Linux监控服务之zabbix使用
    Linux监控服务之zabbix使用
    恢复zabbix/conf目录的权限为755:
[root@longnian ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf

6.5登录zabbix

zabbix默认登录用户名和密码:

用户名 密码
Admin zabbix

Linux监控服务之zabbix使用

本文地址:https://blog.csdn.net/DragonYear/article/details/107345173