Replicate hive metastore from the cluster to another one
- Run maven build:
mvn clean package -DskipTests
Maven will produce two results:
- directory
target/hive-metastore-sync-<version>/ - zip archive
target/hive-metastore-sync-<version>.zip
- Need installed docker and direct access to internet
- Run the tests:
mvn test
Test suite starts/restarts hadoop and hive every time you run it. You can cut this time by specifying parameter skipStart:
mvn test -DskipStart=true
To run hive-metastore-sync from shell:
<install-dir>/bin/hivesync [parameters]
Log4j2 configuration is stored in <install-dir>/conf/log4j2.xml
The default configuration file produces log file /tmp/hive-metastore-sync.txt
To configure secure Hive sync, you must configure cross realm support for Kerberos and Hadoop
- Create krbtgt principals for the two realms. For example, if you have two realms called SRC.COM and DST.COM, then you need to add the following principals: krbtgt/SRC.COM@DST.COM and krbtgt/DST.COM@SRC.COM. Add these two principals at both realms. Note that passwords should be the same for both realms:
kadmin: addprinc krbtgt/SRC.COM@DST.COM
kadmin: addprinc krbtgt/DST.COM@SRC.COM
- You would need to add respective auth_to_local mapping for SRC cluster principals into your destination cluster Hadoop configuration core-site.xml file. For example, to add maopping for the hdfs/SRC.COM principal into destination cluster:
core-site.xml
<property>
<name>hadoop.security.auth_to_local</name>
<value>
RULE:[2:$1@$0](hdfs@SRC.COM)s/.*/hdfs/
RULE:[1:$1@$0](hdfs@SRC.COM)s/.*/hdfs/
DEFAULT
</value>
</property>
- Add destination realm into /etc/krb5.conf on source cluster:
/etc/krb5.conf
[realms]
...
DST.COM = {
admin_server = admin_server.dst.com
kdc = kdc_server.dst.com
}
[domain_realm]
.dst.com = DST.COM
dst.com = DST.COM
- Add source realm into /etc/krb5.conf on destination cluster:
/etc/krb5.conf
[realms]
...
SRC.COM = {
admin_server = admin_server.src.com
kdc = kdc_server.src.com
}
[domain_realm]
.src.com = SRC.COM
src.com = SRC.COM
- How to check that kerberos has been configured correctly: On the destination cluster check that principal from the source cluster could be mapped correctly:
$ hadoop org.apache.hadoop.security.HadoopKerberosName hdfs@SRC.COM
On the source cluster run beeline and simple query (hive principal is used there):
$ beeline
beeline> !connect jdbc:hive2://hiveserver.dst.com:10000/default;principal=hive/dst.com@DST.COM
beeline> show tables;
- Use
--dry-runto generate log with hive commands:
<install-dir>/bin/hivesync --dry-run --src-meta "thrift://hms.src.com:9083" --dst-meta "thrift://hms.dst.com:9083"
- Review output log and run the same command again, but without
--dry-runparameter to start syncing.
docker compose -f hive1.yaml up -d
docker compose -f hive2.yaml up -d
docker exec -it hive1-hiveserver-1 beeline -u 'jdbc:hive2://localhost:10000/'
docker exec -it hive2-hiveserver-1 beeline -u 'jdbc:hive2://localhost:10000/'