监控服务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)等配合使用。

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

环境说明:

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

因为zabbix是用php语言开发的,所以必须先部署lamp架构,使其能够支持运行php网页

zabbix服务端安装

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

//解压zabbix软件包
[root@mf ~]# tar xf zabbix-5.2.6.tar.gz 

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

//配置zabbix数据库
[root@mf ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.31 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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.01 sec)

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

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

mysql> quit
Bye

[root@mf ~]# cd zabbix-5.2.6/database/mysql/
[root@mf mysql]# ls
data.sql    images.sql   Makefile.in
double.sql  Makefile.am  schema.sql
[root@mf mysql]# ll
total 13384
-rw-r--r--. 1 1000 1000 11535807 Mar 29 17:21 data.sql
-rw-r--r--. 1 1000 1000      282 Mar 29 17:02 double.sql
-rw-r--r--. 1 1000 1000  1978341 Mar 29 16:33 images.sql
-rw-r--r--. 1 1000 1000      482 Mar 29 17:02 Makefile.am
-rw-r--r--. 1 1000 1000    15982 Mar 29 17:21 Makefile.in
-rw-r--r--. 1 1000 1000   160579 Mar 29 17:21 schema.sql

//将schema.spl,images.spl,data.spl导入数据库
[root@mf mysql]# mysql -uroot -p zabbix < schema.sql
Enter password: 
[root@mf mysql]# mysql -uroot -p zabbix < images.sql
Enter password: 
[root@mf mysql]# mysql -uroot -p zabbix < data.sql
Enter password: 
[root@mf mysql]# 

[root@mf mysql]# mysql -uroot -p
Enter password: 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| zabbix             |
+--------------------+
5 rows in set (0.00 sec)

mysql> use zabbix
Database changed
mysql> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| config_autoreg_tls         |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dashboard                  |
| dashboard_user             |
| dashboard_usrgrp           |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_suppress             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| history                    |
| history_log                |
| history_str                |
| history_text               |
| history_uint               |
| host_discovery             |
| host_inventory             |
| host_tag                   |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| hstgrp                     |
| httpstep                   |
| httpstep_field             |
| httpstepitem               |
| httptest                   |
| httptest_field             |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| interface_snmp             |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| item_parameter             |
| item_preproc               |
| item_rtdata                |
| items                      |
| items_applications         |
| lld_macro_path             |
| lld_override               |
| lld_override_condition     |
| lld_override_opdiscover    |
| lld_override_operation     |
| lld_override_ophistory     |
| lld_override_opinventory   |
| lld_override_opperiod      |
| lld_override_opseverity    |
| lld_override_opstatus      |
| lld_override_optag         |
| lld_override_optemplate    |
| lld_override_optrends      |
| maintenance_tag            |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| media_type_message         |
| media_type_param           |
| module                     |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| rights                     |
| role                       |
| role_rule                  |
| screen_user                |
| screen_usrgrp              |
| screens                    |
| screens_items              |
| scripts                    |
| service_alarms             |
| services                   |
| services_links             |
| services_times             |
| sessions                   |
| slides                     |
| slideshow_user             |
| slideshow_usrgrp           |
| slideshows                 |
| sysmap_element_trigger     |
| sysmap_element_url         |
| sysmap_shape               |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| tag_filter                 |
| task                       |
| task_acknowledge           |
| task_check_now             |
| task_close_problem         |
| task_data                  |
| task_remote_command        |
| task_remote_command_result |
| task_result                |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_queue              |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
| widget                     |
| widget_field               |
+----------------------------+
170 rows in set (0.00 sec)

//编译安装zabbix
[root@mf zabbix-5.2.6]# ./configure --enable-server 
> --enable-agent 
> --with-mysql 
> --with-net-snmp 
> --with-libcurl 
> --with-libxml2
。。。。。。。
 Configuration file:    /usr/local/etc/zabbix_agentd.conf
    Modules:               /usr/local/lib/modules

  Enable agent 2:        no

  Enable Java gateway:   no

  LDAP support:          no
  IPv6 support:          no

[root@mf zabbix-5.2.6]# make install

zabbix服务端配置

//在zabbix_server.conf文件里输入zabbix密码
[root@mf ~]# vim /usr/local/etc/zabbix_server.conf
。。。。。。
DBUser=zabbix

