自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何在RHEL8/CentOS8上建立多節(jié)點Elastic stack集群

系統(tǒng) Linux
Elastic stack 俗稱 ELK stack,是一組包括 Elasticsearch、Logstash 和 Kibana 在內(nèi)的開源產(chǎn)品。Elastic Stack 由 Elastic 公司開發(fā)和維護。在本文中,我們將演示如何在 RHEL 8 / CentOS 8 服務器上設置多節(jié)點 elastic stack 集群。

如何在RHEL8 /CentOS8上建立多節(jié)點Elastic stack集群

Elastic stack 俗稱 ELK stack,是一組包括 Elasticsearch、Logstash 和 Kibana 在內(nèi)的開源產(chǎn)品。Elastic Stack 由 Elastic 公司開發(fā)和維護。使用 Elastic stack,可以將系統(tǒng)日志發(fā)送到 Logstash,它是一個數(shù)據(jù)收集引擎,接受來自可能任何來源的日志或數(shù)據(jù),并對日志進行歸一化,然后將日志轉(zhuǎn)發(fā)到 Elasticsearch,用于分析、索引、搜索和存儲,使用 Kibana 表示為可視化數(shù)據(jù),使用 Kibana,我們還可以基于用戶的查詢創(chuàng)建交互式圖表。

在本文中,我們將演示如何在 RHEL 8 / CentOS 8 服務器上設置多節(jié)點 elastic stack 集群。以下是我的 Elastic Stack 集群的詳細信息:

