Linux监控平台搭建(一)

Name Version
Centos 7 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
zabbix zabbix-3.4.2
mysql mysql-5.6.35
httpd httpd-2.4.33
php php-7.1.6

Linux监控平台介绍

常见开源监控软件

  • cacti、nagios、zabbix、smokeping、open-falcon等等

  • cacti、smokeping偏向于基础监控,成图非常漂亮

  • cacti、nagios、zabbix服务端监控中心,需要php环境支持,其中zabbix和cacti都需要mysql作为数据存储,nagios不用存储历史数据,注重服务或者监控项的状态,zabbix会获取服务或者监控项目的数据,会把数据记录到数据库里,从而可以成图

  • open-falcon为小米公司开发,开源后受到诸多大公司和运维工程师的追捧,适合大企业,滴滴、360、新浪微博、京东等大公司在使用这款监控软件,值得研究

  • 后续以介绍zabbix为主

zabbix监控介绍

  • C/S架构,基于C++开发,监控中心支持web界面配置和管理

  • 单server节点可以支持上万台客户端

  • 最新版本3.4,官方文档https://www.zabbix.com/manuals

  • 5个组件

  • zabbix-server 监控中心,接收客户端上报信息,负责配置、统计、操作数据

  • 数据存储 存放数据,比如mysql

  • web界面 也叫web UI,在web界面下操作配置是zabbix简单易用的主要原因

  • zabbix-proxy 可选组件,它可以代替zabbix-server的功能,减轻server的压力

  • zabbix-agent 客户端软件,负责采集各个监控服务或项目的数据,并上报

yum安装出现问题(未知原因,估计是网站有时段限制,拒接连接导致)

源码安装zabbix

zabbix系统基于PHP环境运行,所以前提是系统上有PHP的运行环境,lnmp或者lamp环境。

1、下载源码包

  [root@zyshanlinux-001 src]# wget -O zabbix-3.4.2.tar.gz http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.2/zabbix-3.4.2.tar.gz/download

2、安装依赖库

  [root@zyshanlinux-001 src]# yum -y install net-snmp-devel libxml2-devel libcurl-deve libevent libevent-devel

3、解压包

  [root@zyshanlinux-001 src]# ls
  zabbix-3.4.2.tar.gz
  ​
  [root@zyshanlinux-001 src]# tar -zxf zabbix-3.4.2.tar.gz
  [root@zyshanlinux-001 src]# ls
  zabbix-3.4.2                             zabbix-3.4.2.tar.gz
   

4、编译

  [root@zyshanlinux-001 src]# cd zabbix-3.4.2
  [root@zyshanlinux-001 zabbix-3.4.2]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
  ...
  config.status: creating src/zabbix_java/Makefile
  config.status: creating upgrades/Makefile
  config.status: creating man/Makefile
  config.status: creating include/config.h
  config.status: executing depfiles commands
  ​
  ​
  Configuration:
  ​
    Detected OS:           linux-gnu
    Install path:          /usr/local/zabbix
    Compilation arch:      linux
  ​
    Compiler:              gcc
    Compiler flags:         -g -O2 
  ​
    Library-specific flags:
      database:               -I/usr/local/mysql/include  -fPIC  -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing   
      libXML2:               -I/usr/include/libxml2
      Net-SNMP:               -I/usr/local/include -I/usr/lib64/perl5/CORE -I. -I/usr/include
  ​
    Enable server:         yes
    Server details:
      With database:         MySQL
      WEB Monitoring:        cURL
      Native Jabber:         no
      SNMP:                  yes
      IPMI:                  no
      SSH:                   no
      TLS:                   no
      ODBC:                  no
      Linker flags:             -L/usr/local/mysql/lib        -L/usr/lib64       -rdynamic   
      Libraries:               -lmysqlclient      -lxml2    -lnetsnmp   -levent    -lcurl -lm -ldl  -lresolv -lpcreposix -lpcre 
  ​
    Enable proxy:          no
  ​
    Enable agent:          yes
    Agent details:
      TLS:                   no
      Linker flags:              -rdynamic   
      Libraries:                 -lcurl -lm -ldl  -lresolv -lpcreposix -lpcre 
  ​
    Enable Java gateway:   no
  ​
    LDAP support:          no
    IPv6 support:          yes
  ​
  ***********************************************************
  *            Now run 'make install'                       *
  *                                                         *
  *            Thank you for using Zabbix!                  *
  *              <http://www.zabbix.com>                    *
  ***********************************************************
  ​

5、安装

  [root@zyshanlinux-001 zabbix-3.4.2]# make && make install

6、卸载

隔天yum恢复正常(未知原因,估计是网站有时段限制,拒接连接导致),把源码安装卸载,在make install目录下

  [root@zyshanlinux-001 zabbix-3.4.2]# make uninstall

yum安装zabbix

官网下载地址 www.zabbix.com/download

  [root@zyshanlinux-001 src]# wget https://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm

安装该rpm包

  [root@zyshanlinux-001 src]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
  警告:zabbix-release-3.2-1.el7.noarch.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
  准备中...                          ################################# [100%]
  正在升级/安装...
     1:zabbix-release-3.2-1.el7         ################################# [100%]

安装了zabbix的rpm包后,其实就是多了一个yum源,多了一个zabbix.repo文件

  [root@zyshanlinux-001 yum.repos.d]# ls
  CentOS7-Base-163.repo  CentOS-Media.repo    epel-testing.repo  remi-glpi93.repo  remi-php72.repo  zabbix.repo
  CentOS-CR.repo         CentOS-Sources.repo  nux-dextop.repo    remi-php54.repo   remi-php73.repo
  CentOS-Debuginfo.repo  CentOS-Vault.repo    remi-glpi91.repo   remi-php70.repo   remi.repo
  CentOS-fasttrack.repo  epel.repo            remi-glpi92.repo   remi-php71.repo   remi-safe.repo

文件zabbix.repo的内容

  [root@zyshanlinux-001 yum.repos.d]# cat /etc/yum.repos.d/zabbix.repo 
  [zabbix]
  name=Zabbix Official Repository - $basearch
  baseurl=http://repo.zabbix.com/zabbix/3.2/rhel/7/$basearch/
  enabled=1
  gpgcheck=1
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
  ​
  [zabbix-non-supported]
  name=Zabbix Official Repository non-supported - $basearch 
  baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
  enabled=1
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
  gpgcheck=1

在zabbix源中需要安装的包

zabbix-agent #客户端软件zabbix-get #服务端的工具,可以以命令行的形式获取客户端采集的数据zabbix-server-mysql #与mysql相关的文件zabbix-web #web UIzabbix-web-mysql #web与mysql相关的文件

