開(kāi)篇廢話
沒(méi)錯(cuò),前面扯了一堆SQL SERVER,其實(shí)我連Elastic
Search根本沒(méi)動(dòng)手玩過(guò)(是不是與時(shí)代有點(diǎn)脫節(jié)了?),那今天我就準(zhǔn)備嘗試安裝一個(gè)ELK的簡(jiǎn)單集群出來(lái)(這個(gè)集群是使用我的小米筆記本創(chuàng)建了兩個(gè)虛擬機(jī),虛擬出來(lái)的一個(gè)集群,沒(méi)錢(qián)買阿里云)
虛擬機(jī)的操作系統(tǒng)實(shí)CentOS 7 64位,不同的Linux版本可能略有差異~
直接安裝Elastic Search
安裝Master Node
本文也是參考官網(wǎng)文檔進(jìn)行安裝,大家可以直接看官網(wǎng)文檔,一般來(lái)說(shuō),比較新一些。
官方文檔:
https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-install.html
<https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-install.html>
1)找個(gè)合適的文件夾下載安裝包:
curl -L -O https://
artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-linux-x86_64.tar.gz
友情提示,如果下載速度比較慢,可以拿迅雷這類軟件下載好,上傳到服務(wù)器,迅雷這類軟件在下載這種熱門(mén)資源的時(shí)候,還是有速度上的提升的。
2)解壓下載下來(lái)的文件
本文的版本號(hào)均為7.2.0,安裝不同的版本時(shí),靈活應(yīng)變就行。
tar -xvf elasticsearch-7.2.0-linux-x86_64.tar.gz
3)修改配置文件
進(jìn)入解壓后的elasticsearch-7.2.0 文件夾中的config文件夾,并修改elasticsearch.yml 文件中的配置:
cluster.name: jax-elk-group1 node.name: master node.master: true network.host:
0.0.0.0 http.cors.enabled: true http.cors.allow-origin: "*"
cluster.initial_master_nodes: ["master"]
此時(shí)我們?cè)趀lasticsearch-7.2.0文件夾下執(zhí)行
./bin/elasticsearch
由于我虛擬機(jī)內(nèi)存不夠大的原因,他會(huì)拋個(gè)異常:
ERROR: [2] bootstrap checks failed [1]: max file descriptors [4096] for
elasticsearch process is too low, increase to at least [65535] [2]: max virtual
memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
對(duì)于第一個(gè)報(bào)錯(cuò)ELK官網(wǎng)是這么解釋的:
是由于Elasticsearch需要使用大量的文件描述符或文件句柄,用完文件描述符可能是災(zāi)難性的,也有可能導(dǎo)致數(shù)據(jù)丟失,需要確保將運(yùn)行Elasticsearch的用戶能打開(kāi)文件描述符數(shù)量的限制增加到65,536或更高。
官網(wǎng)鏈接在這里:
https://www.elastic.co/guide/en/elasticsearch/reference/current/file-descriptors.html
<https://www.elastic.co/guide/en/elasticsearch/reference/current/file-descriptors.html>
官網(wǎng)解決方案的鏈接:
https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-system-settings.html#limits.conf
<https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-system-settings.html#limits.conf>
然而,我照官網(wǎng)做了之后,并不管什么用,最終找到了一篇文章:
http://www.kxtry.com/archives/1635 <http://www.kxtry.com/archives/1635>
首先第一個(gè)問(wèn)題,需要修改文件etc/security/limits.conf中的一些配置:
執(zhí)行命令:
sudo vi /etc/security/limits.conf
像文件最后添加內(nèi)容:
* soft nofile 65536
* hard nofile 131072 (貌似只添加這句就行)
* soft nproc 2048
* hard nproc 4096
然后退出當(dāng)前的終端重新連接進(jìn)入,這步非常重要,不重新進(jìn)不起作用的~
第二個(gè)問(wèn)題需要修改/etc/sysctl.conf中的一些配置:
執(zhí)行命令:
sudo vi /etc/sysctl.conf
向文件最后添加記錄:
vm.max_map_count=655360
保存并退出后執(zhí)行命令:
sudo sysctl -p
這步跟上面退出終端重新進(jìn)入一樣重要,不執(zhí)行這個(gè)配置不會(huì)生效的。
執(zhí)行完這兩步,然后重新執(zhí)行就可以啟動(dòng)成功了~
./bin/elasticsearch
可以在新開(kāi)一個(gè)終端執(zhí)行下面命令來(lái)驗(yàn)證安裝的成果:
curl http://服務(wù)器ip <http://服務(wù)器ip> <>:9200/
此時(shí)如果安裝的沒(méi)問(wèn)題,會(huì)打印類似下面的內(nèi)容:
{ "name" : "master", "cluster_name" : "jax-elk-group1", "cluster_uuid" :
"NtmpxdwtRQOiT8sv8bJrvg", "version" : { "number" : "7.2.0", "build_flavor" :
"default", "build_type" : "tar", "build_hash" : "508c38a", "build_date" :
"2019-06-20T15:54:18.811730Z", "build_snapshot" : false, "lucene_version" :
"8.0.0", "minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know,
for Search" }
如果你想在后臺(tái)啟動(dòng)elastic search進(jìn)程,那么可以在啟動(dòng)時(shí)加個(gè) -d參數(shù):
./bin/elasticsearch –d
到此為止,我們的Master節(jié)點(diǎn)(主節(jié)點(diǎn))就安裝完畢了
安裝Slave node
接下來(lái),我們?cè)俅蝸?lái)安裝一臺(tái)Slave節(jié)點(diǎn)(從節(jié)點(diǎn)),并且跟我們當(dāng)前的Master節(jié)點(diǎn)組成一個(gè)Elastic search集群。
Slave節(jié)點(diǎn)的大部分步驟和Master節(jié)點(diǎn)是一樣的,唯一的區(qū)別在于elasticsearch.yml 文件中的配置。
cluster.name: jax-elk-group1 node.name: node-01 network.host: 0.0.0.0
http.cors.enabled:true http.cors.allow-origin: "*"
cluster.initial_master_nodes: ["master"]discovery.zen.ping.unicast.hosts:
["192.168.154.135"]
配置的時(shí)候,需要注意以下幾點(diǎn):
* cluster.name 一定要跟Master節(jié)點(diǎn)配置的一樣
* node.name 是一個(gè)唯一標(biāo)識(shí),一定不要跟Master節(jié)點(diǎn)配置的一樣,各個(gè)不同的Salve也不要重復(fù)
* discovery.zen.ping.unicast.hosts中的IP列表是集群中其他節(jié)點(diǎn)的IP地址列表
到這里為止,我們整個(gè)集群都安裝完成了
使用ElasticSearch-Head可視化界面
默認(rèn)我們只能通過(guò)命令行或者Http的方式來(lái)操作Elastic Search,elasticsearch-head
則是一款開(kāi)源的ElasticSearch管理界面,它的項(xiàng)目主頁(yè)為:https://github.com/mobz/elasticsearch-head
<https://github.com/mobz/elasticsearch-head>
使用起來(lái)也非常簡(jiǎn)單:
* 下載他的源碼,不管是使用Clone還是直接使用Github的download zip功能
* 執(zhí)行命令:npm install 還原npm依賴,(依賴于Node.js和npm)
* 還原完成后,執(zhí)行npm start命令啟動(dòng)項(xiàng)目
* 瀏覽器中打開(kāi)http://localhost:9100/ <http://localhost:9100/>
* 修改瀏覽器中最上方的連接地址(默認(rèn)是http://localhost:9200 <http://localhost:9200>)
<https://img2018.cnblogs.com/blog/602207/201907/602207-20190722213638765-707049806.png>
該項(xiàng)目可以在任意一臺(tái)能訪問(wèn)到ElasticSearch的機(jī)器上安裝,裝在你的本地機(jī)器也可以哦~
ELK的安裝就介紹到這里嘍~更多的ELK的知識(shí),還需要多多探索哦~
熱門(mén)工具 換一換
