大数据技术之Hadoop3.1.2版本HA模式
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.Hadoop的HA特点
1>.主备NameNode
2>.解决单点故障(属性,位置)
1.主NameNode对外提供服务,备NameNode同步主NameNode元数据一带切换; 2.所有DataNode同时向两个NameNode汇报数据块信息(位置); 3.JNN:集群(属性); 4.Standby:备,完成了edits.log文件的合并产生新的image,推送回ANN;
3>.两种切换选择
1.手动切换 通过命令实现主备之间的切换,可以用HDFS升级等场合。 2.自动切换 基于Zookeeper实现。
4>.基于zookeeper自动切换方案
1.Zookeeper Failover Controller进程用于监控NameNode监控状态; 2.并向zookeeper注册NameNode; 3.NameNode挂掉后,ZKFC为NameNode竞争锁,获得ZKFC锁的NameNode变为active;
5>.配置Hadoop3.1.2的官方文档(http://hadoop.apache.org/docs/r3.1.2/hadoop-project-dist/hadoop-hdfs/HDFSHighAvailabilityWithQJM.html)
二.zookeeper完全分布式集群搭建
1>.下载zookeeper软件(下载地址:https://www.apache.org/dyn/closer.cgi/zookeeper/)
[[email protected] ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz --2019-04-12 08:48:40-- https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1 Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 37676320 (36M) [application/x-gzip] Saving to: ‘zookeeper-3.4.14.tar.gz’ 100%[============================================================================================================================================>] 37,676,320 7.57MB/s in 4.5s 2019-04-12 08:48:45 (7.94 MB/s) - ‘zookeeper-3.4.14.tar.gz’ saved [37676320/37676320] [[email protected] ~]#
2>.加压zookeeper并配置环境变量
[[email protected] ~]# tar -zxf zookeeper-3.4.14.tar.gz -C /yinzhengjie/softwares/ [[email protected] ~]# [[email protected] ~]# ll /yinzhengjie/softwares/zookeeper-3.4.14/ total 1672 drwxr-xr-x 2 2002 2002 202 Mar 6 09:09 bin -rw-rw-r-- 1 2002 2002 97426 Mar 6 08:50 build.xml drwxr-xr-x 2 2002 2002 77 Mar 6 09:09 conf drwxr-xr-x 2 2002 2002 4096 Mar 6 09:10 dist-maven -rw-rw-r-- 1 2002 2002 1709 Mar 6 08:50 ivysettings.xml -rw-rw-r-- 1 2002 2002 10742 Mar 6 08:50 ivy.xml drwxr-xr-x 4 2002 2002 308 Mar 6 09:09 lib -rw-rw-r-- 1 2002 2002 11970 Mar 6 08:50 LICENSE.txt -rw-rw-r-- 1 2002 2002 3132 Mar 6 08:50 NOTICE.txt -rw-rw-r-- 1 2002 2002 31622 Mar 6 08:50 pom.xml -rw-rw-r-- 1 2002 2002 1765 Mar 6 08:50 README.md -rw-rw-r-- 1 2002 2002 1770 Mar 6 08:50 README_packaging.txt drwxr-xr-x 3 2002 2002 22 Mar 6 08:50 src -rw-rw-r-- 1 2002 2002 1515359 Mar 6 08:50 zookeeper-3.4.14.jar -rw-rw-r-- 1 2002 2002 836 Mar 6 09:10 zookeeper-3.4.14.jar.asc -rw-rw-r-- 1 2002 2002 33 Mar 6 08:50 zookeeper-3.4.14.jar.md5 -rw-rw-r-- 1 2002 2002 41 Mar 6 08:50 zookeeper-3.4.14.jar.sha1 drwxr-xr-x 3 2002 2002 47 Mar 6 09:09 zookeeper-client drwxr-xr-x 12 2002 2002 4096 Mar 6 09:09 zookeeper-contrib drwxr-xr-x 7 2002 2002 4096 Mar 6 09:09 zookeeper-docs drwxr-xr-x 3 2002 2002 35 Mar 6 09:09 zookeeper-it drwxr-xr-x 4 2002 2002 46 Mar 6 09:09 zookeeper-jute drwxr-xr-x 5 2002 2002 176 Mar 6 09:09 zookeeper-recipes drwxr-xr-x 3 2002 2002 32 Mar 6 09:09 zookeeper-server [[email protected] ~]# [[email protected] ~]#
[[email protected] ~]# tail -3 /etc/profile #ADD ZOOKEEPER_HOME PATH ZOOKEEPER_HOME=/yinzhengjie/softwares/zookeeper-3.4.14 PATH=$PATH:$ZOOKEEPER_HOME/bin [[email protected] ~]# [[email protected] ~]# source /etc/profile [[email protected] ~]#
3>.配置zookeeper的配置文件
[[email protected] ~]# cp /yinzhengjie/softwares/zookeeper-3.4.14/conf/zoo_sample.cfg /yinzhengjie/softwares/zookeeper-3.4.14/conf/zoo.cfg [[email protected] ~]# [[email protected] ~]# ll /yinzhengjie/softwares/zookeeper-3.4.14/conf/ total 16 -rw-rw-r-- 1 2002 2002 535 Mar 6 08:50 configuration.xsl -rw-rw-r-- 1 2002 2002 2161 Mar 6 08:50 log4j.properties -rw-r--r-- 1 root root 922 Apr 12 08:55 zoo.cfg -rw-rw-r-- 1 2002 2002 922 Mar 6 08:50 zoo_sample.cfg [[email protected] ~]# [[email protected] ~]#
[[email protected] ~]# cat /yinzhengjie/softwares/zookeeper-3.4.14/conf/zoo.cfg # 滴答,计时的基本单位,默认是2000毫秒,即2秒。它是zookeeper最小的时间单位,用于丈量心跳时间和超时时间等,通常设置成默认2秒即可。 tickTime=2000 # 初始化限制是10滴答,默认是10个滴答,即默认是20秒。指定follower节点初始化是链接leader节点的最大tick次数。 initLimit=5 # 数据同步的时间限制,默认是5个滴答,即默认时间是10秒。设定了follower节点与leader节点进行同步的最大时间。与initLimit类似,它也是以tickTime为单位进行指定的。 syncLimit=2 # 指定zookeeper的工作目录,这是一个非常重要的参数,zookeeper会在内存中在内存只能中保存系统快照,并定期写入该路径指定的文件夹中。生产环境中需要注意该文件夹的磁盘占用情况。 dataDir=/home/yinzhengjie/zookeeper # 监听zookeeper的默认端口。zookeeper监听客户端链接的端口,一般设置成默认2181即可。 clientPort=2181 # 这个操作将限制连接到 ZooKeeper 的客户端的数量,限制并发连接的数量,它通过 IP 来区分不同的客户端。此配置选项可以用来阻止某些类别的 Dos 攻击。将它设置为 0 或者忽略而不进行设置将会取消对并发连接的限制。 #maxClientCnxns=60 # 在上文中已经提到,3.4.0及之后版本,ZK提供了自动清理事务日志和快照文件的功能,这个参数指定了清理频率,单位是小时,需要配置一个1或更大的整数,默认是0,表示不开启自动清理功能。 #autopurge.purgeInterval=1 # 这个参数和上面的参数搭配使用,这个参数指定了需要保留的文件数目。默认是保留3个。 #autopurge.snapRetainCount=3 #server.x=[hostname]:nnnnn[:nnnnn],这里的x是一个数字,与myid文件中的id是一致的。右边可以配置两个端口,第一个端口用于F和L之间的数据同步和其它通信,第二个端口用于Leader选举过程中投票通信。 server.101=node101.yinzhengjie.org.cn:2888:3888 server.102=node102.yinzhengjie.org.cn:2888:3888 server.103=node103.yinzhengjie.org.cn:2888:3888 [[email protected] ~]#
[[email protected] ~]# cat /yinzhengjie/softwares/zookeeper-3.4.14/conf/java.env #!/bin/bash #@author :yinzhengjie #blog:http://www.cnblogs.com/yinzhengjie #EMAIL:[email protected] #指定JDK的安装路径 export JAVA_HOME=/yinzhengjie/softwares/jdk #指定zookeeper的heap内存大小 export JVMFLAGS="-Xms256m -Xmx256m $JVMFLAGS" [[email protected] ~]# [[email protected] ~]#
4>.编写zookeeper的启动脚本
[[email protected] ~]# vi /usr/local/bin/xzk.sh [[email protected] ~]# [[email protected] ~]# cat /usr/local/bin/xzk.sh #!/bin/bash #@author :yinzhengjie #blog:http://www.cnblogs.com/yinzhengjie #EMAIL:[email protected] #判断用户是否传参 if [ $# -ne 1 ];then echo "无效参数,用法为: $0 {start|stop|restart|status}" exit fi #获取用户输入的命令 cmd=$1 #定义函数功能 function zookeeperManger(){ case $cmd in start) echo "启动服务" remoteExecution start ;; stop) echo "停止服务" remoteExecution stop ;; restart) echo "重启服务" remoteExecution restart ;; status) echo "查看状态" remoteExecution status ;; *) echo "无效参数,用法为: $0 {start|stop|restart|status}" ;; esac } #定义执行的命令 function remoteExecution(){ for (( i=101 ; i<=103 ; i++ )) ; do tput setaf 2 echo ========== node${i}.yinzhengjie.org.cn zkServer.sh $1 ================ tput setaf 9 ssh node${i}.yinzhengjie.org.cn "source /etc/profile ; zkServer.sh $1" done } #调用函数 zookeeperManger [[email protected] ~]#
[[email protected] ~]# ll /usr/local/bin/xzk.sh -rw-r--r-- 1 root root 1125 Apr 12 09:03 /usr/local/bin/xzk.sh [[email protected] ~]# [[email protected] ~]# chmod +x /usr/local/bin/xzk.sh [[email protected] ~]# [[email protected] ~]# ll /usr/local/bin/xzk.sh -rwxr-xr-x 1 root root 1125 Apr 12 09:03 /usr/local/bin/xzk.sh [[email protected] ~]# [[email protected] ~]#
5>.创建myid文件并写入服务器编号
[[email protected] ~]# ansible all -m shell -a 'mkdir /home/yinzhengjie/zookeeper/' [WARNING]: Consider using file module with state=directory rather than running mkdir node101.yinzhengjie.org.cn | SUCCESS | rc=0 >> node103.yinzhengjie.org.cn | SUCCESS | rc=0 >> node102.yinzhengjie.org.cn | SUCCESS | rc=0 >> [[email protected] ~]#
[[email protected] ~]# for (( i=101;i<=103;i++ )) do ssh node${i}.yinzhengjie.org.cn "echo -n $i > /home/yinzhengjie/zookeeper/myid" ;done [[email protected] ~]# [[email protected] ~]# ansible all -m shell -a 'cat /home/yinzhengjie/zookeeper/myid' node103.yinzhengjie.org.cn | SUCCESS | rc=0 >> 103 node102.yinzhengjie.org.cn | SUCCESS | rc=0 >> 102 node101.yinzhengjie.org.cn | SUCCESS | rc=0 >> 101 [[email protected] ~]#
6>.分发配置文件
[[email protected] ~]# scp /etc/profile node102.yinzhengjie.org.cn:/etc/ profile 100% 2127 1.2MB/s 00:00 [[email protected] ~]#
[[email protected] ~]# scp /etc/profile node103.yinzhengjie.org.cn:/etc/ profile 100% 2127 1.4MB/s 00:00 [[email protected] ~]# [[email protected] ~]#
[[email protected] ~]# scp -r /yinzhengjie/softwares/zookeeper-3.4.14/ node102.yinzhengjie.org.cn:/yinzhengjie/softwares/ ........ log.42 100% 184 128.3KB/s 00:00 log.63b 100% 48KB 22.7MB/s 00:00 snapshot.0 100% 296 277.6KB/s 00:00 snapshot.272 100% 55KB 26.5MB/s 00:00 snapshot.273 100% 55KB 24.3MB/s 00:00 snapshot.639 100% 140KB 27.2MB/s 00:00 snapshot.83f 100% 4824 3.5MB/s 00:00 minikdc-krb5.conf 100% 1103 1.3MB/s 00:00 minikdc.ldiff 100% 1630 2.2MB/s 00:00 log.100000001 100% 2401KB 50.2MB/s 00:00 log.100001bf0 100% 1001KB 59.6MB/s 00:00 snapshot.100000000 100% 73 17.1KB/s 00:00 snapshot.100001bec 100% 2507KB 61.6MB/s 00:00 check_compatibility.py 100% 7212 4.7MB/s 00:00 checkstyle-noframes-sorted.xsl 100% 5489 6.5MB/s 00:00 checkstyle.xml 100% 7489 7.3MB/s 00:00 findbugsExcludeFile.xml 100% 5027 6.6MB/s 00:00 log4j.properties 100% 2712 1.9MB/s 00:00 test-patch.properties 100% 855 930.7KB/s 00:00 test-github-pr.sh 100% 24KB 9.7MB/s 00:00 test-patch.sh 100% 24KB 19.4MB/s 00:00 pom.xml 100% 10KB 7.6MB/s 00:00 LICENSE.txt 100% 12KB 5.9MB/s 00:00 NOTICE.txt 100% 3132 1.2MB/s 00:00 README.md 100% 1765 1.4MB/s 00:00 README_packaging.txt 100% 1770 2.5MB/s 00:00 build.xml 100% 95KB 39.5MB/s 00:00 ivy.xml 100% 10KB 8.2MB/s 00:00 ivysettings.xml 100% 1709 1.3MB/s 00:00 pom.xml 100% 31KB 8.9MB/s 00:00 zookeeper-3.4.14.jar 100% 1480KB 41.5MB/s 00:00 zookeeper-3.4.14.jar.md5 100% 33 25.6KB/s 00:00 zookeeper-3.4.14.jar.sha1 100% 41 60.7KB/s 00:00 zookeeper-3.4.14.jar.asc 100% 836 1.2MB/s 00:00 [[email protected] ~]#
[[email protected] ~]# scp -r /yinzhengjie/softwares/zookeeper-3.4.14/ node103.yinzhengjie.org.cn:/yinzhengjie/softwares/ ...... snapshot.273 100% 55KB 14.8MB/s 00:00 snapshot.639 100% 140KB 21.7MB/s 00:00 snapshot.83f 100% 4824 4.4MB/s 00:00 minikdc-krb5.conf 100% 1103 1.0MB/s 00:00 minikdc.ldiff 100% 1630 1.4MB/s 00:00 log.100000001 100% 2401KB 53.2MB/s 00:00 log.100001bf0 100% 1001KB 46.5MB/s 00:00 snapshot.100000000 100% 73 40.2KB/s 00:00 snapshot.100001bec 100% 2507KB 57.4MB/s 00:00 check_compatibility.py 100% 7212 1.4MB/s 00:00 checkstyle-noframes-sorted.xsl 100% 5489 4.4MB/s 00:00 checkstyle.xml 100% 7489 5.0MB/s 00:00 findbugsExcludeFile.xml 100% 5027 4.2MB/s 00:00 log4j.properties 100% 2712 2.5MB/s 00:00 test-patch.properties 100% 855 376.7KB/s 00:00 test-github-pr.sh 100% 24KB 6.3MB/s 00:00 test-patch.sh 100% 24KB 13.5MB/s 00:00 pom.xml 100% 10KB 6.5MB/s 00:00 LICENSE.txt 100% 12KB 4.9MB/s 00:00 NOTICE.txt 100% 3132 2.8MB/s 00:00 README.md 100% 1765 1.9MB/s 00:00 README_packaging.txt 100% 1770 1.6MB/s 00:00 build.xml 100% 95KB 27.3MB/s 00:00 ivy.xml 100% 10KB 10.1MB/s 00:00 ivysettings.xml 100% 1709 1.3MB/s 00:00 pom.xml 100% 31KB 13.6MB/s 00:00 zookeeper-3.4.14.jar 100% 1480KB 42.5MB/s 00:00 zookeeper-3.4.14.jar.md5 100% 33 38.8KB/s 00:00 zookeeper-3.4.14.jar.sha1 100% 41 29.3KB/s 00:00 zookeeper-3.4.14.jar.asc 100% 836 690.2KB/s 00:00 [[email protected] ~]#
7>.启动zookeeper集群
[[email protected] ~]# ansible all -m shell -a 'jps' node101.yinzhengjie.org.cn | SUCCESS | rc=0 >> 10062 Jps node103.yinzhengjie.org.cn | SUCCESS | rc=0 >> 9720 Jps node102.yinzhengjie.org.cn | SUCCESS | rc=0 >> 9759 Jps [[email protected] ~]# [[email protected] ~]#
[[email protected] ~]# xzk.sh start 启动服务 ========== node101.yinzhengjie.org.cn zkServer.sh start ================ ZooKeeper JMX enabled by default Using config: /yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf/zoo.cfg Starting zookeeper ... STARTED ========== node102.yinzhengjie.org.cn zkServer.sh start ================ ZooKeeper JMX enabled by default Using config: /yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf/zoo.cfg Starting zookeeper ... STARTED ========== node103.yinzhengjie.org.cn zkServer.sh start ================ ZooKeeper JMX enabled by default Using config: /yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [[email protected] ~]#
[[email protected] ~]# xzk.sh status 查看状态 ========== node101.yinzhengjie.org.cn zkServer.sh status ================ ZooKeeper JMX enabled by default Using config: /yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf/zoo.cfg Mode: follower ========== node102.yinzhengjie.org.cn zkServer.sh status ================ ZooKeeper JMX enabled by default Using config: /yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf/zoo.cfg Mode: leader ========== node103.yinzhengjie.org.cn zkServer.sh status ================ ZooKeeper JMX enabled by default Using config: /yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf/zoo.cfg Mode: follower [[email protected] ~]#
[[email protected] ~]# ansible all -m shell -a 'jps' node103.yinzhengjie.org.cn | SUCCESS | rc=0 >> 10177 QuorumPeerMain 10279 Jps node102.yinzhengjie.org.cn | SUCCESS | rc=0 >> 10209 QuorumPeerMain 10317 Jps node101.yinzhengjie.org.cn | SUCCESS | rc=0 >> 10765 QuorumPeerMain 10925 Jps [[email protected] ~]#
[[email protected] ~]# zkCli.sh Connecting to localhost:2181 2019-04-12 09:23:04,270 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT 2019-04-12 09:23:04,272 [myid:] - INFO [main:Environment@100] - Client environment:host.name=node101.yinzhengjie.org.cn 2019-04-12 09:23:04,273 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_201 2019-04-12 09:23:04,275 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation 2019-04-12 09:23:04,275 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/yinzhengjie/softwares/jdk1.8.0_201/jre 2019-04-12 09:23:04,275 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/yinzhengjie/softwares/zookeeper-3.4.14/bin/../zookeeper-server/target/classes:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../build/classes:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../zookeeper-server/target/lib/*.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../build/lib/*.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/slf4j-log4j12-1.7.25.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/slf4j-api-1.7.25.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/netty-3.10.6.Final.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/log4j-1.2.17.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/jline-0.9.94.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../lib/audience-annotations-0.5.0.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../zookeeper-3.4.14.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../zookeeper-server/src/main/resources/lib/*.jar:/yinzhengjie/softwares/zookeeper-3.4.14/bin/../conf: 2019-04-12 09:23:04,275 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2019-04-12 09:23:04,275 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2019-04-12 09:23:04,275 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=2019-04-12 09:23:04,275 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2019-04-12 09:23:04,275 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2019-04-12 09:23:04,275 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-957.el7.x86_64 2019-04-12 09:23:04,276 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root 2019-04-12 09:23:04,276 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root 2019-04-12 09:23:04,276 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/root 2019-04-12 09:23:04,277 [myid:] - INFO [main:ZooKeeper@442] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@5ce65a89 Welcome to ZooKeeper! 2019-04-12 09:23:04,303 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1025] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) JLine support is enabled 2019-04-12 09:23:04,365 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@879] - Socket connection established to localhost/127.0.0.1:2181, initiating session 2019-04-12 09:23:04,395 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x6500007f14d00000, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0] ls / [zookeeper] [zk: localhost:2181(CONNECTED) 1] ls /zookeeper [quota] [zk: localhost:2181(CONNECTED) 2] ls /zookeeper/quota [] [zk: localhost:2181(CONNECTED) 3] quit Quitting... 2019-04-12 09:23:13,101 [myid:] - INFO [main:ZooKeeper@693] - Session: 0x6500007f14d00000 closed 2019-04-12 09:23:13,102 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@522] - EventThread shut down for session: 0x6500007f14d00000 [[email protected] ~]# [[email protected] ~]#
三.部署hadoop 3.1.2 HA案例实操(切记,3个namenode之间应该相互配置免密登录哟!)
1>.备份原有的hadoop完全分布式的配置目录
[[email protected] ~]# ll /yinzhengjie/softwares/hadoop-3.1.2/etc/ total 4 drwxr-xr-x 3 1001 1002 4096 Apr 11 09:27 hadoop [[email protected] ~]# [[email protected] ~]# cp -r /yinzhengjie/softwares/hadoop-3.1.2/etc/hadoop/ /yinzhengjie/softwares/hadoop-3.1.2/etc/hadoop-full [[email protected] ~]# [[email protected] ~]# [[email protected] ~]# ll /yinzhengjie/softwares/hadoop-3.1.2/etc/ total 8 drwxr-xr-x 3 1001 1002 4096 Apr 11 09:27 hadoop drwxr-xr-x 3 root root 4096 Apr 12 07:15 hadoop-full [[email protected] ~]# [[email protected] ~]#
2>.编辑hadoop的环境变量配置文件,主要修改各个服务的所属用户
[[email protected] ~]# vi /yinzhengjie/softwares/hadoop-3.1.2/etc/hadoop/hadoop-env.sh [[email protected] ~]# [[email protected] ~]# tail -6 /yinzhengjie/softwares/hadoop-3.1.2/etc/hadoop/hadoop-env.sh #Add Hadoop Path by yinzhengjie export JAVA_HOME=/yinzhengjie/softwares/jdk export HDFS_NAMENODE_USER=root export HDFS_DATANODE_USER=root export HDFS_ZKFC_USER=root export HDFS_JOURNALNODE_USER=root [[email protected] ~]#
3>.编辑core-site.xml配置文件
[[email protected] ~]# cat /yinzhengjie/softwares/hadoop-3.1.2/etc/hadoop/core-site.xml "1.0" encoding="UTF-8"?> "text/xsl" href="configuration.xsl"?>[[email protected] ~]# fs.defaultFS hdfs://yinzhengjie-hdfs hadoop.tmp.dir /data/hadoop/ha hadoop.http.staticuser.user root ha.zookeeper.quorum node101.yinzhengjie.org.cn:2181,node102.yinzhengjie.org.cn:2181,node103.yinzhengjie.org.cn:2181
4>.编辑hdfs-site.xml配置文件
[[email protected] ~]# cat /yinzhengjie/softwares/hadoop-3.1.2/etc/hadoop/hdfs-site.xml "1.0" encoding="UTF-8"?> "text/xsl" href="configuration.xsl"?>dfs.replication 2 dfs.nameservices yinzhengjie-hdfs dfs.ha.namenodes.yinzhengjie-hdfs namenode1,namenode2,namenode3 dfs.namenode.rpc-address.yinzhengjie-hdfs.namenode1 node101.yinzhengjie.org.cn:8020 dfs.namenode.rpc-address.yinzhengjie-hdfs.namenode2 node102.yinzhengjie.org.cn:8020 dfs.namenode.rpc-address.yinzhengjie-hdfs.namenode3 node103.yinzhengjie.org.cn:8020 dfs.namenode.http-address.yinzhengjie-hdfs.namenode1 node101.yinzhengjie.org.cn:9870 dfs.namenode.http-address.yinzhengjie-hdfs.namenode2 node102.yinzhengjie.org.cn:9870 dfs.namenode.http-address.yinzhengjie-hdfs.namenode3 node103.yinzhengjie.org.cn:9870 dfs.namenode.shared.edits.dir qjournal://node101.yinzhengjie.org.cn:8485;node102.yinzhengjie.org.cn:8485;node103.yinzhengjie.org.cn:8485/yinzhengjie-hdfs dfs.client.failover.proxy.provider.yinzhengjie-hdfs org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider dfs.ha.fencing.methods sshfence dfs.ha.fencing.ssh.private-key-files /root/.ssh/id_rsa dfs.journalnode.edits.dir /data/hadoop/ha/journalnode dfs.ha.automatic-failover.enabled true