最近因工作原因,和ES(Elasticsearch)接觸的比較多;ES之前了解過,不怎么熟悉,故打算系統(tǒng)學(xué)習(xí)之。
按照自己的學(xué)習(xí)慣例,一是了解主要概念,二是動手安裝一遍。
故,本文大綱為:
1.?概念理解:
1)?ES是什么?
2)?ES發(fā)展史
3)?ES市場成熟度
2.?安裝部署
1)?Linux下如何安裝
2)?Docker方式如何安裝
Contents:
一、ES概念理解:
1.?ES是什么(Elasticsearch)?
Elasticsearch?是由?Elastic?公司創(chuàng)建。它的代碼位于?GitHub - elastic/elasticsearch: Free and Open, Distributed, RESTful Search Engine。
目前,Elasticsearch?是一個免費及開放(free and open)的項目。
?
Elastic?公司也擁有?Logstash?及?Kibana?開源項目,三個項目形成了?ELK?軟件棧,形成了一個強大的生態(tài)圈。其中:
1.?Logstash?負責(zé)數(shù)據(jù)的采集,處理(豐富數(shù)據(jù),數(shù)據(jù)轉(zhuǎn)換等);
2.?Kibana?負責(zé)數(shù)據(jù)展示,分析,管理,監(jiān)督及應(yīng)用;
3.?Elasticsearch?處于最核心的位置,它可以幫對數(shù)據(jù)進行快速地搜索及分析。
?
Elasticsearch是一個基于Lucene的一個開源的高擴展的分布式全文檢索引擎,基于RESTful web接口,隱藏了Luncee的復(fù)雜性,從而讓全文搜索變得簡單;可近乎實時的存儲、檢索數(shù)據(jù),可擴展性強,可處理PB級別的數(shù)據(jù)。
理解ES的關(guān)鍵在于理解lucene的基本原理:
Lucene是一種高性能、可伸縮的信息搜索(IR)庫,在2000年開源,最初由鼎鼎大名的Doug Cutting開發(fā),是基于Java實現(xiàn)的高性能的開源項目。Lucene采用了基于倒排表的設(shè)計原理,可以非常高效地實現(xiàn)文本查找,在底層采用了分段的存儲模式,使它在讀寫時幾乎完全避免了鎖的出現(xiàn),大大提升了讀寫性能。
關(guān)于lucene的原理,可參見如下鏈接,這里不再贅述:
https://www.jianshu.com/p/28fb017be7a7
?
官方客戶端在Java、.NET(C#)、PHP、Python、Apache Groovy、Ruby和許多其他語言中都是可用的。
Elasticsearch以上大致了解了ES是什么?
接下來再說一下ES的發(fā)展史,了解其發(fā)展史,可幫助我們知道所以然和不然。
4.?ES發(fā)展史
Elasticsearch是一個基于?Apache Lucene?(TM)的開源搜索引擎。無論在開源還是專有領(lǐng)域,Lucene?可以被認為是迄今為止最先進、性能最好的、功能最全的搜索引擎庫。
在?1999?年,Doug Cutting?創(chuàng)建了一個叫做?Lucene?的開源項目:
1.?一個完全用?Java?編寫的搜索引擎庫
2.?截止2005年,是一個頂級的?Apache?開源項目
3.?提供強大的全文搜索功能
但Lucene?只是一個庫,本身并不提供高可用性及分布式部署。想要發(fā)揮其強大的作用,需使用?Java?并要將其集成到應(yīng)用中。而且Lucene?非常復(fù)雜,需要深入的了解檢索相關(guān)知識來理解它是如何工作的,上手比較困難。
大家這里可以類比內(nèi)存溢出和釋放來理解。
在?2004?年,?Shay Banon也就是現(xiàn)在?Elastic?的?CEO,開發(fā)了一個叫做?Compass?的開源項目:
1.?構(gòu)建于?Lucence?之上
2.?目的是使得?Lucene?搜索更容易集成到?Java?應(yīng)用中去
3.?可擴展性變得尤為重要
在?2010?年,Shay?完全重新編寫了?Compass?以實現(xiàn)如下的兩個目的:
1.?設(shè)計之初,就使用分布式部署設(shè)計
2.?可方便地使用其它的語言進行對接調(diào)用
Shay?最終把這個項目稱之為?Elasticsearch,并于2010年10月發(fā)布與?github?上。
不過,Elasticsearch?不僅僅是?Lucene?和全文搜索引擎,它還提供:
1.?分布式的實時文件存儲,每個字段都被索引并可被搜索
2.?實時分析的分布式搜索引擎
3.?可以擴展到上百臺服務(wù)器,處理?PB?級結(jié)構(gòu)化或非結(jié)構(gòu)化數(shù)據(jù)
上述功能被集成到一臺服務(wù)器,應(yīng)用可以通過簡單的?RESTful API、各種語言的客戶端甚至命令行與之交互。上手?Elasticsearch?非常簡單,它提供了許多合理的缺省值,并對初學(xué)者隱藏了復(fù)雜的搜索引擎理論。
Elasticsearch?的特點是它提供了一個極速的搜索體驗。這源于它的高速(speed)。相比較其它的一些大數(shù)據(jù)引擎,Elasticsearch?可以實現(xiàn)秒級的搜索;Elasticsearch?的?cluster?是一種分布式的部署,極易擴展(scale)。
小結(jié):
Elasticsearch?是使用?Java?編寫并使用?Lucene?來建立索引并實現(xiàn)搜索功能,通過簡單連貫的?RESTful API?讓全文搜索變得簡單并隱藏?Lucene?的復(fù)雜性;其是實時分析的分布式搜索引擎,可以擴展到上百臺服務(wù)器,處理?PB?級結(jié)構(gòu)化或非結(jié)構(gòu)化數(shù)據(jù)。
5.?ES市場認可度
Elasticsearch是用Java語言開發(fā)的,并作為Apache許可條款下的開放源碼發(fā)布,是一種流行的企業(yè)級搜索引擎。Elasticsearch用于云計算中,能夠達到實時搜索,穩(wěn)定,可靠,快速,安裝使用方便。
根據(jù)DB-Engines的排名顯示,Elasticsearch是最受歡迎的企業(yè)搜索引擎,其次是Apache Solr,也是基于Lucene。
可以看出5月份的目前Elasticsearch排名為第七名,Solr的DB-Engines排名為第29名。
DB-Engines官網(wǎng)鏈接:
https://db-engines.com/en/ranking
二、動手安裝
了解了ES的概念和發(fā)展史,接下來就該實操起來練練手,所謂爛筆頭好過好記性。
?
Elasticsearch單機版部署
Elasticsearch版本
Elasticsearch版本:8.1.3
Kibana版本:8.1.3
操作系統(tǒng):
麒麟v10 sp2
[root@192 ~]# cat /proc/version
Linux version 4.19.90-24.4.v2101.ky10.x86_64 (KYLINSOFT@localhost.localdomain) (gcc version 7.3.0 (GCC)) #1 SMP Mon May 24 12:14:55 CST 2021
CPU芯片信息:
[root@192 ~]# lscpu
架構(gòu):???????????????????????????x86_64
CPU?運行模式:??????????????????32-bit, 64-bit
字節(jié)序:?????????????????????????Little Endian
Address sizes: ??????????????????45 bits physical, 48 bits virtual
CPU: ????????????????????????????1
在線?CPU?列表:?????????????????0
每個核的線程數(shù):?????????????????1
每個座的核數(shù):???????????????????1
座:?????????????????????????????1
NUMA?節(jié)點:?????????????????????1
廠商?ID:???????????????????????AuthenticAMD
CPU?系列:??????????????????????23
型號:???????????????????????????96
型號名稱:???????????????????????AMD Ryzen 7 4800H with Radeon Graphics
步進:???????????????????????????1
CPU MHz:???????????????????????2894.561
BogoMIPS:??????????????????????5789.12
超管理器廠商:???????????????????VMware
虛擬化類型:?????????????????????完全
L1d?緩存:??????????????????????32 KiB
L1i?緩存:??????????????????????32 KiB
L2?緩存:???????????????????????512 KiB
L3?緩存:???????????????????????4 MiB
NUMA?節(jié)點0 CPU:????????????????0
具體操作步驟如下:
1.?解壓縮
[root@192 es]# gunzip elasticsearch-8.1.3-linux-x86_64.tar.gz
-rw-r--r-- 1 root root 1101649920 ?5月 ?3 18:41 elasticsearch-8.1.3-linux-x86_64.tar
繼續(xù)解壓縮
[root@192 es]# tar -xvf elasticsearch-8.1.3-linux-x86_64.tar
[root@192 es]# ll
總用量?1075832
drwxr-xr-x 9 root root ???????155 ?4月?19 16:19 elasticsearch-8.1.3
-rw-r--r-- 1 root root 1101649920 ?5月 ?3 18:41 elasticsearch-8.1.3-linux-x86_64.tar
2.?創(chuàng)建用戶
基于安全可控的原則,Elasticsearch?不允許?root?用戶直接運行;
所以要創(chuàng)建新用戶,?root?用戶中創(chuàng)建新用戶
[root@192 ~]# useradd es????#新增?es?用戶
[root@192 ~]# passwd es?????#為?es?用戶設(shè)置密碼
更改用戶?es?的密碼 。
新的?密碼:
重新輸入新的?密碼:
passwd:所有的身份驗證令牌已經(jīng)成功更新。
userdel -r es #如果錯了,可以刪除再加
3.?修改屬性(必須要執(zhí)行)
[root@192 es]# pwd
/es
[root@192 es]# chown -R es:es elasticsearch-8.1.3
4.?修改配置文件
修改/es/elasticsearch-8.1.3/config/elasticsearch.yml?文件?#?加入如下配置
[root@192 config]# vim elasticsearch.yml
cluster.name: my-application
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["node-1"]
?
注意:
1.?為es設(shè)置ip綁定,默認是127.0.0.1,也就是默認只能通過127.0.0.1?或者localhost才能訪問,也可配置0.0.0.0全部可以訪問
2.?為es設(shè)置自定義端口,默認是9200
5.?修改OS層系統(tǒng)參數(shù)
修改/etc/security/limits.conf #?在文件末尾中增加下面內(nèi)容
#?每個進程可以打開的文件數(shù)的限制
es soft nofile 65536
es hard nofile 65536
修改/etc/sysctl.conf #?在文件中增加下面內(nèi)容
#?一個進程可以擁有的?VMA(虛擬內(nèi)存區(qū)域)的數(shù)量,默認值為?65536
vm.max_map_count=655360
重新加載
[root@192 security]# sysctl -p
kernel.sysrq = 0
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.tcp_syncookies = 1
kernel.dmesg_restrict = 1
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
vm.max_map_count = 655360
6.?啟動軟件
使用?ES?用戶啟動
su - es
cd?/es/elasticsearch-8.1.3/bin
#后臺啟動
./elasticsearch -d
7.?停止es
ps -ef|grep elasticsearch
kill -9 pid
三、設(shè)置Elasticsearch密碼
步驟1:設(shè)置密碼
[es@192 bin]$ ./elasticsearch-setup-passwords interactive
******************************************************************************
Note: The 'elasticsearch-setup-passwords' tool has been deprecated. This ??????command will be removed in a future release.
******************************************************************************
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
passwords must be at least [6] characters long
Try again.
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana_system]:
Reenter password for [kibana_system]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
因為需要設(shè)置?elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user?這些用戶的密碼,故這個過程比較漫長,耐心設(shè)置。
步驟2:驗證
瀏覽器直接訪問https://192.168.220.110:9200,會出現(xiàn)輸入用戶名、密碼的彈窗,輸入elastic和密碼后,可看到elasticsearch信息。
四、安裝kibana
https://www.elastic.co/cn/downloads/kibana
1.?解壓縮
[root@192 es]# gunzip kibana-8.1.3-linux-x86_64.tar.gz
[root@192 es]# tar -xvf kibana-8.1.3-linux-x86_64.tar
2.?vim config/kibana.yml
server.port:?5601?
server.host:?"0.0.0.0"
elasticsearch.hosts:?["http://192.168.220.110:9200"]?
elasticsearch.username:?"kibana_system"?
elasticsearch.password:?"elastic"
#kibana中文模式
i18n.locale: "zh-CN"
3.?修改權(quán)限
[root@192 es]# chown -R es:es kibana-8.1.3
4.?后臺啟動
[es@192 ~]$ cd?/es/kibana-8.1.3/bin
[es@192 bin]$ nohup ./kibana &
5.?web訪問 ?ip:5601
http://192.168.220.110:5601
注意:192.168.220.110為本虛擬機的ip地址
6) 停止kibana
lsof -i:5601查看進程
[es@192 bin]$ lsof -i:5601
COMMAND ??PID USER ??FD ??TYPE DEVICE SIZE/OFF NODE NAME
node ???89939 ??es ??18u ?IPv4 165188 ?????0t0 ?TCP *:esmagent (LISTEN)
kill -9進程號
總結(jié):
1.?本文闡述了ES的概念;因為不了解,故動手安裝了一遍單機版的ES部署過程;后續(xù)集群版則其部署;
2.?To be continued.
?
【參考】
https://blog.csdn.net/UbuntuTouch/article/details/98871531
【參考】
https://db-engines.com/en/ranking
【參考】
https://elasticstack.blog.csdn.net/article/details/113754619
【參考】
https://www.jianshu.com/p/28fb017be7a7
【參考】
https://www.modb.pro/db/394758
【參考】
https://www.elastic.co/guide/index.html文章來源:http://www.zghlxwxcb.cn/news/detail-406716.html
以下是個人微信公眾號,歡迎關(guān)注:文章來源地址http://www.zghlxwxcb.cn/news/detail-406716.html
到了這里,關(guān)于知識篇 | 麒麟v10 下安裝Elasticsearch的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!