Elasticsearch_8.11.4_kibana_8.11.4_metricbeat_8.11.4安裝及本地部署_ELK日志部署
分布式引擎Elasticsearch_8.11.4安裝及本地部署
Elasticsearch是一個基于 Lucene 庫的分布式搜索和分析引擎,它提供了一個分布式、多租戶的全文搜索引擎,具有 HTTP Web 接口和無模式 JSON 文檔,同時也是是一個非常強大的工具,可以用于各種用途,例如日志分析、搜索引擎、安全分析等等。
遠程連接的好處在于可以讓用戶從遠程位置訪問 Elasticsearch集群,這樣可以方便地進行數(shù)據(jù)查詢和管理。具體好處如下:
1 方便遠程協(xié)作:遠程連接可以讓多個用戶從不同的地方同時訪問 Elasticsearch 集群,方便團隊協(xié)作和數(shù)據(jù)共享。
2 提高數(shù)據(jù)安全性:遠程連接可以讓用戶在本地進行數(shù)據(jù)查詢和管理,避免了在服務(wù)器上直接操作數(shù)據(jù)的風(fēng)險,提高了數(shù)據(jù)的安全性。
3 方便數(shù)據(jù)備份:遠程連接可以讓用戶方便地將數(shù)據(jù)備份到本地,避免了數(shù)據(jù)丟失的風(fēng)險。
4 提高數(shù)據(jù)處理效率:遠程連接可以讓用戶在本地進行數(shù)據(jù)處理和分析,避免了數(shù)據(jù)傳輸?shù)臅r間和帶寬限制,提高了數(shù)據(jù)處理效率。
下面介紹在 Windows 安裝 Elasticsearch 并結(jié)合 Cpolar 實現(xiàn)遠程連接和訪問!
系統(tǒng)環(huán)境要求
安裝前–》需要JDK 1.8的環(huán)境
1 Windows 安裝 Elasticsearch
相關(guān)b站視頻學(xué)習(xí):https://www.bilibili.com/video/BV1o4411j7cX?p=2&vd_source=07fe8b0af86975fbc5f3de79fd3d6186
中文官網(wǎng)https://www.elastic.co/cn/
進入官方下載界面: https://www.elastic.co/downloads/elasticsearch,選擇windows版本下載,Elasticsearch 運行需要 java 環(huán)境,如果沒有安裝環(huán)境,需要提前安裝 JDK.
下載完成后進行解壓,進入 bin 目錄,找到elasticsearch.bat
腳本文件執(zhí)行一鍵啟動.
啟動都選允許訪問網(wǎng)絡(luò)
啟動后,特別注意一下 cmd 窗口的一個用戶名和一個密碼信息,訪問登錄需要這個用戶名密碼
用戶:elastic 密碼:Dd1ScBihh_*-W2vYTLci
看到啟動的端口
訪問時候報錯,版本8以上,默認SSL證書是開啟,我嘗試證書關(guān)閉是沒有成功,下面是生成證書
Elasticsearch 啟動后訪問報錯:[2024-01-12T21:02:18,560][WARN ][o.e.t.TcpTransport ] [20230605-170021] exception caught on transport layer [Netty4TcpChannel{localAddress=/127.0.0.1:9300, remoteAddress=/127.0.0.1:10465, profile=default}], closing connectionio.netty.handler.codec.DecoderException: javax.net.ssl.SSLHandshakeException: Empty client certificate chain
at io.netty.codec@4.1.94.Final/io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:499)
at io.netty.codec@4.1.94.Final/io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
at io.netty.transport@4.1.94.Final/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
at io.netty.transport@4.1.94.Final/io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
at io.netty.transport@4.1.94.Final/io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
第一步:生成證書,我們在ES的bin目錄路徑下,執(zhí)行
bin/elasticsearch-certutil ca
生成ca證書,在期間,會提示我們輸入生成文件名(可直接回車跳過),提示我們輸入證書密碼(可直接回車跳過,也可以設(shè)置一個密碼,密碼盡量統(tǒng)一);這樣,我們就可以得到一個以.p12結(jié)尾的ca證書,其文件名默認為elastic-stack-ca.p12
自動在目錄生成文件
第二步:對生成的證書進行驗證,在ES的bin目錄路徑下,執(zhí)行指令
bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 #依次輸入上一個步驟的密碼?;剀嚕ㄎ募褂媚J名),密碼(建議與上一步密碼相同)
bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password #輸入密碼:第一步中設(shè)置的密碼,例如本樣例中的123456
bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password #輸入密碼:第一步中設(shè)置的密碼,例如本樣例中的12345
keystore和truststore設(shè)置密碼
生成文件在根目錄下
1.1 config參數(shù)解釋和詳細配置可參考
文件路徑window環(huán)境下路徑問題:默認是從D盤開始的,一定要設(shè)定在有效的elasticSearch文件安裝的目錄下的config文件夾下,才會識別成功,這個很重要
elasticsearch.yml配置文件釋義
#集群名字,目前是單節(jié)點
cluster.name: “test”
#節(jié)點名
node.name: “es_test”
#配置可進行數(shù)據(jù)交互的ip
network.host: 0.0.0.0
#允許http跨域訪問,es_head插件必須開啟
http.cors.enabled: true
http.cors.allow-origin: “*”
#數(shù)據(jù)存儲路徑
path.data: /usr/share/elasticsearch/dat
#啟動的端口
http.port: 9200
#日志存儲路徑
path.logs: /usr/share/elasticsearch/logs
#不鎖定jvm內(nèi)存
bootstrap.memory_lock: false
#備份庫
path.repo: [“/usr/share/elasticsearch/data/backup”]
#主節(jié)點
cluster.initial_master_nodes: [“es_test”]
#es_head連接時讀取用戶名密碼
http.cors.allow-headers:
Authorization,X-Requested-With,Content-Length,Content-Type
# 集群
discovery.seed_hosts: ["host1", "host2"]
# 有哪些節(jié)點可以成為主節(jié)點
cluster.initial_master_nodes: ["node-1", "node-2"]
#開啟密碼認證
xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path:【es的安裝路徑】/config/XXX/elastic-certificates.p12
Linux:----------> /usr/share/elasticsearch/config/certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path:【es的安裝路徑】/config/XXX/elastic-certificates.p12
Linux:----------> /usr/share/elasticsearch/config/certs/elastic-certificates.p12
設(shè)置文件路徑的,只配置這兩個:
xpack.security.transport.ssl.keystore.path:
xpack.security.transport.ssl.truststore.path
# Enable security features
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: true
keystore.path: certs/http.p12
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: elastic-certificates.p12
truststore.path: elastic-certificates.p12
jvm文件修改:
config配置文件夾中修改jvm.options 配置,設(shè)置jvm啟動內(nèi)存的大小
-Xms512m
-Xmx512m
啟動
./bin/elasticsearch -d #逐個啟動節(jié)點
進行訪問,這個界面就是啟動成功
1.2 其他服務(wù)指令,查找服務(wù)
tasklist | find "java.exe" # 檢查java服務(wù)是否運行
taskkill /F /IM "java.exe" # 結(jié)束java服務(wù)
java -jar path/java/service.jar #啟動服務(wù)需要日環(huán)java實際的jar包路徑
2 kibana 安裝
Kibana是一個針對Elasticsearch的開源分析及可視化平臺,用來搜索、查看交互存儲在Elasticsearch索引中的數(shù)據(jù)。使用Kibana,可以通過各種圖表進行高級數(shù)據(jù)分析及展示。Kibana讓海量數(shù)據(jù)更容易理解。它操作簡單,基于瀏覽器的用戶界面可以快速創(chuàng)建儀表板(dashboard)實時顯示Elasticsearch查詢動態(tài)。設(shè)置Kibana非常簡單。無需編碼或者額外的基礎(chǔ)架構(gòu),幾分鐘內(nèi)就可以完成Kibana安裝并啟動Elasticsearch索引檢測。
Kibana版本要和ES一致
官方下載地址:https://www.elastic.co/cn/downloads/kibana
,
下載后解壓后的目錄結(jié)構(gòu)
配置文件中主要配置
elasticsearch.hosts: ["http://localhost:9200"] # 填寫的elasticsearch服務(wù)地址
訪問超時的時間
改成漢化
設(shè)置好后,進入bin目錄雙擊kibana.bat
運行
下面常用幾個配置:kibana中配置ES中配置的kibana賬號密碼即可連接ES認證
elasticsearch.username: "kibana"
elasticsearch.password: "XXX"
elasticsearch.hosts: ["http://1.1.1.1:9200","http://2.2.2.2:9200","http://3.3.3.3:9200"]
server.port: 5601
默認端口是5601,127.0.0.1:5601
進行訪問,我這邊都是默認
進入頁面這兩個點擊任何一個都一樣,我選擇的是Explore on my own
滾動屏幕,選擇監(jiān)控
點擊默認選項
提示安裝Download Metricbeat
3 Metricbeat安裝及部署
下載注意:與elastic要保持版本的基本一致
Metricbeat是一個輕量級的托運程序,可以安裝在服務(wù)器上,定期從操作系統(tǒng)和服務(wù)器上運行的服務(wù)收集度量。Metricbeat獲取它收集的度量和統(tǒng)計數(shù)據(jù),并將它們發(fā)送到您指定的輸出,例如Elasticsearch或Logstash。
Metricbeat通過從服務(wù)器上運行的系統(tǒng)和服務(wù)收集指標(biāo),幫助您監(jiān)控服務(wù)器,例如:
- Apache
- HAProxy
- MongoDB
- MySQL
- Nginx
- PostgreSQL
- Redis
- System
- Zookeeper
詳細官方安裝教程
下載地址
1 將zip文件的內(nèi)容解壓到C:\Program Files中
2 將“Metricbeat-8.11.4-windows-x86_64”目錄重命名為“Metricbeat”。
3 以管理員身份打開PowerShell提示符(右鍵單擊PowerShell圖標(biāo)并選擇以管理員身份運行)。
PS > cd 'C:\Program Files\Metricbeat'
PS C:\Program Files\Metricbeat> .\install-service-metricbeat.ps1
4 如果您的系統(tǒng)禁用腳本執(zhí)行,則需要設(shè)置執(zhí)行策略: PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-metricbeat.ps1
執(zhí)行報錯
PS C:\Program Files\Metricbeat> .\install-service-metricbeat.ps1
.\install-service-metricbeat.ps1 : File C:\Program Files\Metricbeat\install-service-metricbeat.ps1 cannot be loaded bec
ause running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.micros
oft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\install-service-metricbeat.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
修改執(zhí)行策略:允許本地腳本和遠程簽名腳本 RemoteSigned
執(zhí)行策略修改:https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.4
PS C:\Program Files\Metricbeat> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): y
PS C:\Program Files\Metricbeat> .\install-service-metricbeat.ps1
[SC] DeleteService SUCCESS
Status Name DisplayName
------ ---- -----------
Stopped metricbeat metricbeat
配置文件說明: metricbeat.yml
# Metricbeat配置文件
# Metricbeat模塊配置
metricbeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
# 設(shè)置模板配置
setup.template.settings:
index.number_of_shards: 1
index.codec: best_compression
# 設(shè)置Kibana相關(guān)配置
setup.dashboards.enabled: true
setup.kibana:
host: "192.168.122.118:5601"
# 輸出到Elasticsearch的配置
output.elasticsearch:
# Elasticsearch集群節(jié)點
hosts: ["https://192.168.122.118:9200", "https://192.168.122.119:9200", "https://192.168.122.120:9200"]
protocol: "https"
username: "elastic"
password: "elastic"
# SSL配置
ssl.certificate_authorities: ["/opt/module/metricbeat-8.11.0/certs/elasticsearch-ca.pem"]
ssl.certificate: "/opt/module/metricbeat-8.11.0/certs/instance.crt"
ssl.key: "/opt/module/metricbeat-8.11.0/certs/instance.key"
# Metricbeat處理器配置
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~
- add_kubernetes_metadata: ~
# 直接發(fā)送elasticsearch
output.elasticsearch:
hosts: ["192.168.0.1:9200"]
# 要加載儀表板,可以在metricbeat設(shè)置中啟用儀表板加載。當(dāng)儀表板加載被啟用時,Metricbeat使用Kibana API來加載樣本儀表板。只有當(dāng)Metricbeat啟動時,才會嘗試儀表板加載。
# 設(shè)置kibana服務(wù)地址
setup.kibana.host: "172.30.1.45:5601"
# 加載默認的儀表盤樣式
setup.dashboards.enabled: true
# 設(shè)置如果存在模板,則不覆蓋原有模板
setup.template.overwrite: false
配置文件主要修改如下,其他默認:
啟動指令start metricbeat
# 啟用modules
# metricbeat modules enable 模塊名
# 禁用modules
# metricbeat modules disable 模塊名
# # 啟動system監(jiān)控,如果想監(jiān)控mysql、redis等則相應(yīng)打開相關(guān)功能
# metricbeat modules enable system
.\metricbeat.exe modules list
.\metricbeat.exe setup -e # 加載資源
.\metricbeat.exe modules enable elasticsearch-xpack # 啟動
PS C:\Program Files\Metricbeat> start metricbeat # 啟動會自動黑框,無需操作等待
.\metricbeat.exe setup --dashboards # 開啟面板命令
執(zhí)行完成后,可以在計算機管理-服務(wù)中看到metricbeat服務(wù)是啟動狀態(tài),在kibana可視化中可以看到Windows主機信息了。
重新打開頁面,發(fā)現(xiàn)頁面有了變化
整個Elasticsearch安裝中間走了很多彎路,最后是成功安裝,如何使用后續(xù)會更新!文章來源:http://www.zghlxwxcb.cn/news/detail-788073.html
4 ELK日志分析
在安裝和配置Metricbeat前,需確保ELK(Elasticsearch、Logstash、Kibana)已正確安裝和工作,關(guān)于ELK部署安裝,請參照文章《ELK日志監(jiān)控分析系統(tǒng)的探索與實踐(一):利用Filebeat監(jiān)控Springboot日志》文章來源地址http://www.zghlxwxcb.cn/news/detail-788073.html
到了這里,關(guān)于Elasticsearch_8.11.4_kibana_8.11.4_metricbeat_8.11.4安裝及本地部署_ELK日志部署的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!