zabbix监控服务

zabbix监控服务

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

常用的监控软件:

cacti(仙人掌): 擅长画图,流量图,架构图,不擅长告警

普罗米修斯 prometheus (大型公司用)

Nagios:只擅长告警,配置非常麻烦

zabbix:结合了cacti和ngios的特点,配置简单,有web界面 ,zabbix也可以画图,但是画的图很丑,所以要用一个插件来画图(grafna)插件

zabbix支持的通知机制: 发邮件,微信(公众号),短信,打电话,声音报警

zabbix sever不能安装在windows上监控硬件设备 IPMI (传感)

zabbix监控指标:

  • 系统监控:

​ cpu 内存 硬盘

  • 网络监控:

​ 网卡 流量 网络设备(路由器,交换机)

  • 业务监控:

​ 端口 进程 日志

  • 硬件监控:

​ 温度 数量

zabbix服务端安装 agent 收集客户端的信息,并监控本机

10050 是服务端的zabbix_ agentd的端口

10051是服务端的zabbix_server 的端口

zabbix特点

zabbix的主要特点:

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

Zabbix主要功能:

  • CPU负荷

  • 内存使用

  • 磁盘使用

  • 网络状况

  • 端口监视

  • 日志监视

    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设置客户端日志文件存放路径
zabbix安装(服务端)
系统安装
CentOS8 server安装zabbix之前需要lamp架构支持,安装: httpd版本2.4.48,MySQL版本5.7.34 php版本7.4.24; zabbix版本5.4.4
CentOS8 clientzabbix agent

安装lamp略,之前的文章有写到,现在需要安装的是服务端的 zabbix,客户端的zabbix不需要lamp架构支持

安装依赖包

[root@localhost ~]# yum -y install net-snmp-devel libevent-devel make gcc gcc-c++ wget 

下载zabbix软件(官网zabbix.com)

wget https://cdn.zabbix.com/zabbix/sources/stable/5.4/zabbix-5.4.4.tar.gz 

解压zabbix软件

[root@localhost ~]# tar xf zabbix-5.4.4.tar.gz -C /usr/local/

创建zabbix用户

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

查看端口正常运行

[root@server local]# 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                            *:*                        

登录数据库,配置zabbix数据库

[root@server local]# mysql -uroot -p123456
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.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> create database zabbix character set utf8 collate utf8_bin;  //创建zabbix库
Query OK, 1 row affected (0.00 sec)

mysql> create user 'zabbix(用户)'@'localhost' identified by 'zabbix'(密码);  //创建zabbix用户
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost'; //授权给zabbix用户
mysql> flush privileges;   //刷新权限
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| zabbix             |
+--------------------+
5 rows in set (0.00 sec)
mysql> exit
Bye

导入数据到zabbix库

[root@server local]# ls
apache     apr-util        etc           include  libexec                              php-7.4.24  share
apr        apr-util-1.6.1  games         lib      mysql                                php7        src
apr-1.7.0  bin             httpd-2.4.48  lib64    mysql-5.7.34-linux-glibc2.12-x86_64  sbin        zabbix-5.4.4
[root@server local]# cd zabbix-5.4.4/
[root@server zabbix-5.4.4]# ls
AUTHORS    INSTALL      NEWS        bin      conf          configure     depcomp     m4    missing  ui
COPYING    Makefile.am  README      build    config.guess  configure.ac  include     man   sass
ChangeLog  Makefile.in  aclocal.m4  compile  config.sub    database      install-sh  misc  src
[root@server zabbix-5.4.4]# cd database/
[root@server database]# ls
Makefile.am  Makefile.in  elasticsearch  mysql  oracle  postgresql  sqlite3

[root@server database]# cd mysql/
[root@server mysql]# ls
Makefile.am  Makefile.in  data.sql  double.sql  images.sql  schema.sql

//导入时顺序一点不能错
[root@server mysql]# mysql -uroot -p123456  zabbix < schema.sql    //导入架构 
mysql: [Warning] Using a password on the command line interface can be insecure.

