0%

Docker+ELK搭建

换了个运行环境,重新搭建一套公司本地内部的ELK,之前也搭过(可访问:https://yanganlin.com/31.html) , 最近做什么事情都想用Docker,这次也用Docker,还算顺利,没掉什么坑里,上次搭建,也用用的6.2+的版本,这都过了一年,Elk这三个产品,都已经上7了,用docker搭建的还是用6.2.4,稳定不落伍就好

安装elasticsearch

安装

1
docker run \
2
    -d \
3
    --name elasticsearch \
4
    -p 9200:9200 \
5
    -p 9300:9300 \
6
    -e "discovery.type=single-node" \
7
    docker.elastic.co/elasticsearch/elasticsearch:6.2.4

访问http://localhost:9200

安装kibana

安装

1
docker run \
2
    -d \
3
    -u 0 \
4
    --name kibana \
5
    -p 5601:5601\
6
    docker.elastic.co/kibana/kibana:6.2.4

进入到容器内部:docker exec -it kibana /bin/bash
找到kibana的配置文件:/usr/share/kibana/config/ kibana.yml
重启容器:doccker restart kibana

修改配置文件,因为要绕过x-pack的安全检查

1
elasticsearch.url: http://localhost:9200
2
xpack.monitoring.ui.container.elasticsearch.enabled: false

安装logstash

安装

1
docker run \
2
    -d \
3
    -u 0 \
4
    --name logstash \
5
    -p 5044:5044\
6
    docker.elastic.co/logstash/logstash:6.2.4

进入容器:docker exec -it logstash /bin/bash

找到文件:/usr/share/logstash/pipeline

修改配置文件logstash.conf

1
input {
2
    tcp {
3
        port => 5044
4
        codec => json_lines
5
    }
6
}
7
8
output{
9
    elasticsearch {
10
        hosts => ["localhost:9200"]
11
        action => "index"
12
        index => "%{[appname]}"
13
    }
14
  stdout { codec => rubydebug }
15
}

重启容器:doccker restart logstash

SpringBoot配置Logstash

logback.xml

1
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
2
    <destination>localhost:5044</destination>
3
    <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
4
        <customFields>{"appname":"eureka-server"}</customFields>
5
    </encoder>
6
</appender>
7
8
<root level="INFO">
9
    <appender-ref ref="LOGSTASH"/>
10
</root>

pom.xml

1
<dependency>
2
	<groupId>net.logstash.logback</groupId>
3
	<artifactId>logstash-logback-encoder</artifactId>
4
	<version>4.9</version>
5
</dependency>

在Kibana创建索引

参考:https://yanganlin.com/31.html