借鑒網上資料並實施驗證結果
elasticsearch6.6安裝
安裝包下載路徑
https://www.elastic.co/downloads/elasticsearch
本文使用安裝包
elasticsearch-6.6.0.tar.gz
系統
Centos 6
安裝
解壓路徑
/opt/elasticsearch-6.6.0
jdk1.8(原系統很多項目是用的jdk1.7的,保持不變,新源碼裝jdk1.8至目錄/opt/jdk1.8)
一.修改es的jdk環境變量(es6.x需要jdk1.8版本)
vim ./bin/elasticsearch-env 添加並修改如下: JAVA_HOME_1="/opt/jdk1.8" 並修改原JAVA_HOME為JAVA_HOME_1
如下圖:
二.修改初始分配jvm內存大小
vim ./config/jvm.options -Xms512m -Xmx512m
三.修改es配置文件
vim ./config/elasticsearch.yml cluster.name: test node.name: test-1 path.data: /opt/elasticsearch-6.6.0/data path.logs: /opt/elasticsearch-6.6.0/logs bootstrap.memory_lock: false bootstrap.system_call_filter: false network.host: 0.0.0.0 http.port: 9400 #啟用http配置 http.cors.enabled: true http.cors.allow-origin: "*"
部分重要配置文件說明:
1.cluster.name:test
配置elasticsearch的集群名稱,elasticsearch會自動發現在同一網段下的集群名為test的主機,如果在同一網段下有多個集群,就可以用這個屬性來區分不同的集群。生產環境時建議更改。
2.node.name: test-1
節點名,生產環境中建議更改以能方便的指定集群中的節點對應的機器
3.path.data: /opt/elasticsearch-6.6.0/data
設置索引數據的存儲路徑,默認是es根目錄下的data文件夾,可以設置多個存儲路徑,用逗號隔開。
四.權限與啟動,es6.x不允許root用戶啟動es(啟動問題及解決見文章末)
useradd elsearch passwd elsearch chown -R elsearch.elsearch elasticsearch-6.6.0 su elsearch
#測試登陸es,如果后台報錯解決辦法在文末 ./bin/elasticsearch
登陸瀏覽器測試,沒問題再退出程序,繼續下一步
五.安裝插件head
1.nodejs安裝 (由於head插件本質上還是一個nodejs的工程,因此需要安裝node,使用npm來安裝依賴的包)
官網下載地址: https://nodejs.org/en/download/
本次使用的源碼包是:node-v8.9.0-linux-x64.tar.gz (最新已經更新到v10版本了,為了防止一些版本兼容問題,我還是按照網上博客版本來的)
#解壓並重命名路徑
/opt/node
#本文也沒有通過修改環境變量的方式,直接通過軟鏈接來使用命令
ln -s /opt/node/bin/node /usr/bin/node ln -s /opt/node/bin/npm /usr/bin/npm
#設定nodejs安裝軟件的代理服務器
npm config set registry https://registry.npm.taobao.org
#執行npm,安裝grunt (grunt是基於Node.js的項目構建工具,可以進行打包壓縮、測試、執行等等工作,elasticsearch-head插件就是通過grunt啟動的)
npm install -g grunt npm install -g grunt-cli
#創建 grunt軟鏈接
ln -s /opt/node/bin/grunt /usr/bin/grunt
2.phantomjs安裝
#官網下載地址
https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
#解壓並重命名路徑
/opt/phantomjs
#安裝依賴
yum -y install wget fontconfig
#創建phantomjs軟鏈接
ln -s /opt/phantomjs/bin/phantomjs /usr/bin/
#測試
[root@danny phantomjs]# phantomjs
phantomjs>
3.安裝head
下載路徑
https://github.com/mobz/elasticsearch-hea
#安裝unzip解壓工具(如果沒有unzip,就需要安裝這個)
yum install -y unzip
#解壓文件到 head
unzip elasticsearch-head-master.zip
#進入head的目錄
cd elasticsearch-head-master/
#安裝一下這個bzip2 ,如果沒有,在編譯head,會報錯
yum install -y bzip2
#更換npm源
npm install -g cnpm --registry=https://registry.npm.taobao.org
#安裝(進入 elasticsearch-head-master)的目錄,執行安裝命令
npm install
注意:此時可能會報錯如下:
#執行以下安裝命令即可
npm -g install phantomjs-prebuilt@2.1.16 --ignore-script
#配置head,默認端口號是9100,此處改一下測試
vim Gruntfile.js connect: { server: { options: { hostname:'0.0.0.0', //此處是添加段 port: 9101, base: '.', keepalive: true } } }
#后台啟動head服務
grunt server &
#或者使用官網啟動方式
npm run start &
如圖
備注:網頁驗證需要es啟用http配置,如上config/elasticsearch.yml添加的http配置
#重啟es
[root@danny elasticsearch-6.6.0]# ./bin/elasticsearch -d
測試
es訪問測試
head訪問測試
感謝:https://blog.csdn.net/yelllowcong/article/details/78787012
六.插件ik分詞器的安裝
1.下載地址 https://github.com/medcl/elasticsearch-analysis-ik/releases
注:分詞器版本一定要與ES版本保持一致
2.安裝
將安裝包直接上傳至es的插件目錄解壓即可
cd /opt/elasticsearch-6.6.0/plugins mkdir ik unzip elasticsearch-analysis-ik-6.6.0.zip rm -rf elasticsearch-analysis-ik-6.6.0.zip #再打開elasticsearch-6.6.0/config下的jvm.options,在最后面加上一行: -Djava.security.policy=/opt/elasticsearch-6.6.0/plugins/ik/plugin-security.policy #重啟 su elsearch ./bin/elasticsearch -d
3.測試ik插件(通過head插件測試)
1)查看日志看是否已經加載analysis-ik
2)登錄head上驗證查看
4.注意
ES6.0與ik6.0進行集成安裝之后,只能通過head工具來進行測試,通過url進行測試的時候會報錯,這是一個bug已經提交到gethub上了
問題
搭建過程遇到過的坑(主要是系統設置問題)
啟動es報錯:
1.
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
vim /etc/sysctl.conf vm.max_map_count = 262144 //添加
2.
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
vim config/elasticsearch.yml #添加下面兩個 bootstrap.memory_lock: false bootstrap.system_call_filter: false
原因:
這是在因為Centos6不支持SecComp,而es6.x默認bootstrap.system_call_filter為true進行檢測,所以導致檢測失敗,失敗后直接導致es不能啟動。
原因解釋出處:https://github.com/elastic/elasticsearch/issues/22899
3.
java.lang.RuntimeException: can not runelasticsearch as root
這是因為es6.x為了安全考慮,已經不讓root啟動,2.x版本的還有解決辦法,修改bin中的啟動文件可實現root啟動,但是后續版本已經沒用了
解決辦法:
useradd elsearch passwd elsearch chown -R elsearch.elsearch elasticsearch-6.6.0 su elsearch ./bin/elasticsearch -d
4.
max file descriptors [65535] for elasticsearchprocess is too low, increase to at least [65536]
maxfile descriptors為最大文件描述符,設置其大於65536即可
vim /etc/security/limits.conf * - nofile 65536 * - memlock unlimited
5.
ERROR: [3] max number of threads [1024] for user [elsearch] is too low, increase to at least [4096]
vim /etc/security/limits.d/90-nproc.conf * soft nproc 4096
注銷用戶,重新登錄生效