11.搭建高可用

https://hadoop.apache.org/docs/r2.6.5/hadoop-project-dist/hadoop-hdfs/HDFSHighAvailabilityWithQJM.html

官方文档查看Apache Hadoop 2.6.5 - Hadoop Distributed File System-2.6.5 - High Availability



11.搭建高可用_第1张图片
HA搭建效果图

HA搭建效果图重要


先是进行node06和node07互相的免秘钥登录

11.搭建高可用_第2张图片
11.搭建高可用_第3张图片

两个nn节点免秘钥

ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa

cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

11.搭建高可用_第4张图片
11.搭建高可用_第5张图片
11.搭建高可用_第6张图片

搭建目标

11.搭建高可用_第7张图片


11.搭建高可用_第8张图片

继续搭建框架

实现自动故障转移


11.搭建高可用_第9张图片
11.搭建高可用_第10张图片

Components

Automatic failover adds two new components to an HDFS deployment: a ZooKeeper quorum, and the ZKFailoverController process (abbreviated as ZKFC).

Apache ZooKeeper is a highly available service for maintaining small amounts of coordination data, notifying clients of changes in that data, and monitoring clients for failures. The implementation of automatic HDFS failover relies on ZooKeeper for the following things:

Failure detection - each of the NameNode machines in the cluster maintains a persistent session in ZooKeeper. If the machine crashes, the ZooKeeper session will expire, notifying the other NameNode that a failover should be triggered.

Active NameNode election - ZooKeeper provides a simple mechanism to exclusively elect a node as active. If the current active NameNode crashes, another node may take a special exclusive lock in ZooKeeper indicating that it should become the next active.

The ZKFailoverController (ZKFC) is a new component which is a ZooKeeper client which also monitors and manages the state of the NameNode. Each of the machines which runs a NameNode also runs a ZKFC, and that ZKFC is responsible for:

Health monitoring - the ZKFC pings its local NameNode on a periodic basis with a health-check command. So long as the NameNode responds in a timely fashion with a healthy status, the ZKFC considers the node healthy. If the node has crashed, frozen, or otherwise entered an unhealthy state, the health monitor will mark it as unhealthy.

ZooKeeper session management - when the local NameNode is healthy, the ZKFC holds a session open in ZooKeeper. If the local NameNode is active, it also holds a special "lock" znode. This lock uses ZooKeeper's support for "ephemeral" nodes; if the session expires, the lock node will be automatically deleted.

ZooKeeper-based election - if the local NameNode is healthy, and the ZKFC sees that no other node currently holds the lock znode, it will itself try to acquire the lock. If it succeeds, then it has "won the election", and is responsible for running a failover to make its local NameNode active. The failover process is similar to the manual failover described above: first, the previous active is fenced if necessary, and then the local NameNode transitions to active state.

For more details on the design of automatic failover, refer to the design document attached to HDFS-2185 on the Apache HDFS JIRA.

Configuring automatic failover

The configuration of automatic failover requires the addition of two new parameters to your configuration. In your hdfs-site.xml file, add:

  dfs.ha.automatic-failover.enabled

  true

This specifies that the cluster should be set up for automatic failover. In your core-site.xml file, add:

  ha.zookeeper.quorum

  zk1.example.com:2181,zk2.example.com:2181,zk3.example.com:2181


11.搭建高可用_第11张图片



11.搭建高可用_第12张图片
11.搭建高可用_第13张图片
在·/opt/sxt/hadoop-2.6.5/etc文件下配置文件

hdfs-site.mml文件

11.搭建高可用_第14张图片

cat一下,发现只是单节点,不能这么做,因为这么做后只是单节点

11.搭建高可用_第15张图片

按照官方文档来配

to configure HA NameNodes, you must add several configuration options to your hdfs-site.xml configuration file.


The order in which you set these configurations is unimportant, but the values you choose for dfs.nameservices and dfs.ha.namenodes.[nameservice ID] will determine the keys of those that follow. Thus, you should decide on these values before setting the rest of the configuration options.

dfs.nameservices - the logical name for this new nameservice

Choose a logical name for this nameservice, for example "mycluster", and use this logical name for the value of this config option. The name you choose is arbitrary. It will be used both for configuration and as the authority component of absolute HDFS paths in the cluster.

