日志分析集群最新版

日志分析集群-8版本

作者:行癲(盜版必究)


第一部分:Elasticsearch

image-20240603232119647

一:環境準備

1.簡介

? 部署模式:es集群采用無主模式

? es版本:8.13.4

? jdk版本:使用es內嵌的jdk21,無需額外安裝jdk環境

? 操作系統:Centos 7

2.環境
IP地址主機名角色
10.9.12.83es-1.xingdian.commaster&data節點
10.9.12.84es-2.xingdian.commaster&data節點
10.9.12.85es-3.xingdian.commaster&data節點

二:服務器配置

1.創建用戶

? es不能使用root用戶進行部署,故創建新用戶管理es集群

# 添加一個用戶  elasticsearch ,密碼   elasticsearch 
[root@es-1 ~]# useradd elasticsearch && echo elasticsearch|passwd --stdin elasticsearch
2.本地解析
[root@es-1 ~]# vim /etc/hosts
10.9.12.83  es-1.xingdian.com
10.9.12.84  es-2.xingdian.com
10.9.12.85  es-3.xingdian.com
3.系統優化

? 優化最大進程數,最大文件打開數,優化虛擬內存

[root@es-1 ~]# vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 131072
* soft nproc 4096
* hard nproc 6553[root@es-1 ~]# vim /etc/sysctl.conf
vm.max_map_count=262144[root@es-1 ~]# sysctl -p

三:集群部署

1.獲取安裝包

? 官網獲取

2.解壓安裝
[root@es-1 ~]# tar -xf elasticsearch-8.13.4-linux-x86_64.tar.gz -C /usr/local
[root@es-1 ~]# mv /usr/local/elasticsearch-8.13.4 /usr/local/es
[root@es-1 ~]# chown -R elasticsearch.elasticsearch /usr/local/es
3.配置環境變量
[root@es-1 ~]# vim /etc/profile
export JAVA_HOME=/usr/local/es/jdk
export ES_HOME=/usr/local/es
export PATH=$PATH:$ES_HOME/bin:$JAVA_HOME/bin# 刷新環境變量
[root@es-1 ~]# source /etc/profile
4.創建目錄

? 目錄用來存儲數據和存放證書并賦予權限

[root@es-1 ~]# mkdir -p /usr/local/es/data
[root@es-1 ~]# mkdir -p /usr/local/es/config/certs
[root@es-1 ~]# chown -R elasticsearch:elasticsearch /usr/local/es

注意:截至到目前為止,所有節點服務器的操作都是一致的

5.簽發證書
# 在第一臺服務器節點 es-1.xingdian.com 設置集群多節點通信密鑰
# 切換用戶
[root@es-1 ~]# su - elasticsearch[elasticsearch@es-1 ~]$ cd /usr/local/es/bin[elasticsearch@es-1 bin]$./elasticsearch-certutil cawarning: ignoring JAVA_HOME=/usr/local/es/jdk; using bundled JDK
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.
The 'ca' mode generates a new 'certificate authority'
This will create a new X.509 certificate and private key that can be used
to sign certificate when running in 'cert' mode.Use the 'ca-dn' option if you wish to configure the 'distinguished name'
of the certificate authorityBy default the 'ca' mode produces a single PKCS#12 output file which holds:* The CA certificate* The CAs private keyIf you elect to generate PEM format certificates (the -pem option), then the output will
be a zip file containing individual files for the CA certificate and private keyPlease enter the desired output file [elastic-stack-ca.p12]: # 回車即可
Enter password for elastic-stack-ca.p12 :  # 回車即可# 用 ca 證書簽發節點證書,過程中需按三次回車鍵,生成目錄:es的home:/usr/local/es/
[elasticsearch@es-1 bin]$ ./elasticsearch-certutil cert --ca elastic-stack-ca.p12If you specify any of the following options:* -pem (PEM formatted output)* -multiple (generate multiple certificates)* -in (generate certificates from an input file)
then the output will be be a zip file containing individual certificate/key filesEnter password for CA (elastic-stack-ca.p12) :  # 回車即可
Please enter the desired output file [elastic-certificates.p12]:  # 回車即可
Enter password for elastic-certificates.p12 :  # 回車即可Certificates written to /usr/local/es/elastic-certificates.p12This file should be properly secured as it contains the private key for
your instance.
This file is a self contained file and can be copied and used 'as is'
For each Elastic product that you wish to configure, you should copy
this '.p12' file to the relevant configuration directory
and then follow the SSL configuration instructions in the product guide.For client applications, you may only need to copy the CA certificate and
configure the client to trust this certificate.# 將生成的證書文件移動到 config/certs 目錄中
[elasticsearch@es-1 bin]$ cd /usr/local/es/
[elasticsearch@okd elasticsearch-8.11.0]$ ls -l | grep "elastic-"
-rw-------  1 elasticsearch elasticsearch   3596 Feb 10 16:05 elastic-certificates.p12
-rw-------  1 elasticsearch elasticsearch   2672 Feb 10 16:03 elastic-stack-ca.p12
[elasticsearch@es-1 es]$
[elasticsearch@es-1 es]$ mv elastic-certificates.p12 config/certs/
[elasticsearch@es-1 es]$ mv elastic-stack-ca.p12 config/certs/
6.設置集群多節點HTTP證書
# 簽發 Https 證書
[elasticsearch@es-1 es]$ cd /usr/local/es/bin/
[elasticsearch@es-1 bin]$ ./elasticsearch-certutil http
warning: ignoring JAVA_HOME=/usr/local/es/jdk; using bundled JDK## Elasticsearch HTTP Certificate Utility
The 'http' command guides you through the process of generating certificates
for use on the HTTP (Rest) interface for Elasticsearch.
This tool will ask you a number of questions in order to generate the right
set of files for your needs.
## Do you wish to generate a Certificate Signing Request (CSR)?
A CSR is used when you want your certificate to be created by an existing
Certificate Authority (CA) that you do not control (that is, you do not have
access to the keys for that CA).
If you are in a corporate environment with a central security team, then you
may have an existing Corporate CA that can generate your certificate for you.
Infrastructure within your organisation may already be configured to trust this
CA, so it may be easier for clients to connect to Elasticsearch if you use a
CSR and send that request to the team that controls your CA.
If you choose not to generate a CSR, this tool will generate a new certificate
for you. That certificate will be signed by a CA under your control. This is a
quick and easy way to secure your cluster with TLS, but you will need to
configure all your clients to trust that custom CA.
######################################################
# 是否生成CSR,選擇 N ,不需要                           #
######################################################
Generate a CSR? [y/N]N## Do you have an existing Certificate Authority (CA) key-pair that you wish to use to sign your certificate?If you have an existing CA certificate and key, then you can use that CA to
sign your new http certificate. This allows you to use the same CA across
multiple Elasticsearch clusters which can make it easier to configure clients,
and may be easier for you to manage.If you do not have an existing CA, one will be generated for you.
######################################################
# 是否使用已經存在的CA證書,選擇 y ,因為已經創建簽發好了CA    #
######################################################
Use an existing CA? [y/N]y## What is the path to your CA?
Please enter the full pathname to the Certificate Authority that you wish to
use for signing your new http certificate. This can be in PKCS#12 (.p12), JKS
(.jks) or PEM (.crt, .key, .pem) format.
######################################################
# 指定CA證書的路徑地址,CA Path:后寫絕對路徑               #
######################################################
CA Path: /usr/local/es/config/certs/elastic-stack-ca.p12
Reading a PKCS12 keystore requires a password.
It is possible for the keystore's password to be blank,
in which case you can simply press <ENTER> at the prompt######################################################
# 設置密鑰庫的密碼,直接 回車 即可                         #
######################################################
Password for elastic-stack-ca.p12:## How long should your certificates be valid?Every certificate has an expiry date. When the expiry date is reached clients
will stop trusting your certificate and TLS connections will fail.
Best practice suggests that you should either:
(a) set this to a short duration (90 - 120 days) and have automatic processes
to generate a new certificate before the old one expires, or
(b) set it to a longer duration (3 - 5 years) and then perform a manual update
a few months before it expires.You may enter the validity period in years (e.g. 3Y), months (e.g. 18M), or days (e.g. 90D)
######################################################
# 設置證書的失效時間,這里的y表示年,5y則代表失效時間5年       #
######################################################
For how long should your certificate be valid? [5y] 5y## Do you wish to generate one certificate per node?If you have multiple nodes in your cluster, then you may choose to generate a
separate certificate for each of these nodes. Each certificate will have its
own private key, and will be issued for a specific hostname or IP address.Alternatively, you may wish to generate a single certificate that is valid
across all the hostnames or addresses in your cluster.If all of your nodes will be accessed through a single domain
(e.g. node01.es.example.com, node02.es.example.com, etc) then you may find it
simpler to generate one certificate with a wildcard hostname (*.es.example.com)
and use that across all of your nodes.However, if you do not have a common domain name, and you expect to add
additional nodes to your cluster in the future, then you should generate a
certificate per node so that you can more easily generate new certificates when
you provision new nodes.######################################################
# 是否需要為每個節點都生成證書,選擇 N 無需每個節點都配置證書   #
######################################################
Generate a certificate per node? [y/N]N## Which hostnames will be used to connect to your nodes?
These hostnames will be added as "DNS" names in the "Subject Alternative Name"
(SAN) field in your certificate.
You should list every hostname and variant that people will use to connect to
your cluster over http.
Do not list IP addresses here, you will be asked to enter them later.If you wish to use a wildcard certificate (for example *.es.example.com) you
can enter that here.Enter all the hostnames that you need, one per line.
######################################################
# 輸入需連接集群節點主機名信息,一行輸入一個IP地址,空行回車結束 #
######################################################
When you are done, press <ENTER> once more to move on to the next step.es-1.xingdian.com
es-2.xingdian.com
es-3.xingdian.comYou entered the following hostnames.- es-1.xingdian.com- es-2.xingdian.com- es-3.xingdian.com####################################################
# 確認以上是否為正確的配置,輸入 Y 表示信息正確            #
####################################################
Is this correct [Y/n]Y## Which IP addresses will be used to connect to your nodes?
If your clients will ever connect to your nodes by numeric IP address, then you
can list these as valid IP "Subject Alternative Name" (SAN) fields in your
certificate.If you do not have fixed IP addresses, or not wish to support direct IP access
to your cluster then you can just press <ENTER> to skip this step.Enter all the IP addresses that you need, one per line.
####################################################
# 輸入需連接集群節點IP信息,一行輸入一個IP地址,空行回車結束 #
####################################################
When you are done, press <ENTER> once more to move on to the next step.10.9.12.83
10.9.12.84
10.9.12.85You entered the following IP addresses.- 10.9.12.83- 10.9.12.84- 10.9.12.85####################################################
# 確認以上是否為正確的配置,輸入 Y 表示信息正確            #
####################################################
Is this correct [Y/n]Y## Other certificate options
The generated certificate will have the following additional configuration
values. These values have been selected based on a combination of the
information you have provided above and secure defaults. You should not need to
change these values unless you have specific requirements.Key Name: es-1.xingdian.com
Subject DN: CN=es-1.xingdian.com
Key Size: 2048####################################################
# 是否要更改以上這些選項,選擇 N ,不更改證書選項配置       #
####################################################
Do you wish to change any of these options? [y/N]N## What password do you want for your private key(s)?Your private key(s) will be stored in a PKCS#12 keystore file named "http.p12".
This type of keystore is always password protected, but it is possible to use a
blank password.####################################################
# 是否要給證書加密,不需要加密,兩次 回車 即可             #
####################################################
If you wish to use a blank password, simply press <enter> at the prompt below.
Provide a password for the "http.p12" file:  [<ENTER> for none]## Where should we save the generated files?
A number of files will be generated including your private key(s),
public certificate(s), and sample configuration options for Elastic Stack products.
These files will be included in a single zip archive.
What filename should be used for the output zip file? [/usr/local/es/elasticsearch-ssl-http.zip]
Zip file written to /usr/local/es/elasticsearch-ssl-http.zip
7.分發證書
# 解壓
[elasticsearch@es-1 bin]$ cd /usr/local/es/
[elasticsearch@es-1 es]$ unzip elasticsearch-ssl-http.zip
# 移動證書
[elasticsearch@es-1 es]$ mv ./elasticsearch/http.p12 config/certs/
[elasticsearch@es-1 es]$ mv ./kibana/elasticsearch-ca.pem config/certs/# 將證書分發到其他節點02 03
[elasticsearch@es-1 es]$ cd /usr/local/es/config/certs
[elasticsearch@es-1 certs]$ ll
total 16
-rw------- 1 elasticsearch elasticsearch 3596 Feb 10 16:05 elastic-certificates.p12
-rw-rw-r-- 1 elasticsearch elasticsearch 1200 Feb 10 16:13 elasticsearch-ca.pem
-rw------- 1 elasticsearch elasticsearch 2672 Feb 10 16:03 elastic-stack-ca.p12
-rw-rw-r-- 1 elasticsearch elasticsearch 3652 Feb 10 16:13 http.p12
[elasticsearch@es-1 certs]$ scp * es-2.xingdian.com:/usr/local/es/config/certs/
[elasticsearch@es-1 certs]$ scp * es-3.xingdian.com:/usr/local/es/config/certs/
8.修改配置
[elasticsearch@es-1 certs]$ cd /usr/local/es/config/
[elasticsearch@es-1 config]$ vim elasticsearch.yml
cluster.name: xingdian-es
node.name: es-1.xingdian.com
path.data: /usr/local/es/data
path.logs: /usr/local/es/logs
network.host: 0.0.0.0
http.port: 9200
# 種子主機,在選舉時用于發現其他主機的,最好配置多個
discovery.seed_hosts: ["es-1.xingdian.com","es-2.xingdian.com","es-3.xingdian.com"]
cluster.initial_master_nodes: ["es-1.xingdian.com","es-2.xingdian.com","es-3.xingdian.com"]
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:enabled: truekeystore.path: /usr/local/es/config/certs/http.p12keystore.password: 123456  #如果生成證書時設置了密碼則要添加密碼配置truststore.path: /usr/local/es/config/certs/http.p12truststore.password: 123456 #如果生成證書時設置了密碼則要添加密碼配置
xpack.security.transport.ssl:enabled: trueverification_mode: certificatekeystore.path: /usr/local/es/config/certs/elastic-certificates.p12keystore.password: 123456  #如果生成證書時設置了密碼則要添加密碼配置truststore.path: /usr/local/es/config/certs/elastic-certificates.p12truststore.password: 123456 #如果生成證書時設置了密碼則要添加密碼配置
http.host: [_local_, _site_]
ingest.geoip.downloader.enabled: false
xpack.security.http.ssl.client_authentication: none

