1. 程式人生 > >Zabbix 3.4.6 新特性:歷史數據支持 Elasticsearch

Zabbix 3.4.6 新特性:歷史數據支持 Elasticsearch

openssl security sql rod start postgre pre first sim

一、升級 cURL

註:先升級 cURL,然後在安裝 Zabbix Server,否則報如下錯誤:

cannot initialize history storage: cURL library support >= 7.28.0 is required for Elasticsearch history backend

開始升級 cURL:

[root@jrgc ~]# uname -r
2.6.32-642.el6.x86_64
[root@jrgc docs]# curl --version
curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz
[root@jrgc ~]# rpm -ivh http://mirror.city-fan.org/ftp/contrib/yum-repo/city-fan.org-release-1-13.rhel6.noarch.rpm
Retrieving http://mirror.city-fan.org/ftp/contrib/yum-repo/city-fan.org-release-1-13.rhel6.noarch.rpm
warning: /var/tmp/rpm-tmp.1lrKA3: Header V3 DSA/SHA1 Signature, key ID b56a8bac: NOKEY
Preparing...                ########################################### [100%]
   1:city-fan.org-release   ########################################### [100%]
[root@jrgc ~ ]# yum upgrade libcurl
Loaded plugins: fastestmirror, security
Setting up Upgrade Process
Loading mirror speeds from cached hostfile
* city-fan.org: nervion.us.es
city-fan.org                                                                                                  | 2.9 kB     00:00     
city-fan.org/primary_db                                                                                       | 459 kB     00:15     
Resolving Dependencies
--> Running transaction check
---> Package libcurl.x86_64 0:7.19.7-53.el6_9 will be updated
--> Processing Dependency: libcurl = 7.19.7-53.el6_9 for package: curl-7.19.7-53.el6_9.x86_64
--> Processing Dependency: libcurl = 7.19.7-53.el6_9 for package: libcurl-devel-7.19.7-53.el6_9.x86_64
---> Package libcurl.x86_64 0:7.57.0-1.0.cf.rhel6 will be an update
--> Processing Dependency: libssh2(x86-64) >= 1.8.0 for package: libcurl-7.57.0-1.0.cf.rhel6.x86_64
--> Processing Dependency: c-ares(x86-64) >= 1.13.0 for package: libcurl-7.57.0-1.0.cf.rhel6.x86_64
--> Processing Dependency: libnghttp2.so.14()(64bit) for package: libcurl-7.57.0-1.0.cf.rhel6.x86_64
--> Running transaction check
---> Package c-ares.x86_64 0:1.10.0-3.el6 will be updated
---> Package c-ares.x86_64 0:1.13.0-3.0.cf.rhel6 will be an update
---> Package curl.x86_64 0:7.19.7-53.el6_9 will be updated
---> Package curl.x86_64 0:7.57.0-1.0.cf.rhel6 will be an update
--> Processing Dependency: libmetalink.so.3()(64bit) for package: curl-7.57.0-1.0.cf.rhel6.x86_64
---> Package libcurl-devel.x86_64 0:7.19.7-53.el6_9 will be updated
---> Package libcurl-devel.x86_64 0:7.57.0-1.0.cf.rhel6 will be an update
epel/filelists_db                                                                                             | 7.8 MB     00:00     
city-fan.org/filelists_db                                                                                     | 334 kB     00:20     
--> Processing Dependency: libssh2-devel for package: libcurl-devel-7.57.0-1.0.cf.rhel6.x86_64
---> Package libnghttp2.x86_64 0:1.6.0-1.el6.1 will be installed
---> Package libssh2.x86_64 0:1.4.2-2.el6_7.1 will be updated
---> Package libssh2.x86_64 0:1.8.0-5.0.cf.rhel6 will be an update
--> Running transaction check
---> Package libmetalink.x86_64 0:0.1.3-4.rhel6 will be installed
---> Package libssh2-devel.x86_64 0:1.8.0-5.0.cf.rhel6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================
Package                         Arch                     Version                               Repository                      Size
=====================================================================================================================================
Updating:
libcurl                         x86_64                   7.57.0-1.0.cf.rhel6                   city-fan.org                   427 k
Installing for dependencies:
libmetalink                     x86_64                   0.1.3-4.rhel6                         city-fan.org                    24 k
libnghttp2                      x86_64                   1.6.0-1.el6.1                         epel                            56 k
libssh2-devel                   x86_64                   1.8.0-5.0.cf.rhel6                    city-fan.org                    73 k
Updating for dependencies:
c-ares                          x86_64                   1.13.0-3.0.cf.rhel6                   city-fan.org                    97 k
curl                            x86_64                   7.57.0-1.0.cf.rhel6                   city-fan.org                   494 k
libcurl-devel                   x86_64                   7.57.0-1.0.cf.rhel6                   city-fan.org                   946 k
libssh2                         x86_64                   1.8.0-5.0.cf.rhel6                    city-fan.org                    99 k

