在观察索引时一般习惯用es-head,如果你的运维加了安全限制你该怎么办?
1、ES安全主要是加xpack,这个需要我们在使用访问es-head:9100后面加base_uri=&auth_user&auth_password就可以了 这个信息被es-head打开时就会读取并发送给ES做安全验证。
<html>
<head>
<meta charset="UTF-8">
<title>elasticsearch-head</title>
<link rel="stylesheet" href="base/reset.css">
<link rel="stylesheet" href="vendor.css">
<link rel="stylesheet" href="app.css">
<script src="i18n.js" data-baseDir="lang" data-langs="en,fr,pt,zh,zh-TW,tr,ja"></script>
<script src="vendor.js"></script>
<script src="app.js"></script>
<script>window.onload = function() {
if (location.href.contains("/_plugin/")) {
var base_uri = location.href.replace(/_plugin/.*/, '');
}
var args = location.search.substring(1).split("&").reduce(function(r, p) {
r[decodeURIComponent(p.split("=")[0])] = decodeURIComponent(p.split("=")[1]);
return r;
},
{}); // 在这一部分获取 用户名 密码 new app.App("body", { id: "es", base_uri: args["base_uri"] || base_uri, auth_user : args["auth_user"] || "", auth_password : args["auth_password"], dashboard: args["dashboard"] }); };
</script>
<link rel="icon" href="base/favicon.png" type="image/png"></head>
<body></body>
</html>
2、如果你的运维用Nigex代码的9200,然后在Nigex上加了 auth_basic、auth_basic_user_file “HTTP基本认证”(HTTP Basic Authentication)协议的用户名密码验证。指定的参数被用作域。这该怎么办
我之前用的是静态es-head,就是打开index.html页面使用这样很不规范,发现连接不上连接,点击连接无反应报跨域问题,查看一下浏览器连接情况 如下:
这个是就用了静态html访问的原因,那就换es-head服务,安装后打开9100然后依然无反应依然报跨域问题?
报错信息:
Access to XMLHttpRequest at ‘http://xx.xx.xx.xx:9200/_cluster/health’ from origin ‘null’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
![2063b41d6653214c2db646f503db1cbf.png](https://img-blog.csdnimg.cn/img_convert/2063b41d6653214c2db646f503db1cbf.png)
尝试安装es-head服务,安装后打开9100服务依然无法连接并报相同错误。
![7e12b8ace77199940f0bce7bf248b78f.png](https://img-blog.csdnimg.cn/img_convert/7e12b8ace77199940f0bce7bf248b78f.png)
研究下es-head的git项目发现可以安装Chrome插件elasticsearch-head,安装一个试试,克隆源码后各种安装不上,无意间到Chrome商店看了下有这东西,简单安装,打开,输入用户名密码(之前没有发现有输入框),这个输入框应该来自于Nigex,输入后可以正常连接了。
es-head Chrome插件地址:https://chrome.google.com/webstore/detail/elasticsearch-head/ffmkiejjmecolpfloofpjologoblkegm/related
也可以下载:https://www.crx4chrome.com/crx/57382/
![5ebf6c9792ec214215bbaa9c13bbac9e.png](https://img-blog.csdnimg.cn/img_convert/5ebf6c9792ec214215bbaa9c13bbac9e.png)
![aac508e2555073c60605bdf0df780cf6.png](https://img-blog.csdnimg.cn/img_convert/aac508e2555073c60605bdf0df780cf6.png)
3、如果用程序连接带有Nigex安全限制的ES可以使用以下形式
public void initES2(){ HttpHost host=new HttpHost("xx.xx.xx.xx",9200); RestClientBuilder builder=RestClient.builder(host); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin","admin")); builder.setHttpClientConfigCallback(f -> f.setDefaultCredentialsProvider(credentialsProvider)); clientES = new RestHighLevelClient( builder); }
如果喜欢搜索技术来我的公众号吧 'Lucene Elasticsearch 工作积累'
公众号会持续更新,谢谢!
![dfc2b09dcf955c6e03d49795eeed6e13.png](https://img-blog.csdnimg.cn/img_convert/dfc2b09dcf955c6e03d49795eeed6e13.png)