安装上面的包

  [root@zyshanlinux-001 ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
  已加载插件:fastestmirror
  base                                                                                     | 3.6 kB  00:00:00     
  epel/x86_64/metalink                                                                     | 7.5 kB  00:00:00     
  extras                                                                                   | 3.4 kB  00:00:00     
  updates                                                                                  | 3.4 kB  00:00:00     
  zabbix                                                                                   | 2.9 kB  00:00:00     
  zabbix-non-supported                                                                     |  951 B  00:00:00     
  (1/2): zabbix/x86_64/primary_db                                                          |  93 kB  00:00:01     
  (2/2): updates/7/x86_64/primary_db                                                       | 4.3 MB  00:00:12     
  zabbix-non-supported/x86_64/primary                                                      | 1.6 kB  00:00:00     
  Loading mirror speeds from cached hostfile
   * base: mirrors.163.com
   * epel: mirrors.tongji.edu.cn
   * extras: mirrors.163.com
   * updates: linux.cs.nctu.edu.tw
  zabbix-non-supported                                                                                        4/4
  正在解决依赖关系
  --> 正在检查事务
  ---> 软件包 zabbix-agent.x86_64.0.3.4.11-1.el7 将被 安装
  ---> 软件包 zabbix-get.x86_64.0.3.4.11-1.el7 将被 安装
  ---> 软件包 zabbix-server-mysql.x86_64.0.3.4.11-1.el7 将被 安装
  --> 正在处理依赖关系 fping,它被软件包 zabbix-server-mysql-3.4.11-1.el7.x86_64 需要
  --> 正在处理依赖关系 libiksemel.so.3()(64bit),它被软件包 zabbix-server-mysql-3.4.11-1.el7.x86_64 需要
  --> 正在处理依赖关系 libOpenIPMIposix.so.0()(64bit),它被软件包 zabbix-server-mysql-3.4.11-1.el7.x86_64 需要
  --> 正在处理依赖关系 libOpenIPMI.so.0()(64bit),它被软件包 zabbix-server-mysql-3.4.11-1.el7.x86_64 需要
  --> 正在处理依赖关系 libodbc.so.2()(64bit),它被软件包 zabbix-server-mysql-3.4.11-1.el7.x86_64 需要
  ---> 软件包 zabbix-web.noarch.0.3.4.11-1.el7 将被 安装
  --> 正在处理依赖关系 php >= 5.4,它被软件包 zabbix-web-3.4.11-1.el7.noarch 需要
  --> 正在处理依赖关系 httpd,它被软件包 zabbix-web-3.4.11-1.el7.noarch 需要
  --> 正在处理依赖关系 php-gd,它被软件包 zabbix-web-3.4.11-1.el7.noarch 需要
  --> 正在处理依赖关系 php-mbstring,它被软件包 zabbix-web-3.4.11-1.el7.noarch 需要
  --> 正在处理依赖关系 dejavu-sans-fonts,它被软件包 zabbix-web-3.4.11-1.el7.noarch 需要
  --> 正在处理依赖关系 php-bcmath,它被软件包 zabbix-web-3.4.11-1.el7.noarch 需要
  --> 正在处理依赖关系 php-ldap,它被软件包 zabbix-web-3.4.11-1.el7.noarch 需要
  --> 正在处理依赖关系 php-xml,它被软件包 zabbix-web-3.4.11-1.el7.noarch 需要
  ---> 软件包 zabbix-web-mysql.noarch.0.3.4.11-1.el7 将被 安装
  --> 正在处理依赖关系 php-mysql,它被软件包 zabbix-web-mysql-3.4.11-1.el7.noarch 需要
  --> 正在检查事务
  ---> 软件包 OpenIPMI-libs.x86_64.0.2.0.23-2.el7 将被 安装
  --> 正在处理依赖关系 OpenIPMI-modalias = 2.0.23-2.el7,它被软件包 OpenIPMI-libs-2.0.23-2.el7.x86_64 需要
  ---> 软件包 dejavu-sans-fonts.noarch.0.2.33-6.el7 将被 安装
  --> 正在处理依赖关系 dejavu-fonts-common = 2.33-6.el7,它被软件包 dejavu-sans-fonts-2.33-6.el7.noarch 需要
  ---> 软件包 fping.x86_64.0.3.10-4.el7 将被 安装
  ---> 软件包 httpd.x86_64.0.2.4.6-80.el7.centos.1 将被 安装
  --> 正在处理依赖关系 httpd-tools = 2.4.6-80.el7.centos.1,它被软件包 httpd-2.4.6-80.el7.centos.1.x86_64 需要
  --> 正在处理依赖关系 /etc/mime.types,它被软件包 httpd-2.4.6-80.el7.centos.1.x86_64 需要
  --> 正在处理依赖关系 libaprutil-1.so.0()(64bit),它被软件包 httpd-2.4.6-80.el7.centos.1.x86_64 需要
  --> 正在处理依赖关系 libapr-1.so.0()(64bit),它被软件包 httpd-2.4.6-80.el7.centos.1.x86_64 需要
  ---> 软件包 iksemel.x86_64.0.1.4-2.el7.centos 将被 安装
  --> 正在处理依赖关系 libgnutls.so.28(GNUTLS_1_4)(64bit),它被软件包 iksemel-1.4-2.el7.centos.x86_64 需要
  --> 正在处理依赖关系 libgnutls.so.28()(64bit),它被软件包 iksemel-1.4-2.el7.centos.x86_64 需要
  ---> 软件包 php.x86_64.0.5.4.16-45.el7 将被 安装
  --> 正在处理依赖关系 php-common(x86-64) = 5.4.16-45.el7,它被软件包 php-5.4.16-45.el7.x86_64 需要
  --> 正在处理依赖关系 php-cli(x86-64) = 5.4.16-45.el7,它被软件包 php-5.4.16-45.el7.x86_64 需要
  ---> 软件包 php-bcmath.x86_64.0.5.4.16-45.el7 将被 安装
  ---> 软件包 php-gd.x86_64.0.5.4.16-45.el7 将被 安装
  --> 正在处理依赖关系 libt1.so.5()(64bit),它被软件包 php-gd-5.4.16-45.el7.x86_64 需要
  ---> 软件包 php-ldap.x86_64.0.5.4.16-45.el7 将被 安装
  ---> 软件包 php-mbstring.x86_64.0.5.4.16-45.el7 将被 安装
  ---> 软件包 php-mysql.x86_64.0.5.4.16-45.el7 将被 安装
  --> 正在处理依赖关系 php-pdo(x86-64) = 5.4.16-45.el7,它被软件包 php-mysql-5.4.16-45.el7.x86_64 需要
  ---> 软件包 php-xml.x86_64.0.5.4.16-45.el7 将被 安装
  ---> 软件包 unixODBC.x86_64.0.2.3.1-11.el7 将被 安装
  --> 正在检查事务
  ---> 软件包 OpenIPMI-modalias.x86_64.0.2.0.23-2.el7 将被 安装
  ---> 软件包 apr.x86_64.0.1.4.8-3.el7_4.1 将被 安装
  ---> 软件包 apr-util.x86_64.0.1.5.2-6.el7 将被 安装
  ---> 软件包 dejavu-fonts-common.noarch.0.2.33-6.el7 将被 安装
  ---> 软件包 gnutls.x86_64.0.3.3.26-9.el7 将被 安装
  --> 正在处理依赖关系 trousers >= 0.3.11.2,它被软件包 gnutls-3.3.26-9.el7.x86_64 需要
  --> 正在处理依赖关系 libnettle.so.4()(64bit),它被软件包 gnutls-3.3.26-9.el7.x86_64 需要
  --> 正在处理依赖关系 libhogweed.so.2()(64bit),它被软件包 gnutls-3.3.26-9.el7.x86_64 需要
  ---> 软件包 httpd-tools.x86_64.0.2.4.6-80.el7.centos.1 将被 安装
  ---> 软件包 mailcap.noarch.0.2.1.41-2.el7 将被 安装
  ---> 软件包 php-cli.x86_64.0.5.4.16-45.el7 将被 安装
  ---> 软件包 php-common.x86_64.0.5.4.16-45.el7 将被 安装
  --> 正在处理依赖关系 libzip.so.2()(64bit),它被软件包 php-common-5.4.16-45.el7.x86_64 需要
  ---> 软件包 php-pdo.x86_64.0.5.4.16-45.el7 将被 安装
  ---> 软件包 t1lib.x86_64.0.5.1.2-14.el7 将被 安装
  --> 正在检查事务
  ---> 软件包 libzip.x86_64.0.0.10.1-8.el7 将被 安装
  ---> 软件包 nettle.x86_64.0.2.7.1-8.el7 将被 安装
  ---> 软件包 trousers.x86_64.0.0.3.14-2.el7 将被 安装
  --> 解决依赖关系完成
  ​
  依赖关系解决
  ​
  ================================================================================================================
   Package                     架构           版本                             源                            大小
  ================================================================================================================
  正在安装:
   zabbix-agent                x86_64         3.4.11-1.el7                     zabbix                       365 k
   zabbix-get                  x86_64         3.4.11-1.el7                     zabbix                       253 k
   zabbix-server-mysql         x86_64         3.4.11-1.el7                     zabbix                       2.0 M
   zabbix-web                  noarch         3.4.11-1.el7                     zabbix                       2.7 M
   zabbix-web-mysql            noarch         3.4.11-1.el7                     zabbix                       6.9 k
  为依赖而安装:
   OpenIPMI-libs               x86_64         2.0.23-2.el7                     base                         521 k
   OpenIPMI-modalias           x86_64         2.0.23-2.el7                     base                          16 k
   apr                         x86_64         1.4.8-3.el7_4.1                  base                         103 k
   apr-util                    x86_64         1.5.2-6.el7                      base                          92 k
   dejavu-fonts-common         noarch         2.33-6.el7                       base                          64 k
   dejavu-sans-fonts           noarch         2.33-6.el7                       base                         1.4 M
   fping                       x86_64         3.10-4.el7                       epel                          46 k
   gnutls                      x86_64         3.3.26-9.el7                     base                         677 k
   httpd                       x86_64         2.4.6-80.el7.centos.1            updates                      2.7 M
   httpd-tools                 x86_64         2.4.6-80.el7.centos.1            updates                       90 k
   iksemel                     x86_64         1.4-2.el7.centos                 zabbix-non-supported          49 k
   libzip                      x86_64         0.10.1-8.el7                     base                          48 k
   mailcap                     noarch         2.1.41-2.el7                     base                          31 k
   nettle                      x86_64         2.7.1-8.el7                      base                         327 k
   php                         x86_64         5.4.16-45.el7                    base                         1.4 M
   php-bcmath                  x86_64         5.4.16-45.el7                    base                          58 k
   php-cli                     x86_64         5.4.16-45.el7                    base                         2.7 M
   php-common                  x86_64         5.4.16-45.el7                    base                         565 k
   php-gd                      x86_64         5.4.16-45.el7                    base                         128 k
   php-ldap                    x86_64         5.4.16-45.el7                    base                          53 k
   php-mbstring                x86_64         5.4.16-45.el7                    base                         505 k
   php-mysql                   x86_64         5.4.16-45.el7                    base                         101 k
   php-pdo                     x86_64         5.4.16-45.el7                    base                          99 k
   php-xml                     x86_64         5.4.16-45.el7                    base                         126 k
   t1lib                       x86_64         5.1.2-14.el7                     base                         166 k
   trousers                    x86_64         0.3.14-2.el7                     base                         289 k
   unixODBC                    x86_64         2.3.1-11.el7                     base                         413 k
  ​
  事务概要
  ================================================================================================================
  安装  5 软件包 (+27 依赖软件包)
  ​
  总下载量:18 M
  安装大小:64 M
  Downloading packages:
  (1/32): OpenIPMI-modalias-2.0.23-2.el7.x86_64.rpm                                        |  16 kB  00:00:00     
  (2/32): dejavu-fonts-common-2.33-6.el7.noarch.rpm                                        |  64 kB  00:00:00     
  (3/32): apr-util-1.5.2-6.el7.x86_64.rpm                                                  |  92 kB  00:00:00     
  (4/32): apr-1.4.8-3.el7_4.1.x86_64.rpm                                                   | 103 kB  00:00:01     
  (5/32): fping-3.10-4.el7.x86_64.rpm                                                      |  46 kB  00:00:03     
  (6/32): OpenIPMI-libs-2.0.23-2.el7.x86_64.rpm                                            | 521 kB  00:00:05     
  (7/32): httpd-tools-2.4.6-80.el7.centos.1.x86_64.rpm                                     |  90 kB  00:00:01     
  (8/32): libzip-0.10.1-8.el7.x86_64.rpm                                                   |  48 kB  00:00:00     
  (9/32): gnutls-3.3.26-9.el7.x86_64.rpm                                                   | 677 kB  00:00:05     
  (10/32): mailcap-2.1.41-2.el7.noarch.rpm                                                 |  31 kB  00:00:00     
  (11/32): nettle-2.7.1-8.el7.x86_64.rpm                                                   | 327 kB  00:00:03     
  warning: /var/cache/yum/x86_64/7/zabbix-non-supported/packages/iksemel-1.4-2.el7.centos.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 79ea5ed4: NOKEY
  iksemel-1.4-2.el7.centos.x86_64.rpm 的公钥尚未安装
  (12/32): iksemel-1.4-2.el7.centos.x86_64.rpm                                             |  49 kB  00:00:05     
  (13/32): dejavu-sans-fonts-2.33-6.el7.noarch.rpm                                         | 1.4 MB  00:00:16     
  (14/32): php-cli-5.4.16-45.el7.x86_64.rpm                                                | 2.7 MB  00:00:14     
  (15/32): php-bcmath-5.4.16-45.el7.x86_64.rpm                                             |  58 kB  00:00:14     
  (16/32): php-gd-5.4.16-45.el7.x86_64.rpm                                                 | 128 kB  00:00:00     
  (17/32): php-ldap-5.4.16-45.el7.x86_64.rpm                                               |  53 kB  00:00:00     
  (18/32): php-common-5.4.16-45.el7.x86_64.rpm                                             | 565 kB  00:00:09     
  (19/32): php-pdo-5.4.16-45.el7.x86_64.rpm                                                |  99 kB  00:00:00     
  (20/32): php-mysql-5.4.16-45.el7.x86_64.rpm                                              | 101 kB  00:00:02     
  (21/32): php-mbstring-5.4.16-45.el7.x86_64.rpm                                           | 505 kB  00:00:02     
  (22/32): php-xml-5.4.16-45.el7.x86_64.rpm                                                | 126 kB  00:00:01     
  (23/32): t1lib-5.1.2-14.el7.x86_64.rpm                                                   | 166 kB  00:00:01     
  (24/32): trousers-0.3.14-2.el7.x86_64.rpm                                                | 289 kB  00:00:02     
  (25/32): unixODBC-2.3.1-11.el7.x86_64.rpm                                                | 413 kB  00:00:03     
  (26/32): php-5.4.16-45.el7.x86_64.rpm                                                    | 1.4 MB  00:00:25     
  warning: /var/cache/yum/x86_64/7/zabbix/packages/zabbix-get-3.4.11-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
  zabbix-get-3.4.11-1.el7.x86_64.rpm 的公钥尚未安装
  (27/32): zabbix-get-3.4.11-1.el7.x86_64.rpm                                              | 253 kB  00:00:06     
  (28/32): httpd-2.4.6-80.el7.centos.1.x86_64.rpm                                          | 2.7 MB  00:00:37     
  (29/32): zabbix-agent-3.4.11-1.el7.x86_64.rpm                                            | 365 kB  00:00:12     
  (30/32): zabbix-server-mysql-3.4.11-1.el7.x86_64.rpm                                     | 2.0 MB  00:01:35     
  (31/32): zabbix-web-mysql-3.4.11-1.el7.noarch.rpm                                        | 6.9 kB  00:00:00     
  (32/32): zabbix-web-3.4.11-1.el7.noarch.rpm                                              | 2.7 MB  00:02:33     
  ----------------------------------------------------------------------------------------------------------------
  总计                                                                             94 kB/s |  18 MB  00:03:15     
  从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 检索密钥
  导入 GPG key 0xA14FE591:
   用户ID     : "Zabbix LLC <[email protected]>"
   指纹       : a184 8f53 52d0 22b9 471d 83d0 082a b56b a14f e591
   软件包     : zabbix-release-3.4-2.el7.noarch (installed)
   来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
  从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX 检索密钥
  导入 GPG key 0x79EA5ED4:
   用户ID     : "Zabbix SIA <[email protected]>"
   指纹       : fbab d5fb 2025 5eca b22e e194 d13d 58e4 79ea 5ed4
   软件包     : zabbix-release-3.4-2.el7.noarch (installed)
   来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
  Running transaction check
  Running transaction test
  Transaction test succeeded
  Running transaction
  警告:RPM 数据库已被非 yum 程序修改。
    正在安装    : apr-1.4.8-3.el7_4.1.x86_64                                                                 1/32 
    正在安装    : apr-util-1.5.2-6.el7.x86_64                                                                2/32 
    正在安装    : httpd-tools-2.4.6-80.el7.centos.1.x86_64                                                   3/32 
    正在安装    : libzip-0.10.1-8.el7.x86_64                                                                 4/32 
    正在安装    : php-common-5.4.16-45.el7.x86_64                                                            5/32 
    正在安装    : php-bcmath-5.4.16-45.el7.x86_64                                                            6/32 
    正在安装    : php-pdo-5.4.16-45.el7.x86_64                                                               7/32 
    正在安装    : php-mysql-5.4.16-45.el7.x86_64                                                             8/32 
    正在安装    : php-cli-5.4.16-45.el7.x86_64                                                               9/32 
    正在安装    : php-ldap-5.4.16-45.el7.x86_64                                                             10/32 
    正在安装    : php-xml-5.4.16-45.el7.x86_64                                                              11/32 
    正在安装    : php-mbstring-5.4.16-45.el7.x86_64                                                         12/32 
    正在安装    : unixODBC-2.3.1-11.el7.x86_64                                                              13/32 
    正在安装    : t1lib-5.1.2-14.el7.x86_64                                                                 14/32 
    正在安装    : php-gd-5.4.16-45.el7.x86_64                                                               15/32 
    正在安装    : dejavu-fonts-common-2.33-6.el7.noarch                                                     16/32 
    正在安装    : dejavu-sans-fonts-2.33-6.el7.noarch                                                       17/32 
    正在安装    : OpenIPMI-modalias-2.0.23-2.el7.x86_64                                                     18/32 
    正在安装    : OpenIPMI-libs-2.0.23-2.el7.x86_64                                                         19/32 
    正在安装    : fping-3.10-4.el7.x86_64                                                                   20/32 
    正在安装    : nettle-2.7.1-8.el7.x86_64                                                                 21/32 
    正在安装    : mailcap-2.1.41-2.el7.noarch                                                               22/32 
    正在安装    : httpd-2.4.6-80.el7.centos.1.x86_64                                                        23/32 
    正在安装    : php-5.4.16-45.el7.x86_64                                                                  24/32 
    正在安装    : zabbix-web-mysql-3.4.11-1.el7.noarch                                                      25/32 
    正在安装    : zabbix-web-3.4.11-1.el7.noarch                                                            26/32 
    正在安装    : trousers-0.3.14-2.el7.x86_64                                                              27/32 
    正在安装    : gnutls-3.3.26-9.el7.x86_64                                                                28/32 
    正在安装    : iksemel-1.4-2.el7.centos.x86_64                                                           29/32 
    正在安装    : zabbix-server-mysql-3.4.11-1.el7.x86_64                                                   30/32 
    正在安装    : zabbix-get-3.4.11-1.el7.x86_64                                                            31/32 
    正在安装    : zabbix-agent-3.4.11-1.el7.x86_64                                                          32/32 
  sed:无法读取 /etc/sysconfig/ipmi:没有那个文件或目录
    验证中      : trousers-0.3.14-2.el7.x86_64                                                               1/32 
    验证中      : mailcap-2.1.41-2.el7.noarch                                                                2/32 
    验证中      : httpd-tools-2.4.6-80.el7.centos.1.x86_64                                                   3/32 
    验证中      : httpd-2.4.6-80.el7.centos.1.x86_64                                                         4/32 
    验证中      : zabbix-web-3.4.11-1.el7.noarch                                                             5/32 
    验证中      : php-bcmath-5.4.16-45.el7.x86_64                                                            6/32 
    验证中      : nettle-2.7.1-8.el7.x86_64                                                                  7/32 
    验证中      : fping-3.10-4.el7.x86_64                                                                    8/32 
    验证中      : OpenIPMI-modalias-2.0.23-2.el7.x86_64                                                      9/32 
    验证中      : php-pdo-5.4.16-45.el7.x86_64                                                              10/32 
    验证中      : OpenIPMI-libs-2.0.23-2.el7.x86_64                                                         11/32 
    验证中      : php-5.4.16-45.el7.x86_64                                                                  12/32 
    验证中      : php-cli-5.4.16-45.el7.x86_64                                                              13/32 
    验证中      : dejavu-fonts-common-2.33-6.el7.noarch                                                     14/32 
    验证中      : t1lib-5.1.2-14.el7.x86_64                                                                 15/32 
    验证中      : zabbix-server-mysql-3.4.11-1.el7.x86_64                                                   16/32 
    验证中      : gnutls-3.3.26-9.el7.x86_64                                                                17/32 
    验证中      : php-ldap-5.4.16-45.el7.x86_64                                                             18/32 
    验证中      : php-xml-5.4.16-45.el7.x86_64                                                              19/32 
    验证中      : zabbix-agent-3.4.11-1.el7.x86_64                                                          20/32 
    验证中      : unixODBC-2.3.1-11.el7.x86_64                                                              21/32 
    验证中      : apr-util-1.5.2-6.el7.x86_64                                                               22/32 
    验证中      : php-gd-5.4.16-45.el7.x86_64                                                               23/32 
    验证中      : dejavu-sans-fonts-2.33-6.el7.noarch                                                       24/32 
    验证中      : php-mysql-5.4.16-45.el7.x86_64                                                            25/32 
    验证中      : apr-1.4.8-3.el7_4.1.x86_64                                                                26/32 
    验证中      : php-common-5.4.16-45.el7.x86_64                                                           27/32 
    验证中      : php-mbstring-5.4.16-45.el7.x86_64                                                         28/32 
    验证中      : zabbix-web-mysql-3.4.11-1.el7.noarch                                                      29/32 
    验证中      : iksemel-1.4-2.el7.centos.x86_64                                                           30/32 
    验证中      : libzip-0.10.1-8.el7.x86_64                                                                31/32 
    验证中      : zabbix-get-3.4.11-1.el7.x86_64                                                            32/32 
  ​
  已安装:
    zabbix-agent.x86_64 0:3.4.11-1.el7                          zabbix-get.x86_64 0:3.4.11-1.el7                  
    zabbix-server-mysql.x86_64 0:3.4.11-1.el7                   zabbix-web.noarch 0:3.4.11-1.el7                  
    zabbix-web-mysql.noarch 0:3.4.11-1.el7                     
  ​
  作为依赖被安装:
    OpenIPMI-libs.x86_64 0:2.0.23-2.el7                   OpenIPMI-modalias.x86_64 0:2.0.23-2.el7                 
    apr.x86_64 0:1.4.8-3.el7_4.1                          apr-util.x86_64 0:1.5.2-6.el7                           
    dejavu-fonts-common.noarch 0:2.33-6.el7               dejavu-sans-fonts.noarch 0:2.33-6.el7                   
    fping.x86_64 0:3.10-4.el7                             gnutls.x86_64 0:3.3.26-9.el7                            
    httpd.x86_64 0:2.4.6-80.el7.centos.1                  httpd-tools.x86_64 0:2.4.6-80.el7.centos.1              
    iksemel.x86_64 0:1.4-2.el7.centos                     libzip.x86_64 0:0.10.1-8.el7                            
    mailcap.noarch 0:2.1.41-2.el7                         nettle.x86_64 0:2.7.1-8.el7                             
    php.x86_64 0:5.4.16-45.el7                            php-bcmath.x86_64 0:5.4.16-45.el7                       
    php-cli.x86_64 0:5.4.16-45.el7                        php-common.x86_64 0:5.4.16-45.el7                       
    php-gd.x86_64 0:5.4.16-45.el7                         php-ldap.x86_64 0:5.4.16-45.el7                         
    php-mbstring.x86_64 0:5.4.16-45.el7                   php-mysql.x86_64 0:5.4.16-45.el7                        
    php-pdo.x86_64 0:5.4.16-45.el7                        php-xml.x86_64 0:5.4.16-45.el7                          
    t1lib.x86_64 0:5.1.2-14.el7                           trousers.x86_64 0:0.3.14-2.el7                          
    unixODBC.x86_64 0:2.3.1-11.el7                       
  ​
  完毕!
  [root@zyshanlinux-001 ~]#

zabbix系统基于PHP环境运行,所以前提是系统上有PHP的运行环境,lnmp或者lamp环境

  [root@zyshanlinux-001 yum.repos.d]# ps aux |grep mysql
  root      1213  0.0  0.0 115428  1712 ?        S    07:42   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/zyshanlinux-001.pid
  mysql     1380  0.0 24.6 1125928 461796 ?      Sl   07:42   0:10 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/zyshanlinux-001.err --pid-file=/data/mysql/zyshanlinux-001.pid --socket=/tmp/mysql.sock
  root     11932  0.0  0.0 112724   972 pts/0    S+   10:59   0:00 grep --color=auto mysql
  [root@zyshanlinux-001 yum.repos.d]# ps aux |grep nginx
  root      1135  0.0  0.0  46032  1276 ?        Ss   07:42   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  nobody    1140  0.0  0.2  48520  4176 ?        S    07:42   0:00 nginx: worker process
  nobody    1141  0.0  0.2  48520  3920 ?        S    07:42   0:00 nginx: worker process
  root     11934  0.0  0.0 112720   972 pts/0    R+   10:59   0:00 grep --color=auto nginx
  [root@zyshanlinux-001 yum.repos.d]# 
  [root@zyshanlinux-001 yum.repos.d]# ps aux |grep mariadb
  root     11936  0.0  0.0 112720   972 pts/0    R+   11:00   0:00 grep --color=auto mariadb
  [root@zyshanlinux-001 yum.repos.d]# ps aux |grep php
  root      1471  0.0  0.2 227252  4948 ?        Ss   07:42   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
  php-fpm   1472  0.0  0.2 227252  4708 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1473  0.0  0.2 227252  4708 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1474  0.0  0.2 227252  4708 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1475  0.0  0.2 227252  4708 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1476  0.0  0.2 227252  4712 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1477  0.0  0.2 227252  4712 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1478  0.0  0.2 227252  4712 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1479  0.0  0.2 227252  4712 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1480  0.0  0.2 227252  4712 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1481  0.0  0.2 227252  4712 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1482  0.0  0.2 227252  4712 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1483  0.0  0.2 227252  4716 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1484  0.0  0.2 227252  4716 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1485  0.0  0.2 227252  4716 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1486  0.0  0.2 227252  4716 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1487  0.0  0.2 227252  4716 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1488  0.0  0.2 227252  4716 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1489  0.0  0.2 227252  4716 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1490  0.0  0.2 227252  4716 ?        S    07:42   0:00 php-fpm: pool www
  php-fpm   1491  0.0  0.2 227252  4716 ?        S    07:42   0:00 php-fpm: pool www
  root     11958  0.0  0.0 112720   972 pts/0    R+   11:03   0:00 grep --color=auto php

设置默认的字符集

  vim /etc/my.cnf //需要增加配置
  character_set_server = utf8

更改配置,需要重启mysql服务

  [root@zyshanlinux-001 ~]# systemctl restart mysql

重启mysqld服务后,进入mysql命令行

  [root@zyshanlinux-001 ~]# mysql -uroot -pmysql01
  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.6.35-log MySQL Community Server (GPL)
  ​
  Copyright (c) 2000, 2016, 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>

创建zabbix库的时候指定字符utf8

  mysql> create database zabbix character set utf8;
  Query OK, 1 row affected (0.04 sec)
  ​
  mysql>

再创建用户,该用户需要让web代码(就是PHP代码)连接mysql,还有就是监控中心(zabbix)连接mysql,再退出

  mysql> grant all on zabbix.* to 'zabbix'@'127.0.0.1' identified by 'zyshan-zabbix';
  Query OK, 0 rows affected (0.04 sec)
  ​
  mysql>quit
  Bye

导入数据,到安装目录去把create.sql.gz包解压,导入到数据,数据量不小导入时间不短。

  [root@zyshanlinux-001 ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/
  [root@zyshanlinux-001 zabbix-server-mysql-3.2.11]# ls
  AUTHORS  ChangeLog  COPYING  create.sql.gz  NEWS  README
  [root@zyshanlinux-001 zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz
  [root@zyshanlinux-001 zabbix-server-mysql-3.2.11]# ls
  AUTHORS  ChangeLog  COPYING  create.sql  NEWS  README
  [root@zyshanlinux-001 zabbix-server-mysql-3.2.11]# mysql -uroot -pmysql01 zabbix < create.sql
  Warning: Using a password on the command line interface can be insecure.
  [root@zyshanlinux-001 zabbix-server-mysql-3.2.11]#

启动zabbix服务,启动httpd服务,先确认80端口没被占用;现在80被nginx占用需要停止该服务,释放80端口。

  [root@zyshanlinux-001 zabbix-server-mysql-3.2.11]# cd
  [root@zyshanlinux-001 ~]# systemctl start zabbix-server
  [root@zyshanlinux-001 ~]# ps aux |grep nginx
  root      1135  0.0  0.0  46032  1276 ?        Ss   07:42   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  nobody    1140  0.0  0.2  48520  4176 ?        S    07:42   0:00 nginx: worker process
  nobody    1141  0.0  0.2  48520  3920 ?        S    07:42   0:00 nginx: worker process
  root     12335  0.0  0.0 112720   968 pts/0    R+   11:29   0:00 grep --color=auto nginx
  [root@zyshanlinux-001 ~]# /etc/init.d/nginx stop
  Stopping nginx (via systemctl):                            [  确定  ]
  [root@zyshanlinux-001 ~]# ps aux |grep nginx
  root     12356  0.0  0.0 112720   964 pts/0    R+   11:32   0:00 grep --color=auto nginx
  [root@zyshanlinux-001 ~]# netstat -lntp
  Active Internet connections (only servers)
  Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
  tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      573/rpcbind         
  tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      1035/rpc.mountd     
  tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1013/sshd           
  tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1424/master         
  tcp        0      0 0.0.0.0:39577           0.0.0.0:*               LISTEN      -                   
  tcp        0      0 0.0.0.0:40729           0.0.0.0:*               LISTEN      1027/rpc.statd      
  tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
  tcp6       0      0 :::111                  :::*                    LISTEN      573/rpcbind         
  tcp6       0      0 :::20048                :::*                    LISTEN      1035/rpc.mountd     
  tcp6       0      0 :::22                   :::*                    LISTEN      1013/sshd           
  tcp6       0      0 ::1:25                  :::*                    LISTEN      1424/master         
  tcp6       0      0 :::40347                :::*                    LISTEN      -                   
  tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
  tcp6       0      0 :::48193                :::*                    LISTEN      1027/rpc.statd      
  tcp6       0      0 :::3306                 :::*                    LISTEN      12232/mysqld

启动httpd服务,确认80端口是被httpd占用

  [root@zyshanlinux-001 ~]# systemctl start httpd
  [root@zyshanlinux-001 ~]# netstat -lntp
  Active Internet connections (only servers)
  Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
  tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      573/rpcbind         
  tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      1035/rpc.mountd     
  tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1013/sshd           
  tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1424/master         
  tcp        0      0 0.0.0.0:39577           0.0.0.0:*               LISTEN      -                   
  tcp        0      0 0.0.0.0:40729           0.0.0.0:*               LISTEN      1027/rpc.statd      
  tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
  tcp6       0      0 :::111                  :::*                    LISTEN      573/rpcbind         
  tcp6       0      0 :::80                   :::*                    LISTEN      12370/httpd         
  tcp6       0      0 :::20048                :::*                    LISTEN      1035/rpc.mountd     
  tcp6       0      0 :::22                   :::*                    LISTEN      1013/sshd           
  tcp6       0      0 ::1:25                  :::*                    LISTEN      1424/master         
  tcp6       0      0 :::40347                :::*                    LISTEN      -                   
  tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
  tcp6       0      0 :::48193                :::*                    LISTEN      1027/rpc.statd      
  tcp6       0      0 :::3306                 :::*                    LISTEN      12232/mysqld

把httpd和zabbix服务配置开机启动,把nginx服务取消开机启动。

  [root@zyshanlinux-001 ~]# systemctl enable httpd
  Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
  [root@zyshanlinux-001 ~]# systemctl enable zabbix-server
  Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
  [root@zyshanlinux-001 ~]# systemctl disable nginx
  nginx.service is not a native service, redirecting to /sbin/chkconfig.
  Executing /sbin/chkconfig nginx off
  [root@zyshanlinux-001 ~]# chkconfig nginx off

确认zabbix服务是否启动,服务启动管理端口没有监听,查看错误日志,没有连接mysql需要配置下文件。

  [root@zyshanlinux-001 ~]# ps aux |grep zabbix
  zabbix   12332  0.0  0.1 254632  3492 ?        S    11:28   0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
  root     12514  0.0  0.0 112720   968 pts/0    R+   11:40   0:00 grep --color=auto zabbix
  [root@zyshanlinux-001 ~]# netstat -lntp
  Active Internet connections (only servers)
  Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
  tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      573/rpcbind         
  tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      1035/rpc.mountd     
  tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1013/sshd           
  tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1424/master         
  tcp        0      0 0.0.0.0:39577           0.0.0.0:*               LISTEN      -                   
  tcp        0      0 0.0.0.0:40729           0.0.0.0:*               LISTEN      1027/rpc.statd      
  tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
  tcp6       0      0 :::111                  :::*                    LISTEN      573/rpcbind         
  tcp6       0      0 :::80                   :::*                    LISTEN      12370/httpd         
  tcp6       0      0 :::20048                :::*                    LISTEN      1035/rpc.mountd     
  tcp6       0      0 :::22                   :::*                    LISTEN      1013/sshd           
  tcp6       0      0 ::1:25                  :::*                    LISTEN      1424/master         
  tcp6       0      0 :::40347                :::*                    LISTEN      -                   
  tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
  tcp6       0      0 :::48193                :::*                    LISTEN      1027/rpc.statd      
  tcp6       0      0 :::3306                 :::*                    LISTEN      12232/mysqld
  ​
  ​
  [root@zyshanlinux-001 ~]# less /var/log/zabbix/zabbix_server.log
  erver through socket '/var/lib/mysql/mysql.sock' (2)
   12332:20180726:112926.610 database is down: reconnecting in 10 seconds
   12332:20180726:112936.611 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL s

vim /etc/zabbix/zabbix_server.conf //修改或增加

DBHost=127.0.0.1 //在DBName=zabbix上面增加

DBPassword=a-zyshanabbix //在DBuser下面增加

更改配置后需要重启一下服务

  [root@zyshanlinux-001 ~]# systemctl restart zabbix-server

再次确认zabbix服务开启和端口监听

  [root@zyshanlinux-001 ~]# ps aux |grep zabbix
  zabbix   12634  0.6  0.2 254812  4184 ?        S    12:00   0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
  zabbix   12637  0.0  0.1 254820  3068 ?        S    12:00   0:00 /usr/sbin/zabbix_server: configuration syncer [synced configuration in 0.011986 sec, idle 60 sec]
  zabbix   12638  0.0  0.1 254812  2892 ?        S    12:00   0:00 /usr/sbin/zabbix_server: db watchdog [synced alerts config in 0.003214 sec, idle 60 sec]
  zabbix   12639  0.0  0.2 361748  5264 ?        S    12:00   0:00 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000012 sec, idle 5 sec]
  zabbix   12640  0.0  0.2 361748  5264 ?        S    12:00   0:00 /usr/sbin/zabbix_server: poller #2 [got 0 values in 0.000007 sec, idle 5 sec]
  zabbix   12641  0.0  0.2 361748  5264 ?        S    12:00   0:00 /usr/sbin/zabbix_server: poller #3 [got 0 values in 0.000008 sec, idle 5 sec]
  zabbix   12642  0.0  0.2 361748  5264 ?        S    12:00   0:00 /usr/sbin/zabbix_server: poller #4 [got 0 values in 0.000008 sec, idle 5 sec]
  zabbix   12643  0.0  0.2 361748  5264 ?        S    12:00   0:00 /usr/sbin/zabbix_server: poller #5 [got 0 values in 0.000008 sec, idle 5 sec]
  zabbix   12644  0.0  0.2 361748  5264 ?        S    12:00   0:00 /usr/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000008 sec, idle 5 sec]
  zabbix   12645  0.0  0.1 254812  3624 ?        S    12:00   0:00 /usr/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection]
  zabbix   12646  0.0  0.1 254812  3624 ?        S    12:00   0:00 /usr/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection]
  zabbix   12647  0.0  0.1 254812  3624 ?        S    12:00   0:00 /usr/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection]
  zabbix   12648  0.0  0.1 254812  3624 ?        S    12:00   0:00 /usr/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection]
  zabbix   12649  0.0  0.1 254812  3624 ?        S    12:00   0:00 /usr/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection]
  zabbix   12653  0.0  0.1 257384  2688 ?        S    12:00   0:00 /usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000008 sec, idle 5 sec]
  zabbix   12654  0.0  0.1 254812  2880 ?        S    12:00   0:00 /usr/sbin/zabbix_server: alerter [sent alerts: 0 success, 0 fail in 0.001612 sec, idle 30 sec]
  zabbix   12656  0.0  0.1 254812  2512 ?        S    12:00   0:00 /usr/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
  zabbix   12657  0.0  0.1 254888  2996 ?        S    12:00   0:00 /usr/sbin/zabbix_server: timer #1 [processed 0 triggers, 0 events in 0.000036 sec, 0 maintenances in 0.000000 sec, idle 30 sec]
  zabbix   12659  0.0  0.1 254812  2896 ?        S    12:00   0:00 /usr/sbin/zabbix_server: http poller #1 [got 0 values in 0.001314 sec, idle 5 sec]
  zabbix   12661  0.0  0.2 359280  5252 ?        S    12:00   0:00 /usr/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.001446 sec, idle 60 sec]
  zabbix   12662  0.0  0.1 254812  2888 ?        S    12:00   0:00 /usr/sbin/zabbix_server: history syncer #1 [synced 0 items in 0.000003 sec, idle 1 sec]
  zabbix   12663  0.0  0.1 254812  2888 ?        S    12:00   0:00 /usr/sbin/zabbix_server: history syncer #2 [synced 0 items in 0.000003 sec, idle 1 sec]
  zabbix   12666  0.0  0.1 254812  2888 ?        S    12:00   0:00 /usr/sbin/zabbix_server: history syncer #3 [synced 0 items in 0.000003 sec, idle 1 sec]
  zabbix   12675  0.0  0.1 254812  2888 ?        S    12:00   0:00 /usr/sbin/zabbix_server: history syncer #4 [synced 0 items in 0.000003 sec, idle 1 sec]
  zabbix   12677  0.0  0.2 254812  3828 ?        S    12:00   0:00 /usr/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.001538 sec, idle 3 sec]
  zabbix   12679  0.0  0.2 254812  3832 ?        S    12:00   0:00 /usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000005 sec, idle 5 sec]
  zabbix   12680  0.0  0.1 254812  2656 ?        S    12:00   0:00 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000009 sec, idle 1 sec]
  zabbix   12682  0.0  0.1 254812  2876 ?        S    12:00   0:00 /usr/sbin/zabbix_server: task manager [processed 0 task(s) in 0.000748 sec, idle 5 sec]
  root     12687  0.0  0.0 112720   968 pts/0    R+   12:01   0:00 grep --color=auto zabbix
  [root@zyshanlinux-001 ~]# netstat -lntp
  Active Internet connections (only servers)
  Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
  tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      573/rpcbind         
  tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      1035/rpc.mountd     
  tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1013/sshd           
  tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1424/master         
  tcp        0      0 0.0.0.0:39577           0.0.0.0:*               LISTEN      -                   
  tcp        0      0 0.0.0.0:40729           0.0.0.0:*               LISTEN      1027/rpc.statd      
  tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
  tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      12634/zabbix_server 
  tcp6       0      0 :::111                  :::*                    LISTEN      573/rpcbind         
  tcp6       0      0 :::80                   :::*                    LISTEN      12370/httpd         
  tcp6       0      0 :::20048                :::*                    LISTEN      1035/rpc.mountd     
  tcp6       0      0 :::22                   :::*                    LISTEN      1013/sshd           
  tcp6       0      0 ::1:25                  :::*                    LISTEN      1424/master         
  tcp6       0      0 :::40347                :::*                    LISTEN      -                   
  tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
  tcp6       0      0 :::48193                :::*                    LISTEN      1027/rpc.statd      
  tcp6       0      0 :::10051                :::*                    LISTEN      12634/zabbix_server 
  tcp6       0      0 :::3306                 :::*                    LISTEN      12232/mysqld

