zabbix

关于作者

周李杰,最后一批90后,现居湖北武汉

孤独患者,懒癌中期,无脑幻想者。但却人畜无害,无需远离。

兴趣众多,然无一精通。正努力成为一个有趣的人。

1
2
> print("👆以上是不完整的我") //请我吃大餐将会了解更多
>

[TOC]

zabbix

官方网站:zabbix

zabbix([`zæbiks])是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。

zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。

zabbix由2部分构成,zabbix server与可选组件zabbix agent。

zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。

zabbix(音同 zæbix)是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。

zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。

zabbix由2部分构成,zabbix server与可选组件zabbix agent

zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。

zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。

zabbix server可以单独监视远程服务器的服务状态;同时也可以与zabbix agent配合,可以轮询zabbix agent主动接收监视数据(trapping方式),同时还可被动接收zabbix agent发送的数据(trapping方式)。

zabbix主要特点

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

zabbix主要功能

  • CPU负荷
  • 内存使用
  • 磁盘使用
  • 网络状况
  • 端口监视
  • 日志监视
  • 插件开发自定义

zabbix运行机制

Zabbix Server 和 Zabbix agent

Zabbix Server 可以通过 SNMP,Zabbix agent,Ping,端口监视等你方法提供对远程服务器/网络状态的 监视,数据收集功能,可以在运行 Linux,Solaris,HP-UX,AIX,FreeBSD,OpenBSD,OX X,Windows 多 平台。

Zabbix Agent 安装在需要被监控的目标服务器上,主要完成对硬件信息与操作系统有关的内存,CPU 等你 信息收集。

Zabbix Server 可以单独监视远程服务器的服务状态,同时也可以与 Zabbix Agent 结合。可以轮询 Zabbix Agent 主动接收监视数据(trapping 传递 方式),同时还可以被动接收 Zabbix Agent 发送的数据。

zabbix运行过程图

Zabbix 支持多种网络方式下的监控,可以通过分布式的部署和安装监控代理 Zabbix,通过 C/S 模式采集数据,通过 B/S 模式在 Web 端展示和配置!Agent 监控端口 10050

服务端安装 Zabbix Server 和 Zabbix Agent 两个服务,客户端只安装 Zabbix Agent 一个服务,监控原理 就是 Zabbix Agent 服务将从系统中获取的相关数据传送给 Zabbix Server,然后 Zabbix Server 服务奖数据分 析之后以 PHP 页面展示出来!

源码编译LNMP

如果不知道LNMP是什么的,可以看下这篇博文:搭建LNMP

搭建网易yum源

此处如果不搭建网易的yum源,后面安装依赖包有一个在本地yum源中是没有的

1
2
3
4
[root@server222 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@server222 ~]# cd /etc/yum.repos.d/
[root@server222 yum.repos.d]# yum clean all
[root@server222 yum.repos.d]# yum makecache

zabbix安装

安装依赖包

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

上传zabbix源码包到/usr/local/src/目录

源码包:

链接:https://pan.baidu.com/s/1g2fs-4VRmsnjk1egj9VQJQ
提取码:euq4
复制这段内容后打开百度网盘手机App,操作更方便哦

解压zabbix

1
2
[root@server222 ~]# cd /usr/local/src/
[root@server222 src]# tar -zxvf zabbix-4.0.3.tar.gz

创建用户

1
2
[root@server222 src]# groupadd zabbix
[root@server222 src]# useradd -s /sbin/nologin -g zabbix zabbix

配置zabbix数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[root@server222 src]# mysql -uroot -p123456
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 13
Server version: 5.6.19 Source distribution

Copyright (c) 2000, 2014, 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;
Query OK, 1 row affected (0.02 sec)

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

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

mysql> exit
Bye

[root@server222 src]# cd zabbix-4.0.3/
[root@server222 zabbix-4.0.3]# mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
Warning: Using a password on the command line interface can be insecure.
[root@server222 zabbix-4.0.3]# mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql
Warning: Using a password on the command line interface can be insecure.
[root@server222 zabbix-4.0.3]# mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql
Warning: Using a password on the command line interface can be insecure.
[root@server222 zabbix-4.0.3]#

编译安装zabbix

1
2
[root@server222 mysql]# cd /usr/local/src/zabbix-4.0.3/
[root@server222 zabbix-4.0.3]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl

如果出现这样一个界面就表示编译完成

1
2
3
4
5
6
7
8
9
> 
> ***********************************************************
> * Now run 'make install' *
> * *
> * Thank you for using Zabbix! *
> * <http://www.zabbix.com> *
> ***********************************************************
>
>
1
[root@server222 zabbix-4.0.3]# make install

编译成功会产生

1
2
[root@server222 zabbix-4.0.3]# ls /usr/local/zabbix/
bin etc lib sbin share

配置zabbix

1
2
3
4
5
6
7
8
9
[root@server222 zabbix-4.0.3]# vim /usr/local/zabbix/etc/zabbix_server.conf

85 DBHost=localhost

94 DBName=zabbix

110 DBUser=zabbix

118 DBPassword= zabbix
1
2
3
4
5
6
7
8
9
[root@server222 zabbix-4.0.3]# vim /usr/local/zabbix/etc/zabbix_agentd.conf

94 Server=127.0.0.1

135 ServerActive=127.0.0.1

146 Hostname=Zabbix server

281 UnsafeUserParameters=1

启动zabbix

1
2
3
4
5
[root@server222 zabbix-4.0.3]# /usr/local/zabbix/sbin/zabbix_server
[root@server222 zabbix-4.0.3]# /usr/local/zabbix/sbin/zabbix_agentd
[root@server222 zabbix-4.0.3]# netstat -antup | grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 120622/zabbix_agent
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 120471/zabbix_serve

server 运行端口 10051

或者脚本启动zabbix

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@server222 etc]# cd /usr/local/src/zabbix-4.0.3/misc/init.d/
[root@server222 init.d]# cp fedora/core/* /etc/rc.d/init.d/
[root@server222 init.d]# vim /etc/init.d/zabbix_server
# BASEDIR=/usr/local/zabbix #找到此行,并修改
21 # Zabbix-Directory
22 BASEDIR=/usr/local/zabbix
[root@server222 init.d]# vim /etc/init.d/zabbix_agentd
# BASEDIR=/usr/local/zabbix #找到此行,并修改
21 # Zabbix-Directory
22 BASEDIR=/usr/local/zabbix
[root@server222 init.d]# /etc/init.d/zabbix_agentd start
Reloading systemd: [ 确定 ]
Starting zabbix_agentd (via systemctl): [ 确定 ]
[root@server222 init.d]# /etc/init.d/zabbix_server start
Starting zabbix_server (via systemctl): [ 确定 ]
[root@server222 init.d]# chkconfig zabbix_server on
[root@server222 init.d]# chkconfig zabbix_agentd on

zabbix的web界面

编辑PHP页面

1
2
3
4
5
6
7
[root@server222 etc]# cd /usr/local/src/zabbix-4.0.3/
[root@server222 zabbix-4.0.3]# cp -r /usr/local/src/zabbix-4.0.3/frontends/php/* /usr/local/nginx/html/
[root@server222 zabbix-4.0.3]# vim /usr/local/nginx/conf/nginx.conf
43 location / {
44 root html;
45 index index.html index.htm index.php;
46 }

重启nginx服务与php-fpm服务

1
2
3
4
5
[root@server222 zabbix-4.0.3]# /usr/local/nginx/sbin/nginx -s reload;
[root@server222 zabbix-4.0.3]# /etc/init.d/zabbix_server restart
[root@server222 init.d]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done

火狐浏览器打开输入:192.168.176.222/index.php

点击下一步

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@server222 zabbix-4.0.3]# vim /usr/local/php/etc/php.ini
375 max_execution_time = 300
.......
385 max_input_time = 300
.......
663 post_max_size = 16M
.......
689 always_populate_raw_post_data = On
.......
913 date.timezone = Asia/Shanghai
.......
1188 mysqli.default_socket = /var/lib/mysql/mysql.sock
[root@server222 zabbix-4.0.3]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done

将页面刷新

1
2
3
4
5
6
7
8
9
10
[root@server222 zabbix-4.0.3]# cd /usr/local/src/php-5.5.14/ext/
[root@server222 ext]# cd ldap/
[root@server222 ldap]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212
[root@server222 ldap]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-ldap
........
configure: error: Cannot find ldap libraries in /usr/lib.

此时会提醒报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@server222 ldap]# yum install openldap-devel openldap -y
[root@server222 ldap]# rsync -avz /usr/lib64/libldap* /usr/lib/
sending incremental file list
libldap-2.3.so.0 -> libldap-2.3.so.0.2.31
libldap-2.3.so.0.2.31
libldap-2.4.so.2 -> libldap-2.4.so.2.10.7
libldap-2.4.so.2.10.7
libldap.so -> libldap-2.4.so.2.10.7
libldap_r-2.3.so.0 -> libldap_r-2.3.so.0.2.31
libldap_r-2.3.so.0.2.31
libldap_r-2.4.so.2 -> libldap_r-2.4.so.2.10.7
libldap_r-2.4.so.2.10.7
libldap_r.so -> libldap_r-2.4.so.2.10.7

sent 564824 bytes received 106 bytes 1129860.00 bytes/sec
total size is 1277076 speedup is 2.26

这时我们再进行编译

1
2
[root@server222 ldap]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-ldap
[root@server222 ldap]# make ; make install
1
2
3
4
5
6
7
[root@server222 ldap]# vim /usr/local/php/etc/php.ini
# 在文件的末尾处添加
1940 extension=ldap.so

[root@server222 ldap]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done

然后点击下一步

1
密码:zabbix

然后点击下一步

先点击Download the configuration file下载文件

我下载之后在下载目录里面

1
[root@server222 下载]# mv zabbix.conf.php /usr/local/nginx/html/conf/zabbix.conf.php

然后我们点击刷新

然后点击下一步

1
使用admin账号登陆,密码zabbix

点击登陆

1
点击右上角用户,进行更改语言

》 点击人头像,再点击Language,选择中文,最后点击update

最后的界面

打赏
  • © 2019-2020 Li Jie
  • Powered by Hexo Theme Ayer
    • PV:
    • UV:

喜欢就打赏吧~

支付宝
微信