Transaction Summary
=====================================================================================================================================
Install       3 Package(s)
Upgrade       5 Package(s)

Total download size: 2.2 M
Is this ok [y/N]: y
Downloading Packages:
(1/8): c-ares-1.13.0-3.0.cf.rhel6.x86_64.rpm                                                                  |  97 kB     00:06     
(2/8): curl-7.57.0-1.0.cf.rhel6.x86_64.rpm                                                                    | 494 kB     00:27     
(3/8): libcurl-7.57.0-1.0.cf.rhel6.x86_64.rpm                                                                 | 427 kB     00:26     
(4/8): libcurl-devel-7.57.0-1.0.cf.rhel6.x86_64.rpm                                                           | 946 kB     00:56     
(5/8): libmetalink-0.1.3-4.rhel6.x86_64.rpm                                                                   |  24 kB     00:01     
(6/8): libnghttp2-1.6.0-1.el6.1.x86_64.rpm                                                                    |  56 kB     00:00     
(7/8): libssh2-1.8.0-5.0.cf.rhel6.x86_64.rpm                                                                  |  99 kB     00:04     
(8/8): libssh2-devel-1.8.0-5.0.cf.rhel6.x86_64.rpm                                                            |  73 kB     00:05     
-------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                 17 kB/s | 2.2 MB     02:12     
warning: rpmts_HdrFromFdno: Header V4 DSA/SHA1 Signature, key ID b56a8bac: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-city-fan.org
Importing GPG key 0xB56A8BAC:
Userid : city-fan.org software librarian <[email protected]>
Package: city-fan.org-release-1-13.rhel6.noarch (installed)
From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-city-fan.org
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Updating   : libssh2-1.8.0-5.0.cf.rhel6.x86_64                                                                                1/13
  Installing : libssh2-devel-1.8.0-5.0.cf.rhel6.x86_64                                                                          2/13
  Updating   : c-ares-1.13.0-3.0.cf.rhel6.x86_64                                                                                3/13
  Installing : libmetalink-0.1.3-4.rhel6.x86_64                                                                                 4/13
  Installing : libnghttp2-1.6.0-1.el6.1.x86_64                                                                                  5/13
  Updating   : libcurl-7.57.0-1.0.cf.rhel6.x86_64                                                                               6/13
  Updating   : libcurl-devel-7.57.0-1.0.cf.rhel6.x86_64                                                                         7/13
  Updating   : curl-7.57.0-1.0.cf.rhel6.x86_64                                                                                  8/13
  Cleanup    : libcurl-devel-7.19.7-53.el6_9.x86_64                                                                             9/13
  Cleanup    : curl-7.19.7-53.el6_9.x86_64                                                                                     10/13
  Cleanup    : libcurl-7.19.7-53.el6_9.x86_64                                                                                  11/13
  Cleanup    : libssh2-1.4.2-2.el6_7.1.x86_64                                                                                  12/13
  Cleanup    : c-ares-1.10.0-3.el6.x86_64                                                                                      13/13
  Verifying  : libnghttp2-1.6.0-1.el6.1.x86_64                                                                                  1/13
  Verifying  : libcurl-devel-7.57.0-1.0.cf.rhel6.x86_64                                                                         2/13
  Verifying  : libmetalink-0.1.3-4.rhel6.x86_64                                                                                 3/13
  Verifying  : libssh2-1.8.0-5.0.cf.rhel6.x86_64                                                                                4/13
  Verifying  : libcurl-7.57.0-1.0.cf.rhel6.x86_64                                                                               5/13
  Verifying  : libssh2-devel-1.8.0-5.0.cf.rhel6.x86_64                                                                          6/13
  Verifying  : curl-7.57.0-1.0.cf.rhel6.x86_64                                                                                  7/13
  Verifying  : c-ares-1.13.0-3.0.cf.rhel6.x86_64                                                                                8/13
  Verifying  : libssh2-1.4.2-2.el6_7.1.x86_64                                                                                   9/13
  Verifying  : libcurl-devel-7.19.7-53.el6_9.x86_64                                                                            10/13
  Verifying  : libcurl-7.19.7-53.el6_9.x86_64                                                                                  11/13
  Verifying  : curl-7.19.7-53.el6_9.x86_64                                                                                     12/13
  Verifying  : c-ares-1.10.0-3.el6.x86_64                                                                                      13/13

