CentOS上安裝ElasticSearch5.4叢集
最近學習Elasticsearch,順便記錄下操作步驟,供日後參考
安裝環境 CentOS release 6.6
1、因Elasticsearch是基於java寫的,所以它的執行環境中需要java的支援,在Linux下執行命令:java -version,檢查Jar包是否安裝
安裝java版本至少是1.8以上
2、首先準備下載Elasticsearch5.5.2 安裝包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.2.tar.gz
3、下載到/usr/local 目錄下,解壓
tar -zxvf elasticsearch-5.2.2.tar.gz
4、因為Elasticsearch5.0之後,不能使用root賬戶啟動,我們先建立一個elasticsearch組和賬戶
useradd elasticsearch -g elasticsearch -p elasticsearch
chown -R elasticsearch:elasticsearch elasticsearch-5.2.2
5、啟動elasticsearch
cd /usr/local/elasticsearch5.2.2/
su elasticsearch
./bin/elasticsearch
這時候我們看見下面的提示,說明就成功了
[plain]- [[email protected] bin]$ ./elasticsearch
- [2017-03-02T21:43:21,185][INFO ][o.e.n.Node ] [] initializing ...
-
[2017-03-02T21:43:21,264][INFO ][o.e.e.NodeEnvironment ] [uY3prpy] using [1] data paths, mounts [[/ (/dev/mapper/VolGroup-lv_root)]], net usable_space [43.5gb], net total_space [54.6gb], spins? [possibly], types [ext4]
- [2017-03-02T21:43:21,265][INFO ][o.e.e.NodeEnvironment ] [uY3prpy] heap size [1.9gb], compressed ordinary object pointers [true]
- [2017-03-02T21:43:21,268][INFO ][o.e.n.Node ] node name [uY3prpy] derived from node ID [uY3prpyqTHim5twauiVWhQ]; set [node.name] to override
- [2017-03-02T21:43:21,271][INFO ][o.e.n.Node ] version[5.2.2], pid[5602], build[f9d9b74/2017-02-24T17:26:45.835Z], OS[Linux/3.10.5-3.el6.x86_64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_121/25.121-b13]
- [2017-03-02T21:43:22,226][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [aggs-matrix-stats]
- [2017-03-02T21:43:22,226][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [ingest-common]
- [2017-03-02T21:43:22,226][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [lang-expression]
- [2017-03-02T21:43:22,227][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [lang-groovy]
- [2017-03-02T21:43:22,227][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [lang-mustache]
- [2017-03-02T21:43:22,227][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [lang-painless]
- [2017-03-02T21:43:22,228][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [percolator]
- [2017-03-02T21:43:22,228][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [reindex]
- [2017-03-02T21:43:22,228][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [transport-netty3]
- [2017-03-02T21:43:22,229][INFO ][o.e.p.PluginsService ] [uY3prpy] loaded module [transport-netty4]
- [2017-03-02T21:43:22,230][INFO ][o.e.p.PluginsService ] [uY3prpy] no plugins loaded
- [2017-03-02T21:43:24,689][INFO ][o.e.n.Node ] initialized
- [2017-03-02T21:43:24,689][INFO ][o.e.n.Node ] [uY3prpy] starting ...
- [2017-03-02T21:43:24,929][INFO ][o.e.t.TransportService ] [uY3prpy] publish_address {10.245.250.65:9300}, bound_addresses {10.245.250.65:9300}
- [2017-03-02T21:43:24,948][INFO ][o.e.b.BootstrapChecks ] [uY3prpy] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
- [2017-03-02T21:43:28,010][INFO ][o.e.c.s.ClusterService ] [uY3prpy] new_master {uY3prpy}{uY3prpyqTHim5twauiVWhQ}{AqALBH68RCucWcPmHCE6dw}{10.245.250.65}{10.245.250.65:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
- [2017-03-02T21:43:28,034][INFO ][o.e.h.HttpServer ] [uY3prpy] publish_address {10.245.250.65:9200}, bound_addresses {10.245.250.65:9200}
- [2017-03-02T21:43:28,034][INFO ][o.e.n.Node ] [uY3prpy] started
- [2017-03-02T21:43:28,061][INFO ][o.e.g.GatewayService ] [uY3prpy] recovered [0] indices into cluster_state
執行 curl http://localhost:9200
開啟另一個終端進行測試:
curl 'http://localhost:9200/?pretty'
你能看到以下返回資訊:
{
"status": 200,
"name": "Shrunken Bones",
"version": {
"number": "1.4.0",
"lucene_version": "4.10"
},
"tagline": "You Know, for Search"
}
說明安裝成功。
但是我們希望能夠使用ip訪問,那麼還需要設定相關內容
跳轉到Elasticsearch的config配置檔案下,使用vim開啟elasticsearch.yml,找到裡面的"network.host",將其改為本機IP,儲存。
cd elasticsearch/config/
vim elasticsearch.yml
重啟ElasticSearch,然後使用http://192.168.37.137:9200/訪問。
我們常見錯誤:
1、啟動 elasticsearch 如出現異常 can not run elasticsearch as root
解決方法:建立ES 賬戶,修改資料夾 檔案 所屬使用者 組
2、啟動異常:ERROR: bootstrap checks failed
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
問題原因:因為Centos6不支援SecComp,而ES5.2.1預設bootstrap.system_call_filter為true進行檢測,所以導致檢測失敗,失敗後直接導致ES不能啟動。詳見 :https://github.com/elastic/elasticsearch/issues/22899
解決方法:在elasticsearch.yml中配置bootstrap.system_call_filter為false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
3、啟動後,如果只有本地可以訪問,嘗試修改配置檔案 elasticsearch.yml
中network.host(注意配置檔案格式不是以 # 開頭的要空一格, : 後要空一格)
為 network.host: 0.0.0.0
預設埠是 9200
注意:關閉防火牆 或者開放9200埠
4、ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]
解決方法:切換到root使用者,編輯limits.conf 新增類似如下內容
vi /etc/security/limits.conf
新增如下內容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
5、max number of threads [1024] for user [lish] likely too low, increase to at least [2048]
解決:切換到root使用者,進入limits.d目錄下修改配置檔案。
vi /etc/security/limits.d/90-nproc.conf
修改如下內容:
* soft nproc 1024
#修改為
* soft nproc 2048
6、max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解決:切換到root使用者修改配置sysctl.conf
vi /etc/sysctl.conf
新增下面配置:
vm.max_map_count=655360
並執行命令:
sysctl -p
然後,重新啟動elasticsearch,即可啟動成功。
問題一:警告提示
[2016-11-06T16:27:21,712][WARN ][o.e.b.JNANatives ] unable to install syscall filter:
java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in
at org.elasticsearch.bootstrap.Seccomp.linuxImpl(Seccomp.java:349) ~[elasticsearch-5.0.0.jar:5.0.0]
at org.elasticsearch.bootstrap.Seccomp.init(Seccomp.java:630) ~[elasticsearch-5.0.0.jar:5.0.0]
報了一大串錯誤,其實只是一個警告。
解決:使用心得linux版本,就不會出現此類問題了。
問題二:ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]
解決:切換到root使用者,編輯limits.conf 新增類似如下內容
vi /etc/security/limits.conf
新增如下內容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
問題三:max number of threads [1024] for user [lish] likely too low, increase to at least [2048]
解決:切換到root使用者,進入limits.d目錄下修改配置檔案。
vi /etc/security/limits.d/90-nproc.conf
修改如下內容:
* soft nproc 1024
#修改為
* soft nproc 2048
問題四:max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解決:切換到root使用者修改配置sysctl.conf
vi /etc/sysctl.conf
新增下面配置:
vm.max_map_count=655360
並執行命令:
sysctl -p
然後,重新啟動elasticsearch,即可啟動成功。
一、 安裝JDK
1.1下載安裝
cd /usr/local/src
tar -zxvf jdk-8u131-linux-x64.tar.gz
mv jdk1.8.0_131 /usr/local/java
1.2修改配置檔案
vim /etc/profile //最後面新增
export JAVA_HOME=/usr/local/java CLASSPATH=/usr/local/java/lib/dt.jar/usr/local/java/lib/tools.jar PATH=/usr/local/java/bin:$PATH export PATH JAVA_HOMECLASSPATH |
source /etc/profile //匯入配置檔案
java -version //檢視java版本
二、安裝Elasticsearch
2.1下載安裝
cd /usr/local/src/
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.0.tar.gz
tar -xvf elasticsearch-5.4.0.tar.gz
mv elasticsearch-5.4.0 /usr/local/
cd /usr/local/elasticsearch-5.4.0/
2.2系統調優
1)配置系統最大開啟檔案描述符數
vim /etc/sysctl.conf
vm.max_map_count = 262144 |
執行以下命令生效
sysctl -p
2)配置程序最大開啟檔案描述符
vim /etc/security/limits.conf //檔案最後
* soft nofile 65536 * hard nofile 65536 |
2.3編寫ES Master節點配置檔案
vim config/elasticsearch.yml
cluster.name: my-es node.name: node-1 network.host: 192.168.19.141 http.port: 9200 transport.tcp.port: 9300 discovery.zen.ping.unicast.hosts: ["192.168.19.141","192.168.19.142","192.168.19.143"] discovery.zen.minimum_master_nodes: 2 #避免出現跨域問題 http.cors.enabled: true http.cors.allow-origin: "*" |
第二個、第三個節點的配置只需修改成對應的即可。
2.4啟動ES
用root賬號啟動會報錯:java.lang.RuntimeException: can not runelasticsearch as root
因為Elasticsearch5.0之後,不能使用root賬戶啟動,我們先建立一個elasticsearch組和賬戶:
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
chown -R elsearch.elsearch /usr/local/elasticsearch-5.4.0/
後臺啟動:
su -elsearch -c "/usr/local/elasticsearch-5.4.0/bin/elasticsearch -d"
2.5安裝head開源外掛
只在master上安裝外掛即可。elasticsearch5不可以直接通過plugin -install mobz/elasticsearch-head安裝,並且head需要在node環境下執行,具體步驟如下:
第一步:安裝node
curl -sL -o /etc/yum.repos.d/khara-nodejs.repohttps://copr.fedoraproject.org/coprs/khara/nodejs/repo/epel-7/khara-nodejs-epel-7.repo
yum install -y nodejs nodejs-npm
檢視安裝版本
第二步:安裝grunt
cd /usr/lib/node_modules/npm/
npm install grunt-cli
npm install grunt
檢視版本:
/usr/lib/node_modules/npm/node_modules/.bin/grunt -version
第三步:安裝head
yum install -y git
cd /usr/local/
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head/
npm install
注意:這步可以會有一些報錯資訊,可以忽略。
vim _site/app.js
# 修改 『http://localhost:9200』欄位到本機ES埠與IP
第四步:啟動head並在後臺執行
./node_modules/grunt/bin/gruntserver &
瀏覽器訪問:
注意:若不能形成叢集,可能是 iptables 或者 selinux 的原因
2.6開機自啟
vim /etc/rc.local
su - elsearch -c "/usr/local/elasticsearch-5.3.1/bin/elasticsearch -d" /usr/local/elasticsearch-head/node_modules/grunt/bin/grunt server & |
儲存退出後,給自啟檔案賦予執行許可權(若不加,Centos7不會開機執行)
chmod +x /etc/rc.d/rc.local