elasticsearch之shield插件安装文档

来源:互联网 发布:朝鲜2015gdp数据 编辑:程序博客网 时间:2024/06/11 00:31

elasticsearch之shield插件安装文档

默认情况下elasticsearch可以不受限制访问,如果在外网的情况下就不安全了,所以,elastic官方提供了shield插件,可以实现权限控制,但是不好的地方就是这个插件是收费的,可以免费试用一个月。那我们就来试试吧!
The Shield plugin must be installed on every node in the cluster and every node must be restarted after installation. Plan for a complete cluster restart before beginning the installation process.

Shield 插件必须安装在集群中的每一个节点,并且每一个节点在安装完成之后必须要重启才能生效。
在开始安装过程之前进行完整的集群重新启动的计划。

To install Shield 2.4.3, you need:
在安装Shield 2.4.3之前,你需要保证下面条件

Java 7 or later
Elasticsearch 2.4.3
Elasticsearch License 2.4.3 plugin

note:You must run the version of Shield that matches the version of Elasticsearch you are running
注意:你必须保证Shield的版本和你运行的Elasticsearch的版本保持一致。

安装shield
1:先安装license
bin/plugin install license

2:安装shield插件
bin/plugin install shield

安装的时候会提示,输入Y确认即可
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: plugin requires additional permissions @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* java.lang.RuntimePermission setFactory
See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html
for descriptions of what these permissions allow and the associated risks.

Continue with installation? [y/N]y

3:【默认这一步不需要操作,因为默认情况下es并没有禁用自动创建索引库功能】If you have disabled automatic index creation in Elasticsearch, configure action.auto_create_index in elasticsearch.yml to allow Shield to create the .security index:
如果你在es中禁用了自动创建索引库的功能。那么你需要在elasticsearch.yml中配置action.auto_create_index 以便允许Shield去创建.security 索引库。
action.auto_create_index: .security
4:启动/重启es
bin/elasticsearch

创建用户:

用户级别

admin
Can perform any cluster or index action.
可以对就所有集群或者索引库执行操作
power_user
Can monitor the cluster and perform any index action.
可以监控集群并且对所有索引库执行操作
user
Can perform read actions on any index.

可以对所有索引库执行read操作

创建用户命令:【执行之后会提示用户设置密码】
bin/shield/esusers useradd es_admin -r admin
解释:
useradd:表示添加用户
es_admin:表示要新建的用户名称
-r:指定权限信息
admin:给新建的用户赋予admin权限

note:When prompted, enter a password for the new user. Passwords must be at least 6 characters long.
注意:当提示输入密码的时候,给新用户设置一个新密码,密码必须至少包含6个字符

访问es:-u es_admin 表示使用用户es_admin进行访问
curl -u es_admin -XGET ‘http://localhost:9200/’

访问的会提示输入刚才设置的密码。
这样以后再访问es的时候就需要输入用户名和密码了。

kibana中也能使用shield
https://www.elastic.co/guide/en/shield/current/kibana.html

If your security requirements are more complex, you can also:
如果您的安全要求更复杂,你可以这样做
https://www.elastic.co/guide/en/shield/current/enable-basic-auth.html
1:Define and Use Custom Roles for fine-grained access control.
定义和使用细粒度访问控制的自定义角色
2:Integrate with LDAP or Active Directory, or require certificates for authentication.
使用LDAP或Active Directory集成,或使用证书的认证。
3:Use IP Filtering to allow or deny requests from particular IP addresses or address ranges.
使用IP过滤来自特定IP地址或地址范围的请求
https://www.elastic.co/guide/en/shield/current/ip-filtering.html

开启shield之后,使用javaapi操作需要执行下面步骤
https://www.elastic.co/guide/en/shield/current/_using_elasticsearch_java_clients_with_shield.html
1:在java项目中的pom文件中添加maven依赖



elasticsearch-releases
https://maven.elasticsearch.org/releases

true


false




org.elasticsearch.plugin
shield
2.4.3

注意:shield的maven依赖版本必须是2.4.3的,官方例子写的是2.2.0的无法正常运行。因为我们的shield安装的版本也是2.4.3、要保持版本一致。

2:代码如下:
Settings settings = Settings.settingsBuilder()
.put(“cluster.name”, “elasticsearch”)
//设置shield创建的用户名和密码
.put(“shield.user”, “es_admin:123456”)
.build();
TransportClient client = TransportClient.builder()
//添加shield plugin
.addPlugin(ShieldPlugin.class)
.settings(settings).build();
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(“192.168.80.100”), 9300));

卸载shield
To uninstall Shield:
如果不想使用shield,需要移除掉。

1:停止es
2:从es中移除shield插件:
bin/plugin remove shield

3:启动es.

链接:http://www.bigdata1024.com/?p=41

0 0
原创粉丝点击