Docker 安装 Elasticsearch 7.7.1 + Kibana

一、安装es

docker拉取es镜像

docker pull docker.elastic.co/elasticsearch/elasticsearch:7.7.1

启动es

docker run -d --name=es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.7.1

安装ik分词插件

docker exec -it es /bin/bash
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.7.1/elasticsearch-analysis-ik-7.7.1.zip

修改es跨域访问配置

 vi config/elasticsearch.yml 

修改后的内容为:

cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"

# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
discovery.zen.minimum_master_nodes: 1

退出容器,重启es容器

exit
docker restart es

使用浏览器访问 http://localhost:9200 查看是否显示es版本等信息

二、安装Kibana

docker拉取es镜像

 docker pull docker.elastic.co/kibana/kibana:7.7.1

启动kibana容器

docker run -it -d -e ELASTICSEARCH_URL=http://172.17.0.2:9200 --name kibana -p 5601:5601 docker.elastic.co/kibana/kibana:7.7.1

需要注意的是我这里配置的IP地址为容器内部的ip,这里需要根据你自己的部署环境去调整,后面在kibana的配置文件里也是可以配置的,可以通过 “docker inspect 容器ID | grep IPAddress” 命令去查看容器的ip

修改kibana配置文件

docker exec -it kibana /bin/bash
vi config/kibana.yml 

修改配置文件内容为:

#
# ** THIS IS AN AUTO-GENERATED FILE **
#

# Default Kibana configuration for docker target
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://172.17.0.2:9200" ]
monitoring.ui.container.elasticsearch.enabled: true

elasticsearch.hosts 为es的容器地址,可以使用docker inspect命令查看

同样,退出容器重启服务
浏览器访问 http://localhost:5601,如果服务启动失败可以使用docker logs命令查看失败原因

三、给ES设置密码

在elasticsearch.yml添加:

xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true

然后执行

bin/elasticsearch-setup-passwords interactive

y继续后,依次设置几个账户的密码

重启es

kibana.yml也需要添加:

elasticsearch.username: "kibana"
elasticsearch.password: "*****"

其他

修改密码
curl -H “Content-Type:application/json” -XPOST -u elastic ‘http://127.0.0.1:9200/_xpack/security/user/elastic/_password’ -d ’
{ “password” : “123456” }’

忘记密码
进入es容器
创建一个临时的超级用户 RyanMiao用这个用户去修改elastic用户的密码:
curl -XPUT -u ryan:ryan123 http://localhost:9200/_xpack/security/user/elastic/_password -H
“Content-Type: application/json” -d ’
{
“password”: “q5f2qNfUJQyvZPIz57MZ”
}’

猜你喜欢

转载自blog.csdn.net/bluerebel/article/details/110495239