作为一个Master/Slaves架构的分布式系统,都会存在单点故障。在Alluxio分布式系统中,Alluxio的容错通过多Master实现。同一时刻,有多个Master进程运行。其中一个被选举为Leader,作为所有Workers和 Clients的通信首选。其余Master进入备用状态,和Leader共享日志,以确保和Leader维护着同样的文件系统元数据并在 Leader失效时迅速接管Leader的工作。当前Leader失效时,自动从可用的备用Master中选举一个作为新的Leader,Alluxio继续正常运行。但在切换到备用 Master时,客户端会有短暂的延迟或瞬态错误。
搭建一个容错的Alluxio集群需要两方面的准备:
1) ZooKeeper:Alluxio使用Zookeeper实现Master的容错。Alluxio Master使
用Zookeeper选举Leader。Alluxio Clients使用 Zookeeper查询当前Leader的ID和地址。Alluxio使用Zookeeper实现容错和Leader选举,可以保证在任何时间最多只有一个Leader。需搭建一个ZooKeeper环境,用户维护管理多Master。
2) 用于存放日志的可靠的共享底层文件系统。
Alluxio使用共享底层文件系统存放日志。共享文件系统必须可以被所有Master访问,可以选择 HDFS、Amazon S3或 GlusterFS作为共享文件系统。Leader Master将日志写到共享文件系统,其它(备用) Master持续地重播日志条目与Leader的最新状态保持一致。所有Master必须能够从共享文件系统进行读写。只有Leader Master可以在任何时间写入日志,但所有Master可以读取共享日志来重播Alluxio的系统状态。
共享文件系统必须单独安装(不能通过Alluxio),并且要在Alluxio启动之前处于运行状态。这里选择HDFS作为底层文件系统进行案例实战。
(一) 环境准备
在环境中已经安装ZooKeeper、Hadoop集群。
节点 |
部署集群 |
Master |
ZooKeeper、Hadoop |
Worker1 |
ZooKeeper、Hadoop |
Worker2 |
ZooKeeper、Hadoop |
Worker3 |
Hadoop |
在Master节点、Worker1、Worker2节点上分别启动ZooKeeper集群及检查
状态。其中Worker1的ZooKeeper节点是Leader。
root@master:~# zkServer.sh start
JMX enabled by default
Using config:/usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
root@master:~# zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower
………
root@worker1:~# zkServer.sh start
JMX enabled by default
Using config:/usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
root@worker1:~# zkServer.sh status
JMX enabled by default
Using config:/usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: leader
…..
root@worker2:~# zkServer.sh start
JMX enabled by default
Using config:/usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
root@worker2:~# zkServer.sh status
JMX enabled by default
Using config:/usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower
检查Master的进程,其中,QuorumPeerMain进程就是启动的ZooKeeper进程:
root@master:~# jps
8448 QuorumPeerMain
5893 AlluxioMaster
6135 AlluxioProxy
6744 ResourceManager
6600 SecondaryNameNode
6393 NameNode
8987 Jps
(二) Alluxio容错环境配置
实现Alluxio上的容错,需要为Alluxio Master、Worker和Client增加额外的配置。
Hadoop节点 |
Alluxio部署多Master |
Master(192.168.189.1) |
Alluxio Master |
Worker1(192.168.189.2) |
Alluxio Master |
Worker2(192.168.189.3) |
Alluxio Worker |
Worker3(192.168.189.4) |
Alluxio Worker |
1) 用HDFS来存放日志,首先在HDFS中建立Journal目录。
root@master:~# hdfs dfs -mkdir /alluxio/data/journal/
2) Alluxio Master配置。
l 在Alluxio 第一个Master节点(192.168.189.1)配置Alluxio Master。
在conf/alluxio-env.sh中,配置ALLUXIO_JAVA_OPTS选项,配置Zookeeper地址及在ALLUXIO_JAVA_OPTS中设置alluxio.master.journal.folder。
root@master:/usr/local/alluxio-1.7.0-hadoop-2.6/conf# vialluxio-env.sh
…….
export ALLUXIO_JAVA_OPTS+="
-Dalluxio.zookeeper.enabled=true
-Dalluxio.zookeeper.address=192.168.189.1:2181,192.168.189.2:2181,192.168.189.3:2181
-Dalluxio.master.journal.folder=hdfs://master:9000/alluxio/data/journal/"
export ALLUXIO_MASTER_ADDRESS=master
l 在Alluxio 第二个Master节点,即Worker节点(192.168.189.2)配置Alluxio Master。
在conf/alluxio-env.sh中,配置ALLUXIO_JAVA_OPTS选项,配置Zookeeper地址及在ALLUXIO_JAVA_OPTS中设置alluxio.master.journal.folder。
root@master:/usr/local/alluxio-1.7.0-hadoop-2.6/conf# vialluxio-env.sh
…….
export ALLUXIO_JAVA_OPTS+="
-Dalluxio.zookeeper.enabled=true
-Dalluxio.zookeeper.address=192.168.189.1:2181,192.168.189.2:2181,192.168.189.3:2181
-Dalluxio.master.journal.folder=hdfs://master:9000/alluxio/data/journal/"
export ALLUXIO_MASTER_ADDRESS=worker1
所有Alluxio Master(Master节点(192.168.189.1)、Worker节点(192.168.189.2))以这种方式配置后(配置Master地址),都可以启动用于Alluxio的容错。其中一个成为Leader,其余重播日志直到当前Master失效。
3) Alluxio Worker配置。
只要以上参数配置正确,Alluxio Worker就可以咨询ZooKeeper,找到当前
应当连接的Master。所以,Alluxio Worker无需设置ALLUXIO_MASTER_ADDRESS。
l Worker2(192.168.189.3)、Worker3(192.168.189.4)的conf/alluxio-env.sh配置。
root@worker2:/usr/local/alluxio-1.7.0-hadoop-2.6/conf# vialluxio-env.sh
…….
export ALLUXIO_JAVA_OPTS+="
-Dalluxio.zookeeper.enabled=true
-Dalluxio.zookeeper.address=192.168.189.1:2181,192.168.189.2:2181,192.168.189.3:2181"
4) Alluxio Client配置。
无需为容错模式配置更多的参数,只要以下两项已经设置,在Client应用中
正确设置,应用可以咨询ZooKeeper获取当前 Leader Master。
-Dalluxio.zookeeper.enabled=true
-Dalluxio.zookeeper.address=[zookeeper_hostname]:2181
5) 重新格式化Alluxio。如果是首次修改底层存储系统为HDFS的话,需要进行格式化。
root@master:~# alluxio format
.......
2018-02-12 14:22:28,519 INFO UfsJournal - Formattinghdfs://master:9000/alluxio/data/journal/BlockMaster/v1
2018-02-12 14:22:29,311 INFO UfsJournal - Formattinghdfs://master:9000/alluxio/data/journal/FileSystemMaster/v1
2018-02-12 14:22:29,438 INFO Format - Formatting complete
6) 启动Alluxio集群,启动第一个Master节点。
root@master:~# alluxio-start.sh all Mount
ALLUXIO_MASTER_ADDRESS is deprecated since version 1.1and will be remove in version 2.0.
Please use "ALLUXIO_MASTER_HOSTNAME" instead.
ALLUXIO_MASTER_ADDRESS is deprecated since version 1.1and will be remove in version 2.0.
Please use "ALLUXIO_MASTER_HOSTNAME" instead.
Executing the following command on all master nodes andlogging to /usr/local/alluxio-1.7.0-hadoop-2.6/logs/task.log:/usr/local/alluxio-1.7.0-hadoop-2.6/bin/alluxio-stop.sh proxy
Waiting for tasks to finish...
……
Waiting for tasks to finish...
All tasks finished
查看Web Interface界面(http://192.168.189.1:19999/home ,第一个Master的地址),如图6-15、图6-16所示,启动成功。显示运行的Worker数为2个。
图 6 - 15 Alluxio启动后的界面
图 6 - 16 运行Worker
(三) 测试Alluxio Master容错性。
1) 启动第二个Alluxio Master节点(即Worker1 192.168.189.2),登陆到Worker1(192.168.189.2)节点上,启动Alluxio Master。
root@worker1:~# alluxio-start.sh master
ALLUXIO_MASTER_ADDRESS is deprecated since version 1.1and will be remove in version 2.0.
Please use "ALLUXIO_MASTER_HOSTNAME" instead.
Starting master @ worker1. Logging to/usr/local/alluxio-1.7.0-hadoop-2.6/logs
检查Alluxio Master进程AlluxioMaster。启动的AlluxioMaster进程就是StandbyMaster。
root@worker1:~# jps
4564 DataNode
6536 AlluxioProxy
5611 QuorumPeerMain
4700 NodeManager
6621 AlluxioMaster
6654 Jps
2) Alluxio Master多Master节点切换测试。登陆到第一个Master节点(192.168.189.1),将AlluxioMaster进程Kill掉。
root@master:~# jps
8448 QuorumPeerMain
10163 Jps
9992 AlluxioProxy
6744 ResourceManager
6600 SecondaryNameNode
6393 NameNode
9743 AlluxioMaster
root@master:~# kill -9 9743
Alluxio Master多Master节点发生切换,查看新的Master上的Web Interface(http://192.168.189.2:19999/home,第二个Master的地址)界面,如图6-17所示。
图 6 - 17 Alluxio切换Master后的界面
3) 查看Active Master与 StandbyMaster的切换
切换Master的时间大概在十几秒左右,从界面可以看到,Master节点已经成功切换到192.168.189.2了。注意:作为Master节点时,需要已经配置SSH无密登录到其他节点。
(四) Alluxio容错机制的扩展
除了使用HA方式对Master节点进行容错外,对于具体的文件数据,Alluxio借鉴
了Spark,使用血统关系(Lineage)进行容错。文件元数据中记录了文件之间的依赖关系,当文件丢失时,能够根据依赖关系进行重计算来恢复文件数据。