生活随笔
收集整理的這篇文章主要介紹了
elasticsearch-6.0.1安装
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
elasticsearch-6.0.1安裝
0. 介紹: ElasticSearch是一個基于Lucene的搜索服務(wù)器。它提供了一個分布式多用戶能力的全文搜索引擎;是目前全文搜索引擎的首選。 Elastic 的底層是開源庫 Lucene。但是,沒法直接用 Lucene,必須自己寫代碼去調(diào)用它的接口。Elastic 是 Lucene 的封裝,提供了 REST API 的操作接口,開箱即用。 Elasticsearch是用Java開發(fā)的,并作為Apache許可條款下的開放源碼發(fā)布,是當(dāng)前流行的企業(yè)級搜索引擎。設(shè)計用于云計算中,能夠達(dá)到實(shí)時搜索,穩(wěn)定,可靠,快速,安裝使用方便。
1. 環(huán)境準(zhǔn)備: ? ? 系統(tǒng): CentOS Linux release 7.4.1708 (Core)
? ? Java環(huán)境: JDK1.8(若未安裝,需先安裝)
集群環(huán)境: 172.16.64.137 (默認(rèn)master node) 172.16.64.138 172.16.64.147
2.下載elasticsearch-6.0.1: ? ? ?官網(wǎng): https://www.elastic.co/downloads/elasticsearch
? ? 下載鏈接: https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.1.tar.gz
? ? 解壓、移動 Python 1 2 tar -zxvf elasticsearch-6.0.1.tar.gz mv elasticsearch-6.0.1.tar.gz /usr/local/elasticsearch
3. 配置主配置文件: vim /usr/local/elasticsearch/config/elasticsearch.yml
Python 1 2 3 4 5 6 7 8 9 10 11 12 13 cluster.name: cluster-es node.name: es-node1 path.data: /usr/local/elasticsearch/data path.logs: /usr/local/elasticsearch/logs network.host: 172.16.64.137 http.port: 9200 discovery.zen.minimum_master_nodes: 1 discovery.zen.ping.unicast.hosts: ["172.16.64.137", "172.16.64.138", "172.16.64.147"] node.master: true node.data: false discovery.zen.fd.ping_timeout: 180s discovery.zen.fd.ping_retries: 10 discovery.zen.fd.ping_interval: 30s
配置文件詳解: Python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 cluster.name: cluster-es # 集群名稱 node.name: es-node1 # 節(jié)點(diǎn)名稱,其余兩臺為es-node2、es-node3 path.data: /usr/local/elasticsearch/data # 數(shù)據(jù)目錄 path.logs: /usr/local/elasticsearch/logs # 日志目錄 network.host: 172.16.64.137 # 本機(jī)IP http.port: 9200 # 本機(jī)http端口 discovery.zen.minimum_master_nodes: 1 # 指定集群中的節(jié)點(diǎn)中有幾個有master資格的節(jié)點(diǎn) discovery.zen.ping.unicast.hosts: ["172.16.64.137", "172.16.64.138", "172.16.64.147"] # 指定集群中其他節(jié)點(diǎn)的IP node.master: true # 是否為master node.data: false # 是否為數(shù)據(jù)節(jié)點(diǎn) discovery.zen.fd.ping_timeout: 180s # 設(shè)置集群中自動發(fā)現(xiàn)其它節(jié)點(diǎn)時ping連接超時時間 discovery.zen.fd.ping_retries: 10 # 集群中節(jié)點(diǎn)之間ping的次數(shù) discovery.zen.fd.ping_interval: 30s # 集群中節(jié)點(diǎn)之間ping的時間間隔
4. 配置足夠內(nèi)存 Python 1 2 3 vim /usr/local/elasticsearch/config/jvm.options -Xms2g -Xmx2g
5. 啟動 ES有執(zhí)行腳本的能力,因安全因素,
不能在root用戶下運(yùn)行,強(qiáng)行運(yùn)行會報如下錯誤: org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
Python 1 2 3 4 5 6 7 8 9 # 創(chuàng)建用戶 useradd ela # 賦予ela用戶所有者權(quán)限 chown -R ela:ela /usr/local/elasticsearch su - ela [ela@test1 ~]$/usr/local/elasticsearch/bin/elasticsearch -d??# -d參數(shù)是后臺運(yùn)行 # 建議按以下命令啟動 [ela@test1 ~]$ nohup /usr/local/elasticsearch/bin/elasticsearch &
正常情況下,啟動后,網(wǎng)頁訪問172.16.16.206:9200會有以下內(nèi)容顯示
Python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { ??"name" : "dcV-DRJ", ??"cluster_name" : "elasticsearch", ??"cluster_uuid" : "N6qGE15TQqq9-RQedQqqEw", ??"version" : { ????"number" : "6.1.1", ????"build_hash" : "bd92e7f", ????"build_date" : "2017-12-17T20:23:25.338Z", ????"build_snapshot" : false, ????"lucene_version" : "7.1.0", ????"minimum_wire_compatibility_version" : "5.6.0", ????"minimum_index_compatibility_version" : "5.0.0" ??}, ??"tagline" : "You Know, for Search" }
啟動錯誤收集: ? ? 錯誤一: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
? ? 解決: Python 1 2 3 4 5 6 7 vi /etc/security/limits.conf #添加如下內(nèi)容: * soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096
? ? 錯誤二: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
? ? 解決: 最大虛擬內(nèi)存太小
Python 1 2 3 4 5 vim /etc/sysctl.conf 添加一行 vm.max_map_count=655360 # 執(zhí)行命令: sysctl -p
7. head插件安裝 安裝head插件前,需要先安裝Node.js,需要手動安裝,yum安裝的版本太低
? ? 7.1安裝Node.js ? ? 官網(wǎng): https://nodejs.org/en/download/
? ? 下載鏈接: wget https://nodejs.org/dist/v8.9.3/node-v8.9.3.tar.gz
Python 1 2 3 4 5 tar node-v8.9.3.tar.gz cd node-v8.9.3 ./configure --prefix=/usr/local/node/ make # make時間較長 make install
? ? 添加系統(tǒng)變量: Python 1 2 3 4 5 6 vim /etc/profile export NODEJS_HOME=/usr/local/node/ export PATH=$PATH:$NODEJS_HOME/bin # 使變量生效 source /etc/profile
? ? 驗(yàn)證: Python 1 2 [root@test1 bin]# node -v v8.9.3
在安裝node的同時,會將npm模塊一起安裝
? ? 7.2 安裝head插件 ? ? 下載 Python 1 2 git clone git://github.com/mobz/elasticsearch-head.git cd elasticsearch-head
? ? 安裝(方法1) Python ? ? 安裝(方法2) 使用cnpm安裝,因?yàn)樵趎pm安裝時,因?yàn)橛行┮蕾嚨膯栴},速度慢且容易出錯中斷。
Python 1 2 3 4 5 #安裝國內(nèi)鏡像 npm install -g cnpm --registry=https://registry.npm.taobao.org # 安裝插件(在elasticsearch-head目錄下) cnpm install
? ? 安裝成功后,修改配置Gruntfile.js Python 1 2 3 4 5 6 7 8 9 10 11 vi Gruntfile.js connect: { ???? server: { ???????? options: { ???????? hostname: "0.0.0.0",??#新增的一行 ???????? port: 9100, ???????? base: '.', ???????? keepalive: true ???????? } ???? } }
? ? 修改_site/app.js配置 Python 1 2 3 4 # 搜索 http://localhost:9200 # 修改為本機(jī)IP this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.1.138:9200";
? ? elasticSearch整合elasticsearch-head插件: Python 1 2 3 4 5 6 7 # 在配置文件的最后加上運(yùn)行head插件跨域訪問rest接口 vim /usr/local/elasticsearch/config/elasticsearch.yml # 添加如下內(nèi)容: http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-credentials: true
? ? 重啟elasticsearch 重啟elasticsearch需要kill掉進(jìn)程,然后再啟動
? ? 運(yùn)行elasticsearch-head Python 方法3 (離線安裝) 在離線情況下,需要在有網(wǎng)絡(luò)的環(huán)境里安裝好,然后將整個elasticsearch-head目錄壓縮拷貝過來。
?? 重要: head插件目錄不能放在es的目錄里,需要單獨(dú)放(es從版本5以上不支持直接安裝head)
? ? 首先 ,安裝grunt,將整個elasticsearch-head目錄包括目錄下的node_models內(nèi)容一起拷貝過來
?然后 ,修改方法2中的兩個配置文件
Gruntfile.js ?和
_site/app.js ? ? 最后, 使用../elasticsearch-head/node_models/grunt/bin/grunt? server? &?來啟動?
? ? 正常運(yùn)行elasticsearch-head會有以下結(jié)果輸出: Python 1 2 3 4 5 6 7 8 9 10 11 [root@test1 elasticsearch-head]# npm run start > elasticsearch-head@0.0.0 start /usr/local/elasticsearch-head > grunt server >> Local Npm module "grunt-contrib-jasmine" not found. Is it installed? (node:16304) ExperimentalWarning: The http2 module is an experimental API. Running "connect:server" (connect) task Waiting forever... Started connect web server on http://localhost:9100
按照屏幕提示通過瀏覽器訪問: http://172.16.64.137:9100/
最后: 如果在服務(wù)器上安裝Elasticsearch,而想在本地機(jī)器上進(jìn)行開發(fā),這時候就需要在關(guān)閉終端的時候,讓Elasticsearch繼續(xù)保持運(yùn)行。
最簡單的方法就是使用nohup。先按Ctrl + C,停止當(dāng)前運(yùn)行的Elasticsearch,改用下面的命令運(yùn)行Elasticsearch
?
Python 1 nohup ./bin/elasticsearch &
附:es啟動腳本 Python 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 #!/bin/sh #chkconfig: 2345 80 05 #description: es export JAVA_HOME=/usr/local/jdk1.8.0_151 export JAVA_BIN=/usr/local/jdk1.8.0_151/bin export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME JAVA_BIN PATH CLASSPATH case $1 in start) ????su ela<<! ????cd /usr/local/elasticsearch ????./bin/elasticsearch -d exit ! ????echo "es startup" ????;;?? stop) ????es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'` ????kill -9 $es_pid ????echo "es stopup" ????;;?? restart) ????es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'` ????kill -9 $es_pid ????echo "es stopup" ????su ela<<! ????cd /usr/local/elasticsearch ????./bin/elasticsearch -d ! ????echo "es startup" ????;;?? *) ????echo "start|stop|restart" ????;;?? esac
根據(jù)實(shí)際情況,修改jdk目錄,ela安裝目錄
?寫進(jìn)啟動文件/etc/init.d/ela,給予x權(quán)限,添加到啟動菜單: ? ? vim /etc/init.d/ela? ? ? chmod 755 /etc/init.d/ela ? ? chkconfig –add ela ? ? chkconfig ela on
轉(zhuǎn)載于:https://www.cnblogs.com/Su-per-man/p/8625463.html
總結(jié)
以上是生活随笔 為你收集整理的elasticsearch-6.0.1安装 的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔 推薦給好友。