Linux系统:centos7下搭建ElasticSearch中间件,常用接口演示
一、中間件簡(jiǎn)介
1、基礎(chǔ)概念
ElasticSearch是一個(gè)基于Lucene的搜索服務(wù)器。它提供了一個(gè)分布式多用戶能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java開發(fā)的,并作為Apache許可條款下的開放源碼發(fā)布,是當(dāng)前流行的企業(yè)級(jí)搜索引擎。
2、分布式數(shù)據(jù)庫
分布式數(shù)據(jù)庫系統(tǒng)通常使用較小的計(jì)算機(jī)系統(tǒng),每臺(tái)計(jì)算機(jī)可單獨(dú)放在一個(gè)地方,每臺(tái)計(jì)算機(jī)中都可能有DBMS的一份完整拷貝副本,或者部分拷貝副本,并具有自己局部的數(shù)據(jù)庫,位于不同地點(diǎn)的許多計(jì)算機(jī)通過網(wǎng)絡(luò)互相連接,共同組成一個(gè)完整的、全局的邏輯上集中、物理上分布的大型數(shù)據(jù)庫。
3、核心角色
1)節(jié)點(diǎn)和集群
cluster代表一個(gè)集群,集群中有多個(gè)節(jié)點(diǎn),其中有一個(gè)為主節(jié)點(diǎn),這個(gè)主節(jié)點(diǎn)是可以通過選舉產(chǎn)生的,主從節(jié)點(diǎn)是對(duì)于集群內(nèi)部來說的。es的一個(gè)概念就是去中心化,字面上理解就是無中心節(jié)點(diǎn),這是對(duì)于集群外部來說的,因?yàn)閺耐獠縼砜磂s集群,在邏輯上是個(gè)整體。單個(gè) Elastic 實(shí)例稱為一個(gè)節(jié)點(diǎn)(node)。一組節(jié)點(diǎn)構(gòu)成一個(gè)集群(cluster)。
2)Shards分片
代表索引分片,es可以把一個(gè)完整的索引分成多個(gè)分片,這樣的好處是可以把一個(gè)大的索引拆分成多個(gè),分布到不同的節(jié)點(diǎn)上。構(gòu)成分布式搜索。分片的數(shù)量只能在索引創(chuàng)建前指定,并且索引創(chuàng)建后不能更改。
3)Document文檔
Index 里面單條的記錄稱為 Document(文檔)。許多條 Document 構(gòu)成了一個(gè) Index。Document 使用 JSON 格式表示。
4)Index索引
Elastic 會(huì)索引所有字段,查找數(shù)據(jù)的時(shí)候,直接查找該索引。每個(gè) Index (即理解為數(shù)據(jù)庫名稱)的名字必須是小寫。
5)Type類型
Document 可以根據(jù)Type進(jìn)行虛擬的邏輯分組,用來過濾 Document,即理解為數(shù)據(jù)庫表名稱。
二、中間件安裝
1、安裝環(huán)境和版本
Centos7 JDK1.8 elasticsearch-6.3.22、下載解壓
下載的路徑,當(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.zip3、啟動(dòng)軟件
[root@localhost mysoft]# cd elasticsearch-6.3.2/ [root@localhost elasticsearch-6.3.2]# ./bin/elasticsearch1)報(bào)錯(cuò)一
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 esrootesroot用戶授權(quán)
chown esroot /usr/local/mysoft/elasticsearch-6.3.2 -R切換到esroot用戶
[root@localhost mysoft]# su - esroot [esroot@localhost ~]$ su #回到root用戶2)報(bào)錯(cuò)二
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用戶
再次啟動(dòng),沒有報(bào)錯(cuò)信息。
4、打開命令行測(cè)試
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)境搭建成功。
請(qǐng)求9200端口,Elastic 返回一個(gè) JSON 對(duì)象,包含當(dāng)前節(jié)點(diǎn)、集群、版本等信息。
按下 Ctrl + C,Elastic 就會(huì)停止運(yùn)行。
5、配置外部訪問
默認(rèn)情況下,Elastic 只允許本機(jī)訪問,如果需要遠(yuǎn)程訪問,可以修改 Elastic 安裝目錄的config/elasticsearch.yml文件,去掉network.host的注釋,將它的值改成0.0.0.0,然后重新啟動(dòng) Elastic。
[esroot@localhost config]$ cd /usr/local/mysoft/elasticsearch-6.3.2/config [esroot@localhost config]$ vim elasticsearch.yml network.host: 0.0.0.06、安裝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' # 返回?cái)?shù)據(jù) {"acknowledged": true,"shards_acknowledged": true,"index": "esindex01" }服務(wù)器返回一個(gè) JSON 對(duì)象,acknowledged:true字段表示操作成功。
2、刪除索引
[esroot@localhost ~]$ curl -X DELETE 'localhost:9200/esindex01' {"acknowledged":true}acknowledged:true字段表示操作成功。
四、源代碼地址
GitHub地址:知了一笑 https://github.com/cicadasmile 碼云地址:知了一笑 https://gitee.com/cicadasmile
總結(jié)
以上是生活随笔為你收集整理的Linux系统:centos7下搭建ElasticSearch中间件,常用接口演示的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 面向领域驱动的应用开发框架Apworks
- 下一篇: mybatisnet - 1 获取 my