一、 安裝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
<a href="https://s2.51cto.com/wyfs02/M02/95/E3/wKiom1kau03S4pXYAADW-ftKISc096.png" target="_blank"></a>
因為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"
<a href="https://s2.51cto.com/wyfs02/M02/95/E3/wKiom1kau7TgS7UlAAA8HMjWqEY921.png" target="_blank"></a>
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
檢視安裝版本
<a href="https://s2.51cto.com/wyfs02/M02/95/E3/wKiom1kavCzgL6dlAAANmF9-EeM123.png" target="_blank"></a>
第二步:安裝grunt
cd /usr/lib/node_modules/npm/
npm install grunt-cli
npm install grunt
檢視版本:
/usr/lib/node_modules/npm/node_modules/.bin/grunt -version
<a href="https://s2.51cto.com/wyfs02/M02/95/E3/wKioL1kavD6RUiYsAAAU-ALvXI8507.png" target="_blank"></a>
第三步:安裝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
<a href="https://s2.51cto.com/wyfs02/M01/95/E3/wKiom1kavFzg6O3kAAA6UTJvgu8398.png" target="_blank"></a>
第四步:啟動head并在背景運作
./node_modules/grunt/bin/gruntserver &
<a href="https://s1.51cto.com/wyfs02/M02/95/E3/wKioL1kavHaywrbEAAAwb8KRJUg286.png" target="_blank"></a>
浏覽器通路:
<a href="https://s2.51cto.com/wyfs02/M01/95/E3/wKioL1kavI3yaVRDAAChTQTCHEA851.png" target="_blank"></a>
注意:若不能形成叢集,可能是 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
本文轉自M四月天 51CTO部落格,原文連結:http://blog.51cto.com/msiyuetian/1926325,如需轉載請自行聯系原作者