Linux下如何安裝Logstash
一、安裝Logstash
1.解壓tar包
cd /data/app/elk/elk-6.8.5 tar zxvf logstash-6.8.5.tar.gz
2.配置config目錄下的logstash.conf
# 數(shù)據(jù)輸入部分 input { # 讀取nginx訪問日志 file { #path:監(jiān)聽文件的路徑,絕對路徑 path => "/data/app/nginx/logs/access.log" #為Nginx的access.log路徑 # 格式:json codec => "json" #start_position:監(jiān)聽文件的起始位置,beginning:從文件的頭開始讀取 start_position => "beginning" #type:自定義類型 type => "nginx-access-log" } # 讀取nginx異常日志 file { path => "/data/app/nginx/logs/error.log" #為Nginx的error.log路徑 # 格式:plain,輸入的是字符串,輸出把全部內(nèi)容放到message字段 codec => "plain" start_position => "beginning" type => "nginx-error-log" } #filebeats方式 beats { port => 5044 type => "beats_log" } #自定義端口,一個(gè)項(xiàng)目可對應(yīng)一個(gè)自定義tcp端口接收數(shù)據(jù) tcp { mode => "server" host => "192.168.X.X" #IP地址 port => 21022 codec => json type => "application-log" #application一般為項(xiàng)目名稱 } } # 數(shù)據(jù)處理部分 filter{ if[type] == "application-log"{ mutate { rename => {"host" => "hostname"} } } } # 數(shù)據(jù)輸出部分 output { # beat監(jiān)控信息 if [type] == "beats_log"{ elasticsearch { hosts => ["192.168.X.X:9200"] manage_template => false index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}" user => "elastic" password => "elastic2021" } } # nginx訪問日志 if[type] == "nginx-access-log" { elasticsearch { hosts => ["192.168.X.X:9200"] index => "nginx-access-log-%{+YYYY.MM.dd}" # elasticsearch的用戶名、密碼 user => "elastic" password => "elastic2021" } } # nginx異常日志 if[type] == "nginx-error-log"{ elasticsearch{ hosts => ["192.168.X.X:9200"] index => "nginx-error-log-%{+YYYY.MM.dd}" user => "elastic" password => "elastic2021" } } # 應(yīng)用系統(tǒng)日志 if[type] == "application-log"{ elasticsearch { hosts => ["192.168.X.X:9200"] index => "application-log-%{+YYYY.MM.dd}" user => "elastic" password => "elastic2021" } } }
3.啟動(dòng)命令
cd /data/app/elk/elk-6.8.5/logstash-6.8.5 nohup ./bin/logstash -f config/logstash.conf &
4.查看Logstash是否啟動(dòng)成功
ps -ef | grep logstash
二、配置應(yīng)用項(xiàng)目的logback環(huán)境
1.在pom.xml中添加Logstash依賴
<!-- logstash 6.2 --> <dependency> <groupId>net.logstash.logback</groupId> <artifactId>logstash-logback-encoder</artifactId> <version>6.2</version> </dependency>
2.在resouces目錄下添加logback-spring.xml
<?xml version="1.0" encoding="UTF-8" ?> <configuration debug="false"> <!-- 為logstash輸出的JSON格式的Appender --> <appender name="logstash_dev" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> <destination>192.168.X.X:21021</destination> <!-- 日志輸出編碼 --> <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> <providers> <timestamp> <timeZone>UTC</timeZone> </timestamp> <pattern> <pattern> { "severity": "%level", "service": "${APP_NAME:-}", "trace": "%X{X-B3-TraceId:-}", "span": "%X{X-B3-SpanId:-}", "parent": "%X{X-B3-ParentSpanId:-}", "exportable": "%X{X-Span-Export:-}", "pid": "${PID:-}", "thread": "%thread", "class": "%logger", "rest": "%message" } </pattern> </pattern> </providers> </encoder> </appender> <!-- 開發(fā)環(huán)境 --> <springProfile name="develop"> <!--設(shè)置根日志級(jí)別--> <root level="INFO"> <appender-ref ref="logstash_dev"/> </root> </springProfile> </configuration>
三、在kibana界面查看數(shù)據(jù)
瀏覽器訪問192.168.X.X:5601
1.查看索引管理
2.配置索引模式
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
通過yum升級(jí)CentOS/RHEL最小化安裝的方法
下面小編就為大家?guī)硪黄ㄟ^yum升級(jí)CentOS/RHEL最小化安裝的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-12-12Linux文件服務(wù)器實(shí)戰(zhàn)詳解(匿名用戶)
這篇文章主要介紹了Linux文件服務(wù)器實(shí)戰(zhàn)(匿名用戶),非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-06-06解決linux系統(tǒng)中運(yùn)行node進(jìn)程卻無法殺死進(jìn)程的問題
這篇文章主要介紹了linux系統(tǒng)中運(yùn)行node進(jìn)程無法殺死進(jìn)程的問題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-02-02Linux使用crontab實(shí)現(xiàn)定時(shí)拆分日志與清理過期文件
crontab是一個(gè)用于管理定時(shí)任務(wù)的工具,可以讓在特定的時(shí)間間隔內(nèi)自動(dòng)運(yùn)行腳本或命令,本文將使用crontab實(shí)現(xiàn)定時(shí)拆分日志與清理過期文件,需要的可以參考下2024-04-04Linux系統(tǒng)設(shè)置開機(jī)自動(dòng)運(yùn)行腳本的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Linux系統(tǒng)設(shè)置開機(jī)自動(dòng)運(yùn)行腳本的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Linux系統(tǒng)具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06Ubuntu 18.04 Server 設(shè)置靜態(tài)IP 的方法
Netplan是Ubuntu 17.10中引入的一種新的命令行網(wǎng)絡(luò)配置實(shí)用程序,用于在Ubuntu系統(tǒng)中輕松管理和配置網(wǎng)絡(luò)設(shè)置。這篇文章主要介紹了Ubuntu 18.04 Server 設(shè)置靜態(tài)IP 的方法,需要的朋友可以參考下2018-11-11Nginx+PHP+MySQL雙機(jī)互備、全自動(dòng)切換方案
在生產(chǎn)應(yīng)用中,某臺(tái)“Nginx+PHP+MySQL”接口數(shù)據(jù)服務(wù)器,扮演的角色十分重要,如果服務(wù)器硬件或Nginx、MySQL發(fā)生故障,而短時(shí)間內(nèi)無法恢復(fù),后果將非常嚴(yán)重。為了避免單點(diǎn)故障,我設(shè)計(jì)了此套方案,編寫了failover.sh腳本,實(shí)現(xiàn)了雙機(jī)互備、全自動(dòng)切換,故障轉(zhuǎn)移時(shí)間只需幾十秒。2008-12-12