如果Hadoop得core-site.xml中的fs.defaultFS配置由於多種原因(集群遷移、集群升級、NameNode主機名更改等)需要更改,會導致Hive無法通過元數據找到的數據存儲地址,因此需要對元數據數據庫中的地址更新。
報錯場景:
解決方案:
1. 直接去數據庫中修改。我們知道,Hive的元數據信息是存放在關系型數據庫中的,我們只要找到存放這些數據的Table,然后用SQL去修改就行了。但是這樣比較麻煩,你還得去登錄數據庫,最重要的是這樣還很容易出錯,所以不推薦使用。
2. 使用Hive自帶命令修改(推薦)。Hive自帶了修改元素相關的命令,我們可以直接使用bin/metatool命令去修改。查看該工具有什么功能。
bin/metatool -help
Initializing HiveMetaTool.. usage: metatool -dryRun Perform a dry run of updateLocation changes.When run with the dryRun option updateLocation changes are displayed
but not persisted. dryRun is valid only with the updateLocation option. -executeJDOQL <query-string> execute the given JDOQL query -help print this message -listFSRoot
print the current FS root locations -serdePropKey <serde-prop-key> Specify the key for serde property to be updated. serdePropKey option is valid only with updateLocation
option. -tablePropKey <table-prop-key> Specify the key for table property to be updated. tablePropKey option is valid only with updateLocation option.
-updateLocation <new-loc> <old-loc> Update FS root location in the metastore to new location.Both new-loc and old-loc should be valid URIs with valid host names and
schemes.When run with the dryRun option changes are displayed but are not persisted. When run with the serdepropKey/tablePropKey option updateLocation looks for the
serde-prop-key/table-prop-key that is specified and updates its value if found.
然后進入Mysql數據庫查詢:
在Hive目錄下執行元數據工具更新地址:
# 命令格式如metatool -updateLocation newPath oldPath
./bin/metatool -updateLocation hdfs://hadoop:9000/user/hive/warehouse hdfs://192.168.87.140:9000/user/hive/warehouse
更新完之后,我們可以再看下FS Roots信息是否修改完成:
./bin/metatool -listFSRoot
已成功修改!