不用插件的参考:docker启动elasticsearch 未授权访问【原理扫描】 - james-roger - 博客园

HTTP 基本身份验证:

下载地址:https://github.com/huhublog/elasticsearch7-http-basic

注意:如果下载的是zip,则需要在本地使用idea进行打包编译为jar,然后上传到服务器的elasticsearch安装目录下的 plugins / http-basic 目录下

里面需要配置文件plugin-descriptor.properties

classname=com.cleafy.elasticsearch6.plugins.http.HttpBasicServerPlugin
name=elasticsearch6-http-basic
description=Plugin to enable HTTP basic authentication and/or Ip based authentication
version=1.0.0
java.version=1.8
elasticsearch.version=7.0.0

配置 elasticsearch.yml

cluster.name: social_es  #集群唯一名称,所有节点一致
node.name: node8                     #节点名称
network.bind_host: 0.0.0.0              #设置可以访问的ip,默认为0.0.0.0,这里全部设置通过
network.publish_host: xxxx.xxx.x.xx       #设置其它结点和该结点交互的ip地址
http.port: 9200                     #设置对外服务的http端口,默认为9200
transport.tcp.port: 9300           #设置节点之间交互的tcp端口,默认是9300
#http.cors.enabled: true
#http.cors.allow-origin: "*"
#node.master: true           #配置该结点是否有资格被选举为主结点(候选主结点),为了防止脑裂,配置奇数个候选主结点
#node.data: true              #配置该结点是数据结点,用于保
#discovery.zen.ping.unicast.hosts: ["175.24.205.203:9300"] #集群个节点IP地址
#discovery.zen.minimum_master_nodes: 1  #自动发现master节点的最小数
#indices.query.bool.max_clause_count: 1024
http.basic.enabled: true
http.basic.log: true
http.basic.username: "es"
http.basic.password: "123456"
http.basic.ipwhitelist: xxxx.xxx.xxxx.xxx,xxx.xxx.xxx.xxx.
xpack.security.enabled: false
#http.basic.trusted_proxy_chains: ["xxx.xxx.xxx.xxx"]

然后重启es进行

测试:

curl -v --user my_username:my_password no_local_host:9200/foo

或 在白明单的ip上:

curl http://xxxx.xxx.x.xx:9200

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