Dependency Installed:
  libmetalink.x86_64 0:0.1.3-4.rhel6        libnghttp2.x86_64 0:1.6.0-1.el6.1        libssh2-devel.x86_64 0:1.8.0-5.0.cf.rhel6       

Updated:
  libcurl.x86_64 0:7.57.0-1.0.cf.rhel6                                                                                               

Dependency Updated:
  c-ares.x86_64 0:1.13.0-3.0.cf.rhel6       curl.x86_64 0:7.57.0-1.0.cf.rhel6       libcurl-devel.x86_64 0:7.57.0-1.0.cf.rhel6      
  libssh2.x86_64 0:1.8.0-5.0.cf.rhel6      

Complete!
[root@jrgc~]# curl --version                   
curl 7.57.0 (x86_64-pc-linux-gnu) libcurl/7.57.0 OpenSSL/1.0.1e zlib/1.2.3
Release-Date: 2017-11-29
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL libz UnixSockets HTTPS-proxy

升級 Zabbix

見 Zabbix 3.2 升級到 Zabbix 3.4.6

二、編輯配置 Zabbix 3.4.6 相關配置文件

Zabbix Web 配置歷史數據讀 Elasticsearch
[root@jrgc ~]# rm -rf /app/product/nginx/html/zabbix/conf/zabbix.conf.php
[root@jrgc ~]# cd /app/product/nginx/html/zabbix/conf
[root@centos68-evc conf]# ls
maintenance.inc.php  zabbix.conf.php  zabbix.conf.php.example
[root@jrgc conf]# cp zabbix.conf.php.example zabbix.conf.php
[root@jrgc conf]# vim zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB, $HISTORY;

$DB['TYPE']  = 'MYSQL';
$DB['SERVER'] = 'localhost';
$DB['PORT'] = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER']   = 'zabbix';
$DB['PASSWORD'] = '123456';
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA']                   = '';

$ZBX_SERVER                     = 'localhost';
$ZBX_SERVER_PORT                = '10051';
$ZBX_SERVER_NAME                = '';

$IMAGE_FORMAT_DEFAULT   = IMAGE_FORMAT_PNG;