注意:

? 1.xpack.security.http.ssl和xpack.security.transport.ssl后的子配置需要空一格,遵循yml的格式要求

? 2.如果不需要后續的http證書認證或者用戶密碼認證可以將以下參數的值改為false

xpack.security.http.ssl:enabled: false
xpack.security.transport.ssl:enabled: false

? 3.如果后續在業務場景中遇到了跨域的問題,解決跨域的問題添加以下參數

http.cors.enabled: true
http.cors.allow-origin: "*"
9.參數解釋
cluster.name: xingdian-es
含義: 指定Elasticsearch集群的名稱。在此例中,集群名為xingdian-es,所有想要加入此集群的節點都應配置相同的集群名稱。
node.name: es-1.xingdian.com
含義: 設置單個節點的名稱。這里將節點命名為es-1.xingdian.com,有助于標識和管理集群中的不同節點。
path.data: /usr/local/es/data
含義: 指定Elasticsearch存儲數據的路徑。數據文件將保存在/usr/local/es/data目錄下。
path.logs: /usr/local/es/logs
含義: 配置日志文件的存放路徑,即日志將會被寫入到/usr/local/es/logs目錄中。
network.host: 0.0.0.0
含義: 設置監聽所有可用網絡接口的IP地址,允許Elasticsearch從任何網絡接口接收連接請求。
http.port: 9200
含義: 指定HTTP服務監聽的端口號,這里是9200,是Elasticsearch默認的HTTP訪問端口。
discovery.seed_hosts: ["es-1.xingdian.com","es-2.xingdian.com","es-3.xingdian.com"]
含義: 列出初始種子節點的地址,用于集群啟動時發現其他節點。這有助于新節點加入或現有節點重啟后找到集群。
cluster.initial_master_nodes: ["es-1.xingdian.com","es-2.xingdian.com","es-3.xingdian.com"]
含義: 在初次啟動或集群完全重啟后,指定哪些節點可以成為初始主節點,用于選舉過程。
xpack.security.enabled: true
含義: 啟用X-Pack安全特性,提供認證、授權、加密傳輸等功能,增強Elasticsearch的安全性。
xpack.security.http.ssl.enabled: true
含義: 開啟HTTP通信的SSL加密,確保客戶端與Elasticsearch之間的數據傳輸安全。
keystore.path, truststore.path, keystore.password, truststore.password
含義: 分別指定了SSL證書的存放路徑和密鑰庫、信任庫的密碼。這些設置用于保護SSL連接的密鑰和信任信息。
http.host: [local, site]
含義: 指定HTTP服務可以綁定的主機名,_local_表示綁定本地主機,_site_允許綁定所有公開站點地址。
ingest.geoip.downloader.enabled: false
含義: 禁用了GeoIP數據庫的自動下載功能。GeoIP用于地理定位,禁用后需要手動管理數據庫更新。
xpack.security.http.ssl.client_authentication: none
含義: 設置客戶端認證方式為“無”,意味著HTTP客戶端連接到Elasticsearch時不需要提供證書進行認證。
10.JVM參數調整
[elasticsearch@es-1 config]$ vim jvm.options
-Xms2g
-Xmx2g

注意:該值為真實內存的1/2

11.啟動集群
[elasticsearch@es-1 es]$ nohup  /usr/local/es/bin/elasticsearch  &
[elasticsearch@es-2 es]$ nohup  /usr/local/es/bin/elasticsearch  &
[elasticsearch@es-3 es]$ nohup  /usr/local/es/bin/elasticsearch  &
12.設置登錄密碼
# 手工指定elastic的新密碼 (-i參數)
[elasticsearch@okd ~]$ /usr/local/es/bin/elasticsearch-reset-password -u elastic -i
warning: ignoring JAVA_HOME=/usr/local/es/jdk; using bundled JDK
bThis tool will reset the password of the [elastic] user.
You will be prompted to enter the password.
Please confirm that you would like to continue [y/N]y
Did not understand answer 'by'
Please confirm that you would like to continue [y/N]yEnter password for [elastic]: # 輸入用戶elastic的密碼
Re-enter password for [elastic]: # 輸入用戶elastic的密碼
Password for the [elastic] user successfully reset.
13.瀏覽器訪問

https://es-1.xingdian.com:9200

https://es-2.xingdian.com:9200

https://es-3.xingdian.com:9200

賬戶密碼為:elastic 密碼自己設定的

image-20240531230253137

14.HEAD插件訪問

image-20240531232520580

image-20240531232556596

15.模擬數據插入

? 模擬post請求插入數據

? 索引名為:xingdian/_doc xingdian為自定義 _doc為固定格式

? 內容:采用json格式 {“user”:“xingdian”,“mesg”:“hello world”}

image-20240531233352735

四:基本概念

1.ES與傳統數據的區別

? 一個ES集群可以包含多個索引(數據庫),每個索引又包含了很多類型(表),類型中包含了很多文檔(行),每個文檔使用 JSON 格式存儲數據,包含了很多字段(列)。

關系型數據庫Elasticsearch
數據庫>表>行>列索引>類型>文檔>字段
2.基本概念
索引(index)

? ES將數據存儲于一個或多個索引中。類比傳統的關系型數據庫領域來說,索引相當于SQL中的一個數據庫,索引由其名稱(必須為全小寫字符)進行標識。一個ES集群中可以按需創建任意數目的索引。

類型(type)

? 類型是索引內部的邏輯分區(category/partition),一個索引內部可定義一個或多個類型(type)。類比傳統的關系型數據庫領域來說,類型相當于“表”。

文檔(document)

? 文檔是索引和搜索的原子單位,它是包含了一個或多個域(Field)的容器,每個域擁有一個名字及一個或多個值,有多個值的域通常稱為“多值域”,文檔基于JSON格式進行表示。每個文檔可以存儲不同的域集,但同一類型下的文檔至應該有某種程度上的相似之處。類比傳統的關系型數據庫領域來說,類型相當于“行”。

集群(cluster)

? 一個或者多個擁有相同cluster.name配置的節點組成, 它們共同承擔數據和負載的壓力。

節點(node)

? 一個運行中的 Elasticsearch 實例稱為一個節點。es中的節點分為三種類型:

? 主節點:負責管理集群范圍內的所有變更,例如增加、刪除索引,或者增加、刪除節點等。 主節點并不需要涉及到文檔級別的變更和搜索等操作。可以通過屬性node.master進行設置。

? 數據節點:存儲數據和其對應的倒排索引。默認每一個節點都是數據節點(包括主節點),可以通過node.data屬性進行設置。

? 協調節點:如果node.masternode.data屬性均為false,則此節點稱為協調節點,用來響應客戶請求,均衡每個節點的負載。

注意:

? 使用index和doc_type來組織數據。doc_type中的每條數據稱為一個document,是一個JSON Object

? ES分布式搜索,傳統數據庫遍歷式搜索

案例解釋:

? 要計算出2.38億會員中有多少80后的已婚的北京男士:

? 傳統數據庫執行時間: 5個小時左右

? ES執行時間:1分鐘

image-20240601232056381

分片(Shards)

? 分片是Elasticsearch進行數據分布和擴展的基礎。每個索引都可以被分割成多個分片,每個分片其實是一個獨立的索引。分片使得Elasticsearch可以把巨大的數據集分散存儲在多個節點上,這樣可以實現:

? 水平擴展:隨著數據量的增加,可以通過增加更多的節點來分攤數據和負載,從而提高處理能力

? 提升性能:搜索操作可以并行在多個分片上執行,每個分片處理的速度更快,整體搜索性能得以提升

副本(Replicas)

? 副本是分片的復制,主要用于提高數據的可用性和搜索查詢的并發處理能力。每個分片都可以有一個或多個副本,這些副本分布在不同的節點上,從而提供了:

? 數據可用性:當某個節點發生故障時,該節點上的分片如果有副本存在于其他節點上,那么這些副本可以保證數據不會丟失,并且服務還可以繼續運行

? 負載均衡:讀取操作(如搜索請求)可以在所有副本之間進行負載均衡,這樣可以提高查詢的吞吐量和響應速度

定義分片和副本

? 創建索引時指定分片和副本數

? 當您通過Elasticsearch的REST API創建一個新的索引時,可以在請求體中使用settings部分來指定該索引的分片數(number_of_shards)和副本數(number_of_replicas)。以下是一個具體的示例:

