Linux 下 Docker 安装elasticsearch并配置密码使用X-pack做安全验证
引言:
在做练习项目的时候,需要使用elasticsearch做搜索引擎。因为使用的是阿里云的服务器,为了更好的管理所以使用了docker来安装elasticsearch。但是本着安全性考虑,需要给elasticsearch做安全验证。这时后难题来了,elasticsearch默认的是不开启安全验证的,在网上找了很多文章和方法,均不行,各种报错。经过八九个小时的查找资料,算是总结出了自己亲自尝试的方法吧,希望能够帮到大家。
下载docker什么的大家都会我就不献丑了,就直接开始吧。
第一步:
我在网上查的,据说(未查找资料考证)elasticsearch7.x.x之前好像是没有安全验证机制的。所以这里我使用的是7.6.2的版本,大家按我的步骤一步一步来吧。
下载镜像
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.6.2
第二步:
创建elasticsearch.yml文件
个人习惯我是在 /home/user/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插件
创建docker
命令给你们,你们自己修改吧
docker run -d -it --restart=always --privileged=true --name=es7 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -v /home/user/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -e es_java_opts="-xms256m -xmx256m" f29a1ee41030
第三步:
进入容器并修改配置
docker exec -it es7 /bin/bash # 进入容器 [root@f18d8bc7b8f5 elasticsearch]# cd bin [root@f18d8bc7b8f5 bin]# ls elasticsearch elasticsearch-croneval elasticsearch-migrate elasticsearch-setup-passwords elasticsearch-syskeygen x-pack-watcher-env elasticsearch-certgen elasticsearch-env elasticsearch-node elasticsearch-shard elasticsearch-users elasticsearch-certutil elasticsearch-env-from-file elasticsearch-plugin elasticsearch-sql-cli x-pack-env elasticsearch-cli elasticsearch-keystore elasticsearch-saml-metadata elasticsearch-sql-cli-7.6.2.jar x-pack-security-env [root@f18d8bc7b8f5 bin]# 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] [root@f18d8bc7b8f5 bin]# exit #退出容器
现在重启一下容器测试一些效果吧
docker restart es7
默认用户名是elastic
这样就成功了。
另外elasticsearch7.6.2配套的ik分词器的链接我放上
转自:https://www.cnblogs.com/chenmu/p/12680739.html
下一篇: django静态文件