Docker/elasticsearch:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第44行: 第44行:
验证,打开网页 http://10.220.188.195:5601/。
验证,打开网页 http://10.220.188.195:5601/。


== 插件 ==
=== 分词器 ===
{{shc|<syntaxhighlight lang="bash">
bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.2/elasticsearch-analysis-ik-7.6.2.zip</syntaxhighlight>|$|/home/kangkk}}
== 角色管理 ==
== 角色管理 ==
=== 设置用户名密码 ===
=== 设置用户名密码 ===

2021年5月30日 (日) 11:29的版本

引言

查看镜像。

/home/kangkk
sudo docker images

安装

/home/kangkk
sudo docker pull elasticsearch:7.6.2

运行

/home/kangkk
sudo docker run -it --name elasticsearch -e ES_JAVA_OPTS="-Xms1024m -Xmx1024m" -e "discovery.type=single-node" -d -p 9200:9200 -p 9300:9300 -p 5601:5601 elasticsearch:7.6.2

验证容器 start 正确。

[jian@kang /home/kangkk]$
curl http://localhost:9200
{
  "name" : "a9580fa1184b",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "hgRneH8eTtunGDi2_CveYA",
  "version" : {
    "number" : "7.6.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
    "build_date" : "2020-03-26T06:34:37.794943Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

启动 kibana。

[jian@kang /home/kangkk]$
sudo docker run -it -d -e ELASTICSEARCH_URL=http://127.0.0.1:9200 --name kibana --network=container:elasticsearch kibana:7.6.2
fb7f8f6373ac05afdf9f1ce086a5d336bd4ac959b3163b410508314f8fea69e5
--network 指定容器共享elasticsearch容器的网络栈 (使用了--network 就不能使用-p 来暴露端口)

验证,打开网页 http://10.220.188.195:5601/。

插件

分词器

/home/kangkk
bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.2/elasticsearch-analysis-ik-7.6.2.zip

角色管理

设置用户名密码

添加

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

重启 ElasticSearch,然后执行。

/home/kangkk
bin/elasticsearch-setup-passwords interactive

查看用户信息。

[jian@kang /home/kangkk]$
curl -XGET -u elastic 'http://localhost:9200/_xpack/security/user'
{"elastic":{"username":"elastic","roles":["superuser"],"full_name":null,"email":null,"metadata":{"_reserved":true},"enabled":true},"kibana":{"username":"kibana","roles":["kibana_system"],"full_name":null,"email":null,"metadata":{"_reserved":true},"enabled":true},"logstash_system":{"username":"logstash_system","roles":["logstash_system"],"full_name":null,"email":null,"metadata":{"_reserved":true},"enabled":true},"beats_system":{"username":"beats_system","roles":["beats_system"],"full_name":null,"email":null,"metadata":{"_reserved":true},"enabled":true},"apm_system":{"username":"apm_system","roles":["apm_system"],"full_name":null,"email":null,"metadata":{"_reserved":true},"enabled":true},"remote_monitoring_user":{"username":"remote_monitoring_user","roles":["remote_monitoring_collector","remote_monitoring_agent"],"full_name":null,"email":null,"metadata":{"_reserved":true},"enabled":true}}[

修改密码。

/home/kangkk
curl -H "Content-Type:application/json" -XPOST -u elastic 'http://localhost:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "123456" }'

kibana

配置

kibana.yml
#
# ** THIS IS AN AUTO-GENERATED FILE **
#

# Default Kibana configuration for docker target
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://localhost:9200" ]
elasticsearch.username: "elastic"
elasticsearch.password: "1234567890"

xpack.monitoring.ui.container.elasticsearch.enabled: true

# chinese language
i18n.locale: "zh-CN"

参考