PUT /my_index
{"settings": {"index": {"number_of_shards": 3,    # 指定該索引將有3個主分片"number_of_replicas": 2   # 每個主分片將有2個副本分片}}
}

? 這個例子中,PUT /my_index是創建名為my_index的索引的請求。在請求體中,settings部分指出這個索引將被分成3個主分片,并且每個主分片將會有2個副本分片。這意味著,總共會有9個分片(3個主分片 + 6個副本分片)被分布在集群中

? 主分片數量:一旦索引被創建,其主分片的數量就無法更改。因此,在創建時應謹慎選擇合適的分片數量。

? 副本數量:與主分片數量不同,副本的數量是可以動態調整的。如果需要更多的數據冗余或查詢吞吐量,可以增加副本的數量。

? 伸縮性與性能:選擇分片和副本的數量時需要考慮數據量、查詢負載和集群的硬件資源。過多的分片可能會增加集群的管理開銷,而過少的分片可能會限制數據和查詢的伸縮性。

分片數的確定

? 數據量預估:估計索引的總數據量大小。一般來說,每個分片處理20GB到50GB數據是比較理想的。這不是固定規則,但可以作為一個起點。

? 硬件資源:考慮你的硬件資源,尤其是內存和CPU。分片越多,消耗的資源也越多。確保你的Elasticsearch集群有足夠的資源來處理這些分片。

? 寫入吞吐量:如果你的應用會有大量的寫入操作,更多的分片可能有助于提高寫入性能,因為可以并行寫入多個分片。

? 查詢性能:更多的分片意味著查詢可以并行于更多的分片上執行,這可能會提高查詢性能。但是,如果每個查詢都要訪問大多數分片,那么管理過多的分片會減慢查詢速度。

副本數的確定

? 數據可用性:至少有一個副本可以確保當某個節點失敗時,數據不會丟失,并且Elasticsearch服務仍然可用。

? 讀取性能:更多的副本意味著更高的讀取吞吐量,因為讀取請求可以在多個副本之間分配。如果你的應用主要是讀取密集型的,增加副本數可以提高查詢性能。

? 集群負載:考慮集群的整體負載。增加副本會提高數據冗余和讀取性能,但也會增加存儲需求和網絡流量,因此需要確保你的硬件資源可以支持。

五:ES集群架構

1.Discovery發現

? 發現是集群形成模塊尋找其他節點以形成集群的過程。當您啟動 Elasticsearch 節點或節點認為主節點發生故障時,此過程將運行,并持續到找到主節點或選出新的主節點為止。

? 此過程從來自一個或多個種子主機提供商的種子地址列表開始,同時包含最后已知集群中所有符合主節點資格的節點的地址。

? 此過程分為兩個階段:首先,每個節點通過連接到每個地址并嘗試識別其所連接的節點以及驗證其是否符合主節點資格來探測種子地址。其次,如果成功,它將與遠程節點共享其所有已知符合主節點資格的對等節點的列表,然后遠程節點依次與其對等節點進行響應。然后,節點探測它剛剛發現的所有新節點,請求其對等節點,依此類推。

? 如果節點不符合主節點資格,則它將繼續此發現過程,直到發現選舉的主節點。如果沒有發現選舉的主節點,則節點將重試,之后discovery.find_peers_interval默認為1s

? 如果節點符合主節點條件,則它會繼續此發現過程,直到發現當選主節點或發現足夠多的無主主節點來完成選舉。如果上述兩種情況都發生得不夠快,則節點將重試,之后discovery.find_peers_interval默認為1s

? 一旦主節點被選出,它通常會繼續擔任主節點,直到被故意停止。如果 故障檢測確定集群出現故障,它也可能會停止擔任主節點。當某個節點不再是主節點時,它會再次開始發現過程。

2.種子主機提供商

? 默認情況下,集群形成模塊提供兩個種子主機提供程序來配置種子節點列表

? 基于設置的種子主機提供程序

? 基于文件的種子主機提供程序

? 種子主機提供程序使用設置進行配置discovery.seed_providers ,默認為基于設置的主機提供程序

基于設置的種子主機提供商:

? 基于設置的種子主機提供程序使用節點設置來配置種子節點地址的靜態列表。這些地址可以作為主機名或 IP 地址指定;在每輪發現期間,指定為主機名的主機都會解析為 IP 地址。

discovery.seed_hosts:- 192.168.1.10:9300- 192.168.1.11 - seeds.mydomain.com 或者:
discovery.seed_hosts: ["es-1.xingdian.com","es-2.xingdian.com","es-3.xingdian.com"]

基于文件的種子主機提供商:

? 基于文件的種子主機提供程序通過外部文件配置主機列表。Elasticsearch會在文件更改時重新加載此文件,這樣種子節點列表就可以動態更改,而無需重新啟動每個節點。例如,這為在Docker容器中運行的 Elasticsearch 實例提供了一種方便的機制,當節點啟動時可能不知道這些IP地址時,可以動態地為其提供要連接的IP地址列表。

discovery.seed_providers: file

? 然后按照下面描述的格式創建一個文件$ES_PATH_CONF/unicast_hosts.txt。每當對文件進行更改時,Elasticsearch都會獲取新的更改并使用新的主機列表。

? 該unicast_hosts.txt文件每行包含一個節點條目。每個節點條目由主機(主機名或 IP 地址)和一個可選的傳輸端口號組成。如果指定了端口號,它必須緊跟在主機之后(在同一行上)。

? 允許使用主機名代替 IP 地址,并由 DNS 解析,如上所述。IPv6 地址必須在括號中給出,如果需要,端口號也應放在括號后面

cat $ES_PATH_CONF/unicast_hosts.txt
10.10.10.5
10.10.10.6:9305
10.10.10.5:10005
# an IPv6 address
[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:9301
3.基于群體的決策

? 選舉主節點和更改集群狀態是符合主節點條件的節點必須協同執行的兩個基本任務。即使某些節點發生故障,這些活動也必須能夠穩健地運行。Elasticsearch 通過在收到來自法定人數(集群中符合主節點條件的節點的子集)的響應后將每個操作視為成功來實現這種穩健性。僅要求一部分節點響應的優點是,這意味著某些節點可以發生故障而不會阻止集群繼續運行。法定人數是經過精心選擇的,即集群被分成兩部分,以至于每個部分可能做出與另一部分不一致的決策。

? Elasticsearch 允許您向正在運行的集群添加和刪除符合主節點條件的節點。在許多情況下,您只需根據需要啟動或停止節點即可完成此操作。

? 隨著節點的添加或刪除,Elasticsearch 通過更新集群的投票配置來保持最佳容錯水平,投票配置是一組符合主節點條件的節點,在做出諸如選舉新主節點或提交新集群狀態等決策時,這些節點的響應會被計算在內。只有在投票配置中超過一半的節點做出響應后,才會做出決策。通常,投票配置與集群中當前所有符合主節點條件的節點集相同。但是,在某些情況下,它們可能會有所不同。

? 為了確保集群保持可用,不能同時停止投票配置中的一半或更多節點。只要超過一半的投票節點可用,集群仍可正常工作。這意味著,如果有三個或四個主節點,集群可以容忍其中一個不可用。如果有兩個或更少的主節點,它們必須全部保持可用。

? 如果您同時停止投票配置中的一半或更多節點,則集群將不可用,直到您使足夠多的節點重新聯機以再次形成法定人數。當集群不可用時,任何剩余節點都會在其日志中報告它們無法發現或選舉主節點。

4.主節點選舉

? Elasticsearch 使用選舉流程來商定選舉的主節點,無論是在啟動時還是在現有選舉主節點發生故障時。任何符合主節點條件的節點都可以啟動選舉,通常第一次選舉將會成功。只有當兩個節點恰好同時開始選舉時,選舉才會失敗,因此每個節點都會隨機安排選舉以降低發生這種情況的概率。節點將重試選舉,直到選出主節點,如果失敗則放棄,以便最終選舉能夠成功(概率任意高)。主節點選舉的安排由主節點選舉設置控制。

5.投票配置

? 每個 Elasticsearch 集群都有一個投票配置,它是一組 符合主節點條件的節點,在做出諸如選舉新主節點或提交新集群狀態等決策時,這些節點的響應會被計入。只有在投票配置中的大多數節點(超過一半)響應后,才會做出決策。通常,投票配置與集群中當前所有符合主節點條件的節點集相同。但是,在某些情況下,它們可能會有所不同。

? 較大的投票配置通常更具彈性,因此 Elasticsearch 通常傾向于在符合主節點資格的節點加入集群后將其添加到投票配置中。同樣,如果投票配置中的節點離開集群,并且集群中還有另一個不符合主節點資格的節點不在投票配置中,則最好交換這兩個節點。因此,投票配置的大小保持不變,但其彈性會增加。

? 在節點離開集群后自動從投票配置中刪除節點并不是那么簡單。不同的策略有不同的優點和缺點,可以使用設置來控制投票配置是否自動cluster.auto_shrink_voting_configuration

? 如果cluster.auto_shrink_voting_configuration設置為true(這是默認值和推薦值)并且集群中至少有三個主合格節點,則只要除一個主合格節點之外的所有節點都健康,Elasticsearch 仍然能夠處理集群狀態更新

? 在某些情況下,Elasticsearch 可能會容忍多個節點丟失,但這并不能保證在所有故障序列下都能做到。如果設置cluster.auto_shrink_voting_configurationfalse,則必須手動從投票配置中移除已離開的節點。

配置參數如下:

cluster.auto_shrink_voting_configuration
(動態)控制投票配置是否自動刪除已離開的節點(只要它仍包含至少 3 個節點)。默認值為true。如果設置為,投票配置永遠不會自動縮小,您必須使用投票配置排除 APIfalse手動刪除已離開的節點 。
cluster.election.back_off_time
(靜態)設置每次選舉失敗時選舉前等待時間的上限增加量。請注意,這是線性退避。默認值為 100ms。更改此設置(默認設置)可能會導致您的集群無法選舉主節點。
cluster.election.duration
(靜態)設置每次選舉允許花費多長時間,之后節點才會認為選舉失敗并安排重試。默認值為500ms。更改此設置可能會導致您的集群無法選舉出主節點。
cluster.election.initial_timeout
(靜態)設置節點在首次嘗試選舉之前(或當選主節點失敗后)等待的時間上限。默認值為 100ms。更改此設置(默認設置)可能會導致您的集群無法選舉主節點。
cluster.election.max_timeout
(靜態)設置節點在嘗試首次選舉之前等待時間的最大上限,以便長時間持續的網絡分區不會導致選舉過于稀疏。默認值為10s。更改此設置(默認設置)可能會導致您的集群無法選舉主節點。
cluster.fault_detection.follower_check.interval
(靜態)設置當選主節點在集群中每個其他節點的跟隨節點檢查之間等待的時間。默認為1s。更改此設置(默認設置除外)可能會導致集群變得不穩定。
cluster.fault_detection.follower_check.timeout
(靜態)設置當選主節點等待跟隨者檢查響應的時間,超過該時間則認為主節點失敗。默認為10s。更改此設置可能會導致集群變得不穩定。
cluster.fault_detection.follower_check.retry_count
(靜態)設置每個節點必須發生多少次連續的跟隨者檢查失敗,當選主節點才會認為該節點有故障并將其從集群中移除。默認為3。更改此設置可能會導致集群變得不穩定。
cluster.fault_detection.leader_check.interval
(靜態)設置每個節點在檢查當選主節點之間等待的時間。默認為 1s。更改此設置可能會導致集群變得不穩定。
cluster.fault_detection.leader_check.timeout
(靜態)設置每個節點等待當選主節點對領導者檢查的響應的時間,超過該時間則認為主節點已發生故障。默認為10s。更改此設置可能會導致集群變得不穩定。
cluster.fault_detection.leader_check.retry_count
(靜態)設置必須發生多少次連續的領導者檢查失敗,節點才會認為當選主節點有故障,并嘗試查找或選舉新主節點。默認為3。更改此設置(默認設置)可能會導致集群變得不穩定。
cluster.follower_lag.timeout
(靜態)設置主節點等待從滯后節點接收集群狀態更新確認的時間。默認值為90s。如果節點在此時間段內未成功應用集群狀態更新,則該節點被視為發生故障并從集群中刪除。請參閱 發布集群狀態。
cluster.max_voting_config_exclusions
(動態)設置一次投票配置排除的數量限制。默認值為10。請參閱在集群中添加和刪除節點。
cluster.publish.info_timeout
(靜態)設置主節點等待每個集群狀態更新完全發布到所有節點的時間,然后記錄一條消息,表明某些節點響應緩慢。默認值為10s。
cluster.publish.timeout
(靜態)設置主節點等待每個集群狀態更新完全發布到所有節點的時間,除非discovery.type設置為 single-node。默認值為30s。請參閱發布集群狀態。
cluster.discovery_configuration_check.interval
(靜態)設置某些檢查的間隔,這些檢查將記錄有關不正確的發現配置的警告。默認值為30s。
cluster.join_validation.cache_timeout
(靜態)當一個節點請求加入集群時,當選的主節點會向其發送一份最新集群狀態的副本,以檢測可能阻止新節點加入集群的某些問題。主節點會緩存其發送的狀態,如果另一個節點不久后加入集群,則使用緩存的狀態。此設置控制主節點等待清除此緩存的時間。默認為60s。

? 通常,集群中的主節點數應為奇數。如果為偶數,Elasticsearch 會將其中一個節點排除在投票配置之外,以確保其大小為奇數

6.引導集群

? 首次啟動 Elasticsearch 集群時,需要在集群中的一個或多個主節點上明確定義初始主節點集。這稱為集群引導。這僅在集群首次啟動時才需要。加入正在運行的集群的新啟動節點從集群的選定主節點獲取此信息。

? cluster.initial_master_nodes初始的符合主節點資格的節點集在設置中定義 。這應該設置為一個列表,其中包含每個符合主節點資格的以下項目之一:

? 節點名稱

? node.name如果未設置,則默認為節點的主機名

? 集群形成后,cluster.initial_master_nodes從每個節點的配置中刪除該設置。不應為非主節點、加入現有集群的主節點或正在重新啟動的節點設置該設置

配置使用如下:

? 創建新集群的最簡單方法是選擇一個主節點,該節點將自行引導到單節點集群中,然后所有其他節點將加入該集群

cluster.initial_master_nodes: master-a

? 對于容錯集群引導,請使用所有符合主節點條件的節點。例如,如果您的集群有 3 個符合主節點條件的節點,節點名稱master-a為,master-b則按master-c如下方式配置它們:

cluster.initial_master_nodes:- master-a- master-b- master-c

選擇集群名稱:

? 此cluster.name設置允許您創建多個彼此獨立的集群。節點在首次連接時會驗證它們是否同意其集群名稱,并且 Elasticsearch 只會從具有相同集群名稱的節點組成集群。集群名稱的默認值為elasticsearch,但建議將其更改為反映集群的邏輯名稱。

開發模式下的自動引導:

? 默認情況下,每個節點在首次啟動時都會自動引導到單節點集群。如果配置了以下任何設置,則不會進行自動引導:

discovery.seed_providers
discovery.seed_hosts
cluster.initial_master_nodes

注意:

? 一旦 Elasticsearch 節點加入現有集群或引導新集群,它就不會再加入其他集群。Elasticsearch 不會在集群形成后將單獨的集群合并在一起,即使您隨后嘗試將所有節點配置為單個集群。這是因為沒有辦法將這些單獨的集群合并在一起而不丟失數據。

六:IK分詞器

1.簡介

? ES IK分詞器是一種基于中文文本的分詞器,它是Elasticsearch中文分詞的一種實現。它采用了自然語言處理技術,可以將中文文本進行切分,抽取出其中的詞匯,從而提高搜索引擎對中文文本的搜索和檢索效率。

? ES IK分詞器的原理是采用了一種叫做“正向最大匹配”(Forward Maximum Matching,簡稱FMM)和“逆向最大匹配”(Backward Maximum Matching,簡稱BMM)的分詞算法,通過對文本進行多次切分,最終確定最優的分詞結果。

? ES IK分詞器可以用于各種中文文本處理應用,包括搜索引擎、文本挖掘、信息檢索等。它支持多種分詞模式,包括最細粒度切分、智能切分和最大切分等模式,可以根據具體應用場景進行靈活配置。

2.分類

細粒度分詞模式(ik_max_word):

? 在這種模式下,IK分詞器會盡可能地按照詞典中的詞語進行最大長度匹配,將文本切分成連續的詞語序列

? 這種模式適用于對文本進行細致的切分,盡可能將句子切分為最小的詞語單元,獲得更加精確的分詞結果

智能分詞模式(ik_smart):

? 在智能切分模式下,IK分詞器會結合詞典匹配和機器學習算法,根據上下文信息分詞,保留詞語的完整性

? 這種模式能夠更好地處理一些特殊情況,如未登錄詞和新詞等,提高了分詞的準確性和適用性

3.下載地址

? https://github.com/infinilabs/analysis-ik/releases/tag/Latest

4.安裝插件

? 注意:

? 安裝的插件版本需要跟elasticsearch的版本一致,否則無法安裝或報錯

? 安裝完成后重啟elasticsearch

[elasticsearch@es-1 es]$ bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/8.13.4
warning: ignoring JAVA_HOME=/usr/local/es/jdk; using bundled JDK
-> Installing https://get.infini.cloud/elasticsearch/analysis-ik/8.13.4
-> Downloading https://get.infini.cloud/elasticsearch/analysis-ik/8.13.4
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@     WARNING: plugin requires additional permissions     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.net.SocketPermission * connect,resolve
See https://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.Continue with installation? [y/N]y
-> Installed analysis-ik
-> Please restart Elasticsearch to activate any plugins installed
5.項目需求

? 如果對應的項目使用到了ES IK插件,我們需要在ES集群中構建IK環境

七:冷熱溫節點部署

1.簡介

? 在某些大規模數據分析場景(比如時間數據分析),可以采用此架構:基于時間創建 index,然后持續地把溫/冷數據遷移到相應的數據節點。

? 專有主節點:由于不保存數據,也就不參與索引和查詢操作,不會被長 GC 干擾,負載可以保持在較低水平,能極大提高集群的穩定性

? 熱數據節點:保存近期的 index,承擔最頻繁的寫入和查詢操作,可以配置較高的資源,如超高性能主機及硬盤。可以在集群配置參數里 Elasticsearch 節點的參數node.attr.data(熱)做修改,默認為 hot

? 溫/冷數據節點:保存只讀 index,會接收少量的查詢請求,可以配置較低的資源。可以在集群配置參數里 Elasticsearch 節點的參數 node.attr.data(溫)和 node.attr.data(冷)做修改,默認為 warm cold

架構

image-20240602003659406

image-20240602003855682

2.準備工作

? 前期部署參考:三:集群部署

3.修改配置
es-1-data_hot
[elasticsearch@es-1 es]$ cat config/elasticsearch.yml 
cluster.name: xingdian-es
node.name: es-1.xingdian.com
path.data: /usr/local/es/data
path.logs: /usr/local/es/logs
network.host: 0.0.0.0
http.port: 9200
node.roles: [data_hot, data_content, master, ingest]
discovery.seed_hosts: ["es-1.xingdian.com","es-2.xingdian.com","es-3.xingdian.com"]
cluster.initial_master_nodes: ["es-1.xingdian.com"]
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:enabled: truekeystore.path: /usr/local/es/config/certs/http.p12#keystore.password: 123456  如果生成證書時設置了密碼則要添加密碼配置truststore.path: /usr/local/es/config/certs/http.p12#truststore.password: 123456 如果生成證書時設置了密碼則要添加密碼配置
xpack.security.transport.ssl:enabled: trueverification_mode: certificatekeystore.path: /usr/local/es/config/certs/elastic-certificates.p12#keystore.password: 123456  #如果生成證書時設置了密碼則要添加密碼配置truststore.path: /usr/local/es/config/certs/elastic-certificates.p12#truststore.password: 123456 #如果生成證書時設置了密碼則要添加密碼配置
http.host: [_local_, _site_]
ingest.geoip.downloader.enabled: false
xpack.security.http.ssl.client_authentication: none
es-2-data_warm
[elasticsearch@es-2 es]$ cat config/elasticsearch.yml 
cluster.name: xingdian-es
node.name: es-2.xingdian.com
path.data: /usr/local/es/data
path.logs: /usr/local/es/logs
network.host: 0.0.0.0
http.port: 9200
node.roles: [data_warm, data_content, master, ingest]
discovery.seed_hosts: ["es-1.xingdian.com","es-2.xingdian.com","es-3.xingdian.com"]
cluster.initial_master_nodes: ["es-1.xingdian.com"]
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:enabled: truekeystore.path: /usr/local/es/config/certs/http.p12#keystore.password: 123456  如果生成證書時設置了密碼則要添加密碼配置truststore.path: /usr/local/es/config/certs/http.p12#truststore.password: 123456 如果生成證書時設置了密碼則要添加密碼配置
xpack.security.transport.ssl:enabled: trueverification_mode: certificatekeystore.path: /usr/local/es/config/certs/elastic-certificates.p12#keystore.password: 123456  #如果生成證書時設置了密碼則要添加密碼配置truststore.path: /usr/local/es/config/certs/elastic-certificates.p12#truststore.password: 123456 #如果生成證書時設置了密碼則要添加密碼配置
http.host: [_local_, _site_]
ingest.geoip.downloader.enabled: false
xpack.security.http.ssl.client_authentication: none
es-3-data_cold
[elasticsearch@es-3 es]$ cat config/elasticsearch.yml 
cluster.name: xingdian-es
node.name: es-3.xingdian.com
path.data: /usr/local/es/data
path.logs: /usr/local/es/logs
network.host: 0.0.0.0
http.port: 9200
node.roles: [data_cold, data_content, master, ingest]
discovery.seed_hosts: ["es-1.xingdian.com","es-2.xingdian.com","es-3.xingdian.com"]
cluster.initial_master_nodes: ["es-1.xingdian.com"]
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:enabled: truekeystore.path: /usr/local/es/config/certs/http.p12#keystore.password: 123456  如果生成證書時設置了密碼則要添加密碼配置truststore.path: /usr/local/es/config/certs/http.p12#truststore.password: 123456 如果生成證書時設置了密碼則要添加密碼配置
xpack.security.transport.ssl:enabled: trueverification_mode: certificatekeystore.path: /usr/local/es/config/certs/elastic-certificates.p12#keystore.password: 123456  #如果生成證書時設置了密碼則要添加密碼配置truststore.path: /usr/local/es/config/certs/elastic-certificates.p12#truststore.password: 123456 #如果生成證書時設置了密碼則要添加密碼配置
http.host: [_local_, _site_]
ingest.geoip.downloader.enabled: false
xpack.security.http.ssl.client_authentication: none
4.啟動服務

? 依次啟動所有節點

[elasticsearch@es-1 es]$ nohup ./bin/elasticsearch &
[elasticsearch@es-2 es]$ nohup ./bin/elasticsearch &
[elasticsearch@es-3 es]$ nohup ./bin/elasticsearch &
5.修改密碼

? 依次修改所有節點

[elasticsearch@es-1 es]$ /usr/local/es/bin/elasticsearch-reset-password -u elastic -i
warning: ignoring JAVA_HOME=/usr/local/es/jdk; using bundled JDK
This tool will reset the password of the [elastic] user.
You will be prompted to enter the password.
Please confirm that you would like to continue [y/N]yEnter password for [elastic]: 
Re-enter password for [elastic]: 
Password for the [elastic] user successfully reset.
6.訪問驗證
GET /_cat/nodes

image-20240602002653864

7.應用案例

設置特定的索引,分片設置為5

PUT kibana_sample_data_logs_ext
{"settings": {"number_of_replicas": 0,"number_of_shards": 5}
}

image-20240602211427418

準備索引數據,首先你得先確保您索引有:diandian

POST _reindex
{"source": {"index": "diandian"},"dest": {"index": "kibana_sample_data_logs_ext"}
}

image-20240602212723862

這是現在的分片情況

image-20240602212836510

設置索引分片信息,主要參數:index.routing.allocation.include._tier_preference

索引-路由-分配,分配到data_hot節點上,之前我們在配置文件內定義的節點

PUT kibana_sample_data_logs_ext/_settings
{"settings": {"index.number_of_replicas": 0,"index.routing.allocation.include._tier_preference": "data_hot","index.blocks.write": true}
}

image-20240602213031466

在查詢就能看到分片都在hot節點上了

image-20240602213100443

第二部分:Kibana

image-20240603101339652

一:基本概念

1.Kibana簡介

? Kibana 是一個開源的數據分析和可視化平臺,它是 Elastic Stack(包括 Elasticsearch、Logstash、Kibana 和 Beats)的一部分,主要用于對 Elasticsearch 中的數據進行搜索、查看、交互操作。

2.Kibana功能

數據可視化:Kibana 提供了豐富的數據可視化選項,如柱狀圖、線圖等,幫助用戶以圖形化的方式理解數據

數據探索:Kibana 提供了強大的數據探索功能,用戶可以通過 Kibana 的界面進行數據篩選和排序

儀表盤:用戶可以將多個可視化組件組合在一起,創建交互式的儀表盤,用于實時監控數據

機器學習:Kibana 還集成了 Elasticsearch 的機器學習功能,可以用于異常檢測、預測等任務

定制和擴展:Kibana 提供了豐富的 API 和插件系統,用戶可以根據自己的需求定制和擴展 Kibana

二:安裝部署

1.獲取安裝包

? 對應Elasticsearch版本獲取Kibana的安裝包

? 官網獲取:https://www.elastic.co/

2.安裝部署
[root@kibana ~]# tar xf kibana-8.13.4-linux-x86_64.tar.gz  -C /usr/local/
[root@kibana ~]# mv /usr/local/kibana-8.13.4/ /usr/local/kibana
[root@kibana ~]# mkdir /usr/local/kibana/config/certs
3.修改配置
server.port:Kibana 服務監聽的端口,默認為 5601server.host:Kibana Kibana 服務可以被遠程主機訪問,你可以將此設置為遠程主機的 IP 地址server.name:Kibana 服務的名稱。默認情況下,它設置為 your-hostnameelasticsearch.hosts:Kibana 連接 Elasticsearch 服務的地址elasticsearch.username:連接到 Elasticsearch 服務時使用的用戶名 kibanaelasticsearch.password:連接到 Elasticsearch 服務時使用的密碼i18n.locale: "zh-CN"   設置頁面中文
4.獲取Elasticsearch的CA證書
[root@es-1 kibana]# scp elasticsearch-ca.pem 10.9.12.80:/usr/local/kibana/config/certs/
5.創建運行用戶
[root@kibana kibana]# useradd kibana
[root@kibana kibana]# echo kibana |passwd --stdin kibana
[root@kibana kibana]# chown kibana.kibana /usr/local/kibana/ -R
6.啟動Kibana
[kibana@kibana kibana]$ nohup ./bin/kibana &
7.常見故障

故障原因:

Error: [config validation of [elasticsearch].username]: value of "elastic" is forbidden. This is a superuser account that cannot write to system indices that Kibana needs to function. Use a service account token instead. Learn more: https://www.elastic.co/guide/en/elasticsearch/reference/8.0/service-accounts.htmlat ensureValidConfiguration (/usr/local/kibana/node_modules/@kbn/core-config-server-internal/src/ensure_valid_configuration.js:23:11)

解決方案:

? 該版本的kibana在連接es集群中,不支持使用elasticsearch中elastic(超級管理員)賬戶連接

? 在es集群中自帶的kibana賬戶設定密碼

[elasticsearch@es-1 es]$ /usr/local/es/bin/elasticsearch-reset-password -u kibana -i
warning: ignoring JAVA_HOME=/usr/local/es/jdk; using bundled JDK
This tool will reset the password of the [kibana] user.
You will be prompted to enter the password.
Please confirm that you would like to continue [y/N]yEnter password for [kibana]: 
Re-enter password for [kibana]: 
Password for the [kibana] user successfully reset.

擴展:

Elasticsearch中創建用戶

[elasticsearch@es-1 es]$ bin/elasticsearch-users useradd   test_account

為用戶分配角色

[elasticsearch@es-1 es]$ bin/elasticsearch-users roles -a superuser  test_account
8.瀏覽器訪問

image-20240602223130084

注意:

? 用戶名和密碼是es集群登錄的用戶和密碼

image-20240602223603070

image-20240602223659975

三:配置使用

注意:此部分的使用在做完《第三部分:Logstash》中第一節和第二節后在使用

1.Logstash采集到數據進行展示

? 進入管理界面

image-20240603210143788

? 進入索引管理

image-20240603210229439

? 進入要管理的索引

image-20240603210511677

? 展示索引數據

image-20240603210547068

? 創建數據視圖

image-20240603210620653

image-20240603210734511 圖形展示

image-20240603210842957

注意:

? 這里我們就可以看到Logstash采集的數據,并以圖形的方式展示

? 在圖形界面我們可以設置時間范圍

? 在圖形界面我們可以設置時間自動刷新時間

第三部分:Logstash

image-20240603101245218

一:基本概念

1.Logstash簡介

? Logstash 是 Elastic Stack 的中央數據流引擎,用于收集、豐富和統一所有數據,而不管格式或模式

? 當與Elasticsearch,Kibana,及 Beats 共同使用的時候便會擁有特別強大的實時處理能力

2.Logstash原理

? Logstash 管道中的每個輸入階段都在其自己的線程中運行。輸入將事件寫入位于內存(默認)或磁盤上的中央隊列。每個管道工作線程從此隊列中取出一批事件,通過配置的過濾器運行這批事件,然后通過任何輸出運行過濾后的事件。批次的大小和管道工作線程的數量是可配置的。

? 默認情況下,Logstash 使用管道階段(輸入 → 過濾器和過濾器 → 輸出)之間的內存有界隊列來緩沖事件。如果 Logstash 不安全地終止,則存儲在內存中的所有事件都將丟失。為了防止數據丟失,您可以啟用 Logstash 將傳輸中的事件保存到磁盤。

二:安裝部署

1.下載安裝包

? 官網下載

? 對應跟ES使用同一版本

2.解壓安裝
[root@logstash ~]# tar xf logstash-8.13.4-linux-x86_64.tar.gz  -C /usr/local/
[root@logstash ~]# cd /usr/local/
[root@logstash local]# mv logstash-8.13.4/ logstash
3.配置jdk環境

? Java 11

? Java 17(默認)

[root@logstash ~]# vi /etc/profile 
JAVA_HOME=/usr/local/logstash/jdk
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME PATH
[root@logstash logstash]# java --version
openjdk 17.0.11 2024-04-16
OpenJDK Runtime Environment Temurin-17.0.11+9 (build 17.0.11+9)
OpenJDK 64-Bit Server VM Temurin-17.0.11+9 (build 17.0.11+9, mixed mode, sharing)
4.數據流向

image-20240603102459401

5.模擬運行

輸入和輸出都來自于終端

[root@logstash logstash]# bin/logstash -e 'input { stdin { } } output { stdout {} }'
....
此處省略了運行過程
....
nihao (INPUT)
{"@version" => "1","@timestamp" => 2024-06-03T02:28:49.450917895Z,"event" => {"original" => "nihao"},"host" => {"hostname" => "logstash"},"message" => "nihao"
}

輸入來自終端,輸出到ES集群

? Elasticsearch 從8.0開始, 默認開啟了SSL安全驗證

? 因此我們需要為 Logstash 配置身份驗證憑據才能建立與 Elasticsearch 集群的通信

? Logstash創建目錄存儲Elasticsearch的CA證書

[root@logstash logstash]# mkdir /usr/local/logstash/config/certs

? Elasticsearch中將證書拷貝到Logstash

[root@es-1 es]# scp config/certs/elasticsearch-ca.pem 10.9.12.82:/usr/local/logstash/config/certs

? 創建Logstash采集數據配置文件

[root@logstash logstash]# cat /opt/stdin.confinput {stdin{}
}
output {elasticsearch {index => "stdin_logstash"hosts => [ "https://es-1.xingdian.com:9200" ]cacert => "/usr/local/logstash/config/certs/elasticsearch-ca.pem"user => "elastic"password => "xingdian"}}

? 執行Logstash

[root@logstash logstash]# ./bin/logstash -f /opt/stdin.conf
Using bundled JDK: /usr/local/logstash/jdk
.....
省略啟動過程,以下是終端的標準輸入
.....
hello world
hello xingdian

? ES插件查看索引信息

image-20240603205440850

輸入來自日志文件,輸出到ES集群

? 此處只展示Logstash配置文件

[root@logstash logstash]# cat /opt/nginx_access_logstash.conf 
input {file {path => "/var/log/nginx/access.log"start_position => "beginning"}
}
output {elasticsearch {index => "nginx_access_logstash"hosts => [ "https://es-1.xingdian.com:9200" ]cacert => "/usr/local/logstash/config/certs/elasticsearch-ca.pem"user => "elastic"password => "xingdian"}}

? ES插件展示索引

image-20240603213136672

? Kibana展示數據

image-20240603213353625

輸入來自日志多文件,輸出到ES集群

? Logstash采集配置文件

[root@logstash ~]# cat /opt/files.conf 
input {file {path => "/var/log/messages"type => "system"start_position => "beginning"}}
input {file {path => "/var/log/yum.log"type => "safeware"start_position => "beginning"}}output {if [type] == 'system' {elasticsearch {index => "system-%{+YYYY.MM.dd}"hosts => [ "https://es-1.xingdian.com:9200" ]cacert => "/usr/local/logstash/config/certs/elasticsearch-ca.pem"user => "elastic"password => "xingdian"}}if [type] == 'safeware' {elasticsearch {index => "safeware-%{+YYYY.MM.dd}"hosts => [ "https://es-1.xingdian.com:9200" ]cacert => "/usr/local/logstash/config/certs/elasticsearch-ca.pem"user => "elastic"password => "xingdian"}}}

? ES插件展示索引

image-20240603214026145

三:數據過濾

1.插件grok簡介

? grok插件有非常強大的功能,他能匹配一切數據,但是他的性能和對資源的損耗同樣讓人詬病

? filter的grok是目前logstash中解析非結構化日志數據最好的方式

? grok位于正則表達式之上,所以任何正則表達式在grok中都是有效的

官網地址:

正則:https://github.com/logstash-plugins/logstash-patterns-core/blob/main/patterns/ecs-v1/grok-patterns

2.語法格式

? Grok 模式的語法是:%{SYNTAX:SEMANTIC}

? 是SYNTAX將與您的文本匹配的模式的名稱

? 是SEMANTIC您為匹配的文本片段指定的標識符

3.應用案例

針對nginx的訪問日志,獲取對應的IP地址

? Logstash采集數據配置文件:

[root@logstash ~]# cat /opt/grok_nginx_access_logstash.conf 
input {file {path => "/var/log/nginx/access.log"start_position => "beginning"}
}filter {grok {match => { "message" => "%{IP:remote_addr}"}}
}
output {elasticsearch {index => "grok_nginx_access_logstash"hosts => [ "https://es-1.xingdian.com:9200" ]cacert => "/usr/local/logstash/config/certs/elasticsearch-ca.pem"user => "elastic"password => "xingdian"}}

? 執行:

[root@logstash logstash]# ./bin/logstash -f /opt/grok_nginx_access_logstash.conf

? ES插件確認索引:

image-20240603223117630

? Kibana查看新字段:

image-20240603223230586

針對nginx的訪問日志,對應生成新的字段

? Logstash采集數據配置文件:

 [root@logstash ~]# cat /opt/grok_nginx_access_logstash.conf 
input {file {path => "/var/log/nginx/access.log"start_position => "beginning"}
}filter {grok {match => { "message" => "%{IPORHOST:client_ip} - %{DATA:user} \[%{HTTPDATE:timestamp}\] \"%{WORD:method} %{DATA:request} HTTP/%{NUMBER:httpversion}\" %{NUMBER:response_code} %{NUMBER:bytes_sent} \"%{DATA:referrer}\" \"%{DATA:user_agent}\"" }}date {match => [ "timestamp" , "dd/MMM/YYYY:HH:mm:ss Z" ]}
}
output {elasticsearch {index => "grok_nginx_access_logstash"hosts => [ "https://es-1.xingdian.com:9200" ]cacert => "/usr/local/logstash/config/certs/elasticsearch-ca.pem"user => "elastic"password => "xingdian"}}

? Kibana查看新字段:

image-20240603231310744

第四部分:Filebeat

image-20240604232929247

一:基本概念

1.Filebeat簡介

? Filebeat是本地文件的日志數據采集器。 作為服務器上的代理安裝,Filebeat監視日志目錄或特定日志文件,并將它們轉發給Elasticsearch、Logstash、kafka 等

2.核心組件

? prospector:負責讀取單個文件的內容。讀取每個文件,并將內容發送到 the output每個文件啟動一harvester, harvester 負責打開和關閉文件,這意味著在運行時文件描述符保持打開狀態,如果文件在讀取時被刪除,Filebeat將繼續讀取文件

? harvester:負責管理harvester并找到所有要讀取的文件來源。如果輸入類型為日志,則查找器將查找路徑匹配的所有文件,并為每個文件啟動一個harvester。每個prospector都在自己的Go協程中運行

3.工作原理

? 啟動Filebeat時,它會啟動一個或多個查找器,查看您為日志文件指定的本地路徑。 對于prospector 所在的每個日志文件,prospector 啟動harvester,每個harvester都會為新內容讀取單個日志文件,并將新日志數據發送到libbeat,后者將聚合事件并將聚合數據發送到您為Filebeat配置的輸出

注意:

? Filebeat目前支持兩種prospector類型:log和stdin

image-20240604224834388

4.為什么使用filebeat

? Filebeat是一種輕量級的日志搜集器,其不占用系統資源,自出現之后,迅速更新了原有的elk架構。它將收集到的數據發送給Logstash解析過濾,在Filebeats與Logstash傳輸數據的過程中,為了安全性,可以通過ssl認證來加強安全性。之后將其發送到Elasticsearch存儲,并由kibana可視化分析

二:安裝部署

1.安裝方式

? rpm包的方式安裝:filebeat-8.13.4-x86_64.rpm

? 壓縮包解壓安裝:filebeat-8.13.4-linux-x86_64.tar.gz

2.獲取安裝包

? 官網地址:

? https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.13.4-x86_64.rpm

? https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.13.4-linux-x86_64.tar.gz

3.二進制安裝
[root@filebeat ~]# yum -y install ./filebeat-8.13.4-x86_64.rpm
4.修改配置
[root@filebeat ~]# vim /etc/filebeat/filebeat.yml
注意:在配置文件中找到以下參數修改,主要指定的是輸出和kibana
output.elasticsearch:hosts: ["<es_url>"]protocol: "https"username: "elastic"password: "<password>"# If using Elasticsearch's default certificatessl.ca_trusted_fingerprint: "<es cert fingerprint>"
setup.kibana:host: "<kibana_url>"

注意:

? 在生產環境中,請勿使用內置 elastic 用戶來保護客戶端

? 而要設置授權用戶或 API 密鑰,并且不要在配置文件中暴露密碼

? 如何獲取ssl.ca_trusted_fingerprint參數的值

? 在ES節點上利用ES的CA文件獲取

[root@es-1 certs]# openssl x509 -fingerprint -sha256 -noout -in ./elasticsearch-ca.pem | awk --field-separator="=" '{print $2}' | sed 's/://g'
79FFAE0C4E8B2D14AC4E41338C0463757D7612372F952D3304F611F5885F69E5

擴展:

? 該實驗不用

? 輸出到kafka配置

output.kafka:enabled: true hosts: ["172.17.0.4:9092","172.17.0.5:9092"]topic: 'kafka_run_log'
5.啟用Nginx模塊
[root@filebeat ~]# filebeat modules enable nginx

修改:參考官方文檔

https://www.elastic.co/guide/en/beats/filebeat/8.13/filebeat-module-nginx.html

- module: nginx# Access logsaccess:enabled: true# Set custom paths for the log files. If left empty,# Filebeat will choose the paths depending on your OS.var.paths: ["/var/log/nginx/access.log*"]# Error logserror:enabled: true# Set custom paths for the log files. If left empty,# Filebeat will choose the paths depending on your OS.var.paths: ["/var/log/nginx/error.log*"]

啟動服務:

[root@filebeat ~]# filebeat setup
[root@filebeat ~]# systemctl start filebeat
6.模擬產生數據

? 訪問Nginx產生數據

7.查看圖表

? 獲取狀態碼訪問情況

image-20240604231915593

? 獲取錯誤日志情況

image-20240604231949435

? 獲取訪問路徑請求

image-20240604232018090

? 獲取訪問數據量情況

image-20240604232059076

? 獲取客戶端使用情況

image-20240604232121809

? 獲取服務器訪問量

image-20240604232235177

三:配置文件詳解

1.配置文件
############### Filebeat 配置文件說明#############
filebeat:# List of prospectors to fetch data.prospectors:-# paths指定要監控的日志paths:- /var/log/*.log#指定被監控的文件的編碼類型使用plain和utf-8都是可以處理中文日志的。# Some sample encodings:#   plain, utf-8, utf-16be-bom, utf-16be, utf-16le, big5, gb18030, gbk,#    hz-gb-2312, euc-kr, euc-jp, iso-2022-jp, shift-jis, ...#encoding: plain#指定文件的輸入類型log(默認)或者stdin。input_type: log# 在輸入中排除符合正則表達式列表的那些行# exclude_lines: ["^DBG"]# 包含輸入中符合正則表達式列表的那些行默認包含所有行include_lines執行完畢之后會執行exclude_lines。# include_lines: ["^ERR", "^WARN"]# 忽略掉符合正則表達式列表的文件默認為每一個符合paths定義的文件都創建一個harvester。# exclude_files: [".gz$"]# 向輸出的每一條日志添加額外的信息比如“level:debug”方便后續對日志進行分組統計。默認情況下會在輸出信息的fields子目錄下以指定的新增fields建立子目錄例如fields.level。#fields:#  level: debug#  review: 1# 如果該選項設置為true則新增fields成為頂級目錄而不是將其放在fields目錄下。自定義的field會覆蓋filebeat默認的field。#fields_under_root: false# 可以指定Filebeat忽略指定時間段以外修改的日志內容比如2h兩個小時或者5m(5分鐘)。#ignore_older: 0# 如果一個文件在某個時間段內沒有發生過更新則關閉監控的文件handle。默認1h,change只會在下一次scan才會被發現#close_older: 1h# 設定Elasticsearch輸出時的document的type字段也可以用來給日志進行分類。Default: log#document_type: log# Filebeat以多快的頻率去prospector指定的目錄下面檢測文件更新比如是否有新增文件如果設置為0s則Filebeat會盡可能快地感知更新占用的CPU會變高。默認是10s。#scan_frequency: 10s# 每個harvester監控文件時使用的buffer的大小。#harvester_buffer_size: 16384# 日志文件中增加一行算一個日志事件max_bytes限制在一次日志事件中最多上傳的字節數多出的字節會被丟棄。The default is 10MB.#max_bytes: 10485760# 適用于日志中每一條日志占據多行的情況比如各種語言的報錯信息調用棧。這個配置的下面包含如下配置#multiline:# The regexp Pattern that has to be matched. The example pattern matches all lines starting with [#pattern: ^\[# Defines if the pattern set under pattern should be negated or not. Default is false.#negate: false# Match can be set to "after" or "before". It is used to define if lines should be append to a pattern# that was (not) matched before or after or as long as a pattern is not matched based on negate.# Note: After is the equivalent to previous and before is the equivalent to to next in Logstash#match: after# The maximum number of lines that are combined to one event.# In case there are more the max_lines the additional lines are discarded.# Default is 500#max_lines: 500# After the defined timeout, an multiline event is sent even if no new pattern was found to start a new event# Default is 5s.#timeout: 5s# 如果設置為trueFilebeat從文件尾開始監控文件新增內容把新增的每一行文件作為一個事件依次發送而不是從文件開始處重新發送所有內容。#tail_files: false# Filebeat檢測到某個文件到了EOF之后每次等待多久再去檢測文件是否有更新默認為1s。#backoff: 1s# Filebeat檢測到某個文件到了EOF之后等待檢測文件更新的最大時間默認是10秒。#max_backoff: 10s# 定義到達max_backoff的速度默認因子是2到達max_backoff后變成每次等待max_backoff那么長的時間才backoff一次直到文件有更新才會重置為backoff。#backoff_factor: 2# 這個選項關閉一個文件,當文件名稱的變化。#該配置選項建議只在windows。#force_close_files: false# Additional prospector#-# Configuration to use stdin input#input_type: stdin# spooler的大小spooler中的事件數量超過這個閾值的時候會清空發送出去不論是否到達超時時間。#spool_size: 2048# 是否采用異步發送模式(實驗!)#publish_async: false# spooler的超時時間如果到了超時時間spooler也會清空發送出去不論是否到達容量的閾值。#idle_timeout: 5s# 記錄filebeat處理日志文件的位置的文件registry_file: /var/lib/filebeat/registry# 如果要在本配置文件中引入其他位置的配置文件可以寫在這里需要寫完整路徑但是只處理prospector的部分。#config_dir:############################# Output ############# 輸出到數據配置.單個實例數據可以輸出到elasticsearch或者logstash選擇其中一種注釋掉另外一組輸出配置。
output:### 輸出數據到Elasticsearchelasticsearch:# IPv6 addresses should always be defined as: https://[2001:db8::1]:9200hosts: ["localhost:9200"]# 輸出認證.#protocol: "https"#username: "admin"#password: "s3cr3t"# 啟動進程數.#worker: 1# 輸出數據到指定index default is "filebeat"  可以使用變量[filebeat-]YYYY.MM.DD keys.#index: "filebeat"# 一個模板用于設置在Elasticsearch映射默認模板加載是禁用的,沒有加載模板這些設置可以調整或者覆蓋現有的加載自己的模板#template:# Template name. default is filebeat.#name: "filebeat"# Path to template file#path: "filebeat.template.json"# Overwrite existing template#overwrite: false# Optional HTTP Path#path: "/elasticsearch"# Proxy server url#proxy_url: http://proxy:3128# 發送重試的次數取決于max_retries的設置默認為3#max_retries: 3# 單個elasticsearch批量API索引請求的最大事件數。默認是50。#bulk_max_size: 50# elasticsearch請求超時事件。默認90秒.#timeout: 90# 新事件兩個批量API索引請求之間需要等待的秒數。如果bulk_max_size在該值之前到達額外的批量索引請求生效。#flush_interval: 1# elasticsearch是否保持拓撲。默認false。該值只支持Packetbeat。#save_topology: false# elasticsearch保存拓撲信息的有效時間。默認15秒。#topology_expire: 15# 配置TLS參數選項如證書頒發機構等用于基于https的連接。如果tls丟失主機的CAs用于https連接elasticsearch。#tls:# List of root certificates for HTTPS server verifications#certificate_authorities: ["/etc/pki/root/ca.pem"]# Certificate for TLS client authentication#certificate: "/etc/pki/client/cert.pem"# Client Certificate Key#certificate_key: "/etc/pki/client/cert.key"# Controls whether the client verifies server certificates and host name.# If insecure is set to true, all server host names and certificates will be# accepted. In this mode TLS based connections are susceptible to# man-in-the-middle attacks. Use only for testing.#insecure: true# Configure cipher suites to be used for TLS connections#cipher_suites: []# Configure curve types for ECDHE based cipher suites#curve_types: []# Configure minimum TLS version allowed for connection to logstash#min_version: 1.0# Configure maximum TLS version allowed for connection to logstash#max_version: 1.2### 發送數據到logstash 單個實例數據可以輸出到elasticsearch或者logstash選擇其中一種注釋掉另外一組輸出配置。#logstash:# Logstash 主機地址#hosts: ["localhost:5044"]# 配置每個主機發布事件的worker數量。在負載均衡模式下最好啟用。#worker: 1# #發送數據壓縮級別#compression_level: 3# 如果設置為TRUE和配置了多臺logstash主機輸出插件將負載均衡的發布事件到所有logstash主機。#如果設置為false輸出插件發送所有事件到隨機的一臺主機上如果選擇的不可達將切換到另一臺主機。默認是false。#loadbalance: true# 輸出數據到指定index default is "filebeat"  可以使用變量[filebeat-]YYYY.MM.DD keys.#index: filebeat# Optional TLS. By default is off.#配置TLS參數選項如證書頒發機構等用于基于https的連接。如果tls丟失主機的CAs用于https連接elasticsearch。#tls:# List of root certificates for HTTPS server verifications#certificate_authorities: ["/etc/pki/root/ca.pem"]# Certificate for TLS client authentication#certificate: "/etc/pki/client/cert.pem"# Client Certificate Key#certificate_key: "/etc/pki/client/cert.key"# Controls whether the client verifies server certificates and host name.# If insecure is set to true, all server host names and certificates will be# accepted. In this mode TLS based connections are susceptible to# man-in-the-middle attacks. Use only for testing.#insecure: true# Configure cipher suites to be used for TLS connections#cipher_suites: []# Configure curve types for ECDHE based cipher suites#curve_types: []### 文件輸出將事務轉存到一個文件每個事務是一個JSON格式。主要用于測試。也可以用作logstash輸入。#file:# 指定文件保存的路徑。#path: "/tmp/filebeat"# 文件名。默認是 Beat 名稱。上面配置將生成 packetbeat, packetbeat.1, packetbeat.2 等文件。#filename: filebeat# 定義每個文件最大大小。當大小到達該值文件將輪滾。默認值是1000 KB#rotate_every_kb: 10000# 保留文件最大數量。文件數量到達該值將刪除最舊的文件。默認是7一星期。#number_of_files: 7### Console output 標準輸出JSON 格式。# console:#如果設置為TRUE事件將很友好的格式化標準輸出。默認false。#pretty: false############################# Shipper #############shipper:# #日志發送者信息標示# 如果沒設置以hostname名自居。該名字包含在每個發布事務的shipper字段。可以以該名字對單個beat發送的所有事務分組。#name:# beat標簽列表包含在每個發布事務的tags字段。標簽可用很容易的按照不同的邏輯分組服務器。#例如一個web集群服務器可以對beat添加上webservers標簽然后在kibana的visualisation界面以該標簽過濾和查詢整組服務器。#tags: ["service-X", "web-tier"]# 如果啟用了ignore_outgoing選項beat將忽略從運行beat服務器上所有事務。#ignore_outgoing: true# 拓撲圖刷新的間隔。也就是設置每個beat向拓撲圖發布其IP地址的頻率。默認是10秒。#refresh_topology_freq: 10# 拓撲的過期時間。在beat停止發布其IP地址時非常有用。當過期后IP地址將自動的從拓撲圖中刪除。默認是15秒。#topology_expire: 15# Internal queue size for single events in processing pipeline#queue_size: 1000# GeoIP數據庫的搜索路徑。beat找到GeoIP數據庫后加載然后對每個事務輸出client的GeoIP位置目前只有Packetbeat使用該選項。#geoip:#paths:#  - "/usr/share/GeoIP/GeoLiteCity.dat"#  - "/usr/local/var/GeoIP/GeoLiteCity.dat"############################# Logging ############## 配置beats日志。日志可以寫入到syslog也可以是輪滾日志文件。默認是syslog。
logging:# 如果啟用發送所有日志到系統日志。#to_syslog: true# 日志發送到輪滾文件。#to_files: false# files:# 日志文件目錄。#path: /var/log/mybeat# 日志文件名稱#name: mybeat# 日志文件的最大大小。默認 10485760 (10 MB)。rotateeverybytes: 10485760 # = 10MB# 保留日志周期。 默認 7。值范圍為2 到 1024。#keepfiles: 7# Enable debug output for selected components. To enable all selectors use ["*"]# Other available selectors are beat, publish, service# Multiple selectors can be chained.#selectors: [ ]# 日志級別。debug, info, warning, error 或 critical。如果使用debug但沒有配置selectors* selectors將被使用。默認error。#level: error
2.參數詳解

? 解壓方式安裝使用

-c, --c FILE指定用于Filebeat的配置文件。 你在這里指定的文件是相對于path.config。 如果未指定-c標志,則使用默認配置文件filebeat.yml。
-d, --d SELECTORS啟用對指定選擇器的調試。 對于選擇器,可以指定逗號分隔的組件列表,也可以使用-d“*”為所有組件啟用調試。 例如,-d “publish”顯示所有“publish”相關的消息。
-e, --e記錄到stderr并禁用syslog /文件輸出。
-v, --v記錄INFO級別的消息。1.測試filebeat啟動后,查看相關輸出信息:
./filebeat -e -c filebeat.yml -d "publish"2.后臺方式啟動filebeat:
nohup ./filebeat -e -c filebeat.yml >/dev/null 2>&1 &  將所有標準輸出及標準錯誤輸出到/dev/null空設備,即沒有任何輸出
nohup ./filebeat -e -c filebeat.yml > filebeat.log &    

第五部分:Metricbeat

image-20240604232903382

一:基本概念

1.Metricbeat簡介

? Metricbeat是輕量型指標采集器

? Metricbeat 能夠以一種輕量型的方式,輸送各種系統和服務統計數據

? 用于從系統和服務收集指標

? 可以獲取系統級的 CPU 使用率、內存、文件系統、磁盤 IO 和網絡 IO 統計數據

? 還可針對系統上的每個進程獲得與 top 命令類似的統計數據

? Metricbeat 提供多種內部模塊,這些模塊可從多項服務諸如 Apache、NGINX…中收集指標

2.工作原理

image-20240604233256173

? Metricbeat 由模塊和指標集組成。Metricbeat模塊定義了從特定服務(如 Redis、MySQL 等)收集數據的基本邏輯;模塊指定有關服務的詳細信息,包括如何連接、收集指標的頻率以及要收集哪些指標

? 每個模塊都有一個或多個指標集;指標集是模塊的一部分,用于獲取和構建數據;指標集不是將每個指標作為單獨的事件收集,而是在對遠程系統的單個請求中檢索多個相關指標的列表

? Metricbeat 根據period您在配置模塊時指定的值定期詢問主機系統來檢索指標。由于多個指標集可以向同一服務發送請求,因此 Metricbeat 會盡可能重復使用連接;如果 Metricbeat 無法在配置設置指定的時間內連接到主機系統timeout,則會返回錯誤;Metricbeat 異步發送事件,這意味著不會確認事件檢索;如果配置的輸出不可用,事件可能會丟失

例如:(每個模塊都有對應的文檔)

? Redis 模塊提供了一個指標集,info指令 它通過運行命令并解析返回的結果來從 Redis 收集信息和統計信息

? MySQL 模塊提供了一個status指標集,可通過運行 SQL 查詢從 MySQL 收集數據SHOW GLOBAL STATUS

? Nginx結合ngx_http_stub_status_module模塊實現對Nginx指標的獲取

二:安裝部署

1.安裝方式

? rpm包的方式安裝:metricbeat-8.13.4-x86_64.rpm

? 壓縮包解壓安裝:metricbeat-8.13.4-linux-x86_64.tar.gz

2.獲取安裝包

? 官網地址:

? https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-8.13.4-x86_64.rpm

? https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-8.13.4-linux-x86_64.tar.gz

3.二進制安裝
[root@metricbeat ~]# yum -y install ./metricbeat-8.13.4-x86_64.rpm
4.修改配置
[root@metricbeat ~]# vim /etc/metricbeat/metricbeat.yml
output.elasticsearch:hosts: ["<es_url>"]username: "elastic"password: "<password>"# If using Elasticsearch's default certificatessl.ca_trusted_fingerprint: "<es cert fingerprint>"
setup.kibana:host: "<kibana_url>"

注意:

? 在生產環境中,請勿使用內置 elastic 用戶來保護客戶端

? 而要設置授權用戶或 API 密鑰,并且不要在配置文件中暴露密碼

? 如何獲取ssl.ca_trusted_fingerprint參數的值

? 在ES節點上利用ES的CA文件獲取

[root@es-1 certs]# openssl x509 -fingerprint -sha256 -noout -in ./elasticsearch-ca.pem | awk --field-separator="=" '{print $2}' | sed 's/://g'
79FFAE0C4E8B2D14AC4E41338C0463757D7612372F952D3304F611F5885F69E5
5.啟用Nginx模塊
[root@metricbeat ~]# ./metricbeat modules enable nginx

先修改:參考官方文檔

https://www.elastic.co/guide/en/beats/metricbeat/8.13/metricbeat-module-nginx.html

- module: nginxmetricsets:- stubstatusperiod: 10senabled: true# Nginx hostshosts: ["http://10.9.12.74"]# Path to server status. Default nginx_statusserver_status_path: "status"#username: "user"#password: "secret"
6.開啟Nginx的對應模塊
[root@metricbeat ~]# vim /etc/nginx/nginx.conf
location = /status {stub_status;
}[root@metricbeat ~]# nginx -s reload
7.模擬產生數據

? 瀏覽器訪問網站

8.查看圖表

? 活躍連接數

image-20240605093629080

? 請求速率

image-20240605093718794

? 接受率和處理率

image-20240605093845333

? 讀/寫/等待率

image-20240605093930514

三:配置文件詳解

1.配置文件
# 可選,定義 Metricbeat 的全局設置
metricbeat.config:modules:# 需要加載的模塊配置文件路徑。可以是文件或目錄。path: ${path.config}/modules.d/*.yml# 設置為true時, Metricbeat將會定期檢查模塊配置文件的變更并重新加載它們。reload.enabled: false# 定義模塊配置文件重新加載的周期, 默認是 10sreload.period: 10s# 設置日志的詳細程度。支持 "error", "warning", "info", "debug"。
logging.level: info
# 可選,日志的輸出路徑。如果沒有設置,日志將輸出到 stdout。
logging.to_files: true
logging.files:path: /var/log/metricbeatname: metricbeatkeepfiles: 7permissions: 0644# 定義 Metricbeat 啟用的模塊及其設置
metricbeat.modules:- module: systemmetricsets:- cpu- memory- network- process- process_summary- uptime- socket_summary- entropyenabled: trueperiod: 10sprocesses: ['.*']cpu_ticks: false# 定義 Metricbeat 數據的輸出位置# 輸出到 Elasticsearch
output.elasticsearch:hosts: ["http://localhost:9200"]username: "elastic"password: "changeme"# 配置索引名稱模式index: "metricbeat-%{[agent.version]}-%{+yyyy.MM.dd}"# 輸出到 Logstash
output.logstash:hosts: ["localhost:5044"]# 可選,啟用SSL/TLS
ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]
ssl.certificate: "/etc/pki/client/cert.pem"
ssl.key: "/etc/pki/client/cert.key"# 監控 Metricbeat 自身的指標并發送到指定的 Elasticsearch
monitoring.enabled: true
monitoring.elasticsearch:hosts: ["http://localhost:9200"]username: "elastic"password: "changeme"更多查看官方文檔:https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-reference-yml.html

第六部分:Elastic-agent(了解)

一:基本概念

二:安裝部署

1.代理背景

? 由于業務需求,我們需要在7個不同的業務平臺安裝ES-Agent以收取其數據

? 我們的策略是在每個平臺上安裝一個Fleet Server,用于管理各平臺的ES-Agent

2.生成證書

? ES節點操作

? 生成CA

[root@es-1 es]# ./bin/elasticsearch-certutil ca --pem

? 生成了elastic-stack-ca.zip文件,將其解壓,內置ca.crt和ca.key

[root@es-1 es]# unzip elastic-stack-ca.zip

? 使用CA為不同的Fleet Server主機生成證書,每個Fleet Server節點都需要單獨的證書

./bin/elasticsearch-certutil cert \--name fleet-server \--ca-cert /path/to/ca/ca.crt \ (填寫(1)中生成的ca.crt路徑)--ca-key /path/to/ca/ca.key \ (填寫(1)中生成的ca.key路徑)--dns your.host.name.here \(填寫Fleet Server主機的hostname)--ip 192.0.2.1 \ (填寫Fleet Server主機的IP地址)--pem例如:./bin/elasticsearch-certutil cert \--name fleet-server \--ca-cert /usr/local/es/ca/ca.crt \--ca-key /usr/local/es/ca/ca.key \ --dns fleet-server.xingdian.com \--ip 10.9.12.72 \--pem 

? 生成一個叫做 certificate-bundle.zip的文件,將它拷貝到要安裝Fleet Server的主機上

? 注意:將ES的ca證書也拷貝到fleet-server主機(elasticsearch-ca.pem

3.Agent部署

下載安裝

? 官網獲取

解壓并安裝

[root@fleet-server ~]# tar xf elastic-agent-8.13.4-linux-x86_64.tar.gz  -C /usr/local/
[root@fleet-server ~]# mv /usr/local/elastic-agent-8.13.4-linux-x86_64/ /usr/local/elastic-agent
4.創建Fleet

image-20240605170633110

image-20240605170705295

image-20240605170741540

image-20240605170918969

image-20240605171447501

image-20240605171509242

image-20240605171611471

image-20240605171712779

image-20240605171804501

image-20240605171846951

image-20240605171927828

image-20240605171947968

image-20240605172014803

5.在agent上安裝

? 以下內容來自上面圖片中的復制,注意修改參數的值

[root@fleet-server elastic-agent]# cat a.sh
./elastic-agent install --url=https://fleet-server.xingdian.com:8220 \--fleet-server-es=https://es-1.xingdian.com:9200 \--fleet-server-service-token=AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyL3Rva2VuLTE3MTc1NzkxNzQzNDA6MEVlODhuMXhRaktEenhFOFRZRy1TZw \--fleet-server-policy=72d46cef-c33d-4360-bc20-60d829634076 \--certificate-authorities=/opt/ca/ca.crt \--fleet-server-es-ca=/opt/elasticsearch-ca.pem \--fleet-server-cert=/opt/fleet-server/fleet-server.crt \--fleet-server-cert-key=/opt/fleet-server/fleet-server.key \--fleet-server-port=8220
6.fleet注冊

image-20240605173246207

image-20240605180350981

至此:代理安裝成功

第七部分:Kafka

image-20240605094605165

一:基本概念

1.kafka簡介

? kafka是一個分布式的消息發布—訂閱系統,是Apache基金會并成為頂級開源項目

? 是一個分布式、支持分區的(partition)、多副本的(replica),基于zookeeper協調的分布式消息系統

? 最大的特性就是可以實時的處理大量數據以滿足各種需求場景

? 比如基于hadoop的批處理系統、低延遲的實時系統等等

2.kafka特性

? 高吞吐量、低延遲:kafka每秒可以處理幾十萬條消息,它的延遲最低只有幾毫秒

? 可擴展性:kafka集群支持熱擴展

? 可靠性:消息被持久化到本地磁盤,并且支持數據備份防止數據丟失

? 容錯性:允許集群中節點失敗(若副本數量為n,則允許n-1個節點失敗)

? 高并發:支持數千個客戶端同時讀寫

3.核心組件

? 話題(Topic):是特定類型的消息流。消息是字節的有效負載,話題是消息的分類名或種子(Feed)名

? 生產者(Producer):是能夠發布消息到話題的任何對象(發布消息到 kafka 集群的終端或服務)

? 服務代理(Broker):已發布的消息保存在一組服務器中,它們被稱為代理(Broker)或Kafka集群

? 消費者(Consumer):可以訂閱一個或多個話題,并從Broker拉數據,從而消費這些已發布的消息

? partition(區):每個 topic 包含一個或多個 partition,每一個topic將被分為多個partition(區)

? replication:partition 的副本,保障 partition 的高可用

? leader:replication 中的一個角色, producer 和 consumer 只跟 leader 交互

? follower:replication 中的一個角色,從 leader 中復制數據

? controller:kafka 集群中的其中一個服務器,用來進行 leader election 以及 各種 failover

? zookeeper:kafka 通過 zookeeper 來存儲集群的 meta 信息

? Consumer group:每個 consumer 都屬于一個 consumer group,每條消息只能被 consumer group 中的一個 Consumer 消費,但可以被多個 consumer group 消費

4.架構圖

image-20240605095031575

二:集群部署

? 無

q8-1717741628915)]

