一、ES
docker pull elasticsearch:7.7.1
mkdir -p /usr/local/myapp/es/{config, data, logs}
chown -R 1000:1000 /usr/local/myapp/es
cd /usr/local/myapp/es/config
touch elasticsearch.yml
cluster.name: "es"
network.host: 0.0.0.0
http.port: 9200
http.cors.enabled: true # 开启跨域
http.cors.allow-origin: "*"
docker run -it -d -p 9200:9200 -p 9300:9300 --name es -e ES_JAVA_OPTS="-Xms2g -Xmx2g" -e "discovery.type=single-node" --restart=always
-v /usr/local/myapp/es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
-v /usr/local/myapp/es/data:/usr/share/elasticsearch/data
-v /usr/local/myapp/es/logs:/usr/share/elasticsearch/logs
elasticsearch:7.7.1
二、kibana
docker pull kibana:7.7.1
docker inspect --format '{{ .NetworkSettings.IPAddress }}' es //172.17.0.2
mkdir -p /usr/local/myapp/kibana/
vi /usr/local/myapp/kibana/kibana.yml
server.name: kibana
server.host: "0"
elasticsearch.hosts: ["http://172.17.0.2:9200"]
xpack.monitoring.ui.container.elasticsearch.enabled: true
docker run -d --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name kibana -p 5601:5601 -v /usr/local/myapp/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml kibana:7.7.1
三、logstash
# 拉取镜像
docker pull logstash:7.7.1
# 创建配置文件
mkdir /usr/local/myapp/logstash/conf.d
cd /usr/local/myapp/logstash
# 编辑文件信息
vim logstash.yml
path.config: /usr/share/logstash/conf.d/*.conf
path.logs: /var/log/logstash
cd /usr/local/myapp/logstash/conf.d
vi test.conf
# 收录springboot项目日志配置 test.conf
input {
tcp {
port => 5044
}
}
output {
elasticsearch {
hosts => ["172.17.0.2:9200"]
}
stdout {}
}
# 以下为filebeat的配置
input {
beats {
port => 5044
codec => "json"
}
}
# 保存日志到es中
output {
elasticsearch { hosts => ["172.17.0.2:9200"] }
stdout { codec => rubydebug }
}
docker run -it -d -p 5044:5044 -p 5045:5045 -p 5046:5046 --name logstash \
-v /usr/local/myapp/logstash/logstash.yml:/usr/share/logstash/config/logstash.yml \
-v /usr/local/myapp/logstash/conf.d/:/usr/share/logstash/conf.d/ \
logstash:7.7.1