[root@server mysql]# mysql -uroot -p123456  zabbix < images.sql   //再导入images
mysql: [Warning] Using a password on the command line interface can be insecure.

[root@server mysql]# mysql -uroot -p123456  zabbix < data.sql    //最后导入数据
mysql: [Warning] Using a password on the command line interface can be insecure.


//登录数据库查看
[root@server mysql]# mysql -uroot -p123456
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 9
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| zabbix             |
+--------------------+
5 rows in set (0.00 sec)

mysql> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |

........

| widget_field               |
+----------------------------+
166 rows in set (0.00 sec)
mysql> exit
Bye

编译安装zabbix

[root@server ~]# cd /usr/local/zabbix-5.4.4/
[root@server zabbix-5.4.4]# ./configure --enable-server \   (打开sever)
--enable-agent \   (打开agent代理)                                         
--with-mysql \       (用数据库)
--with-net-snmp \
--with-libcurl \
--with-libxml2
.......
  IPv6 support:          no

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************
[root@server zabbix-5.4.4]# make install  //安装
Making install in src
make[1]: Entering directory '/usr/local/zabbix-5.4.4/src'
Making install in libs
make[2]: Entering directory '/usr/local/zabbix-5.4.4/src/libs'
Making install in zbxcrypto

......

make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/usr/local/zabbix-5.4.4'
make[1]: Leaving directory '/usr/local/zabbix-5.4.4'
[root@server zabbix-5.4.4]# 

zabbix服务端配置(修改配置文件)

[root@server zabbix-5.4.4]# 
[root@server zabbix-5.4.4]# cd /usr/local/etc
[root@server etc]# ls
zabbix_agentd.conf  zabbix_agentd.conf.d  zabbix_server.conf  zabbix_server.conf.d

[root@server etc]# vim zabbix_server.conf
....
115 DBUser=zabbix
116 
117 ### Option: DBPassword
118 #       Database password.
119 #       Comment this line if no password is used.
120 #
121 # Mandatory: no
122 # Default:
123  DBPassword=zabbix    //取消注释,写入数据库中创建zabbix用户时设置的密码
......

//创建一个软连接,将MySQL配置文件中设置的路径/tmp/mysql.sock套接字链接到/var/lib/mysql/,不然zabbix起不来
[root@server ~]# mkdir /var/lib/mysql   
[root@server ~]# ln -s /tmp/mysql.sock /var/lib/mysql/  //创建软连接

[root@server ~]# zabbix_server    //启动zabbix_server
[root@server ~]# zabbix_agentd   //启动zabbix_agentd
[root@server ~]# 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                                 *:*

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

zabbix web界面安装前配置

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

[root@server ~]# mkdir /usr/local/apache/htdocs/zabbix //创建一个访问web界面的目录
[root@server ~]# cp -r /usr/local/zabbix-5.4.4/ui/* /usr/local/apache/htdocs/zabbix/ //将zabbix web界面的文件放进去
[root@server ~]# chown -R apache.apache /usr/local/apache/htdocs


//配置apache虚拟主机
[root@server ~]# vim /usr/local/apache/conf/httpd.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName www.po.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix
    <Directory "/usr/local/apache/htdocs/zabbix">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php


[root@server ~]# ll -d /usr/local/apache/htdocs/zabbix/conf  //查看原来的权限
drwxr-xr-x. 3 apache apache 117 Sep 26 07:56 /usr/local/apache/htdocs/zabbix/conf

[root@server ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf  //修改权限
[root@server ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx. 3 apache apache 94 Sep 26 07:57 /usr/local/apache/htdocs/zabbix/conf

重启httpd,访问zabbixWeb界面进行安装

[root@server ~]# systemctl restart httpd.service

开始安装 zabbix web界面
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
Web界面安装完zabbix后,恢复之前的权限

[root@server ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@server ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxr-xr-x. 3 apache apache 117 Sep 26 08:09 /usr/local/apache/htdocs/zabbix/conf

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值