[外鏈圖片轉存中…(img-fvyCqep4-1717741628916)]

[外鏈圖片轉存中…(img-ZQqysPC8-1717741628917)]

[外鏈圖片轉存中…(img-aQYfCpmo-1717741628918)]

[外鏈圖片轉存中…(img-LoRS9nvf-1717741628918)]

[外鏈圖片轉存中…(img-yA0yP4UN-1717741628919)]

[外鏈圖片轉存中…(img-z3Prep00-1717741628920)]

[外鏈圖片轉存中…(img-0uhHnWAw-1717741628921)]

[外鏈圖片轉存中…(img-vHQwMjLp-1717741628922)]

[外鏈圖片轉存中…(img-8Dj650Ev-1717741628923)]

[外鏈圖片轉存中…(img-iebWGpRr-1717741628924)]

[外鏈圖片轉存中…(img-jGjS4SsP-1717741628925)]

5.在agent上安裝

? 以下內容來自上面圖片中的復制,注意修改參數的值

[root@fleet-server elastic-agent]# cat a.sh
./elastic-agent install --url=https://fleet-server.xingdian.com:8220 \--fleet-server-es=https://es-1.xingdian.com:9200 \--fleet-server-service-token=AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyL3Rva2VuLTE3MTc1NzkxNzQzNDA6MEVlODhuMXhRaktEenhFOFRZRy1TZw \--fleet-server-policy=72d46cef-c33d-4360-bc20-60d829634076 \--certificate-authorities=/opt/ca/ca.crt \--fleet-server-es-ca=/opt/elasticsearch-ca.pem \--fleet-server-cert=/opt/fleet-server/fleet-server.crt \--fleet-server-cert-key=/opt/fleet-server/fleet-server.key \--fleet-server-port=8220
6.fleet注冊

