ES搜索引擎學(xué)習(xí)之環(huán)境搭建

1.下載ElasticSearch6.2.4

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz

2.解壓文件

tar -zxvf elasticsearch-6.2.4.tar.gz

3.重新命名

mv elasticsearch-6.2.4 /usr/local/elastic/elasticsearch

4.創(chuàng)建數(shù)據(jù)存放路徑

mkdir /usr/local/elastic/elasticsearch/data

5.創(chuàng)建日志存放路徑(如已存在不用創(chuàng)建)

mkdir /usr/local/elastic/elasticsearch/logs

6.創(chuàng)建用戶并授權(quán)(因?yàn)閑s不能root用戶運(yùn)行)

useradd es

chown -R es:es /usr/local/elastic/elasticsearch

7. 修改es配置

#集群的名稱

cluster.name: es6.2.4

#節(jié)點(diǎn)名稱,其余兩個(gè)節(jié)點(diǎn)分別為node-2 和node-3

node.name: node-1

#指定該節(jié)點(diǎn)是否有資格被選舉成為master節(jié)點(diǎn),默認(rèn)是true,es是默認(rèn)集群中的 第一臺(tái)機(jī)器為master,如果這臺(tái)機(jī)掛了就會(huì)重新選舉master

node.master: true

#允許該節(jié)點(diǎn)存儲(chǔ)數(shù)據(jù)(默認(rèn)開啟)

node.data: true

#索引數(shù)據(jù)的存儲(chǔ)路徑

path.data: /usr/local/elastic/elasticsearch/data

#日志文件的存儲(chǔ)路徑

path.logs: /usr/local/elastic/elasticsearch/logs

#設(shè)置為true來(lái)鎖住內(nèi)存。因?yàn)閮?nèi)存交換到磁盤對(duì)服務(wù)器性能來(lái)說是致命的,當(dāng)jvm 開始swapping時(shí)es的效率會(huì)降低,所以要保證它不swap

bootstrap.memory_lock: true

#綁定的ip地址 這里所有都可訪問

network.host: 0.0.0.0

#設(shè)置對(duì)外服務(wù)的http端口,默認(rèn)為9200

http.port: 9200

# 設(shè)置節(jié)點(diǎn)間交互的tcp端口,默認(rèn)是9300

transport.tcp.port: 9300

#Elasticsearch將綁定到可用的環(huán)回地址,并將掃描端口9300到9305以嘗試連接到 運(yùn)行在同一臺(tái)服務(wù)器上的其他節(jié)點(diǎn)。

#這提供了自動(dòng)集群體驗(yàn),而無(wú)需進(jìn)行任何配置。數(shù)組設(shè)置或逗號(hào)分隔的設(shè)置。每 個(gè)值的形式應(yīng)該是host:port或host

#(如果沒有設(shè)置,port默認(rèn)設(shè)置會(huì)transport.profiles.default.port 回落到 transport.tcp.port)。

#請(qǐng)注意,IPv6主機(jī)必須放在括號(hào)內(nèi)。默認(rèn)為127.0.0.1, [::1]

discovery.zen.ping.unicast.hosts: ["ip:9300", "ip:9300", "ip:9300"]

#如果沒有這種設(shè)置,遭受網(wǎng)絡(luò)故障的集群就有可能將集群分成兩個(gè)獨(dú)立的集群 - 分裂的大腦 - 這將導(dǎo)致數(shù)據(jù)丟失

discovery.zen.minimum_master_nodes: 3

# 增加新的參數(shù),這樣head插件可以訪問es,解決跨域訪問問題

http.cors.enabled: true

http.cors.allow-origin: "*"

http.cors.allow-credentials: true

8. 調(diào)整jvm內(nèi)存

vim /usr/local/elk/elasticsearch/config/jvm.options

#默認(rèn)是1g官方建議對(duì)jvm進(jìn)行一些修改,不然很容易出現(xiàn)OOM,參考官網(wǎng)改參數(shù)配置 最好不要超過內(nèi)存的50%

-Xms1g

-Xmx1g

9. 分別啟動(dòng)各個(gè)節(jié)點(diǎn)的es

/usr/local/elastic/elasticsearch/bin/elasticsearch -d

注意:

使用ps -ef|grep elasticsearc查看進(jìn)程是否啟動(dòng),發(fā)現(xiàn)并沒有啟動(dòng),什么原因呢?查看一下日志在我們配置的日志路徑下:

cd ../logs

第一個(gè)坑:日志文件會(huì)以集群名稱命名,查看es6.2.log文件,日志報(bào)以下異常:

[ERROR][o.e.b.Bootstrap ] [node-1] node validation exception

[3] bootstrap checks failed

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

[2]: memory locking requested for elasticsearch process but memory is not locked

[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解決方法:

切回root用戶su - root,修改配置?

① vim /etc/security/limits.conf

soft nofile 65536

* hard nofile 65536

* soft nproc 2048

* hard nproc 4096

#我選擇鎖住swapping因此需要在這個(gè)配置文件下再增加兩行代碼

es soft memlock unlimited

es hard memlock unlimited

打開:?vim /etc/sysctl.conf

執(zhí)行一句命令sysctl -p使系統(tǒng)配置生效(使用root用戶)。

Es不能使用root啟動(dòng)

10.? 再次重啟Elasticsearch


安裝elasticsearch-head

1.安裝nodejs和rpm

su - root

yum install epel-release

yum install nodejs npm

2.下載并安裝elasticsearch-head

git clone https://github.com/mobz/elasticsearch-head.git

cd elasticsearch-head

npm install

npm run start

3.修改elasticsearch參數(shù),以便于head插件訪問es

1.在elasticsearch下的elasticsearch.yml下新增一下兩行: http.cors.enabled: true

http.cors.allow-origin: "*"

2.重啟es

4.修改es-head的localhost地址

cd ./elasticsearch-head

vim Gruntfile.js

Add hostname

connect: {

server: {

options: {

hostname: '0.0.0.0',

port: 9100,

base: '.',

keepalive: true

}

}

}

5.修改head連接地址

1.cd ./elasticsearch-head #(elasticsearch-head源碼文件夾)

2.vim ./_site/app.js

3.將localhost修改為ESdeIP地址 修改前:this.base_uri = this.config.base_uri; 修改后: this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://you ip address:9200";

6. 啟動(dòng)elasticsearch-head

cd elasticsearch-head(elasticsearch-head源碼目錄)

./node_modules/grunt/bin/grunt server


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容