ELK-01搭建简单的EFK日志服务器

268 阅读2分钟

搭建简单的EFK日志服务器

镜像拉取

docker pull elasticsearch:7.17.5

docker pull kibana:7.17.5

容器创建

Elasticsearch 容器创建运行

创建挂载目录

目录可以自己定义,如果自己定义了则需要自己修改成自己的

mkdir -p /usr/local/elasticsearch/config
mkdir -p /usr/local/elasticsearch/data

创建yml文件

cd /usr/local/elasticsearch/config/
vi elasticsearch.yml

elasticsearch.yml 配置如下

network.host: 0.0.0.0   
network.bind_host: 0.0.0.0  #外网可访问

http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.security.enabled: true # 这条配置表示开启xpack认证机制 spring boot连接使用
xpack.security.transport.ssl.enabled: true

xpack.security 配置后,elasticsearch 需要账号密码使用,建议安排上。如果使用 springboot 查询,那一定要设置,否者会报错!

启动

docker run --name elasticsearch \
-p 9200:9200 \
-p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" \
-v /Users/vv/local/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /Users/vv/local/elasticsearch/data:/usr/share/elasticsearch/data \
-v /Users/vv/local/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.17.5
​
--net log  -d elasticsearch:7.17.5

注意: --net log指令是我专门为本次搭建创建的独立的网络,你可以修改为自己的网络也可以去掉、后续安装这里需要统一。

  • -p 9200:9200 :指定端口号
  • --name elasticsearch \ :指定容器名称
  • -e "discovery.type=single-node" \ :单机模式
  • -e ES_JAVA_OPTS="-Xms1g -Xmx2g" \ :指定内存
  • -v/usr/local/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch

.yml :指定 config 在宿主机位置

  • -v /usr/local/elasticsearch/data:/usr/share/elasticsearch/data \ :指定数据在宿主机位置
  • -v /usr/local/elasticsearch/plugins:/usr/share/elasticsearch/plugins \ :指定插件在宿主机位置
  • -d elasticsearch:7.10.1 :指定镜像

设置密码

docker exec -it elasticsearch /bin/bash

bin/elasticsearch-setup-passwords interactive

按照提示输入即可

检查验证:

http://localhost:9200/ 输入账号密码

账号elastic 密码为你刚输入的密码。

{
  "name" : "42d40c8bc971",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "bbKceo-US9em9Pj4aoZRrQ",
  "version" : {
    "number" : "7.17.5",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "8d61b4f7ddf931f219e3745f295ed2bbc50c8e84",
    "build_date" : "2022-06-23T21:57:28.736740635Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

安装kibana

设置kibana.yml

i18n.locale: "zh-CN"
server.port: 5601
server.host: 0.0.0.0
elasticsearch.username: "elastic" #es中配置
elasticsearch.password: "ES输入的密码"    #安装es输入的密码
xpack.reporting.encryptionKey: "a_random_string" #自己定义
xpack.security.encryptionKey: "something_at_least_32_characters" #自己定义

启动

docker run --name kibana \
 -e ELASTICSEARCH_HOSTS=http://elasticsearch:9200 \
 -p 5601:5601 \
 --link elasticsearch \
 -v /var/config/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml \
 -d kibana:7.17.5

参数说明

--link  让容器间的网络能通过容器名访问

访问

http://localhost:5601

image-20220720151516934