[外鏈圖片轉存中…(img-OUa9fA6T-1717741628926)]

[外鏈圖片轉存中…(img-6xAjWAAs-1717741628927)]

至此:代理安裝成功

第七部分:Kafka

[外鏈圖片轉存中…(img-SsIeXHQD-1717741628928)]

一:基本概念

1.kafka簡介

? kafka是一個分布式的消息發布—訂閱系統,是Apache基金會并成為頂級開源項目

? 是一個分布式、支持分區的(partition)、多副本的(replica),基于zookeeper協調的分布式消息系統

? 最大的特性就是可以實時的處理大量數據以滿足各種需求場景

? 比如基于hadoop的批處理系統、低延遲的實時系統等等

2.kafka特性

? 高吞吐量、低延遲:kafka每秒可以處理幾十萬條消息,它的延遲最低只有幾毫秒

? 可擴展性:kafka集群支持熱擴展

? 可靠性:消息被持久化到本地磁盤,并且支持數據備份防止數據丟失

? 容錯性:允許集群中節點失敗(若副本數量為n,則允許n-1個節點失敗)

? 高并發:支持數千個客戶端同時讀寫

3.核心組件

? 話題(Topic):是特定類型的消息流。消息是字節的有效負載,話題是消息的分類名或種子(Feed)名