#所有類型使用相同 ES 集群
// Elasticsearch url (can be string if same url is used for all types).
$HISTORY['url']   = 'http://192.168.29.21:9200';
// Value types stored in Elasticsearch.
$HISTORY['types'] = ['uint', 'text', 'log', 'str', 'dbl'];
--------------------------------------------------------------------------------------------------------------------------
如果不同類型使用不同的 ES 集群,可以按如下進行配置
$HISTORY['url']   = [
    'uint' => 'http://192.168.29.21:9200 ',
    'text' => 'http://192.168.29.21:9200 '
];
$HISTORY['types'] = ['uint', 'text'];
Zabbix Server 配置支持 Elasticsearch
[root@centos68-evc etc]# vim zabbix_server.conf
### Option: HistoryStorageURL
#       History storage HTTP[S] URL.
#
# Mandatory: no
# Default:
HistoryStorageURL=http://192.168.29.21:9200

### Option: HistoryStorageTypes
#       Comma separated list of value types to be sent to the history storage.
#
# Mandatory: no
# Default:
HistoryStorageTypes=uint,dbl,str,log,text
停止 Zabbix Server
[root@jrgc ~]# /etc/init.d/zabbix_server stop
Shutting down zabbix_server:                                     [  OK  ]

Elasticsearch 支持的監控項類型:uint,dbl,str,log,text

監控項數據類型|數據庫表|對應 Elasticsearch 類型:

監控項數據類型
數據庫表
對應Elasticsearch類型
Numeric(unsigned)history_uintuint
Numeric(float)
historydbl
Character
history_str
str
Log
history_log
log
Text
history_text
text

三、編輯 Elasticsearch 文件

root@centos68-evc ~]# cd /opt/software/zabbix-3.4.6/database/elasticsearch/
[root@centos68-evc elasticsearch]# ll
total 4
-rw-r--r-- 1 1001 1001 3142 Jan 15 17:11 elasticsearch.map
[root@centos68-evc elasticsearch]# more elasticsearch.map
# uint mapping

{
   "settings" : {
      "index" : {
         "number_of_replicas" : 1,
         "number_of_shards" : 5
      }
   },
   "mappings" : {
      "values" : {
         "properties" : {
            "itemid" : {
               "type" : "long"
            },
            "clock" : {
               "format" : "epoch_second",
               "type" : "date"
            },
            "value" : {
               "type" : "long"
            }
         }
      }
   }
}


# dbl mapping

{
   "settings" : {
      "index" : {
         "number_of_replicas" : 1,
         "number_of_shards" : 5
      }
   },
   "mappings" : {
      "values" : {
         "properties" : {
            "itemid" : {
               "type" : "long"
            },
            "clock" : {
               "format" : "epoch_second",
               "type" : "date"
            },
            "value" : {
               "type" : "double"
            }
         }
      }
   }
}


# str mapping

{
   "settings" : {
      "index" : {
         "number_of_replicas" : 1,
         "number_of_shards" : 5
      }
   },
   "mappings" : {
      "values" : {
         "properties" : {
            "itemid" : {
               "type" : "long"
            },
            "clock" : {
               "format" : "epoch_second",
               "type" : "date"
            },
            "value" : {
               "fields" : {
                  "analyzed" : {
                     "index" : true,
                     "type" : "text",
                     "analyzer" : "standard"
                  }
               },
               "index" : false,
               "type" : "text"
            }
         }
      }
   }
}


# text mapping

{
   "settings" : {
      "index" : {
         "number_of_replicas" : 1,
         "number_of_shards" : 5
      }
   },
   "mappings" : {
      "values" : {
         "properties" : {
            "itemid" : {
               "type" : "long"
            },
            "clock" : {
               "format" : "epoch_second",
               "type" : "date"
            },
            "value" : {
               "fields" : {
                  "analyzed" : {
                     "index" : true,
                     "type" : "text",
                     "analyzer" : "standard"
                  }
               },
               "index" : false,
               "type" : "text"
            }
         }
      }
   }
}


# log mapping