浏览器访问http://ip/zabbix/ ,yum安装不需要配置什么,直接就可以进入web页面非常方便;编译安装则需要配置

web界面下面配置zabbix,显示OK的不用管,只看Fail的,提示PHP option "date.timezone"

配置php的文件,加上data.timezone = Asia/Shanghai

  [root@zyshanlinux-001 ~]# vi /etc/php.ini

更改完配置需要重启httpd服务

  [root@zyshanlinux-001 ~]# systemctl restart httpd

刷新网页,Fail变为OK了

配置端口账户信息

定义zabbix的主机名,随意

安装成功

用默认账户:admin,密码:zabbix 登录

进入后台第一件事情就是修改默认密码

重新刷新就看到中文了,重新登录下修改的密码生效。

忘记Admin密码如何做

类似mysql修改root密码一样,进入数据库去修改密码。

1、首先登录进mysql

  [root@zyshanlinux-001 ~]# mysql -uroot -pmysql01
  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 1249
  Server version: 5.6.35-log MySQL Community Server (GPL)
  ​
  Copyright (c) 2000, 2016, 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>

2、进入zabbix库,查看库里的表

  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 table;
  ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
  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                |
  | dbversion                  |
  | dchecks                    |
  | dhosts                     |
  | drules                     |
  | dservices                  |
  | escalations                |
  | event_recovery             |
  | event_tag                  |
  | events                     |
  | expressions                |
  | functions                  |
  | globalmacro                |
  | globalvars                 |
  | graph_discovery            |
  | graph_theme                |
  | graphs                     |
  | graphs_items               |
  | group_discovery            |
  | group_prototype            |
  | groups                     |
  | history                    |
  | history_log                |
  | history_str                |
  | history_text               |
  | history_uint               |
  | host_discovery             |
  | host_inventory             |
  | hostmacro                  |
  | hosts                      |
  | hosts_groups               |
  | hosts_templates            |
  | housekeeper                |
  | httpstep                   |
  | httpstepitem               |
  | httptest                   |
  | httptestitem               |
  | icon_map                   |
  | icon_mapping               |
  | ids                        |
  | images                     |
  | interface                  |
  | interface_discovery        |
  | item_application_prototype |
  | item_condition             |
  | item_discovery             |
  | items                      |
  | items_applications         |
  | 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_url         |
  | sysmap_url                 |
  | sysmap_user                |
  | sysmap_usrgrp              |
  | sysmaps                    |
  | sysmaps_elements           |
  | sysmaps_link_triggers      |
  | sysmaps_links              |
  | task                       |
  | task_close_problem         |
  | timeperiods                |
  | trends                     |
  | trends_uint                |
  | trigger_depends            |
  | trigger_discovery          |
  | trigger_tag                |
  | triggers                   |
  | users                      |
  | users_groups               |
  | usrgrp                     |
  | valuemaps                  |
  +----------------------------+
  127 rows in set (0.00 sec)
  ​
  mysql>