? 生產者(Producer):是能夠發布消息到話題的任何對象(發布消息到 kafka 集群的終端或服務)

? 服務代理(Broker):已發布的消息保存在一組服務器中,它們被稱為代理(Broker)或Kafka集群

? 消費者(Consumer):可以訂閱一個或多個話題,并從Broker拉數據,從而消費這些已發布的消息

? partition(區):每個 topic 包含一個或多個 partition,每一個topic將被分為多個partition(區)

? replication:partition 的副本,保障 partition 的高可用

? leader:replication 中的一個角色, producer 和 consumer 只跟 leader 交互

? follower:replication 中的一個角色,從 leader 中復制數據

? controller:kafka 集群中的其中一個服務器,用來進行 leader election 以及 各種 failover

? zookeeper:kafka 通過 zookeeper 來存儲集群的 meta 信息

? Consumer group:每個 consumer 都屬于一個 consumer group,每條消息只能被 consumer group 中的一個 Consumer 消費,但可以被多個 consumer group 消費

4.架構圖

[外鏈圖片轉存中…(img-bOW0tdbn-1717741628929)]

二:集群部署

? 無

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/24551.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/24551.shtml
英文地址,請注明出處:http://en.pswp.cn/web/24551.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

GAT1399協議分析(10)--單圖像刪除

