Elasticsearch簡(jiǎn)介
ElasticSearch是一個(gè)基于Lucene的搜索服務(wù)器。它提供了一個(gè)分布式多用戶能力的全文檢索引擎,基于RESTful web接口。Elasticsearch是用Java開(kāi)發(fā)的,并作為Apache許可條款下的開(kāi)放源碼發(fā)布,是當(dāng)前流行的企業(yè)級(jí)搜索引擎。設(shè)計(jì)用于云計(jì)算中,能夠達(dá)到實(shí)時(shí)搜索,穩(wěn)定,可靠,快速,安裝使用方便。
實(shí)驗(yàn)部署
1、實(shí)驗(yàn)所需組件及環(huán)境
1)JDK8以上環(huán)境
2)CentOS7.3,IP地址:192.168.144.112
3)elasticsearch6.3.2
- es最新軟件軟件包可在官方網(wǎng)站下載:https://www.elastic.co/downloads/elasticsearch
2、安裝jdk8以上版本
yum install java -y
java -version 查看java版本
3、部署elasticsearch6.3.2
-
首先在官網(wǎng)當(dāng)中下載es的軟件包,本文采用壓縮包解壓縮安裝方式啟動(dòng)服務(wù)。
- 值得注意的是,在es5.0版本后不支持與logstash和kibana2.x版本的混用,且安全級(jí)別的提升,使得es在后續(xù)的版本中不允許使用root用戶啟動(dòng),因此我們需要?jiǎng)?chuàng)建另外獨(dú)立賬戶專(zhuān)供es使用。并且需要在root權(quán)限下將該特定環(huán)境準(zhǔn)備好。
tar zxvf elasticsearch-6.3.2.tar.gz -C /opt/
- 創(chuàng)建獨(dú)立用戶與組(root用戶下創(chuàng)建設(shè)定)
groupadd ela 創(chuàng)建ela組
useradd -g ela ela 創(chuàng)建ela用戶,并且加入ela組
passwd ela 為ela用戶設(shè)定登錄密碼
visudo(或者vim /etc/sudoers)
- 為了讓ela用戶擁有對(duì)elasticsearch執(zhí)行權(quán)限,在root用戶權(quán)限下解壓后,需要將軟件包更改屬主屬組。
chown -R ela.ela /opt/elasticsearch-6.3.2/
ls -l /opt/elasticsearch-6.3.2/
- 切換到ela用戶,編輯配置文件,準(zhǔn)備啟動(dòng)es
su ela
[ela@localhost ~]$ cd /opt/elasticsearch-6.3.2/config/
[ela@localhost config]$ sudo vim elasticsearch.yml
# ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: # cluster.name: abner //打開(kāi)設(shè)定es群集名稱(chēng) # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: node-1 //es當(dāng)前節(jié)點(diǎn)名稱(chēng),用于區(qū)分不同節(jié)點(diǎn) # # Add custom attributes to the node: # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # path.data: /data/es-data //修改數(shù)據(jù)目錄,此目錄為自定義,需要在root用戶下創(chuàng)建,且屬主屬組更改為ela # # Path to log files: # path.logs: /var/log/elasticsearch //日志目錄位置,需自己創(chuàng)建,方式同上 //yum安裝則系統(tǒng)自定義,在軟件版本或者系統(tǒng)升級(jí)時(shí)會(huì)被刪除,所以建議修改 # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # bootstrap.memory_lock: true //elasticsearch官網(wǎng)建議生產(chǎn)環(huán)境需要設(shè)置bootstrap.memory_lock: true # # Make sure that the heap size is set to about half the memory available # on the system and that the owner of the process is allowed to use this # limit. # # Elasticsearch performs poorly when the system is swapping the memory. # # ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # network.host: 0.0.0.0 //監(jiān)聽(tīng)訪問(wèn)地址為任意網(wǎng)段 # # Set a custom port for HTTP: # http.port: 9200 //服務(wù)監(jiān)聽(tīng)端口 #
- 編輯完成配置文件后,數(shù)據(jù)目錄以及日志文件目錄需要?jiǎng)?chuàng)建
sudo mkdir -p /data/es-data
sudo mkdir -p /var/log/elasticsearch
sudo chown -R ela.ela /data/
sudo chown -R ela.ela /var/log/elasticsearch
- 準(zhǔn)備工作完成,啟動(dòng)es
[ela@localhost /]$ cd /opt/elasticsearch-6.3.2/bin/
[ela@localhost bin]$ ./elasticsearch 后面可以跟上-d后臺(tái)執(zhí)行
4、啟動(dòng)發(fā)現(xiàn)異常情況以及處理方式
-當(dāng)發(fā)現(xiàn)如上圖無(wú)法分配內(nèi)存錯(cuò)誤等,可執(zhí)行如下操作。(需要在root用戶權(quán)限下)
vim /etc/security/limits.conf
* soft nofile 65536 * hard nofile 131072 ela soft memlock unlimited ela hard memlock unlimited
- 當(dāng)發(fā)現(xiàn)ERROR: [1] bootstrap checks failed錯(cuò)誤時(shí),解決方式如下(root用戶狀態(tài)下)
vim /etc/sysctl.conf
vm.max_map_count = 655360 //添加
sysctl -p
- 切換到ela用戶,執(zhí)行啟動(dòng)程序
[ela@localhost abc]$ cd /opt/elasticsearch-6.3.2/bin/
[ela@localhost bin]$ ./elasticsearch
- 新建終端,以root用戶查看9200端口是否開(kāi)啟
netstat -ntap | grep 9200
tcp6 0 0 :::9200 :::* LISTEN 2095/java
- 打開(kāi)瀏覽器訪問(wèn)驗(yàn)證,出現(xiàn)如下界面即安裝成功,訪問(wèn)時(shí)記得關(guān)閉防火墻!?。?/li>