本套技术专栏是作者(秦凯新)平时工作的总结和升华,通过从真实商业环境抽取案例进行总结和分享,并给出商业应用的调优建议和集群环境容量规划等内容,请持续关注本套博客。期待加入IOT时代最具战斗力的团队。QQ邮箱地址:1120746959@qq.com,如有任何学术交流,可随时联系。
1 core-site.xml 配置:
-
1:配置统一视图viewfs:///
-
2: 配置不同命名空间下,每一个HDFS实例默认的访问空间,注意不是主机名。比如:
<configuration> <property> <name>fs.defaultFS</name> <value>viewfs:///</value> </property> <property> <name>fs.viewfs.mounttable.default.link./my</name> <value>hdfs://mycluster/</value> </property> <property> <name>fs.viewfs.mounttable.default.link./your</name> <value>hdfs://yourcluster/</value> </property> <property> <name>ha.zookeeper.quorum</name> <value>Master:2181,Worker1:2181,Worker2:2181</value> </property> <property> <name>hadoop.tmp.dir</name> <value>/home/tmp/hadoop2.0</value> </property> </configuration>
2 hdfs-site.xml 配置:
-
1:指定dfs.nameservices,也即Hdfs实例两个。比如:mycluster,yourcluster
-
2:指定两个Hdfs实例mycluster和yourcluster的namenode Id 比如:nn1,nn2
-
3:设置两个Hdfs实例mycluster和yourcluster对应的两个namenode(ANN,SNN)实例对应的rpc-address(4个)和http-address(4个)。比如:
namenode1:9000(ANN),namenode2:9000(SNN)| namenode3:9000,namenode4:9000 namenode1:50070,namenode2:50070|namenode3:50070,namenode4:50070
-
4:指定自动容错机制automatic-failover,比如:设置为True
-
5:指定共享存储指定目录shared.edits.dir。比如:路径为
qjournal://Master:8485;Worker1:8485;Worker2:8485/mycluster 和qjournal://Master:8485;Worker1:8485;Worker2:8485/yourcluster
-
6 总览配置
<configuration> <property> <name>dfs.nameservices</name> <value>mycluster,yourcluster</value> </property> <property> <name>dfs.ha.namenodes.mycluster</name> <value>nn1,nn2</value> </property> <property> <name>dfs.ha.namenodes.yourcluster</name> <value>nn1,nn2</value> </property> <property> <name>dfs.namenode.rpc-address.mycluster.nn1</name> <value>namenode1:9000</value> </property> <property> <name>dfs.namenode.rpc-address.mycluster.nn2</name> <value>namenode2:9000</value> </property> <property> <name>dfs.namenode.rpc-address.yourcluster.nn1</name> <value>namenode3:9000</value> </property> <property> <name>dfs.namenode.rpc-address.yourcluster.nn2</name> <value>namenode4:9000</value> </property> <property> <name>dfs.namenode.http-address.mycluster.nn1</name> <value>namenode1:50070</value> </property> <property> <name>dfs.namenode.http-address.mycluster.nn2</name> <value>namenode2:50070</value> </property> <property> <name>dfs.namenode.http-address.yourcluster.nn1</name> <value>namenode3:50070</value> </property> <property> <name>dfs.namenode.http-address.yourcluster.nn2</name> <value>namenode4:50070</value> </property> <property> <name>dfs.journalnode.edits.dir</name> <value>/usr/local/soft/cdh_support/hadoop-2.6.0-cdh5.9.3/journal</value> </property> <property> <name>dfs.namenode.shared.edits.dir</name> <value>qjournal://Master:8485;Worker1:8485;Worker2:8485/mycluster</value> </property> <property> <name>dfs.namenode.shared.edits.dir</name> <value>qjournal://Master:8485;Worker1:8485;Worker2:8485/yourcluster</value> </property> <property> <name>dfs.client.failover.proxy.provider.my-cluster</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property> <property> <name>dfs.client.failover.proxy.provider.yourcluster</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property> <property> <name>dfs.ha.fencing.methods</name> <value>sshfence</value> </property> <property> <name>dfs.ha.fencing.ssh.private-key-files</name> <value>/home/admin/.ssh/id_rsa</value> </property> <property> <name>dfs.ha.fencing.ssh.connect-timeout</name> <value>6000</value> </property> <property> <name>dfs.ha.automatic-failover.enabled</name> <value>true</value> </property> <property> <name>dfs.replication</name> <value>3</value> </property> <property> <name>dfs.datanode.max.xcievers</name> <value>8192</value> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:/hadoop/datanode</value> </property> <property> <name>dfs.namenode.datanode.registration.ip-hostname-check</name> <value>false</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>file:/hadoop/namenode</value> </property> <property> <name>dfs.permissions</name> <value>false</value> </property> </configuration>
3 参数设置
dfs.namenode.shared.edits.dir
这个参数要注意,在两组HA中的值是不一样的,即在“mycluster”(namenode1和namenode2)和是“yourcluster”(namenode3和namenode4)中不同。
4 管理
1 先启动journalnode,在journalnode节点上执行以下命令
$HADOOP_HOME/sbin/hadoop-daemon.sh start journalnode
2在namenode1和namenode3上执行格式化命令并启动namenode
$HADOOP_HOME/bin/hdfs namenode -format –clusterId hellokitty
$HADOOP_HOME/sbin/hadoop-daemon.sh start namenode
3 在namenode2和namenode4上执行bootstrapStandby命令并启动namenode
$HADOOP_HOME/sbin/hadoop-daemon.sh start namenode -bootstrapStandby
$HADOOP_HOME/sbin/hadoop-daemon.sh start namenode
这时namenode1,namenode2,namenode3,namenode4四个namenode都是“standby”状态。
4 在namenode1和namenode3执行以下命令,切换成“active”状态
$HADOOP_HOME/bin/hdfs haadmin -transitionToActive nn1
5 在zookeeper中初始化
$HADOOP_HOME/bin/hdfs zkfc -formatZK
6 启动zkfc daemon进程,在namenode1,namenode2,namenode3,namenode4上都启动zkfc daemon进程。
$HADOOP_HOME/sbin/hadoop-daemon.sh start zkfc
5 总结
秦凯新 于深圳