本文主要记录安装和配置Sentry的过程,关于Sentry的介绍,请参考Apache Sentry架构介绍

1. 环境说明

系统环境:

  • 操作系统:CentOs 6.6
  • Hadoop版本:CDH5.4
  • 运行用户:root

这里,我参考使用yum安装CDH Hadoop集群一文搭建了一个测试集群,并选择cdh1节点来安装sentry服务。

2. 安装

在cdh1节点上运行下面命令查看Sentry的相关组件有哪些:

  1. $ yum list sentry*
  2. sentry.noarch 1.4.0+cdh5.4.0+155-1.cdh5.4.0.p0.47.el6 @cdh
  3. sentry-hdfs-plugin.noarch 1.4.0+cdh5.4.0+155-1.cdh5.4.0.p0.47.el6 @cdh
  4. sentry-store.noarch 1.4.0+cdh5.4.0+155-1.cdh5.4.0.p0.47.el6 @cdh

以上组件说明:

  • sentry:sentry的基本包
  • sentry-hdfs-plugin:hdfs插件
  • sentry-store:sentry store组件

这里安装以上所有组件:

  1. $ yum install sentry* -y

3. 配置

参考sentry-site.xml.service.template,来修改Sentry的配置文件 /etc/sentry/conf/sentry-site.xml。

配置 sentry service 相关的参数

  1. <property>
  2. <name>sentry.service.admin.group</name>
  3. <value>impala,hive,solr,hue</value>
  4. </property>
  5. <property>
  6. <name>sentry.service.allow.connect</name>
  7. <value>impala,hive,solr,hue</value>
  8. </property>
  9. <property>
  10. <name>sentry.verify.schema.version</name>
  11. <value>false</value>
  12. </property>
  13. <property>
  14. <name>sentry.service.reporting</name>
  15. <value>JMX</value>
  16. </property>
  17. <property>
  18. <name>sentry.service.server.rpc-address</name>
  19. <value>cdh1</value>
  20. </property>
  21. <property>
  22. <name>sentry.service.server.rpc-port</name>
  23. <value>8038</value>
  24. </property>
  25. <property>
  26. <name>sentry.service.web.enable</name>
  27. <value>true</value>
  28. </property>

如果需要使用kerberos认证,则还需要配置以下参数:

  1. <property>
  2. <name>sentry.service.security.mode</name>
  3. <value>kerberos</value>
  4. </property>
  5. <property>
  6. <name>sentry.service.server.principal</name>
  7. <value></value>
  8. </property>
  9. <property>
  10. <name>sentry.service.server.keytab</name>
  11. <value></value>
  12. </property>

配置 sentry store 相关参数

sentry store可以使用两种方式,如果使用基于SimpleDbProviderBackend的方式,则需要设置jdbc相关的参数:

  1. <property>
  2. <name>sentry.store.jdbc.url</name>
  3. <value>jdbc:postgresql://cdh1:5432/sentry</value>
  4. </property>
  5. <property>
  6. <name>sentry.store.jdbc.driver</name>
  7. <value>org.postgresql.Driver</value>
  8. </property>
  9. <property>
  10. <name>sentry.store.jdbc.user</name>
  11. <value>sentry</value>
  12. </property>
  13. <property>
  14. <name>sentry.store.jdbc.password</name>
  15. <value>sentry</value>
  16. </property>

Sentry store的组映射sentry.store.group.mapping有些两种配置方式:org.apache.sentry.provider.common.HadoopGroupMappingService或者org.apache.sentry.provider.file.LocalGroupMapping,当使用后者的时候,还需要配置sentry.store.group.mapping.resource参数,即设置Policy file的路径。

  1. <property>
  2. <name>sentry.store.group.mapping</name>
  3. <value>org.apache.sentry.provider.common.HadoopGroupMappingService</value>
  4. </property>
  5. <property>
  6. <name>sentry.store.group.mapping.resource</name>
  7. <value> </value>
  8. <description> Policy file for group mapping. Policy file path for local group mapping, when sentry.store.group.mapping is set to LocalGroupMapping Service class.</description>
  9. </property>

配置客户端的参数:

配置Sentry和hive集成时的服务名称,默认值为HS2,这里设置为server1:

  1. <property>
  2. <name>sentry.hive.server</name>
  3. <value>server1</value>
  4. </property>

初始化数据库

如果配置 sentry store 使用 posrgres 数据库,当然你也可以使用其他的数据库,则需要创建并初始化数据库。数据库的创建过程,请参考 Hadoop自动化安装shell脚本,下面列出关键脚本。

  1. yum install postgresql-server postgresql-jdbc -y
  2. ln -s /usr/share/java/postgresql-jdbc.jar /usr/lib/hive/lib/postgresql-jdbc.jar
  3. ln -s /usr/share/java/postgresql-jdbc.jar /usr/lib/sentry/lib/postgresql-jdbc.jar
  4. su -c "cd ; /usr/bin/pg_ctl start -w -m fast -D /var/lib/pgsql/data" postgres
  5. su -c "cd ; /usr/bin/psql --command \"create user sentry with password 'sentry'; \" " postgres
  6. su -c "cd ; /usr/bin/psql --command \"drop database sentry;\" " postgres
  7. su -c "cd ; /usr/bin/psql --command \"CREATE DATABASE sentry owner=sentry;\" " postgres
  8. su -c "cd ; /usr/bin/psql --command \"GRANT ALL privileges ON DATABASE sentry TO sentry;\" " postgres
  9. su -c "cd ; /usr/bin/pg_ctl restart -w -m fast -D /var/lib/pgsql/data" postgres

然后,修改 /var/lib/pgsql/data/pg_hba.conf 内容如下:

  1. # TYPE DATABASE USER CIDR-ADDRESS METHOD
  2. # "local" is for Unix domain socket connections only
  3. local all all md5
  4. # IPv4 local connections:
  5. #host all all 0.0.0.0/0 trust
  6. host all all 127.0.0.1/32 md5
  7. # IPv6 local connections:
  8. #host all all ::1/128 nd5

如果是第一次安装,则初始化 sentry 的元数据库:

  1. $ sentry --command schema-tool --conffile /etc/sentry/conf/sentry-site.xml --dbType postgres --initSchema
  2. Sentry store connection URL: jdbc:postgresql://cdh1/sentry
  3. Sentry store Connection Driver : org.postgresql.Driver
  4. Sentry store connection User: sentry
  5. Starting sentry store schema initialization to 1.4.0-cdh5-2
  6. Initialization script sentry-postgres-1.4.0-cdh5-2.sql
  7. Connecting to jdbc:postgresql://cdh1/sentry
  8. Connected to: PostgreSQL (version 8.4.18)
  9. Driver: PostgreSQL Native Driver (version PostgreSQL 9.0 JDBC4 (build 801))
  10. Transaction isolation: TRANSACTION_REPEATABLE_READ
  11. Autocommit status: true
  12. 1 row affected (0.002 seconds)
  13. No rows affected (0.004 seconds)
  14. Closing: 0: jdbc:postgresql://cdh1/sentry
  15. Initialization script completed
  16. Sentry schemaTool completed

如果是更新,则执行:

  1. $ sentry --command schema-tool --conffile /etc/sentry/conf/sentry-site.xml --dbType postgres --upgradeSchema

4. 启动

在cdh1上启动sentry-store服务:

  1. $ /etc/init.d/sentry-store start

查看日志:

  1. $ cat /var/log/sentry/sentry-store.out

查看sentry的web监控界面http://cdh1:51000/

5. 参考文章