一、官方接口 由于批量刪除的接口&#xff0c;圖像只能單獨刪除。 二、wireshark實例 這個接口比較簡單&#xff0c;調用request delete即可 文本化&#xff1a; DELETE /VIID/Images/34078100001190001002012024060513561300065 HTTP/1.1 Host: 10.0.201.56:31400 User-Age…

【sklearn】【邏輯回歸1】

學習筆記來自&#xff1a; 所用的庫和版本大家參考&#xff1a; Python 3.7.1Scikit-learn 0.20.1 Numpy 1.15.4, Pandas 0.23.4, Matplotlib 3.0.2, SciPy 1.1.0 1 概述 1.1 名為“回歸”的分類器 在過去的四周中&#xff0c;我們接觸了不少帶“回歸”二字的算法&#xf…

生物神經網絡 原理分析研讀02

可能有用基礎介紹 人類交互1 大腦視覺的處理過程 人類交互2 聽覺處理和語言中樞 人類交互3 皮膚感覺與運動系統 人類交互4 感覺輸入和運動輸出 人類交互5 大腦信號編碼與解碼 相關材料分析研讀 當前為了實現人工智能的兩個主流技術是深度學習和類腦計算&#xff0c;深度學習…

linux防止nmap掃描

1、首先關閉Centos7自帶的firewalld [rootnode ~]# systemctl disable firewalld.service && systemctl stop firewalld.service 2、安裝iptables服務 [rootnode ~]# yum install iptables-services iptables-devel -y [rootnode ~]# systemctl enable iptables …