Note: If you are also using HDFS Federation, this configuration setting should also include the list of other nameservices, HA or otherwise, as a comma-separated list.

  dfs.nameservices

  mycluster

dfs.ha.namenodes.[nameservice ID] - unique identifiers for each NameNode in the nameservice

Configure with a list of comma-separated NameNode IDs. This will be used by DataNodes to determine all the NameNodes in the cluster. For example, if you used "mycluster" as the nameservice ID previously, and you wanted to use "nn1" and "nn2" as the individual IDs of the NameNodes, you would configure this as such:

  dfs.ha.namenodes.mycluster

  nn1,nn2

Note: Currently, only a maximum of two NameNodes may be configured per nameservice.

dfs.namenode.rpc-address.[nameservice ID].[name node ID] - the fully-qualified RPC address for each NameNode to listen on

For both of the previously-configured NameNode IDs, set the full address and IPC port of the NameNode processs. Note that this results in two separate configuration options. For example:

  dfs.namenode.rpc-address.mycluster.nn1

  machine1.example.com:8020

  dfs.namenode.rpc-address.mycluster.nn2

  machine2.example.com:8020

Note: You may similarly configure the "servicerpc-address" setting if you so desire.

dfs.namenode.http-address.[nameservice ID].[name node ID] - the fully-qualified HTTP address for each NameNode to listen on

Similarly to rpc-address above, set the addresses for both NameNodes' HTTP servers to listen on. For example:

  dfs.namenode.http-address.mycluster.nn1

  machine1.example.com:50070

  dfs.namenode.http-address.mycluster.nn2

  machine2.example.com:50070

看了上面的文档,有点乱,总结一下

打开hdfs-site.xml


去掉snn的配置

                  dfs.namenode.secondary.http-address

            node07:50090

没必要了

增加:

  dfs.nameservices

  mycluster

Choose a logical name for this nameservice, for example "mycluster", and use this logical name for the value of this config option. The name you choose is arbitrary. It will be used both for configuration and as the authority component of absolute HDFS paths in the cluster.

名字可以随便改,nameservice,叫主节点服务id,id叫mycluster,用来指向需要做namenode配置的主从节点,入口

  dfs.ha.namenodes.mycluster

  nn1,nn2

Configure with a list of comma-separated NameNode IDs. This will be used by DataNodes to determine all the NameNodes in the cluster. For example, if you used "mycluster" as the nameservice ID previously, and you wanted to use "nn1" and "nn2" as the individual IDs of the NameNodes, you would configure this as such。

名字必须和上一个配置相同,都是mycluster

2.0只能搭建两个,一主一从


dfs.namenode.rpc-address.[nameservice ID].[name node ID] - the fully-qualified RPC (远程物理调用)address for each NameNode to listen on

For both of the previously-configured NameNode IDs, set the full address and IPC port of the NameNode processs. Note that this results in two separate configuration options. For example:

上面都是逻辑id,怎么和机器联系起来呢?

下面的配置描述了

物理机和物理映射做了修改

  dfs.namenode.rpc-address.mycluster.nn1

  node06:8020


  dfs.namenode.rpc-address.mycluster.nn2

  node07:8020


dfs.namenode.http-address.[nameservice ID].[name node ID] - the fully-qualified HTTP address for each NameNode to listen on

Similarly to rpc-address above, set the addresses for both NameNodes' HTTP servers to listen on. For example:

为了浏览器配置

  dfs.namenode.http-address.mycluster.nn1

  node06:50070

  dfs.namenode.http-address.mycluster.nn2

  node07:50070


dfs.namenode.shared.edits.dir - the URI which identifies the group of JNs where the NameNodes will write/read edits

This is where one configures the addresses of the JournalNodes which provide the shared edits storage, written to by the Active nameNode and read by the Standby NameNode to stay up-to-date with all the file system changes the Active NameNode makes. Though you must specify several JournalNode addresses, you should only configure one of these URIs. The URI should be of the form: "qjournal://host1:port1;host2:port2;host3:port3/journalId". The Journal ID is a unique identifier for this nameservice, which allows a single set of JournalNodes to provide storage for multiple federated namesystems. Though not a requirement, it's a good idea to reuse the nameservice ID for the journal identifier.

