zabbix

1. 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)等配合使用。

2. zabbix特点

zabbix的主要特点:

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

监控指标

  • 系统监控
    • 内存使用率
    • 硬盘使用率
    • cpu使用率
  • 网络监控
    • 流量
    • 网卡
  • 硬件监控
    • 电源
    • cpu温度
    • 硬盘温度
  • 业务监控

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 设置服务端监听
IPListenPort 设置服务端监听的端口号
PidFile 设置服务端进程号文件存放路径
DBHost 指定zabbix的数据库服务器I
PDBName 指定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 设置客户端日志文件存放路径

4. 部署zabbix

环境说明:

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

基于lamp

[root@mr ~]# cd /etc/yum.repos.d/
[root@mr yum.repos.d]# ls
CentOS-Stream-AppStream.repo  CentOS-Stream-HighAvailability.repo
CentOS-Stream-BaseOS.repo     CentOS-Stream-Media.repo
CentOS-Stream-Debuginfo.repo  CentOS-Stream-PowerTools.repo
CentOS-Stream-Extras.repo     CentOS-Stream-RealTime.repo
[root@mr yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2495  100  2495    0     0   7252      0 --:--:-- --:--:-- --:--:--  7231
[root@mr yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@mr yum.repos.d]# ls
CentOS-Base.repo              CentOS-Stream-HighAvailability.repo
CentOS-Stream-AppStream.repo  CentOS-Stream-Media.repo
CentOS-Stream-BaseOS.repo     CentOS-Stream-PowerTools.repo
CentOS-Stream-Debuginfo.repo  CentOS-Stream-RealTime.repo
CentOS-Stream-Extras.repo
[root@mr yum.repos.d]# dnf clean all
Failed to set locale, defaulting to C.UTF-8
Repository extras is listed more than once in the configuration
36 files removed
[root@mr yum.repos.d]# dnf makecache
Failed to set locale, defaulting to C.UTF-8
Repository extras is listed more than once in the configuration
CentOS-8.5.2111 - Base - mirrors.aliyun.com   204 kB/s | 4.6 MB     00:22    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com  18 kB/s |  10 kB     00:00    
CentOS-8.5.2111 - AppStream - mirrors.aliyun. 105 kB/s | 8.4 MB     01:22    
CentOS Stream 8 - AppStream                   8.4 MB/s |  25 MB     00:02    
CentOS Stream 8 - BaseOS                      4.1 MB/s |  25 MB     00:06    
Last metadata expiration check: 0:00:01 ago on Thu Sep  1 16:17:43 2022.
Metadata cache created.
[root@mr ~]# dnf -y module install mariadb*
[root@mr ~]# dnf -y module install php:7.4
[root@mr ~]# dnf install -y httpd
[root@mr ~]# cp /usr/share/doc/httpd/httpd-vhosts.conf /etc/httpd/conf.d/
[root@mr ~]# vim /etc/httpd/conf.d/httpd-vhosts.conf 
<VirtualHost *:80>
    DocumentRoot "/var/www/html/zabbix.example.com"
    ServerName zabbix.example.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/zabbix.example.com/$1
    <Directory "/var/www/html/zabbix.example.com">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
    ErrorLog "/var/log/httpd/zabbix.example.com-error_log"
    CustomLog "/var/log/httpd/zabbix.example.com-access_log" common
</VirtualHost>
[root@mr ~]# vim /etc/httpd/conf/httpd.conf
DirectoryIndex indexphp index.html
 AddType application/x-httpd-php .php
 AddType application/x-httpd-php-source .phps
 [root@mr ~]# cd /var/www/html/
[root@mr html]# mkdir zabbix.example.com
[root@mr html]# ls
doudizhu  zabbix.example.com  zhuawawa
[root@mr html]# cd zabbix.example.com/
[root@mr zabbix.example.com]# vim index.php
<?
    php phpinfo(); 
?>
[root@mr zabbix.example.com]# cd
[root@mr ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@mr ~]# systemctl enable --now mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@mr ~]# systemctl enable --now php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@mr ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.9-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 password = password ('123456');
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> quit
Bye
[root@mr ~]# vim /etc/php-fpm.d/www.conf
listen = 0.0.0.0:9000
[root@mr ~]# systemctl restart php-fpm
[root@mr ~]# 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:9000              0.0.0.0:*                  
LISTEN    0          128                        *:80                      *:*                  
LISTEN    0          128                     [::]:22                   [::]:*                  
LISTEN    0          80                         *:3306                    *:*                  
[root@mr ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@mr ~]# setenforce 0
[root@mr ~]# vim /etc/selinux/config
SELINUX=disabled

部署zabbix
[root@mr ~]# dnf install -y net-snmp-devel libevent-devel gcc gcc-c++ make libxml2-devel libcurl-devel pcre-devel openssl openssl-devel mysql-devel php-bcmath php-gd php-mysqlnd wget
[root@mr ~]# cd /usr/src/
[root@mr src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.2.tar.gz
[root@mr src]# useradd -r -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
[root@mr src]#  mkdir -p /usr/lib/zabbix
[root@mr src]# chmod 770 /usr/lib/zabbix
[root@mr src]# chown -R zabbix.zabbix /usr/lib/zabbix
[root@mr src]# mysql -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.9-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)]> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.010 sec)

MariaDB [(none)]> create user 'zabbix'@'localhost' identified by 'zabbix123!'
    -> ;
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> SET GLOBAL log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> quit
Bye
[root@mr src]# cd zabbix-6.2.2/database/mysql/
[root@mr mysql]# mysql -uroot -p123456 zabbix < schema.sql
[root@mr mysql]# mysql -uroot -p123456 zabbix < images.sql
[root@mr mysql]# mysql -uroot -p123456 zabbix < data.sql
[root@mr mysql]# mysql -uroot -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.5.9-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)]> 
[root@mr ~]# cd /usr/src/zabbix-6.2.2
[root@mr zabbix-6.2.2]# ./configure --enable-server --enable-agent --with-mysql --with-libcurl --with-libxml2
.....
***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

[root@mr zabbix-6.2.2]# make install
[root@mr zabbix-6.2.2]# cd /usr/local/etc/
[root@mr etc]# vim zabbix_server.conf
DBPassword=zabbix123!
[root@mr etc]# zabbix_server
[root@mr etc]# zabbix_agentd 
[root@mr 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         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                  0.0.0.0:9000               0.0.0.0:*                  
LISTEN    0         128                        *:80                       *:*                  
LISTEN    0         128                     [::]:22                    [::]:*                  
LISTEN    0         80                         *:3306                     *:*                  
[root@mr ~]# cd /usr/src/zabbix-6.2.2
[root@mr zabbix-6.2.2]# cp -a ui/* /var/www/html/zabbix.example.com/
cp: overwrite '/var/www/html/zabbix.example.com/index.php'? y
[root@mr zabbix-6.2.2]# chown -R apache.apache /var/www/html
[root@mr zabbix-6.2.2]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@mr zabbix-6.2.2]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@mr zabbix-6.2.2]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@mr zabbix-6.2.2]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@mr zabbix-6.2.2]# systemctl restart php-fpm




posted @   溜溜威  阅读(133)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示