天天看點

SQL資料同步到ELK(二)- Elastic Search 安裝

開篇廢話

沒錯,前面扯了一堆SQL SERVER,其實我連Elastic Search根本沒動手玩過(是不是與時代有點脫節了?),那今天我就準備嘗試安裝一個ELK的簡單叢集出來(這個叢集是使用我的小米筆記本建立了兩個虛拟機,虛拟出來的一個叢集,沒錢買阿裡雲)

虛拟機的作業系統實CentOS 7 64位,不同的Linux版本可能略有差異~

直接安裝Elastic Search

安裝Master Node

本文也是參考官網文檔進行安裝,大家可以直接看官網文檔,一般來說,比較新一些。

官方文檔:https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-install.html

1)找個合适的檔案夾下載下傳安裝包:

curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-linux-x86_64.tar.gz      

友情提示,如果下載下傳速度比較慢,可以拿迅雷這類軟體下載下傳好,上傳到伺服器,迅雷這類軟體在下載下傳這種熱門資源的時候,還是有速度上的提升的。

2)解壓下載下傳下來的檔案

本文的版本号均為7.2.0,安裝不同的版本時,靈活應變就行。

tar -xvf elasticsearch-7.2.0-linux-x86_64.tar.gz      

3)修改配置檔案

進入解壓後的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"]      

此時我們在elasticsearch-7.2.0檔案夾下執行

./bin/elasticsearch      

由于我虛拟機記憶體不夠大的原因,他會抛個異常:

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]      

對于第一個報錯ELK官網是這麼解釋的:

是由于Elasticsearch需要使用大量的檔案描述符或檔案句柄,用完檔案描述符可能是災難性的,也有可能導緻資料丢失,需要確定将運作Elasticsearch的使用者能打開檔案描述符數量的限制增加到65,536或更高。

官網連結在這裡:https://www.elastic.co/guide/en/elasticsearch/reference/current/file-descriptors.html

官網解決方案的連結:https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-system-settings.html#limits.conf

然而,我照官網做了之後,并不管什麼用,最終找到了一篇文章:

http://www.kxtry.com/archives/1635

首先第一個問題,需要修改檔案etc/security/limits.conf中的一些配置:

執行指令:

sudo vi /etc/security/limits.conf      

像檔案最後添加内容:

* soft nofile 65536      

* hard nofile 131072 (貌似隻添加這句就行)

* soft nproc 2048

* hard nproc 4096

然後退出目前的終端重新連接配接進入,這步非常重要,不重新進不起作用的~

第二個問題需要修改/etc/sysctl.conf中的一些配置:

sudo vi /etc/sysctl.conf      

向檔案最後添加記錄:

vm.max_map_count=655360      

儲存并退出後執行指令:

sudo sysctl -p      

這步跟上面退出終端重新進入一樣重要,不執行這個配置不會生效的。

執行完這兩步,然後重新執行就可以啟動成功了~

./bin/elasticsearch      

可以在新開一個終端執行下面指令來驗證安裝的成果:

curl http://伺服器ip:9200/      

此時如果安裝的沒問題,會列印類似下面的内容:

{
  "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"
}      

如果你想在背景啟動elastic search程序,那麼可以在啟動時加個 -d參數:

./bin/elasticsearch –d      

到此為止,我們的Master節點(主節點)就安裝完畢了

安裝Slave node

接下來,我們再次來安裝一台Slave節點(從節點),并且跟我們目前的Master節點組成一個Elastic search叢集。

Slave節點的大部分步驟和Master節點是一樣的,唯一的差別在于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"]      

配置的時候,需要注意以下幾點:

  • cluster.name 一定要跟Master節點配置的一樣
  • node.name 是一個唯一辨別,一定不要跟Master節點配置的一樣,各個不同的Salve也不要重複
  • discovery.zen.ping.unicast.hosts中的IP清單是叢集中其他節點的IP位址清單

到這裡為止,我們整個叢集都安裝完成了

使用ElasticSearch-Head可視化界面

預設我們隻能通過指令行或者Http的方式來操作Elastic Search,elasticsearch-head 則是一款開源的ElasticSearch管理界面,它的項目首頁為:https://github.com/mobz/elasticsearch-head

使用起來也非常簡單:

  1. 下載下傳他的源碼,不管是使用Clone還是直接使用Github的download zip功能
  2. 執行指令:npm install 還原npm依賴,(依賴于Node.js和npm)
  3. 還原完成後,執行npm start指令啟動項目
  4. 浏覽器中打開http://localhost:9100/
  5. 修改浏覽器中最上方的連接配接位址(預設是http://localhost:9200)
SQL資料同步到ELK(二)- Elastic Search 安裝

該項目可以在任意一台能通路到ElasticSearch的機器上安裝,裝在你的本地機器也可以哦~

ELK的安裝就介紹到這裡喽~更多的ELK的知識,還需要多多探索哦~

西安.NET俱樂部群

SQL資料同步到ELK(二)- Elastic Search 安裝