3、密码 存在users表里面,就是passwd那行,我们要修改的就是这行

  mysql> desc users;
  +----------------+---------------------+------+-----+---------+-------+
  | Field          | Type                | Null | Key | Default | Extra |
  +----------------+---------------------+------+-----+---------+-------+
  | userid         | bigint(20) unsigned | NO   | PRI | NULL    |       |
  | alias          | varchar(100)        | NO   | UNI |         |       |
  | name           | varchar(100)        | NO   |     |         |       |
  | surname        | varchar(100)        | NO   |     |         |       |
  | passwd         | char(32)            | NO   |     |         |       |
  | url            | varchar(255)        | NO   |     |         |       |
  | autologin      | int(11)             | NO   |     | 0       |       |
  | autologout     | int(11)             | NO   |     | 900     |       |
  | lang           | varchar(5)          | NO   |     | en_GB   |       |
  | refresh        | int(11)             | NO   |     | 30      |       |
  | type           | int(11)             | NO   |     | 1       |       |
  | theme          | varchar(128)        | NO   |     | default |       |
  | attempt_failed | int(11)             | NO   |     | 0       |       |
  | attempt_ip     | varchar(39)         | NO   |     |         |       |
  | attempt_clock  | int(11)             | NO   |     | 0       |       |
  | rows_per_page  | int(11)             | NO   |     | 50      |       |
  +----------------+---------------------+------+-----+---------+-------+
  16 rows in set (0.00 sec)
  ​
  mysql>