For example, if the JournalNodes for this cluster were running on the machines "node1.example.com", "node2.example.com", and "node3.example.com" and the nameservice ID were "mycluster", you would use the following as the value for this setting (the default port for the JournalNode is 8485):

这是为了配置journalnode集群,管理日志文件

  dfs.namenode.shared.edits.dir

  qjournal://node06:8485;node07:8485;node08:8485/mycluster

mycluster代表当前集群的日志信息,代表信息放在此下

qjorual固定写法


直接写就是了,实现故障转移,代理

  dfs.client.failover.proxy.provider.mycluster

  org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider


  dfs.ha.fencing.methods

  sshfence

  dfs.ha.fencing.ssh.private-key-files

  /root/.ssh/id_dsa

这是私钥。dsa和rsa原理一样

改配置保证隔离。一旦故障,把他状态降低

保证任何时候只有一台处于存活状态,另一台standby

  dfs.journalnode.edits.dir

  /var/sxt/hadoop/ha/jn

表示存放地址

  dfs.ha.automatic-failover.enabled

  true

实现自动故障转移


在core-site.xml

-----------------------------------------

hadoop.tmp.dir的配置要变更:/var/sxt/hadoop-2.6/ha

  fs.defaultFS

  hdfs://mycluster

原来为node006:9000,现在改变就是为了集群,名称为mycluster,电脑可以从mycluster进入,一主一从,开启服务

  ha.zookeeper.quorum

  node07:2181,node08:2181,node09:2181

可以随意搭建,最小节点三台

然后

分发 hdfs.xml 和core.xml 给其他节点

scp core-site.xml hdfs-site .xml node07:`pwd`还有八和九



11.搭建高可用_第16张图片

开始搭建zookeeper

注意

这里安装在node07并不是node06


11.搭建高可用_第17张图片

11.搭建高可用_第18张图片

11.搭建高可用_第19张图片

11.搭建高可用_第20张图片
10


11.搭建高可用_第21张图片

zookeeper是一主多从的机制,这里配置serverid,id谁大谁优先级高这里编号123

11.搭建高可用_第22张图片
分发


11.搭建高可用_第23张图片
11.搭建高可用_第24张图片
因为在上面配置过,var/sxt/zk

所以要mkdir一下,存储信息

11.搭建高可用_第25张图片

七八九都要执行一遍,因为启动时要读取这个文件id也不要写错,123

11.搭建高可用_第26张图片
11.搭建高可用_第27张图片
配置环境变量
11.搭建高可用_第28张图片
11.搭建高可用_第29张图片
分发给其他节点
11.搭建高可用_第30张图片
11.搭建高可用_第31张图片
11.搭建高可用_第32张图片
11.搭建高可用_第33张图片
11.搭建高可用_第34张图片
11.搭建高可用_第35张图片
25


11.搭建高可用_第36张图片
11.搭建高可用_第37张图片
11.搭建高可用_第38张图片
11.搭建高可用_第39张图片
11.搭建高可用_第40张图片
11.搭建高可用_第41张图片
11.搭建高可用_第42张图片

让六七八都跑journalnode

11.搭建高可用_第43张图片
11.搭建高可用_第44张图片
11.搭建高可用_第45张图片

格式化生成集群地址和clusterid,如果其他执行了。id不一致构不成集群

11.搭建高可用_第46张图片
11.搭建高可用_第47张图片

启动namenode

11.搭建高可用_第48张图片

-bootstrapstandby把namenode原数据同步

11.搭建高可用_第49张图片
11.搭建高可用_第50张图片
11.搭建高可用_第51张图片
格式化zookeeper

并不是初始化zok,而是hdfs在zookeeper上执行

11.搭建高可用_第52张图片
11.搭建高可用_第53张图片
11.搭建高可用_第54张图片
11.搭建高可用_第55张图片
11.搭建高可用_第56张图片


11.搭建高可用_第57张图片
11.搭建高可用_第58张图片
11.搭建高可用_第59张图片
11.搭建高可用_第60张图片
11.搭建高可用_第61张图片


11.搭建高可用_第62张图片
11.搭建高可用_第63张图片

这是千万不要使用formate命令了

你可能感兴趣的:(11.搭建高可用)