使用docker安装elastic search和kibana,版本均为7.17.1
去dockerhub看具体版本,这里用7.17.1
docker pull elasticsearch:7.17.1docker pull kibana:7.17.1 docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms256m -Xmx256m" elasticsearch:7.17.1参数说明
-d 后台启动–name 起别名即:NAMES-p 9200:9200 将端口映射出来-e "discovery.type=single-node"单节点启动-e ES_JAVA_OPTS="-Xms256m -Xmx256m" 限制内存大小确保成功启动
docker psmkdir -p /data/elasticsearch/{config,data,logs,plugins}ymldocker cp elasticsearch:/usr/share/elasticsearch/config /data/elasticsearchdocker cp elasticsearch:/usr/share/elasticsearch/logs /data/elasticsearchdocker cp elasticsearch:/usr/share/elasticsearch/data /data/elasticsearchdocker cp elasticsearch:/usr/share/elasticsearch/plugins /data/elasticsearchvi /data/elasticsearch/config/elasticsearch.ymlcluster.name: "docker-cluster"network.hosts:0.0.0.0# 跨域http.cors.allow-origin: "*"http.cors.enabled: truehttp.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Typedocker stop elasticsearchdocker rm elasticsearchdocker run -d --name elasticsearch \-p 9200:9200 \-p 9300:9300 \-e "discovery.type=single-node" \-e ES_JAVA_OPTS="-Xms256m -Xmx256m" \-v /data/elasticsearch/logs:/usr/share/elasticsearch/logs \-v /data/elasticsearch/data:/usr/share/elasticsearch/data \-v /data/elasticsearch/plugins:/usr/share/elasticsearch/plugins \-v /data/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \elasticsearch:7.17.1等docker容器起来一分钟左右,再访问9200 端口,会返回
因为安装的是V7版本的,默认没开启x-pack(v8默认开启),所以能直接访问
[root@iZuf6ai62xce7wexx4wwi9Z config]# curl "http://localhost:9200"{ "name" : "6a1036c69d59", "cluster_name" : "docker-cluster", "cluster_uuid" : "0zgLiGhESGKQYTYy9gH4iA", "version" : { "number" : "7.17.1", "build_flavor" : "default", "build_type" : "docker", "build_hash" : "e5acb99f822233d62d6444ce45a4543dc1c8059a", "build_date" : "2022-02-23T22:20:54.153567231Z", "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"}[root@iZuf6ai62xce7wexx4wwi9Z config]#docker run -d --name kibana -p 5601:5601 kibana:7.17.1mkdir -p /data/kibana/configdocker cp kibana:/usr/share/kibana/config /data/kibana/在本地就能看到拷贝出来的kibana.yml文件,
vim /data/kibana/config/kibana.yml修改配置为
## ** THIS IS AN AUTO-GENERATED FILE **## Default Kibana configuration for docker targetserver.host: "0"server.shutdownTimeout: "5s"elasticsearch.hosts: [ "http://localhost:9100" ] # 记得修改ipmonitoring.ui.container.elasticsearch.enabled: truei18n.locale: "zh-CN"docker stop kibanadocker rm kibanadocker run -d --name kibana -p 5601:5601 -v /data/kibana/config:/usr/share/kibana/config kibana:7.17.1访问kibana发现需要token
进入es容器获取token
docker exec -it {elastic_search_container_id} /bin/bashbin/elasticsearch-create-enrollment-token --scope kibanadocker exec -it kibana /bin/bash# 执行生成验证码命令bin/kibana-verification-code 进入es容器
docker exec -it {elastic_search_container_id} /bin/bashbin/elasticsearch-reset-password --username elastic -i后面就使用elastic账户和密码登录kibana
vim /data/elasticsearch/config/elasticsearch.yml增加以下xpack.security.enabled
cluster.name: "docker-cluster-01"network.host: 0.0.0.0http.cors.enabled: truehttp.cors.allow-origin: "*"http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type# 此处开启xpackxpack.security.enabled: true重启es容器
docker restart elasticsearchdocker exec -ti elasticsearch /bin/bash/usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive然后会分别让重置以下的密码,这里重置成123456
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.You will be prompted to enter passwords as the process progresses.Please confirm that you would like to continue [y/N]yEnter password for [elastic]:passwords must be at least [6] characters longTry again.Enter password for [elastic]:Reenter password for [elastic]:Enter password for [apm_system]:Reenter password for [apm_system]:Enter password for [kibana_system]:Reenter password for [kibana_system]:Enter password for [logstash_system]:Reenter password for [logstash_system]:Enter password for [beats_system]:Reenter password for [beats_system]:Enter password for [remote_monitoring_user]:Reenter password for [remote_monitoring_user]:Changed password for user [apm_system]Changed password for user [kibana_system]Changed password for user [kibana]Changed password for user [logstash_system]Changed password for user [beats_system]Changed password for user [remote_monitoring_user]Changed password for user [elastic][root@k8s-master ~]# curl localhost:9200 -u elasticEnter host password for user 'elastic':{ "name" : "cd52e7fbacd1", "cluster_name" : "docker-cluster", "cluster_uuid" : "0S-V9zElSie_zXtcDRssAQ", "version" : { "number" : "8.1.2", "build_flavor" : "default", "build_type" : "docker", "build_hash" : "31df9689e80bad366ac20176aa7f2371ea5eb4c1", "build_date" : "2022-03-29T21:18:59.991429448Z", "build_snapshot" : false, "lucene_version" : "9.0.0", "minimum_wire_compatibility_version" : "7.17.0", "minimum_index_compatibility_version" : "7.0.0" }, "tagline" : "You Know, for Search"}[root@k8s-master ~]#vi /data/kibana/config/kibana.yml## ** THIS IS AN AUTO-GENERATED FILE **## Default Kibana configuration for docker targetserver.host: "0"server.shutdownTimeout: "5s"elasticsearch.hosts: [ "http://172.17.0.3:9200" ]monitoring.ui.container.elasticsearch.enabled: truei18n.locale: "zh-CN"# 此处设置elastic的用户名和密码elasticsearch.username: elasticelasticsearch.password: "123456"docker restart kibanadocker run -d \--name=elasticsearch-head \-p 9100:9100 \mobz/elasticsearch-head:5-alpinehttp://{ip}:9200/http://{ip}:9100/?auth_user=elastic&auth_password=123456