{
   "settings" : {
      "index" : {
         "number_of_replicas" : 1,
         "number_of_shards" : 5
      }
   },
   "mappings" : {
      "values" : {
         "properties" : {
            "itemid" : {
               "type" : "long"
            },
            "clock" : {
               "format" : "epoch_second",
               "type" : "date"
            },
            "value" : {
               "fields" : {
                  "analyzed" : {
                     "index" : true,
                     "type" : "text",
                     "analyzer" : "standard"
                  }
               },
               "index" : false,
               "type" : "text"
            }
         }
      }
   }
}
[root@centos68-evc ~]# curl -XPUT http://10.153.29.21:9200/uint -d '
{
    "settings" : {
       "index" : {
          "number_of_replicas" : 1,
          "number_of_shards" : 5
       }
    },
    "mappings" : {
       "values" : {
          "properties" : {
             "itemid" : {
                "type" : "long"
             },
             "clock" : {
                "format" : "epoch_second",
                "type" : "date"
             },
             "value" : {
                "type" : "long"
             }
           }
        }
     }
}
'
{"acknowledged":true,"shards_acknowledged":true}
[root@centos68-evc ~]# curl -XPUT http://10.153.29.21:9200/dbl -d '
{
   "settings" : {
      "index" : {
         "number_of_replicas" : 1,
         "number_of_shards" : 5
      }
   },
   "mappings" : {
      "values" : {
         "properties" : {
            "itemid" : {
               "type" : "long"
            },
            "clock" : {
               "format" : "epoch_second",
               "type" : "date"
            },
            "value" : {
               "type" : "double"
            }
         }
      }
   }
}
'
{"acknowledged":true,"shards_acknowledged":true}
[root@centos68-evc elasticsearch]# curl -XPUT http://10.153.29.21:9200/log -d '
 {
    "settings" : {
       "index" : {
          "number_of_replicas" : 1,
          "number_of_shards" : 5
       }
    },
    "mappings" : {
       "values" : {
          "properties" : {
             "itemid" : {
                "type" : "long"
             },
             "clock" : {
                "format" : "epoch_second",
                "type" : "date"
             },
             "value" : {
                "fields" : {
                   "analyzed" : {
                      "index" : true,
                      "type" : "text",
                      "analyzer" : "standard"
                   }
                },
                "index" : false,
                "type" : "text"
             }
          }
       }
    }
 }
 '
{"acknowledged":true,"shards_acknowledged":true}
[root@centos68-evc ~]# curl -XPUT http://10.153.29.21:9200/text -d '
 {
    "settings" : {
       "index" : {
          "number_of_replicas" : 1,
          "number_of_shards" : 5
       }
    },
    "mappings" : {
       "values" : {
          "properties" : {
             "itemid" : {
                "type" : "long"
             },
             "clock" : {
                "format" : "epoch_second",
                "type" : "date"
             },
             "value" : {
                "fields" : {
                   "analyzed" : {
                      "index" : true,
                      "type" : "text",
                      "analyzer" : "standard"
                   }
                },
                "index" : false,
                "type" : "text"
             }
          }
       }
    }
 }
 '
{"acknowledged":true,"shards_acknowledged":true}
[root@centos68-evc ~]# curl -XPUT http://10.153.29.21:9200/str -d '
 {
    "settings" : {
       "index" : {
          "number_of_replicas" : 1,
          "number_of_shards" : 5
       }
    },
    "mappings" : {
       "values" : {
          "properties" : {
             "itemid" : {
                "type" : "long"
             },
             "clock" : {
                "format" : "epoch_second",
                "type" : "date"
             },
             "value" : {
                "fields" : {
                   "analyzed" : {
                      "index" : true,
                      "type" : "text",
                      "analyzer" : "standard"
                   }
                },
                "index" : false,
                "type" : "text"
             }
          }
       }
    }
 }
 '
{"acknowledged":true,"shards_acknowledged":true}

四、測試

創建索引


Zabbix 3.4.6 新特性:歷史數據支持 Elasticsearch