Hdfs主备切换导致spark应用中断

场景:使用structured streaming消费kafka中数据写入hdfs中

说明:集群有两个namenode,分别为node1,node2。起初node1状态为active,在程序中涉及hdfs路径的地方,写的是hdfs://node1:8020/your path。后来集群中node1为standby状态,node2为active状态,spark应用就会中断,除非将hdfs路径修改为hdfs://node2:8020/your path。这样操作很麻烦,每次node1,node2状态调整都会影响spark程序,那么有没有什么方法可以避免这种操作?

解决:涉及hdfs路径hdfs://node1:8020/your path,可以将node1:8020修改为参数dfs.nameservices的值,比如dfs.nameservices=nameservice1,则此时hdfs路径为hdfs://nameservice1/your path,其中参数dfs.nameservices可以去hdfs-site.xml中查找,或者core-site.xml中参数fs.defaultFS的值。

posted @ 2022-03-24 12:40  linhaifeng  阅读(191)  评论(0编辑  收藏  举报