【Vue】練習-Vuex中的值和組件中的input雙向綁定

目標 實時輸入&#xff0c;實時更新&#xff0c;鞏固 mutations 傳參語法 實現步驟 代碼示例 App.vue <input :value"count" input"handleInput" type"text"> <script>export default {methods: {handleInput (e) {// 1. 實時獲取…

MyQL 事務隔離級別解析

隔離級別臟讀不可重復讀幻讀未提交讀可能可能可能已提交讀不可能可能可能可重復讀不可能不可能可能可串行化不可能不可能不可能 當我們談論數據庫事務的隔離級別時&#xff0c;經常會聽到“臟讀”、“不可重復讀”和“幻讀”這三個術語。下面我會盡量用通俗的語言來解釋它們&a…

分布式Shiro,SpringBoot項目Shiro整合Redis

分布式Shiro&#xff0c;SpringBoot項目Shiro整合Redis 重要 Begin 你的SpringBoot項目已經使用了Shiro&#xff0c;并且可以正常使用。本篇文章的主要目的是將Shiro保存在服務器內存中的session信息改為使用Redis保存session信息 重要 End 正文開始 0、前情概要 由于shiro…

Python通過數據驗證功能在Excel文件中創建下拉列表

Excel表格的靈活性和功能性深受各行各業人士的喜愛。在Excel表格中&#xff0c;下拉列表功能是提升數據錄入效率與準確性的一個重要利器&#xff0c;能夠為用戶提供預設的選擇項&#xff0c;限制輸入范圍&#xff0c;避免手動輸入錯誤&#xff0c;還能夠簡化數據錄入過程&#…

Rust : windows下protobuf嘗試

此前dbpystream庫是用python開發 web api。今天在rust中試用一下protobuf。 一、 protobuf編譯器下載 具體見相關文章。沒有編譯器&#xff0c;protobuf無法運行。 windows參見&#xff1a; https://blog.csdn.net/wowotuo/article/details/139458846?spm1001.2014.3001.550…

推薦系統三十六式學習筆記:原理篇.內容推薦05|從文本到用戶畫像有多遠?

目錄 從文本開始構建用戶畫像一、結構化文本1、TF-IDF2、TextRank3、內容分類&#xff1a;4、實體識別5、聚類6、詞嵌入 二、標簽選擇1、卡方檢驗2、信息增益 總結 對于一個早期的推薦系統來說&#xff0c;基于內容推薦離不開用戶構建一個初級的畫像&#xff0c;這種初級的畫像…

【數據結構】棧的應用

目錄 0 引言 1 棧在括號匹配中的應用 2 棧在表達式求值中的應用 2.1 算數表達式 2.2 中綴表達式轉后綴表達式 2.3 后綴表達式求值 3 棧在遞歸中的應用 3.1 棧在函數調用中的作用 3.2 棧在函數調用中的工作原理 4 總結 0 引言 棧&#xff08;Stack&#xff09;是一…

MySQL A表的字段值更新為B表的字段值

MySQL A表的字段值更新為B表的字段值 準備數據表 create table person (id int unsigned auto_increment comment 主鍵 primary key,uuid varchar(32) not null comment 系統唯一標識符32個長度的字符串,mobile varchar(11) null comment 中國國內手機號,nickn…

使用 Ollama 和 Open WebUI 自托管 LLM 聊天機器人(無需 GPU)

?點擊這里?&#xff1a;&#x1f680;原文鏈接&#xff1a;&#xff08;更好排版、視頻播放、社群交流、最新AI開源項目、AI工具分享都在這個公眾號&#xff01;&#xff09; 使用 Ollama 和 Open WebUI 自托管 LLM 聊天機器人&#xff08;無需 GPU&#xff09; &#x1f31…

二叉查找樹詳解

目錄 二叉查找樹的定義 二叉查找樹的基本操作 查找 插入 建立 刪除 二叉樹查找樹的性質 二叉查找樹的定義 二叉查找樹是一種特殊的二叉樹&#xff0c;又稱為排序二叉樹、二叉搜索樹、二叉排序樹。 二叉樹的遞歸定義如下&#xff1a; &#xff08;1&#xff09;要么二…

10. MySQL 用戶

文章目錄 【 1. 權限表 】1.1 user 權限表1.1.1 用戶列1.1.2 權限列1.1.3 安全列1.1.4 資源控制列 1.2 db 表用戶列權限列 1.3 tables_priv 表1.4 columns_priv 表1.5 procs_priv表 【 2. 用戶管理 】2.1 創建用戶 CREATE USER2.2 用戶的登陸、退出登陸 MySQL退出 MySQL 2.3 重…

Java常見錯誤-內部類-簡要分析

Java常見錯誤-內部類-簡要分析 概念分類成員內部類&#xff08;非靜態內部類&#xff09;靜態內部類成員內部類和靜態內部類區別 局部內部類匿名內部類 注意事項總結 概念 ? 內部類&#xff0c;顧名思義&#xff0c;就是在一個類的內部定義的類。這種設計允許將一個類的實現細…

深度學習-10-測試

深度學習-10-測試 本文是《深度學習入門2-自製框架》 的學習筆記&#xff0c;記錄自己學習心得&#xff0c;以及對重點知識的理解。如果內容對你有幫助&#xff0c;請支持正版&#xff0c;去購買正版書籍&#xff0c;支持正版書籍不僅是尊重作者的辛勤勞動&#xff0c;也是鼓勵…

Web前端ES6-ES13筆記合集(下)

#### 五.ES10新特性 ##### 1. Object.fromEntries > Object.fromEntries()方法允許你輕松地將鍵值對列表轉換為對象 js const arr [["name", "kerwin"], ["age", 100]]; console.log(Object.fromEntries(arr))//{name: kerwin, age: 100} …

pytorch 筆記:pytorch 優化內容(更新中)

1 Tensor創建類 1.1 直接創建Tensor&#xff0c;而不是從Python或Numpy中轉換 不要使用原生Python或NumPy創建數據&#xff0c;然后將其轉換為torch.Tensor直接用torch.Tensor創建或者直接&#xff1a;torch.empty(), torch.zeros(), torch.full(), torch.ones(), torch.…

樹莓派【Raspberry Pi-64位】3b+,Pi4J 2.0入門

一.前言: 前面的文章講解了樹莓派在centos7 arm64版本下的使用,用一款智能小車為例子,做了代碼實踐。 由于centos7不再維護,且Pi4J 1.x版本也因為WiringPi 的局限,Pi4J從1.x升級為2.x.所以本專欄的技術棧也將進行調整,A.從centos7系統回到Raspberry Pi-64位系統。B.Pi4…