本文內容 Elasticsearch logstash 本文介紹安裝 logstash 2.2.0 和 elasticsearch 2.2.0,操作系統環境版本是 CentOS/Linux 2.6.32-504.23.4.el6.x86_64。 安裝 JDK 是必須的,一般操作系統都會有,只是版本的...
本文內容
- Elasticsearch
- logstash
本文介紹安裝 logstash 2.2.0 和 elasticsearch 2.2.0,操作系統環境版本是 CentOS/Linux 2.6.32-504.23.4.el6.x86_64。
安裝 JDK 是必須的,一般操作系統都會有,只是版本的問題,後面會提到。
而 Kibana 只是一個用純 JavaScript 寫的前端 UI,暫不介紹。因為,最近公司需要分析所有系統的日誌,才搞 ELK,但人員和時間有限,三個框架都研究,不太現實。
Elasticsearch
Elasticsearch(簡稱,ES)提供 ZIP、TAR、DEB 和 RPM 包。但 Github 上提供了一個針對中文環境的 Elasticsearch-RTF,RTF 即 Ready To Fly,它是一個繼承了基本插件(如服務封裝、中文分詞、mapper-attachments、transport-thrift、tools.carrot2 等)的並帶有示常式序的可直接上手的簡易工程版本,換句話說,幫你入門的。本文針對 Elasticsearch-RTF 為例。基本上,elasticsearch 解壓後就能使用。
假設你已經從 Github 上下載 elasticsearch-rtf,名為 elasticsearch-master.zip,並上傳到你的 Linux 伺服器 /usr/local/elasticsearch目錄(如果沒有,就用 mkdir 命令創建一個)。
- 現在,解壓,並重新命名文件夾:
[root@vcyber local]# cd /usr/local/elasticsearch
[root@vcyber local]# unzip elasticsearch-master.zip
[root@vcyber elasticsearch]# ls
elasticsearch-master elasticsearch-master.zip
[root@vcyber local]# mv elasticsearch-master elasticsearch
[root@vcyber elasticsearch]# ls
elasticsearch elasticsearch-master.zip
- 嘗試運行 elasticsearch:
Linux 環境:
[root@vcyber elasticsearch]# pwd
/usr/local/elasticsearch/elasticsearch
[root@vcyber elasticsearch]# bin/elasticsearch
windows 環境,執行相應的 .bat 文件,即 elasticsearch.bat。
但報錯了:
[root@vcyber elasticsearch]# bin/elasticsearch
Exception in thread "main" java.lang.RuntimeException: Java version: Oracle Cooration 1.7.0_51 [Java HotSpot(TM) 64-Bit Server VM 24.51-b03] suffers from crical bug https://bugs.openjdk.java.net/browse/JDK-8024830 which can cause dataorruption.
Please upgrade the JVM, see http://www.elastic.co/guide/en/elasticsearch/referce/current/_installation.html for current recommendations.
If you absolutely cannot upgrade, please add -XX:-UseSuperWord to the JAVA_OPT environment variable.
Upgrading is preferred, this workaround will result in degraded performance.
at org.elasticsearch.bootstrap.JVMCheck.check(JVMCheck.java:123)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:283)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:3
Refer to the log for complete error details.
大意是:Java 運行時異常,本機版本 JDK 有 bug……讓升級 JVM。如果實在不能升級,就向 JAVA_OPT 環境變數添加 -XX:-UseSuperWord 選項。
於是,看一下本機的Java 版本:
[root@vcyber elasticsearch]# java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
[root@vcyber elasticsearch]# echo $JAVA_HOME
/usr/java/jdk1.7.0_51
[root@vcyber elasticsearch]#
版本是 1.7.0_51。再在官網查了一下,說:“Elasticsearch requires at least Java 7. Specifically as of this writing, it is recommended that you use the Oracle JDK version 1.8.0_72. Java installation varies from platform to platform so we won’t go into those details here. Oracle’s recommended installation documentation can be found on Oracle’s website. Suffice to say, before you install Elasticsearch, please check your Java version first by running (and then install/upgrade accordingly if needed):”,大意是,ES 至少要求 7,推薦使用 1.8.0_72。
- 那就刪除之前的版本,按個新的吧。先刪掉之前的 JDK,然後再用 yum 按個新的:
[root@vcyber elasticsearch]# yum list installed | grep java
[root@vcyber elasticsearch]# yum list installed | grep jdk
jdk.x86_64 2000:1.7.0_51-fcs installed
[root@vcyber elasticsearch]# yum -y remove jdk.x86_64
……
[root@vcyber elasticsearch]#yum -y install java-1.8.0-openjdk*
……
註意:java-1.8.0-openjdk*”,後面有個星號,即安裝 java 全部相關的東西~
- 安裝完成後,設置 JDK 的環境變數:
[root@vcyber elasticsearch]# export JAVA_HOME=/usr/lib/jvm/java-1.8.0
[root@vcyber elasticsearch]# export PATH=$JAVA_HOME/bin:$PATH
[root@vcyber elasticsearch]# export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
[root@vcyber elasticsearch]# java -version
openjdk version "1.8.0_71"
OpenJDK Runtime Environment (build 1.8.0_71-b15)
OpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)
[root@vcyber elasticsearch]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0
[root@vcyber elasticsearch]#
另外,JDK 安裝在了我機器的 /usr/lib/jvm 目錄下,自己確認一下你的路徑。
- 再次運行:
[root@vcyber elasticsearch]# bin/elasticsearch
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:285)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.
[root@vcyber elasticsearch]#
- 又報錯,elasticsearch 不能用 root 用戶運行,那就建立一個:
[root@vcyber elasticsearch]# groupadd es
[root@vcyber elasticsearch]# useradd -g es es
[root@vcyber elasticsearch]# passwd es
Changing password for user es.
New password:
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@vcyber elasticsearch]#
[root@vcyber elasticsearch]# chown -R root .
[root@vcyber elasticsearch]# chown -R es .
[root@vcyber elasticsearch]# chgrp -R es .
[root@vcyber elasticsearch]# ls -l