ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

监控服务zabbix部署

2019-08-29 20:03:00  阅读:362  来源: 互联网

标签:conf 部署 lihuaixin zabbix usr 监控 root LISTEN


文章目录

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

2. zabbix特点

zabbix的主要特点:

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

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 设置服务端监听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 设置客户端日志文件存放路径

4.部署zabbix

环境说明

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

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

4.1 zabbix服务端安装

安装依赖包
[root@lihuaixin ~]# yum -y install net-snmp-devel libevent-devel
安装过程省略...

下载zabbix到/usr/src
[root@lihuaixin src]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz
下载过程省略
如不行直接去官网下载www.zabbix.com

解压
[root@lihuaixin src]# tar xf zabbix-4.0.3.tar.gz

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


配置zabbix数据库
[root@lihuaixin ~]# mysql -uroot -pqiaoben
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123!';
Query OK, 0 rows affected, 2 warnings (0.00 sec)

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

把zabbix自带的备份导入数据库

注意一定要按照顺序导入
先导入schema.sql,再导入images.sql,最后data.sql

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

查看恢复的数据(ps恢复的只有表结构)

[root@lihuaixin mysql]# mysql -uzabbix -pzabbix123!
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.22 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| zabbix             |
+--------------------+
2 rows in set (0.01 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                     |
| application_discovery      |
| application_prototype      |
| application_template       |
| applications               |
| auditlog                   |
| auditlog_details           |
| autoreg_host               |
| conditions                 |
| config                     |
| 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             |
| 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        |
| item_application_prototype |
| item_condition             |
| item_discovery             |
| item_preproc               |
| items                      |
| items_applications         |
| maintenance_tag            |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| mappings                   |
| media                      |
| media_type                 |
| 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                     |
| 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_remote_command        |
| task_remote_command_result |
| timeperiods                |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemaps                  |
| widget                     |
| widget_field               |
+----------------------------+
144 rows in set (0.01 sec)

编译安装zabbix

[root@lihuaixin ~]# cd /usr/src/zabbix-4.0.3
[root@lihuaixin zabbix-4.0.3]# ./configure --enable-server \
 --enable-agent \
 --with-mysql \
 --with-net-snmp \
 --with-libcurl \
 --with-libxml2
编译过程省略....

[root@lihuaixin zabbix-4.0.3]# make install

4.2 zabbix服务端配置

[root@lihuaixin ~]# ls /usr/local/etc/
zabbix_agentd.conf  zabbix_agentd.conf.d  zabbix_server.conf  zabbix_server.conf.d
[root@lihuaixin ~]# vim /usr/local/etc/zabbix_server.conf
如果都是按照上面配置的那就只需要给DBPassword加上zabbix数据库的密码
DBPassword=zabbix123!  
# 设置zabbix数据库连接密码

启动zabbix_server和zabbix_agentd

[root@lihuaixin ~]# zabbix_server 
[root@lihuaixin ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128           *:22                        *:*                  
LISTEN      0      100    127.0.0.1:25                        *:*                  
LISTEN      0      128           *:10051                     *:*                  
LISTEN      0      128    127.0.0.1:9000                      *:*                  
LISTEN      0      128          :::80                       :::*                  
LISTEN      0      128          :::22                       :::*                  
LISTEN      0      100         ::1:25                       :::*                  
LISTEN      0      80           :::3306                     :::*                  
[root@lihuaixin ~]# zabbix_agentd 
[root@lihuaixin ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128           *:22                        *:*                  
LISTEN      0      100    127.0.0.1:25                        *:*                  
LISTEN      0      128           *:10050                     *:*                  
LISTEN      0      128           *:10051                     *:*                  
LISTEN      0      128    127.0.0.1:9000                      *:*                  
LISTEN      0      128          :::80                       :::*                  
LISTEN      0      128          :::22                       :::*                  
LISTEN      0      100         ::1:25                       :::*                  
LISTEN      0      80           :::3306                     :::*

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

4.3.1 zabbix web界面安装前配置

修改/etc/php.ini的配置并重启php-fpm

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

配置apach虚拟主机

[root@lihuaixin ~]# vim /etc/httpd24/httpd.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName www.qiaoben.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>

配置了虚拟机后在/usr/local/apache/htdocs/下创建zabbix目录
[root@lihuaixin ~]# cd /usr/src/zabbix-4.0.3
[root@lihuaixin zabbix-4.0.3]# ls
aclocal.m4  compile        config.sub    depcomp     m4           misc     src
AUTHORS     conf           configure     frontends   Makefile     missing
bin         config.guess   configure.ac  include     Makefile.am  NEWS
build       config.log     COPYING       INSTALL     Makefile.in  README
ChangeLog   config.status  database      install-sh  man          sass
[root@lihuaixin zabbix-4.0.3]# mkdir /usr/local/apache/htdocs/zabbix
[root@lihuaixin zabbix-4.0.3]# \cp -r frontends/php/* /usr/local/apache/htdocs/zabbix/

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

[root@lihuaixin ~]# chmod 777 /usr/local/apache/htdocs/zabbix/co
conf/            conf.import.php  correlation.php  
[root@lihuaixin ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@lihuaixin ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwsrwx 2 root apache 81 8月  21 19:10 /usr/local/apache/htdocs/zabbix/conf

重启apache

[root@lihuaixin ~]# apachectl -t
Syntax OK
[root@lihuaixin ~]# apachectl stop
[root@lihuaixin ~]# apachectl start
[root@lihuaixin ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128           *:22                        *:*                  
LISTEN      0      100    127.0.0.1:25                        *:*                  
LISTEN      0      128           *:10050                     *:*                  
LISTEN      0      128           *:10051                     *:*                  
LISTEN      0      128    127.0.0.1:9000                      *:*                  
LISTEN      0      128          :::80                       :::*                  
LISTEN      0      128          :::22                       :::*                  
LISTEN      0      100         ::1:25                       :::*                  
LISTEN      0      80           :::3306                     :::*

4.3.2 安装zabbix web界面

  • 有必要时可以修改/etc/hosts文件,来添加域名与ip的映射
    这里我们直接用ip
  • 恢复zabbix/conf目录的权限为755

在浏览器上访问域名进行安装:
在浏览器上访问域名进行安装:在这里插入图片描述在这里插入图片描述在这里插入图片描述name为默认的直接进入

在这里插入图片描述恢复zabbix/conf目录的权限为755:

[root@lihuaixin ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@lihuaixin ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxr-sr-x 2 root apache 104 8月  21 19:33 /usr/local/apache/htdocs/zabbix/conf

4.4 登录zabbix

zabbix默认登录用户和密码:

用户名 密码
Admin zabbix

5 客户端操作

安装依赖包

[root@qiaobenhuannai ~]# yum -y install net-snmp-devel libevent-devel

下载zabbix包

[root@qiaobenhuannai src]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz
[root@qiaobenhuannai src]# ls
debug  kernels  zabbix-4.0.3.tar.gz
[root@qiaobenhuannai src]# tar xf zabbix-4.0.3.tar.gz

创建zabbix用户和组

[root@qiaobenhuannai ~]# groupadd -r zabbix
[root@qiaobenhuannai ~]# useradd -r -M -s /sbin/nologin -g zabbix zabbix

配置安装zabbix

[root@qiaobenhuannai zabbix-4.0.3]# ./configure --enable-agent
[root@qiaobenhuannai zabbix-4.0.3]# make install
[root@qiaobenhuannai ~]# ls /usr/local/etc/
zabbix_agentd.conf  zabbix_agentd.conf.d

修改配置文件
修改以下配置:

[root@qiaobenhuannai ~]# vim /usr/local/etc/zabbix_agentd.conf
 Server=192.168.199.173   #
 修改为服务端ip
 ServerActive=192.168.199.173   
 #主动模式
 Hostname=777 
 #此主机名不是客户端主机名

启动zabbix_agentd

[root@qiaobenhuannai ~]# zabbix_agentd 
[root@qiaobenhuannai ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128           *:111                       *:*                  
LISTEN      0      128           *:22                        *:*                  
LISTEN      0      100    127.0.0.1:25                        *:*                  
LISTEN      0      128           *:10050                     *:*                  
LISTEN      0      128          :::111                      :::*                  
LISTEN      0      128          :::22                       :::*                  
LISTEN      0      100         ::1:25                       :::*

在zabbix里添加客户端
在这里插入图片描述
在这里插入图片描述

标签:conf,部署,lihuaixin,zabbix,usr,监控,root,LISTEN
来源: https://blog.csdn.net/kiyomi_de/article/details/99987280

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有