### Option: DBPassword
#       Database password.
#       Comment this line if no password is used.
#
# Mandatory: no
# Default:
DBPassword=123456

//把zabbix_server干掉然后再启动
[root@mf ~]# ps -ef|grep zabbix
zabbix    24714      1  0 16:27 ?        00:00:00 zabbix_server
root      24806   2310  0 16:37 pts/2    00:00:00 grep --color=auto zabbix
[root@mf ~]# pkill zabbix
[root@mf ~]# ps -ef|grep zabbix
root      24809   2310  0 16:38 pts/2    00:00:00 grep --color=auto zabbix
[root@mf ~]# zabbix_server
[root@mf ~]# ss -antl
State  Recv-Q  Send-Q      Local Address:Port      Peer Address:Port  
LISTEN 0       128               0.0.0.0:22             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                  [::]:22                [::]:*     
LISTEN 0       80                      *:3306                 *:*     

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

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

zabbix web界面安装前配置

[root@mf ~]# cd /usr/local/apache/htdocs/
[root@mf htdocs]# ls
index.html  index.php
[root@mf htdocs]# mkdir zabbix
[root@mf htdocs]# ls
index.html  index.php  zabbix

[root@mf ui]# pwd
/root/zabbix-5.2.6/ui
[root@mf ui]# cp -r * /usr/local/apache/htdocs/zabbix/
[root@mf htdocs]# ls zabbix/
actionconf.php               index.php
api_jsonrpc.php              index_sso.php
app                          items.php
assets                       js
。。。。。。

//设置属组
[root@mf htdocs]# chown -R apache.apache zabbix/
[root@mf htdocs]# ll
total 12
-rw-r--r--.  1 apache apache   45 Jun 12  2007 index.html
-rw-r--r--.  1 apache apache   24 Apr  6 19:36 index.php
drwxr-xr-x. 12 apache apache 4096 Apr  7 16:56 zabbix

//配置虚拟主机
[root@mf htdocs]# vim ../conf/extra/vhosts.conf 

<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName www.mufeng.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*.php)$ fcgi://192.168.186.130: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@mf zabbix]# chmod 777 conf
[root@mf zabbix]# ll -d conf
drwxrwxrwx. 3 apache apache 94 Apr  7 16:56 conf

//重启apache
[root@mf ui]# apachectl -t
Syntax OK
[root@mf ui]# apachectl restart
httpd not running, trying to start
[root@mf ui]# ss -antl
State  Recv-Q  Send-Q      Local Address:Port      Peer Address:Port  
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                  [::]:22                [::]:*     
LISTEN 0       80                      *:3306                 *:*     
LISTEN 0       128                     *:80                   *:*     
[root@mf ~]# sed -ri 's/(post_max_size =).*/1 16M/g' /etc/php.ini
[root@mf ~]# sed -ri 's/(max_execution_time =).*/1 300/g' /etc/php.ini
[root@mf ~]# sed -ri 's/(max_input_time =).*/1 300/g' /etc/php.ini
[root@mf ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@mf ~]# ss -antl
State  Recv-Q  Send-Q      Local Address:Port      Peer Address:Port  
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                  [::]:22                [::]:*     
LISTEN 0       80                      *:3306                 *:*     
LISTEN 0       128                     *:80                   *:*    
//设置zabbix_agentd和zabbix_server开机自动启动
[root@mf ~]# cd zabbix-5.2.6/misc/init.d/fedora/core5/
[root@mf core5]# ls
zabbix_agentd  zabbix_server
[root@mf core5]# cp -a zabbix_agentd /etc/init.d/
[root@mf core5]# cp -a zabbix_server /etc/init.d/
[root@mf core5]# chkconfig --add zabbix_server 
[root@mf core5]# chkconfig zabbix_server on
[root@mf core5]# chkconfig --list|grep zabbix_server 

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

zabbix_server      0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@mf core5]# chkconfig --add zabbix_agentd 
[root@mf core5]# chkconfig zabbix_agentd on
[root@mf core5]# chkconfig --list|grep zabbix_agentd 

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

zabbix_agentd      0:off    1:off    2:on    3:on    4:on    5:on    6:off

安装zabbix web界面

这里出现了报错,

解决办法:关闭SElinux

原文地址:https://www.cnblogs.com/mfdsg/p/14629159.html