ZABBIX4.0.2監控歷史資料存放Elasticsearch及叢集高可用方案
阿新 • • 發佈:2018-12-01
一、概述
Zabbix 4.0.2是一個長期支援版本(LTS),至少提供 5 年的技術支援;
下面簡單看一下Zabbix 4.0.2 新特徵
更具時效的監控項值檢查(Checking item value immediately)
新的 HTTP 監控項型別(New HTTP item type)
監控項原型可以依賴於常規的監控項(Item prototypes can depend on regular items)
更靈活的主動式 Agent 自動註冊(More flexible active agent auto-registration)
支援 MySQL 8.0(MySQL 8.0 supported)
Elasticsearch 配置基於日期的索引(Date-based indices setup for Elasticsearch)
1、環境準備
172.16.8.76 qas-zabbix-node01
172.16.8.77 vip地址
172.16.8.78 qas-zabbix-node02
2、OS及軟體版本
CentOS Linux release 7.5.1804 (Core)
zabbix-4.0.2.tar.gz
mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
jdk-8u181-linux-x64.tar.gz
elasticsearch-6.5.1.tar.gz
kibana-6.5.1-linux-x86_64.tar.gz
3、架構圖
二、mysql資料安裝(分別在node1、node2安裝)
mysql安裝請參考相關連結:
Centos7.5安裝mysql5.7.24二進位制包方式部署
三、Zabbix安裝及配置(分別在node1、node2安裝)
1、下載原始碼包
相關連結
zabbix官網:https://www.zabbix.com/
zabbix下載:https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.2/zabbix-4.0.2.tar.gz/download
2、 YUM安裝PHP環境及所需要依賴包
yum -y install gcc* make php php-gd php-mysql php-bcmath \ php-mbstring php-xml curl curl-devel net-snmp net-snmp-devel \ perl-DBI httpd mysql-devel libxml2-devel curl-devel unixODBC-devel \ net-snmp-devel OpenIPMI-devel openldap openldap-devel php-ldap libevent-devel
3、建立zabbix使用者及安裝目錄
groupadd zabbix
useradd -g zabbix zabbix
mkdir -pv /app/zabbix4
4、zabbix軟體解壓及安裝
tar -xvf zabbix-4.0.2.tar.gz
cd zabbix-4.0.2
./configure --prefix=/app/zabbix4 --enable-server --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc
make && make install
5、Mysql資料庫建立及匯入基礎資料
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to [email protected] identified by 'zabbix2018';
grant all privileges on zabbix.* to [email protected]"172.16.8.%" identified by 'zabbix2018';
FLUSH PRIVILEGES;
匯入資料庫
cd /app/tools/zabbix-4.0.2/database/mysql/
mysql -uzabbix -pzabbix2018 zabbix < schema.sql
mysql -uzabbix -pzabbix2018 zabbix < images.sql
mysql -uzabbix -pzabbix2018 zabbix < data.sql
6、修改PHP的配置引數
vim /etc/php.ini
date.timezone= Asia/Shanghai
max_execution_time = 300
post_max_size = 32M
memory_limit = 128M
mbstring.func_overload = 1
max_input_time = 300
7、拷貝zabbix資料到httpd目錄並授權
cd /app/tools/zabbix-4.0.2/
cp -r frontends/php/ /var/www/html/zabbix
ll /var/www/html/
chown -R apache.apache /var/www/html/zabbix/
8、修改配置檔案zabbix_server.conf
建立相關目錄
mkdir /app/zabbix4/{tmp,logs,alertscripts,externalscripts} -p
chown -R zabbix.zabbix /app/zabbix4
修配置檔案如下:
# grep -n ^[a-Z] /app/zabbix4/etc/zabbix_server.conf
38:LogFile=/app/zabbix4/logs/zabbix_server.log
68:PidFile=/app/zabbix4/tmp/zabbix_server.pid
94:DBName=zabbix
110:DBUser=zabbix
118:DBPassword=zabbix2018
125:DBSocket=/tmp/mysql.sock
465:Timeout=4
506:AlertScriptsPath=/app/zabbix4/alertscripts
515:ExternalScripts=/app/zabbix4/externalscripts
551:LogSlowQueries=3000
9、拷貝zabbix服務啟動指令碼
cd /app/tools/zabbix-4.0.2/
cp misc/init.d/fedora/core/zabbix_server /etc/init.d/
vim /etc/init.d/zabbix_server
BASEDIR=/app/zabbix4
10、啟動服務及設定開機啟動
chkconfig --add zabbix_server
chkconfig zabbix_server on
systemctl enable httpd.service
systemctl start httpd.service
/etc/init.d/zabbix_server restart
11、web服務初始化
登陸預設使用者名稱:Admin,密碼:zabbix
三、Elasticsearch叢集安裝及配置
1、安裝java
tar -xvf jdk-8u181-linux-x64.tar.gz -C ../
cd /app/
mv jdk1.8.0_181/ jdk
chown -R root.root jdk
編輯profile檔案,新增jdk環境變數
vim /etc/profile
JAVA_HOME=//app/jdk/jdk1.8.0_181
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
2、elasticsearch解壓及安裝
tar -xvf elasticsearch-6.5.1.tar.gz -C ../
cd /app/
mv elasticsearch-6.5.1 elasticsearch6.5
chown -R zabbix.zabbix elasticsearch6.5
su - zabbix
mkdir -p /app/elasticsearch6.5/data
3、修改elasticsearch叢集配置檔案
su - zabbix
node01
mkdir -p /app/elasticsearch6.5/data
grep -n ^[a-Z] /app/elasticsearch6.5/config/elasticsearch.yml
17:cluster.name: app-zabbix
23:node.name: 172.16.8.76
33:path.data: /app/elasticsearch6.5/data
37:path.logs: /app/elasticsearch6.5/logs
43:bootstrap.memory_lock: true
55:network.host: 0.0.0.0
59:http.port: 9200
60:transport.tcp.port: 9300
69:discovery.zen.ping.unicast.hosts: ["172.16.8.76:9300", "172.16.8.78:9300"]
73:discovery.zen.minimum_master_nodes: 1
90:bootstrap.system_call_filter: false
91:http.cors.enabled: true
92:http.cors.allow-origin: "*"
node02
grep -n ^[a-Z] /app/elasticsearch6.5/config/elasticsearch.yml
17:cluster.name: app-zabbix
23:node.name: 172.16.8.78
33:path.data: /app/elasticsearch6.5/data
37:path.logs: /app/elasticsearch6.5/logs
43:bootstrap.memory_lock: true
55:network.host: 0.0.0.0
59:http.port: 9200
60:transport.tcp.port: 9300
69:discovery.zen.ping.unicast.hosts: ["172.16.8.76:9300", "172.16.8.78:9300"]
73:discovery.zen.minimum_master_nodes: 1
90:bootstrap.system_call_filter: false
91:http.cors.enabled: true
92:http.cors.allow-origin: "*"
4、編輯limits.conf配置檔案
vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
zabbix soft memlock unlimited
zabbix hard memlock unlimited
zabbix hard nproc 4096
zabbix soft nproc 4096
5、核心引數優化
vim /etc/sysctl.conf
vm.max_map_count=262144
vm.swappiness=1
用命令sysctl -p 生效
sysctl vm.max_map_count 檢視值是否修改, 也可以通過sysctl -w vm.max_map_count=262144 臨時設定值
6、啟動elasticsearch 服務
```.
./elasticsearch -d
http://172.16.8.76:9200/
![](http://i2.51cto.com/images/blog/201812/01/e9a4db690ef8cb4e11acf4b170f0cfe9.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
http://172.16.8.78:9200/
![](http://i2.51cto.com/images/blog/201812/01/4de59091becd683df9724d610250e3cb.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)