监控服务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等通知功能

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.110.21lamp架构
zabbix server
zabbix agent
客户端192.168.110.20zabbix agent

4.1 zabbix服务端安装

//安装依赖包
[root@lw ~]# yum -y install net-snmp-devel libevent-devel
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
base                                                         | 3.6 kB  00:00:00     
centosplus                                                   | 3.4 kB  00:00:00     
epel/x86_64/metalink                                         | 8.9 kB  00:00:00     
epel                                                         | 4.7 kB  00:00:00     
extras                                                       | 3.4 kB  00:00:00    
...
...
作为依赖被升级:
  elfutils-libelf.x86_64 0:0.172-2.el7     elfutils-libs.x86_64 0:0.172-2.el7       
  libdb.x86_64 0:5.3.21-24.el7             libdb-utils.x86_64 0:5.3.21-24.el7       
  rpm.x86_64 0:4.11.3-35.el7               rpm-build-libs.x86_64 0:4.11.3-35.el7    
  rpm-libs.x86_64 0:4.11.3-35.el7          rpm-python.x86_64 0:4.11.3-35.el7        

完毕!

//下载zabbix
使用wget下载zabbix的安装包

//解压
[root@lw ~]# ls
all-201902211500.mysql        index.html
anaconda-ks.cfg               table-from-liuwei-201902211503.mysql
db-liuwei-201902211506.mysql  test.sh
httpd-2.4.34                  zabbix-3.4.12.tar.gz
[root@lw ~]# tar -xf zabbix-3.4.12.tar.gz 

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

//配置zabbix数据库
[root@lw ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.23-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 on zabbix.* to zabbix@localhost identified by 'lw1234';
Query OK, 0 rows affected, 2 warnings (0.19 sec)

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

[root@lw ~]# cd zabbix-3.4.12/database/mysql/
[root@lw mysql]# ls
data.sql  images.sql  schema.sql
[root@lw mysql]# mysql -uzabbix -plw1234 zabbix < schema.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1050 (42S01) at line 1: Table 'users' already exists
[root@lw mysql]# mysql -uzabbix -plw1234 zabbix < images.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1146 (42S02) at line 1: Table 'zabbix.images' doesn't exist
[root@lw mysql]# mysql -uzabbix -plw1234 zabbix < data.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1146 (42S02) at line 67: Table 'zabbix.graph_theme' doesn't exist
[root@lw zabbix-3.4.12]# ./configure --enable-server \
> --enable-agent \
> --with-mysql \
> --with-net-snmp \
> --with-libcurl \
> --with-libxml2
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
configure: Configuring Zabbix 3.4.12
checking whether make sets $(MAKE)... (cached) yes
...
...
***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <http://www.zabbix.com>                    *
***********************************************************

//编译zabbix
[root@lw zabbix-3.4.12]# make install
Making install in src
make[1]: 进入目录“/root/zabbix-3.4.12/src”
Making install in libs
make[2]: 进入目录“/root/zabbix-3.4.12/src/libs”
Making install in zbxcrypto
make[3]: 进入目录“/root/zabbix-3.4.12/src/libs/zbxcrypto”
gcc -DHAVE_CONFIG_H -I. -I../../../include     -g -O2  -MT libzbxcrypto_a-md5.o -MD -MP -MF .deps/libzbxcrypto_a-md5.Tpo -c -o libzbxcrypto_a-md5.o `test -f 'md5.c' || echo './'`md5.c
...
...
make[2]: 对“install-exec-am”无需做任何事。
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/root/zabbix-3.4.12”
make[1]: 离开目录“/root/zabbix-3.4.12”

4.2 zabbix服务端配置

[root@lw zabbix-3.4.12]# ls /usr/local/etc/
zabbix_agentd.conf  zabbix_agentd.conf.d  zabbix_server.conf  zabbix_server.conf.d

//修改服务端配置文件
//设置数据库信息
[root@lw zabbix-3.4.12]# vim /usr/local/etc/zabbix_server.conf
DBPassword=lw1234

//启动zabbix_server和zabbix_agentd
[root@lw zabbix-4.0.3]#  zabbix_server
[root@lw zabbix-4.0.3]# zabbix_agentd
[root@lw zabbix-4.0.3]# ss -anlt
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      5              *:873                        *:*                  
LISTEN     0      128           :::80                        :::*                  
LISTEN     0      32            :::21                        :::*                  
LISTEN     0      128           :::22                        :::*                  
LISTEN     0      100          ::1:25                        :::*                  
LISTEN     0      5             :::873                       :::*                  
LISTEN     0      80            :::3306                      :::*    

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

4.3.1 zabbix web界面安装前配置

//修改/etc/php.ini的配置并重启php-fpm
[root@lw zabbix-4.0.3]# vim /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
[root@lw zabbix-4.0.3]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done
[root@lw 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@lw zabbix-4.0.3]# mkdir /usr/local/apache/htdocs/zabbix
[root@lw zabbix-4.0.3]# cp -a frontends/php/* /usr/local/apache/htdocs/zabbix/
[root@lw zabbix-4.0.3]# chown -R apache.apache /usr/local/apache/htdocs/

//配置apache虚拟主机
[root@lw zabbix-4.0.3]# tail -15 /etc/httpd24/httpd.conf
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/zabbix"
    ServerName zabbix.liuwei.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@lw zabbix-4.0.3]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@lw zabbix-4.0.3]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx 2 apache apache 81 12月 20 19:24 /usr/local/apache/htdocs/zabbix/conf

//重启apache
[root@lw zabbix-4.0.3]# apachectl -t
Syntax OK
[root@lw zabbix-4.0.3]# apachectl restart
[root@lw zabbix-4.0.3]# ss -anlt
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      5              *:873                        *:*                  
LISTEN     0      128           :::80                        :::*                  
LISTEN     0      32            :::21                        :::*                  
LISTEN     0      128           :::22                        :::*                  
LISTEN     0      100          ::1:25                        :::*                  
LISTEN     0      5             :::873                       :::*                  
LISTEN     0      80            :::3306                      :::*               

4.3.2 安装zabbix web界面

  • 修改/etc/hosts文件,添加域名与IP的映射
  • 在浏览器上访问域名,本文设置的域名为zabbix.wliuwei.com,你需要修改成你自己的域名
  • 恢复zabbix/conf目录的权限#为755
    在这里插入图片描述
    在浏览器上用域名或者ip访问
    在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述
    恢复zabbix/conf目录的权限为755:
[root@lw zabbix-4.0.3]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@lw zabbix-4.0.3]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxr-xr-x 2 apache apache 104 2月  22 16:24 /usr/local/apache/htdocs/zabbix/conf

4.4 登录zabbix

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

用户名密码
Adminzabbix

总结:部署zabbix监控要先部署lamp架构,才能
运行PHP网页

  • 9
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值