4、修改密码

  mysql> update users set passwd=md5('zabbix01') where alias='Admin';
  Query OK, 1 row affected (0.00 sec)
  Rows matched: 1  Changed: 1  Warnings: 0
  ​
  mysql>

5、查看登录的用户,退出该库;重新登录浏览器用新密码登录。

mysql> select * from users;
+--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+------------+---------------+---------------+
| userid | alias | name   | surname       | passwd                           | url | autologin | autologout | lang  | refresh | type | theme   | attempt_failed | attempt_ip | attempt_clock | rows_per_page |
+--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+------------+---------------+---------------+
|      1 | Admin | Zabbix | Administrator | ca8a966eb96b3db632f5492bd44f7d3d |     |         1 |          0 | zh_CN |      30 |    3 | default |              0 |            |             0 |            50 |
|      2 | guest |        |               | d41d8cd98f00b204e9800998ecf8427e |     |         0 |        900 | en_GB |      30 |    1 | default |              0 |            |             0 |            50 |
+--------+-------+--------+---------------+----------------------------------+-----+-----------+------------+-------+---------+------+---------+----------------+------------+---------------+---------------+
2 rows in set (0.00 sec)

mysql> quit
Bye

zabbix客户端安装

在客户端上也需要下载zabbix的yum源

[root@zyshanlinux-02 src]# wget https://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm

安装下载的包

[root@zyshanlinux-02 src]# rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
警告:zabbix-release-3.2-1.el7.noarch.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:zabbix-release-3.2-1.el7         ################################# [100%]

客户端上只需要安装zabbix-agent就可以了

[root@zyshanlinux-02 ~]# yum install -y zabbix-agent

修改配置参数,就是加上认证(白名单IP)

 vim  /etc/zabbix/zabbix_agentd.conf

第一和第二步都修改了,就是连个模式都支持;如果只修改了一个,那就只是修改那个模式生效。

1、定义服务端IP(被动模式):即监控中心过来采集数据

把Server=127.0.0.1修改为Server=192.168.106.128

2、定义服务端IP(主动模式):主动向监控中心上传数据

把ServerActive=127.0.0.1修改为ServerActive=192.168.106.128

3、修改主机名,令服务端识别数据是从哪台机器采集过来的

把Hostname=Zabbix server修改为Hostname=zyshanlinux-02

修改完配置需要重启zabbix-agent服务

[root@zyshanlinux-02 ~]# systemctl start zabbix-agent

确认服务启动端口监听

[root@zyshanlinux-02 ~]# ps aux |grep zabbix
zabbix    1737  0.0  0.0  82780  1280 ?        S    21:47   0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix    1738  0.0  0.0  82780  1332 ?        S    21:47   0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix    1739  0.0  0.0  82780  1852 ?        S    21:47   0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix    1740  0.0  0.0  82780  1852 ?        S    21:47   0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix    1741  0.0  0.0  82780  1852 ?        S    21:47   0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix    1742  0.0  0.1  82908  2240 ?        S    21:47   0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root      1746  0.0  0.0 112720   972 pts/0    R+   21:49   0:00 grep --color=auto zabbix
[root@zyshanlinux-02 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      530/rpcbind         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      913/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1297/master         
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1737/zabbix_agentd  
tcp6       0      0 :::111                  :::*                    LISTEN      530/rpcbind         
tcp6       0      0 :::22                   :::*                    LISTEN      913/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1297/master         
tcp6       0      0 :::10050                :::*                    LISTEN      1737/zabbix_agentd  
tcp6       0      0 :::3306                 :::*                    LISTEN      1257/mysqld

开机启动,添加进启动列表里面去

[root@zyshanlinux-02 ~]# systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.

主动模式和被动模式

  • 主动或者被动是相对客户端来讲的。

  • 被动模式,服务端会主动连接客户端获取监控项目数据,客户端被动地接受连接,并把监控信息传递给服务端。

  • 主动模式,客户端会主动把监控数据汇报给服务端,服务端只负责接收即可。

  • 当客户端数量非常多时,建议使用主动模式,这样可以降低服务端的压力。

  • 服务端有公网ip,客户端只有内网ip,但却能连外网,这种场景适合主动模式。

添加监控主机

1、先添加主机组zyshan-test

2、再添加主机,主机名称和可见名称都写zyshanlinux-02

3、群组选择zyshan_test

4、IP地址填写客户端的ip 192.168.106.130

5、几个概念:

应用集:包含监控项

监控项:组成应用集

触发器:告警规则,分不同级别显示告警程度

图形:记录的历史数据组成图表

自动发现:分区、网卡等自动发现大小、名称等,免去一步步去定义

web监测:检查web的状态码情况

猜你喜欢

转载自blog.csdn.net/zhengyshan/article/details/81218057