1. 什么是Elasticsearch?

image
?? Elasticsearch是一個基于Lucene的搜索服務(wù)器。它提供了一個分布式多用戶能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java語言開發(fā)的,并作為Apache許可條款下的開放源碼發(fā)布,是一種流行的企業(yè)級搜索引擎。
2. Elasticsearch安裝與啟動
- 操作環(huán)境:CentOS release 6.10 (Final)
- Java 版本:Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
1)下載Elasticsearch
?由于較高版本的不再支持JDK8,所以下載的版本是6.8.14
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8-linux-x86_64.tar.gz
2)解壓并移動到指定位置
tar -zxvf elasticsearch-6.8-linux-x86_64.tar.gz
mv elasticsearch-6.8.14 /usr/local/elasticsearch
3)啟動
?這里注意:elasticsearch默認(rèn)不能用root用戶啟動,所以必須使用其他用戶進(jìn)行啟動。
# 創(chuàng)建用戶
adduser elasticsearch
# 將目錄授權(quán)于用戶elasticsearch
chown -R elasticsearch:elasticsearch /usr/local/elasticsearch
# 以指定用戶啟動(-d參數(shù)表示后臺運(yùn)行)
chroot --userspec "elasticsearch:elasticsearch" "/" sh -c "/usr/local/elasticsearch/bin/elasticsearch -d"
# 如果需要開機(jī)啟動則把上面命令添加到 /etc/rc.local即可
vim /etc/rc.local
chroot --userspec "elasticsearch:elasticsearch" "/" sh -c "/usr/local/elasticsearch/bin/elasticsearch -d"
4)驗證服務(wù)是否啟動成功
驗證命令
curl 'http://localhost:9200/?pretty'
或者直接瀏覽器訪問:http://localhost:9200/
如果服務(wù)已正常啟動則會返回
{
"name" : "Tom Foster",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "2.1.0",
"build_hash" : "72cd1f1a3eee09505e036106146dc1949dc5dc87",
"build_timestamp" : "2015-11-18T22:40:03Z",
"build_snapshot" : false,
"lucene_version" : "5.3.1"
},
"tagline" : "You Know, for Search"
}