ELK分別表示:Elasticsearch , Logstash, Kibana 。他們組成了一套完整的日誌系統的解決方案。html
ELK版本對應關係java
ELK全家桶各類版本的下載地址node
yum install wget -y
yum install zip unzip
去官方網站下載:
jdk-8u181-linux-x64.rpmlinux
或者執行web
wget http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/jdk-8u181-linux-x64.rpm?AuthParam=1532483945_1ce1c40fee9c74cdfb2c8c33ba817e88
下載完畢後重命名rpm包spring
mv jdk-8u181-linux-x64.rpm?AuthParam=1532483945_1ce1c40fee9c74cdfb2c8c33ba817e88 jdk-8u181-linux-x64.rpm
rpm -ivh jdk-8u181-linux-x64.rpm
上面全部的步驟完成以後,這時候咱們須要檢查是否安裝成功,輸入以下命令,如圖所示:json
java -version echo $JAVA_HOME
wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/zip/elasticsearch/2.4.6/elasticsearch-2.4.6.zip
unzip elasticsearch-2.4.6.zip
若想以以root權限運行Elasticsearch.解決辦法是運行時加上參數:springboot
bin/elasticsearch -Des.insecure.allow.root=true
或者修改bin/elasticsearch,加上ES_JAVA_OPTS屬性:ruby
ES_JAVA_OPTS="-Des.insecure.allow.root=true"
//臨時關閉 systemctl stop firewalld //禁止開機啓動 systemctl disable firewalld
cluster.name: mntx-cluster node.name= node-1 network.host:192.168.29.129 http.port:9200
./elasticsearch-2.4.6/bin/elasticsearch
後臺運行服務器
./elasticsearch-2.4.6/bin/elasticsearch &
elasticsearch/bin/plugin install mobz/elasticsearch-head
head插件的使用
http://192.168.29.129:9200/_plugin/head/
Wget https://download.elastic.co/logstash/logstash/logstash-2.4.1.zip
unzip logstash-2.4.1.zip
touch ./logstash-2.4.1/config/logstash-es.conf
input { tcp { port => 9601 codec => json_lines } } output { elasticsearch { # 此處配置須要鏈接的elashticsearch地址 hosts => "localhost:9200" } stdout { codec => rubydebug} }
注意縮進要符合規範
./bin/logstash-plugin install logstash-codec-json_lines
./bin/logstash -f ./config/logback-es.conf ##命令窗形式 ./bin/logstash -f ./config/logback-es.conf & ##後臺線程
ps -ef | grep logstash #後臺線程關閉 kill -9 4617 ##pid 4617 爲查處線程的pid
wget https://download.elastic.co/kibana/kibana/kibana-4.6.6-linux-x86_64.tar.gz
tar -xzvf kibana-4.6.6-linux-x86_64.tar.gz
vi ./config/kibana.yml
server.port: 5601 ##服務端口 server.host: "localhost" ##服務器ip 本機 elasticsearch.url: "http://localhost:9200" ##elasticsearch服務地址 與elasticsearch對應
./bin/kibana #命令窗啓動 ./bin/kibana &
<dependency> <groupId>net.logstash.logback</groupId> <artifactId>logstash-logback-encoder</artifactId> <version>4.11</version> </dependency>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration> <configuration> <appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> <destination>192.168.253.6:9601</destination> <!--指定logstash ip:監聽端口 tcpAppender 可本身實現如kafka傳輸等--> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder" /> </appender> <include resource="org/springframework/boot/logging/logback/base.xml"/> <!--引用springboot默認配置--> <root level="INFO"> <appender-ref ref="LOGSTASH" /> <!--使用上述訂閱logstash數據tcp傳輸 --> <appender-ref ref="CONSOLE" /> <!--使用springboot默認配置 調試窗口輸出--> </root> </configuration>
SpringbootLogbackApplication.java 測試,寫一個循環100次的日誌記錄
@SpringBootApplication public class SpringbootLogbackApplication { private final static Logger logger = LoggerFactory.getLogger(SpringbootLogbackApplication.class); public static void main(String[] args) { new Thread(()->{ for (int i=0;i<100;i++){ logger.info("---test---"+i); } }).start(); SpringApplication.run(SpringbootLogbackApplication.class, args); } }