Elasticsearch:

  • 三臺服務器,最小化安裝 RHEL 8 / CentOS 8
  • IP & 主機名 – 192.168.56.40(elasticsearch1.linuxtechi.local)、192.168.56.50 (elasticsearch2.linuxtechi.local)、192.168.56.60(elasticsearch3.linuxtechi.local`)

Logstash:

  • 兩臺服務器,最小化安裝 RHEL 8 / CentOS 8
  • IP & 主機 – 192.168.56.20(logstash1.linuxtechi.local)、192.168.56.30(logstash2.linuxtechi.local

Kibana:

  • 一臺服務器,最小化安裝 RHEL 8 / CentOS 8
  • IP & 主機名 – 192.168.56.10(kibana.linuxtechi.local

Filebeat:

  • 一臺服務器,最小化安裝 CentOS 7
  • IP & 主機名 – 192.168.56.70(web-server

讓我們從設置 Elasticsearch 集群開始,

設置3個節(jié)點 Elasticsearch 集群

正如我已經(jīng)說過的,設置 Elasticsearch 集群的節(jié)點,登錄到每個節(jié)點,設置主機名并配置 yum/dnf 庫。

使用命令 hostnamectl 設置各個節(jié)點上的主機名:

  1. [root@linuxtechi ~]# hostnamectl set-hostname "elasticsearch1.linuxtechi. local"
  2. [root@linuxtechi ~]# exec bash
  3. [root@linuxtechi ~]#
  4. [root@linuxtechi ~]# hostnamectl set-hostname "elasticsearch2.linuxtechi. local"
  5. [root@linuxtechi ~]# exec bash
  6. [root@linuxtechi ~]#
  7. [root@linuxtechi ~]# hostnamectl set-hostname "elasticsearch3.linuxtechi. local"
  8. [root@linuxtechi ~]# exec bash
  9. [root@linuxtechi ~]#

對于 CentOS 8 系統(tǒng),我們不需要配置任何操作系統(tǒng)包庫,對于 RHEL 8 服務器,如果你有有效訂閱,那么用紅帽訂閱以獲得包存儲庫就可以了。如果你想為操作系統(tǒng)包配置本地 yum/dnf 存儲庫,請參考以下網(wǎng)址:

在所有節(jié)點上配置 Elasticsearch 包存儲庫,在 /etc/yum.repo.d/ 文件夾下創(chuàng)建一個包含以下內(nèi)容的 elastic.repo 文件:

  1. ~]# vi /etc/yum.repos.d/elastic.repo
  2.  
  3. [elasticsearch-7.x]
  4. name=Elasticsearch repository for 7.x packages
  5. baseurl=https://artifacts.elastic.co/packages/7.x/yum
  6. gpgcheck=1
  7. gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
  8. enabled=1
  9. autorefresh=1
  10. type=rpm-md

保存文件并退出。

在所有三個節(jié)點上使用 rpm 命令導入 Elastic 公共簽名密鑰。

  1. ~]# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

在所有三個節(jié)點的 /etc/hosts 文件中添加以下行:

  1. 192.168.56.40 elasticsearch1.linuxtechi.local
  2. 192.168.56.50 elasticsearch2.linuxtechi.local
  3. 192.168.56.60 elasticsearch3.linuxtechi.local

使用 yum/dnf 命令在所有三個節(jié)點上安裝 Java:

  1. [root@linuxtechi ~]# dnf install java-openjdk -y
  2. [root@linuxtechi ~]# dnf install java-openjdk -y
  3. [root@linuxtechi ~]# dnf install java-openjdk -y

使用 yum/dnf 命令在所有三個節(jié)點上安裝 Elasticsearch:

  1. [root@linuxtechi ~]# dnf install elasticsearch -y
  2. [root@linuxtechi ~]# dnf install elasticsearch -y
  3. [root@linuxtechi ~]# dnf install elasticsearch -y

注意: 如果操作系統(tǒng)防火墻已啟用并在每個 Elasticsearch 節(jié)點中運行,則使用 firewall-cmd 命令允許以下端口開放:

  1. ~]# firewall-cmd --permanent --add-port=9300/tcp
  2. ~]# firewall-cmd --permanent --add-port=9200/tcp
  3. ~]# firewall-cmd --reload

配置 Elasticsearch, 在所有節(jié)點上編輯文件 /etc/elasticsearch/elasticsearch.yml 并加入以下內(nèi)容:

  1. ~]# vim /etc/elasticsearch/elasticsearch.yml
  2.  
  3. cluster.name: opn-cluster
  4. node.name: elasticsearch1.linuxtechi.local
  5. network.host: 192.168.56.40
  6. http.port: 9200
  7. discovery.seed_hosts: ["elasticsearch1.linuxtechi.local", "elasticsearch2.linuxtechi.local", "elasticsearch3.linuxtechi.local"]
  8. cluster.initial_master_nodes: ["elasticsearch1.linuxtechi.local", "elasticsearch2.linuxtechi.local", "elasticsearch3.linuxtechi.local"]

注意: 在每個節(jié)點上,在 node.name 中填寫正確的主機名,在 network.host 中填寫正確的 IP 地址,其他參數(shù)保持不變。

現(xiàn)在使用 systemctl 命令在所有三個節(jié)點上啟動并啟用 Elasticsearch 服務:

  1. ~]# systemctl daemon-reload
  2. ~]# systemctl enable elasticsearch.service
  3. ~]# systemctl start elasticsearch.service

使用下面 ss 命令驗證 elasticsearch 節(jié)點是否開始監(jiān)聽 9200 端口:

  1. [root@linuxtechi ~]# ss -tunlp | grep 9200
  2. tcp LISTEN 0 128 [::ffff:192.168.56.40]:9200 *:* users:(("java",pid=2734,fd=256))
  3. [root@linuxtechi ~]#

使用以下 curl 命令驗證 Elasticsearch 群集狀態(tài):

  1. [root@linuxtechi ~]# curl http://elasticsearch1.linuxtechi.local:9200
  2. [root@linuxtechi ~]# curl -X GET http://elasticsearch2.linuxtechi.local:9200/_cluster/health?pretty

命令的輸出如下所示: 

如何在RHEL8 /CentOS8上建立多節(jié)點Elastic stack集群

Elasticsearch-cluster-status-rhel8

以上輸出表明我們已經(jīng)成功創(chuàng)建了 3 節(jié)點的 Elasticsearch 集群,集群的狀態(tài)也是綠色的。

注意: 如果你想修改 JVM 堆大小,那么你可以編輯了文件 /etc/elasticsearch/jvm.options,并根據(jù)你的環(huán)境更改以下參數(shù):

  • -Xms1g
  • -Xmx1g

現(xiàn)在讓我們轉(zhuǎn)到 Logstash 節(jié)點。

安裝和配置 Logstash

在兩個 Logstash 節(jié)點上執(zhí)行以下步驟。

登錄到兩個節(jié)點使用 hostnamectl 命令設置主機名:

  1. [root@linuxtechi ~]# hostnamectl set-hostname "logstash1.linuxtechi.local"
  2. [root@linuxtechi ~]# exec bash
  3. [root@linuxtechi ~]#
  4. [root@linuxtechi ~]# hostnamectl set-hostname "logstash2.linuxtechi.local"
  5. [root@linuxtechi ~]# exec bash
  6. [root@linuxtechi ~]#

在兩個 logstash 節(jié)點的 /etc/hosts 文件中添加以下條目:

  1. ~]# vi /etc/hosts
  2. 192.168.56.40 elasticsearch1.linuxtechi.local
  3. 192.168.56.50 elasticsearch2.linuxtechi.local
  4. 192.168.56.60 elasticsearch3.linuxtechi.local

保存文件并退出。

在兩個節(jié)點上配置 Logstash 存儲庫,在文件夾 /ete/yum.repo.d/ 下創(chuàng)建一個包含以下內(nèi)容的文件 logstash.repo

  1. ~]# vi /etc/yum.repos.d/logstash.repo
  2.  
  3. [elasticsearch-7.x]
  4. name=Elasticsearch repository for 7.x packages
  5. baseurl=https://artifacts.elastic.co/packages/7.x/yum
  6. gpgcheck=1
  7. gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
  8. enabled=1
  9. autorefresh=1
  10. type=rpm-md

保存并退出文件,運行 rpm 命令導入簽名密鑰:

  1. ~]# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

使用 yum/dnf 命令在兩個節(jié)點上安裝 Java OpenJDK:

  1. ~]# dnf install java-openjdk -y

從兩個節(jié)點運行 yum/dnf 命令來安裝 logstash:

  1. [root@linuxtechi ~]# dnf install logstash -y
  2. [root@linuxtechi ~]# dnf install logstash -y

現(xiàn)在配置 logstash,在兩個 logstash 節(jié)點上執(zhí)行以下步驟,創(chuàng)建一個 logstash 配置文件,首先我們在 /etc/logstash/conf.d/ 下復制 logstash 示例文件:

  1. # cd /etc/logstash/
  2. # cp logstash-sample.conf conf.d/logstash.conf

編輯配置文件并更新以下內(nèi)容:

  1. # vi conf.d/logstash.conf
  2.  
  3. input {
  4. beats {
  5. port => 5044
  6. }
  7. }
  8.  
  9. output {
  10. elasticsearch {
  11. hosts => ["http://elasticsearch1.linuxtechi.local:9200", "http://elasticsearch2.linuxtechi.local:9200", "http://elasticsearch3.linuxtechi.local:9200"]
  12. index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
  13. #user => "elastic"
  14. #password => "changeme"
  15. }
  16. }

output 部分之下,在 hosts 參數(shù)中指定所有三個 Elasticsearch 節(jié)點的 FQDN,其他參數(shù)保持不變。

使用 firewall-cmd 命令在操作系統(tǒng)防火墻中允許 logstash 端口 “5044”:

  1. ~ # firewall-cmd --permanent --add-port=5044/tcp
  2. ~ # firewall-cmd reload

現(xiàn)在,在每個節(jié)點上運行以下 systemctl 命令,啟動并啟用 Logstash 服務:

  1. ~]# systemctl start logstash
  2. ~]# systemctl eanble logstash

使用 ss 命令驗證 logstash 服務是否開始監(jiān)聽 5044 端口:

  1. [root@linuxtechi ~]# ss -tunlp | grep 5044
  2. tcp LISTEN 0 128 *:5044 *:* users:(("java",pid=2416,fd=96))
  3. [root@linuxtechi ~]#

以上輸出表明 logstash 已成功安裝和配置。讓我們轉(zhuǎn)到 Kibana 安裝。

安裝和配置 Kibana

登錄 Kibana 節(jié)點,使用 hostnamectl 命令設置主機名:

  1. [root@linuxtechi ~]# hostnamectl set-hostname "kibana.linuxtechi.local"
  2. [root@linuxtechi ~]# exec bash
  3. [root@linuxtechi ~]#

編輯 /etc/hosts 文件并添加以下行:

  1. 192.168.56.40 elasticsearch1.linuxtechi.local
  2. 192.168.56.50 elasticsearch2.linuxtechi.local
  3. 192.168.56.60 elasticsearch3.linuxtechi.local

使用以下命令設置 Kibana 存儲庫:

  1. [root@linuxtechi ~]# vi /etc/yum.repos.d/kibana.repo
  2. [elasticsearch-7.x]
  3. name=Elasticsearch repository for 7.x packages
  4. baseurl=https://artifacts.elastic.co/packages/7.x/yum
  5. gpgcheck=1
  6. gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
  7. enabled=1
  8. autorefresh=1
  9. type=rpm-md
  10.  
  11. [root@linuxtechi ~]# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

執(zhí)行 yum/dnf 命令安裝 kibana:

  1. [root@linuxtechi ~]# yum install kibana -y

通過編輯 /etc/kibana/kibana.yml 文件,配置 Kibana:

  1. [root@linuxtechi ~]# vim /etc/kibana/kibana.yml
  2. …………
  3. server.host: "kibana.linuxtechi.local"
  4. server.name: "kibana.linuxtechi.local"
  5. elasticsearch.hosts: ["http://elasticsearch1.linuxtechi.local:9200", "http://elasticsearch2.linuxtechi.local:9200", "http://elasticsearch3.linuxtechi.local:9200"]
  6. …………

啟用并啟動 kibana 服務:

  1. [root@linuxtechi ~]# systemctl start kibana
  2. [root@linuxtechi ~]# systemctl enable kibana

在系統(tǒng)防火墻上允許 Kibana 端口 “5601”:

  1. [root@linuxtechi ~]# firewall-cmd --permanent --add-port=5601/tcp
  2. success
  3. [root@linuxtechi ~]# firewall-cmd --reload
  4. success
  5. [root@linuxtechi ~]#

使用以下 URL 訪問 Kibana 界面:http://kibana.linuxtechi.local:5601 

如何在RHEL8 /CentOS8上建立多節(jié)點Elastic stack集群

Kibana-Dashboard-rhel8

從面板上,我們可以檢查 Elastic Stack 集群的狀態(tài)。 

如何在RHEL8 /CentOS8上建立多節(jié)點Elastic stack集群

Stack-Monitoring-Overview-RHEL8

這證明我們已經(jīng)在 RHEL 8 /CentOS 8 上成功地安裝并設置了多節(jié)點 Elastic Stack 集群。

現(xiàn)在讓我們通過 filebeat 從其他 Linux 服務器發(fā)送一些日志到 logstash 節(jié)點中,在我的例子中,我有一個 CentOS 7服務器,我將通過 filebeat 將該服務器的所有重要日志推送到 logstash。

登錄到 CentOS 7 服務器使用 yum/rpm 命令安裝 filebeat 包:

  1. [root@linuxtechi ~]# rpm -ivh https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.3.1-x86_64.rpm
  2. Retrieving https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.3.1-x86_64.rpm
  3. Preparing... ################################# [100%]
  4. Updating / installing...
  5. 1:filebeat-7.3.1-1 ################################# [100%]
  6. [root@linuxtechi ~]#

編輯 /etc/hosts 文件并添加以下內(nèi)容:

  1. 192.168.56.20 logstash1.linuxtechi.local
  2. 192.168.56.30 logstash2.linuxtechi.local

現(xiàn)在配置 filebeat,以便它可以使用負載平衡技術向 logstash 節(jié)點發(fā)送日志,編輯文件 /etc/filebeat/filebeat.yml,并添加以下參數(shù):

filebeat.inputs: 部分將 enabled: false 更改為 enabled: true,并在 paths 參數(shù)下指定我們可以發(fā)送到 logstash 的日志文件的位置;注釋掉 output.elasticsearchhost 參數(shù);刪除 output.logstash:hosts: 的注釋,并在 hosts 參數(shù)添加兩個 logstash 節(jié)點,以及設置 loadbalance: true。

  1. [root@linuxtechi ~]# vi /etc/filebeat/filebeat.yml
  2.  
  3. filebeat.inputs:
  4. - type: log
  5. enabled: true
  6. paths:
  7. - /var/log/messages
  8. - /var/log/dmesg
  9. - /var/log/maillog
  10. - /var/log/boot.log
  11. #output.elasticsearch:
  12. # hosts: ["localhost:9200"]
  13.  
  14. output.logstash:
  15. hosts: ["logstash1.linuxtechi.local:5044", "logstash2.linuxtechi.local:5044"]
  16. loadbalance: true

使用下面的 2 個 systemctl 命令 啟動并啟用 filebeat 服務:

  1. [root@linuxtechi ~]# systemctl start filebeat
  2. [root@linuxtechi ~]# systemctl enable filebeat

現(xiàn)在轉(zhuǎn)到 Kibana 用戶界面,驗證新索引是否可見。

從左側(cè)欄中選擇管理選項,然后單擊 Elasticsearch 下的索引管理: 

如何在RHEL8 /CentOS8上建立多節(jié)點Elastic stack集群

Elasticsearch-index-management-Kibana

正如我們上面看到的,索引現(xiàn)在是可見的,讓我們現(xiàn)在創(chuàng)建索引模型。

點擊 Kibana 部分的 “Index Patterns”,它將提示我們創(chuàng)建一個新模型,點擊 “Create Index Pattern” ,并將模式名稱指定為 “filebeat”: 

如何在RHEL8 /CentOS8上建立多節(jié)點Elastic stack集群

Define-Index-Pattern-Kibana-RHEL8

點擊下一步。

選擇 “Timestamp” 作為索引模型的時間過濾器,然后單擊 “Create index pattern”: 

如何在RHEL8 /CentOS8上建立多節(jié)點Elastic stack集群

Time-Filter-Index-Pattern-Kibana-RHEL8 

如何在RHEL8 /CentOS8上建立多節(jié)點Elastic stack集群

filebeat-index-pattern-overview-Kibana

現(xiàn)在單擊查看實時 filebeat 索引模型: 

如何在RHEL8 /CentOS8上建立多節(jié)點Elastic stack集群

Discover-Kibana-REHL8

這表明 Filebeat 代理已配置成功,我們能夠在 Kibana 儀表盤上看到實時日志。

以上就是本文的全部內(nèi)容,對這些幫助你在 RHEL 8 / CentOS 8 系統(tǒng)上設置 Elastic Stack 集群的步驟,請不要猶豫分享你的反饋和意見。 

 

責任編輯:龐桂玉 來源: Linux中國
相關推薦

2019-10-28 14:38:36

RsyslogCentOS8開源

2019-12-02 15:45:53

CentOS 8AnsibleLinux

2017-05-03 14:00:00

LinuxCentOSElastic Sta

2020-03-02 14:06:54

CentOS 8FFmpegLinux

2019-12-02 11:50:09

CentOS 8VirtualBoxLinux

2019-10-12 10:24:06

CentOSRHELCockpit

2019-11-14 09:20:15

CentOS 8RHEL 8Nagios Core

2019-11-05 11:20:36

CentOS 8RHEL 8Linux

2017-04-24 18:10:27

DrupalCentOSFedora

2019-10-14 15:00:12

Centos 8 RHEL 8VNC

2023-03-16 08:55:51

RHEL 8MiniKube開源

2014-07-01 09:53:21

DockerHadoop集群

2023-05-29 17:52:29

2023-05-13 17:32:51

2023-05-05 16:20:15

2022-04-30 09:41:14

LinuxNTP服務器

2021-07-07 07:09:51

Centos8 RescueSSH

2015-12-21 13:19:23

CentosRHEL 6.XWetty

2016-01-25 13:03:21

2017-04-11 13:20:06

CentOSRHELFedora
點贊
收藏

51CTO技術棧公眾號