Elasticsearch密码设置及其后续问题解决
一.设置密码
1.在elasticsearch.yml中配置
#开启密码验证
xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
#不添加无法使用head连接es,连接时在http:ip:port/?auth_user=elastic&auth_password=密码
http.cors.allow-headers: Content-Type,Accept,Authorization, x-requested-with
2.在elasticsearch/bin下运行
elasticsearch-setup-passwords interactive
然后设置多个账号的密码
[es@k8snode2 elasticsearch-7.3.0]$ ./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]yEnter 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]
3.启动es即可。
4.使用head连接es时,需要在连接输入框中
http://127.0.0.1:9200/?auth_user=elastic&auth_password=密码
二.修改密码
修改密码命令如下:
curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "123456" }'
三.带密码查询
Elasticsearch设置用户名密码之后,不能再直接使用Elasticsearch head 访问,可以在查询等API上加上用户等参数:
curl -XGET --user(elasticsearch名称) user:passwd 'http://XXXX:9200/XX/XXX'
比如想要清空某个索引下的数据:
curl -XPOST --user(elasticsearch名称) admin:admin 'http://XXXX:9200/XXXX/XXX/_delete_by_query' -H "Content-Type: application/json" -d '{ "query":{"match_all":{}}}'
四.添加自定义角色
添加角色接口为:POST /_xpack/security/role/
下面添加一个超级管理员角色为例:
[elastic@data-backup elasticsearch-6.2.4]$ curl -XPOST -H 'Content-type: application/json' -u elastic:elastic123 'http://10.163.19.231:9600/_xpack/security/role/admin?pretty' -d '{
"run_as":["elastic"],
"cluster":["all"],
"indices":[{"names":["*"],"privileges":["all"]}
]
}'
{"role" : {"created" : true}
}
[elastic@data-backup elasticsearch-6.2.4]$ curl -XGET -H 'Content-type: application/json' -u elastic:elastic123 'http://10.163.19.231:9600/_xpack/security/role/admin?pretty'
{"admin" : {"cluster" : ["all"],"indices" : [{"names" : ["*"],"privileges" : ["all"]}],"run_as" : ["elastic"],"metadata" : { },"transient_metadata" : {"enabled" : true}}
}
五.添加自定义用户
添加用户接口为:POST/_xpack/security/user/
下面以添加一个test用户并添加至admin角色为例:
[elastic@data-backup elasticsearch-6.2.4]$ curl -XGET -H 'Content-type: application/json' -u test:Test123654% 'http://10.163.19.231:9600/_cat/indices?pretty'
green open .monitoring-es-6-2019.09.17 J1K2XG1eTXqw0GHSOH5Gwg 1 0 848 104 846.9kb 846.9kb
green open .watches qHj5owowRC-3DeK8DaLD-g 1 0 6 0 47.8kb 47.8kb
green open .triggered_watches 2pm3BwCnTaKgyzl39eFpUw 1 0 0 0 5.1kb 5.1kb
yellow open monitor yFnfztziSguTq9VsfSANpw 5 1 48 0 226.7kb 226.7kb
green open .watcher-history-7-2019.09.17 uz6RA_8vRraHHLAitWKtAw 1 0 74 0 259.8kb 259.8kb
green open .monitoring-alerts-6 ZPTqnNVOQ5GlUK1ncXNQDQ 1 0 2 0 18.1kb 18.1kb
yellow open track AqSGAZnAQE2NGvZXlp9zcw 5 1 1343729 175384 201mb 201mb
green open .security-6 83fAslPbQDSGbGWfhiMAXA 1 0
注:这里要注意的是用户密码最好不要有"$" "!"之类的字符,这样有可能会导致密码认证不成功,其他字符测试过暂时没问题(具体原因不详,反正我遇到过这个坑)
六.RestHighLevelClient客户端验证密码
//初始化ES操作客户端final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();credentialsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials("elastic", "123456")); //es账号密码(默认用户名为elastic,因为在设置密码时其中的一个用户就是elastic)RestHighLevelClient esClient =new RestHighLevelClient(RestClient.builder(new HttpHost("127.0.0.1",9200)).setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {httpClientBuilder.disableAuthCaching();return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);}})/.setMaxRetryTimeoutMillis(2000)/);
七.设置密码后的使用
1.head连接
需要在http://127.0.0.1:9100/ 后添加?auth_user=elastic&auth_password=密码
2.logstash中
在conf文件中的output中进行修改
output {elasticsearch {#es服务器hosts => ["localhost:9200"]#ES索引名称index => "zfjd"#自增IDdocument_id => "%{id}"#当document_id 不存在时,自动生成#doc_as_upsert => true#索引类型document_type => "xzcf_common"#es的账号密码user => elasticpassword => "密码"# 主要实现想法,就来源于这里action可以指定,那么我前面给数据打上标识,就可以实现删除了action => "%{[@metadata][action]}" }
3.linux命令行
curl --user elastic:密码 -XPUT 需要的操作 -d -H "Content-Type:application/json"
Elasticsearch密码设置及其后续问题解决相关推荐
- 运维(14) docker-compose部署Elasticsearch并设置账号密码
文章目录 一.前言 二.docker-compose部署Elasticsearch 三.访问 四.ES密码 1.设置ES密码 2.修改ES密码 五.其他 docker-compose-elastics ...
- Elasticsearch+Kibana 设置连接密码
1. 版本 Elasticsearch:7.10.2 Kibana:7.10.2 2. 修改Elasticsearch密码 2.1修改配置 修改 elasticsearch.yml ,加上以下配置项: ...
- BLE-NRF51822教程5-静态密码设置
这一讲介绍配对的一些相关理论知识,并且介绍如何实现"静态密码"的设定 程序是基于sdk9.0 下的 uart demo 另外 测试使用的手机app是 iOS下的lightblue. ...
- win7系统ftp服务器密码修改,win7ftp服务器设置用户名密码设置
win7ftp服务器设置用户名密码设置 内容精选 换一换 建议您的密码由数字.大小写字母.特殊符号组成,长度在8至26位.同时建议您从华为云的云市场中下载并安装虚拟化杀毒产品和主机安全加固产品,这样可 ...
- excel怎么设置自动计算_ios14怎么设置自动填充密码-ios14自动填充密码设置方法...
ios14怎么设置自动填充密码?这个功能是目前很多用户都比较关心的问题,因为进入各种软件经常性要自己输密码,不能自动读取,wifi和游戏都有这个问题,那么该怎么去解决呢?下面就一起来看看吧. ios1 ...
- Windows Server 2008 R2 配置笔记,密码设置为任意长度,远程桌面终端连接数的设置...
图片显示不完全时,可在新标签页打开. Windows Server 2008 R2 配置{ 安装企业版(Enterprise Editon),因为企业版功能全面,并且比数据中心版更容易配置{ ...
- android系统密码设置功能,手机锁屏密码怎么设置 三种安卓手机锁屏方式推荐
手机中有很多应用都是与金钱挂钩,特别是微信与支付宝等等既涉及到隐私又与财产关联,这是后手机的安全就尤为重要的,而手机的锁屏密码就是一道最基本的防护措施,那么手机锁屏密码怎么设置?来看看小编推荐的三种安 ...
- plt.figure(figsize(x,y))设置后后续程序都跟着改变,如何处理?走破解它!
plt.figure(figsize(x,y))设置后后续程序都跟着改变,如何处理?走破解它! 目录 plt.figure(figsize(x,y))设置后后续程序都跟着改变,如何处理?走破解它!
- 安卓怎么用抖音做锁屏_把锁屏密码设置成当前时间,随时间的变动!别人怎么也猜不出来...
2019年的第3天,平头哥已经变了. 曾经的平头哥,天真的认为时间就是用来浪费的.而在新年的第一天,我知道时间还能用来设成锁屏密码!果然,新的一年我更加博学了呢. 你们平时都用什么锁屏密码? 是最原始 ...
- Exchange2003表单和OWA选项中更改密码设置
Exchange2003表单和OWA选项中更改密码设置 转载于:https://blog.51cto.com/767293/472043
最新文章
- hdu 1828 pku 1177 Picture
- android 动画 返回,Android TranslateAnimation在动画后重置
- 【控制】《多无人机协同控制技术》周伟老师-第12章-基于 Multi-Agent 的多无人机协同控制仿真平台的设计与实现
- python输出日志文件_python将print输出的信息保留到日志文件中
- 国网浙江电力组建网络安全分析室
- 2009年岁末年总结
- 恭贺微软技术俱乐部苏州站正式成立
- 菜鸟学习数据科学家 5 大误区
- oracle 产看执行计划_ODBA 技能SPM计划
- 6、java中的排序算法
- 如何启动多个WebLogic托管服务器
- centos7.3下apache搭建django[未成功]
- 一篇英文文档中找出频数最多的10个单词
- mysql key_len_浅谈mysql explain中key_len的计算方法
- Angular5--viewChild/viewChildren、contentChild/contentChildren使用规则小结
- html lab颜色,颜色标准LAB值对照表
- spring整合WebService入门详解
- oracle svip地址,木子李QQ8.9 显IP地址SVIP完整版
- iis 10 配置 URL重写不生效
- 第八章 STM32+SGP气体传感器+DHT11温湿度传感器+OLED模块显示室内温湿度、二氧化碳和甲醛浓度