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

一、中間件簡介

專業(yè)成都網(wǎng)站建設公司,做排名好的好網(wǎng)站,排在同行前面,為您帶來客戶和效益!創(chuàng)新互聯(lián)為您提供成都網(wǎng)站建設,五站合一網(wǎng)站設計制作,服務好的網(wǎng)站設計公司,網(wǎng)站建設、網(wǎng)站制作負責任的成都網(wǎng)站制作公司!

1、基礎概念

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

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

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

3、核心角色

1)節(jié)點和集群

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

2)Shards分片

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

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

4)Index索引

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

5)Type類型

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

二、中間件安裝

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

Centos7
JDK1.8
elasticsearch-6.3.2

2、下載解壓

下載的路徑,當前目錄的文件夾下,也可以指定下載路徑。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用戶授權

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權限下操作。

[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 對象,包含當前節(jié)點、集群、版本等信息。
 按下 Ctrl + C,Elastic 就會停止運行。

5、配置外部訪問

默認情況下,Elastic 只允許本機訪問,如果需要遠程訪問,可以修改 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"
}

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

2、刪除索引

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

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

四、源代碼地址

GitHub地址:知了一笑
https://github.com/cicadasmile
碼云地址:知了一笑
https://gitee.com/cicadasmile

總結

以上所述是小編給大家介紹的Linux系統(tǒng)下 centos7下搭建ElasticSearch中間件及常用接口演示 ,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對創(chuàng)新互聯(lián)網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!

新聞標題:Linux系統(tǒng)下centos7下搭建ElasticSearch中間件及常用接口演示
標題網(wǎng)址:http://muchs.cn/article32/ihjipc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供App設計、電子商務網(wǎng)站收錄、小程序開發(fā)網(wǎng)站營銷、網(wǎng)頁設計公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設