溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Linux系統(tǒng):Centos7下搭建ElasticSearch中間件,常用接口演示

發(fā)布時間:2020-06-21 14:26:45 來源:網(wǎng)絡(luò) 閱讀:238 作者:知了一笑 欄目:系統(tǒng)運(yùn)維

本文源碼:GitHub·點(diǎn)這里 || GitEE·點(diǎn)這里

一、中間件簡介

1、基礎(chǔ)概念

ElasticSearch是一個基于Lucene的搜索服務(wù)器。它提供了一個分布式多用戶能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java開發(fā)的,并作為Apache許可條款下的開放源碼發(fā)布,是當(dāng)前流行的企業(yè)級搜索引擎。

2、分布式數(shù)據(jù)庫

分布式數(shù)據(jù)庫系統(tǒng)通常使用較小的計算機(jī)系統(tǒng),每臺計算機(jī)可單獨(dú)放在一個地方,每臺計算機(jī)中都可能有DBMS的一份完整拷貝副本,或者部分拷貝副本,并具有自己局部的數(shù)據(jù)庫,位于不同地點(diǎn)的許多計算機(jī)通過網(wǎng)絡(luò)互相連接,共同組成一個完整的、全局的邏輯上集中、物理上分布的大型數(shù)據(jù)庫。

3、核心角色

1)節(jié)點(diǎn)和集群

cluster代表一個集群,集群中有多個節(jié)點(diǎn),其中有一個為主節(jié)點(diǎn),這個主節(jié)點(diǎn)是可以通過選舉產(chǎn)生的,主從節(jié)點(diǎn)是對于集群內(nèi)部來說的。es的一個概念就是去中心化,字面上理解就是無中心節(jié)點(diǎn),這是對于集群外部來說的,因?yàn)閺耐獠縼砜磂s集群,在邏輯上是個整體。單個 Elastic 實(shí)例稱為一個節(jié)點(diǎn)(node)。一組節(jié)點(diǎn)構(gòu)成一個集群(cluster)。

2)Shards分片

代表索引分片,es可以把一個完整的索引分成多個分片,這樣的好處是可以把一個大的索引拆分成多個,分布到不同的節(jié)點(diǎn)上。構(gòu)成分布式搜索。分片的數(shù)量只能在索引創(chuàng)建前指定,并且索引創(chuàng)建后不能更改。

3)Document文檔

Index 里面單條的記錄稱為 Document(文檔)。許多條 Document 構(gòu)成了一個 Index。Document 使用 JSON 格式表示。

4)Index索引

Elastic 會索引所有字段,查找數(shù)據(jù)的時候,直接查找該索引。每個 Index (即理解為數(shù)據(jù)庫名稱)的名字必須是小寫。

5)Type類型

Document 可以根據(jù)Type進(jìn)行虛擬的邏輯分組,用來過濾 Document,即理解為數(shù)據(jù)庫表名稱。

二、中間件安裝

1、安裝環(huán)境和版本

Centos7
JDK1.8
elasticsearch-6.3.2

2、下載解壓

下載的路徑,當(dāng)前目錄的文件夾下,也可以指定下載路徑。wget -P 目錄 網(wǎng)址。

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.zip
[root@localhost roo]# mv elasticsearch-6.3.2.zip /usr/local/mysoft/
[root@localhost mysoft]# unzip elasticsearch-6.3.2.zip

3、啟動軟件

[root@localhost mysoft]# cd elasticsearch-6.3.2/
[root@localhost elasticsearch-6.3.2]# ./bin/elasticsearch

1)報錯一

org.elasticsearch.bootstrap.StartupException: 
java.lang.RuntimeException: can not run elasticsearch as root

新建用戶組和用戶

[root@localhost]# useradd esroot
[root@localhost]# passwd esroot
[root@localhost]# groupadd esgroup
[root@localhost]# usermod -g esgroup esroot

esroot用戶授權(quán)

chown esroot /usr/local/mysoft/elasticsearch-6.3.2 -R

切換到esroot用戶

[root@localhost mysoft]# su - esroot
[esroot@localhost ~]$ su #回到root用戶

2)報錯二

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

執(zhí)行如下命名,該操作在Root權(quán)限下操作。

[root@localhost roo]# vim /etc/security/limits.conf 
添加內(nèi)容
* soft nofile 65536
* hard nofile 65536

切回esroot用戶
再次啟動,沒有報錯信息。

4、打開命令行測試

curl localhost:9200

[roo@localhost ~]$ curl localhost:9200
{
  "name" : "YMS44oi",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "2ZXjBnkJSjieV_k1IWMzrQ",
  "version" : {
    "number" : "6.3.2",
    "build_flavor" : "default",
    "build_type" : "zip",
    "build_hash" : "053779d",
    "build_date" : "2018-07-20T05:20:23.451332Z",
    "build_snapshot" : false,
    "lucene_version" : "7.3.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

這樣elasticsearch-6.3.2環(huán)境搭建成功。
請求9200端口,Elastic 返回一個 JSON 對象,包含當(dāng)前節(jié)點(diǎn)、集群、版本等信息。
按下 Ctrl + C,Elastic 就會停止運(yùn)行。

5、配置外部訪問

默認(rèn)情況下,Elastic 只允許本機(jī)訪問,如果需要遠(yuǎn)程訪問,可以修改 Elastic 安裝目錄的config/elasticsearch.yml文件,去掉network.host的注釋,將它的值改成0.0.0.0,然后重新啟動 Elastic。

[esroot@localhost config]$ cd /usr/local/mysoft/elasticsearch-6.3.2/config
[esroot@localhost config]$ vim elasticsearch.yml 
network.host: 0.0.0.0

6、安裝IK中文分詞器

切換到root用戶

[root@localhost elasticsearch-6.3.2]$ ./bin/elasticsearch-plugin 
install 
https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.2/elasticsearch-analysis-ik-6.3.2.zip

三、入門操作

索引創(chuàng)建和刪除

1、創(chuàng)建索引

[esroot@localhost ~]$ curl -X PUT 'localhost:9200/esindex01'
# 返回數(shù)據(jù)
{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "esindex01"
}

服務(wù)器返回一個 JSON 對象,acknowledged:true字段表示操作成功。

2、刪除索引

[esroot@localhost ~]$ curl -X DELETE 'localhost:9200/esindex01'
{"acknowledged":true}

acknowledged:true字段表示操作成功。

四、源代碼地址

GitHub·地址
https://github.com/cicadasmile/linux-system-base
GitEE·地址
https://gitee.com/cicadasmile/linux-system-base

Linux系統(tǒng):Centos7下搭建ElasticSearch中間件,常用接口演示

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI