Docker搭建elasticsearch+elasticsearch-analysis-ik分词器+Kibana客户端


前言

搭建docker版本的elasticsearch+elasticsearch-analysis-ik分词器+Kibana客户端
注意:最好是创建一个单独的用户,否则挂载数据与日志时会出现警告,所有使用的版本必须统一


一、elasticsearch搭建

1.下载镜像

docker pull elasticsearch:7.6.2

2.创建elasticsearch.yml文件

个人习惯在 /home/docker/elasticsearch/config 目录下创建的elasticsearch.yml文件。

配置elasticsearch.yml

http.host: 0.0.0.0
 
# Uncomment the following lines for a production cluster deployment
#transport.host: 0.0.0.0
#discovery.zen.minimum_master_nodes: 1
 
#Password config
 
xpack.security.enabled: true   #这一步是开启x-pack插件

目录结构
在这里插入图片描述
启动容器

挂载外部配置文件、data与logs版本:
docker run -d -it --restart=always --privileged=true --name=es -p 9200:9200 -p 9300:9300 -e “discovery.type=single-node” -v /home/docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v/home/docker/elasticsearch/data/nodes:nodes:/usr/share/elasticsearch/data/nodes -v /home/docker/elasticsearch/logs:/usr/share/elasticsearch/logs -e ES_JAVA_OPTS="-Xms256m -Xmx256m" elasticsearch:7.6.2

挂载外部配置文件:
docker run -d -it --restart=always --privileged=true --name=es -p 9200:9200 -p 9300:9300 -e “discovery.type=single-node” -v /home/docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -e ES_JAVA_OPTS="-Xms256m -Xmx256m" elasticsearch:7.6.2

进入容器并修改配置
docker exec -it es /bin/bash # 进入容器
在这里插入图片描述

手动设置密码
elasticsearch-setup-passwords interactive
在这里插入图片描述

Initiating the setup of passwords for reserved users elastic,apm_system,kibana,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]y
 
Enter password for [elastic]:    #在这里设置密码,注意最少六位,下面也一样
Reenter password for [elastic]: 
Passwords do not match.
Try again.
Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [kibana]: 
Reenter password for [kibana]: 
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]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

退出容器
exit

重启一下容器测试一些效果吧
docker restart es
默认用户名是elastic

注意:如果用的是云服务器,确保安全组已打开端口
在这里插入图片描述在这里插入图片描述

二、elasticsearch-analysis-ik分词器

这个要和es版本对应,我es是7.6.2 所以下的也是同版本号
下载地址:
官网地址(慢):https://github.com/medcl/elasticsearch-analysis-ik/releases
CSDN地址: https://download.csdn.net/download/Shangshan_Ruohe/15994650

下载完成后
unzip 命令解压
mv 将接下文件夹名字改为 ik

通过docker cp 复制到容器内 /usr/share/elasticsearch/plugins 就是这个位置,别乱放
docker cp ik/ es:/usr/share/elasticsearch/plugins

重启 es 就好了

三、kibana客户端

1.下载Kibana镜像

docker pull kibana:7.6.2
docker images
在这里插入图片描述

2.编辑kibana.yml配置文件

kibana.yml配置文件放在宿主机/home/docker/kibana目录下,内容如下:

# Kibana is served by a back end server. This setting specifies the port to use.
server.port: 5601
#
# # Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# # The default is 'localhost', which usually means remote machines will not be able to connect.
# # To allow connections from remote users, set this parameter to a non-loopback address.
server.host: "0"
#
# # Enables you to specify a path to mount Kibana at if you are running behind a proxy.
# # Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
# # from requests it receives, and to prevent a deprecation warning at startup.
# # This setting cannot end in a slash.
# #server.basePath: ""
#
# # Specifies whether Kibana should rewrite requests that are prefixed with
# # `server.basePath` or require that they are rewritten by your reverse proxy.
# # This setting was effectively always `false` before Kibana 6.3 and will
# # default to `true` starting in Kibana 7.0.
# #server.rewriteBasePath: false
#
# # The maximum payload size in bytes for incoming server requests.
# #server.maxPayloadBytes: 1048576
#
# # The Kibana server's name.  This is used for display purposes.
server.name: "kibana"
#
# # The URLs of the Elasticsearch instances to use for all your queries.
# elasticsearch.hosts: ["http://172.31.1.229:9200"]
#
# # When this setting's value is true Kibana uses the hostname specified in the server.host
# # setting. When the value of this setting is false, Kibana uses the hostname of the host
# # that connects to this Kibana instance.
# #elasticsearch.preserveHost: true
#
# # Kibana uses an index in Elasticsearch to store saved searches, visualizations and
# # dashboards. Kibana creates a new index if the index doesn't already exist.
# #kibana.index: ".kibana"
#
# # The default application to load.
# #kibana.defaultAppId: "home"
#
# # If your Elasticsearch is protected with basic authentication, these settings provide
# # the username and password that the Kibana server uses to perform maintenance on the Kibana
# # index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
# # is proxied through the Kibana server.
elasticsearch.username: "kibana"
elasticsearch.password: "123456"
#
# # Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively.
# # These settings enable SSL for outgoing requests from the Kibana server to the browser.
# #server.ssl.enabled: false
# #server.ssl.certificate: /path/to/your/server.crt
# #server.ssl.key: /path/to/your/server.key
#
# # Optional settings that provide the paths to the PEM-format SSL certificate and key files.
# # These files validate that your Elasticsearch backend uses the same key files.
# #elasticsearch.ssl.certificate: /path/to/your/client.crt
# #elasticsearch.ssl.key: /path/to/your/client.key
#
# # Optional setting that enables you to specify a path to the PEM file for the certificate
# # authority for your Elasticsearch instance.
# #elasticsearch.ssl.certificateAuthorities: [ "/path/to/your/CA.pem" ]
#
# # To disregard the validity of SSL certificates, change this setting's value to 'none'.
# #elasticsearch.ssl.verificationMode: full
#
# # Time in milliseconds to wait for Elasticsearch to respond to pings. Defaults to the value of
# # the elasticsearch.requestTimeout setting.
# #elasticsearch.pingTimeout: 1500
# # Kibana is served by a back end server. This setting specifies the port to use.
# server.port: 5601
#
# # Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# # The default is 'localhost', which usually means remote machines will not be able to connect.
# # To allow connections from remote users, set this parameter to a non-loopback address.
# server.host: "172.31.1.229"
#
# # Enables you to specify a path to mount Kibana at if you are running behind a proxy.
# # Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
# # from requests it receives, and to prevent a deprecation warning at startup.
# # This setting cannot end in a slash.
# #server.basePath: ""
#
# # Specifies whether Kibana should rewrite requests that are prefixed with
# # `server.basePath` or require that they are rewritten by your reverse proxy.
# # This setting was effectively always `false` before Kibana 6.3 and will
# # default to `true` starting in Kibana 7.0.
# #server.rewriteBasePath: false
#
# # The maximum payload size in bytes for incoming server requests.
# #server.maxPayloadBytes: 1048576
#
# # The Kibana server's name.  This is used for display purposes.
# #server.name: "your-hostname"
#
# # The URLs of the Elasticsearch instances to use for all your queries.
elasticsearch.hosts: ["http://192.168.0.99:9200"]
#
# # When this setting's value is true Kibana uses the hostname specified in the server.host
# # setting. When the value of this setting is false, Kibana uses the hostname of the host
# # that connects to this Kibana instance.
# #elasticsearch.preserveHost: true
#
# # Kibana uses an index in Elasticsearch to store saved searches, visualizations and
# # dashboards. Kibana creates a new index if the index doesn't already exist.
# #kibana.index: ".kibana"
#
# # The default application to load.
# #kibana.defaultAppId: "home"
#
# # If your Elasticsearch is protected with basic authentication, these settings provide
# # the username and password that the Kibana server uses to perform maintenance on the Kibana
# # index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
# # is proxied through the Kibana server.

注意:elasticsearch.hosts为Elasticsearch实例

3.运行 Kibana

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 /home/docker/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml kibana:7.6.2

查看容器启动状态
docker ps

3.启动kibana

访问 http://IP:5601 (启动可能会较慢,如失败等几秒再尝试刷新一下)
在这里插入图片描述账号:elastic
密码:刚刚自己设置的


总结

与大家分享,不足之处,请指正。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值