环境
操作系统:rhel6.5
软件版本:hadoop2.4.1,hbase1.3.3,zookeeper3.4.13,jdk1.7
主机名 | IP地址 | 角色 |
master1 | 192.168.80.182 | NameNode,RegionServer,Hmaster,Zookeeper,ResourceManager |
master2 | 192.168.80.183 | NameNode,RegionServer,HmasterZookeeper,ResourceManager |
slave1 | 192.168.80.184 | DataNode,RegionServer,Zookeeper,NodeManager |
slave2 | 192.168.80.185 | DataNode,RegionServer,Zookeeper,NodeManager |
slave3 | 192.168.80.186 | DataNode,RegionServer,Zookeeper,NodeManager |
步骤
1.关闭防火墙
service iptables stop
chkconfig iptables off
vi /etc/selinux/config
SELINUX=disabled
2.时钟同步
date -s xxxx-xx-xx
date -s xx:xx:xx
3.安装jdk/hadoop/zookeeper/hbase
cd /tmp
tar -zxvf jdk-7u80-linux-x64.tar.gz
tar -zxvf hadoop-2.4.1.tar.gz
tar -zxvf hbase-1.3.3-bin.tar.gz
tar -zxvf zookeeper-3.4.13.tar.gz
mkdir /usr/local/hadoop
mkdir /usr/local/hbase
mkdir /usr/local/zookeeper
mkdir /usr/local/java
cp -r /tmp/jdk1.7.0_80/* /usr/local/java
cp -r /tmp/hadoop-2.4.1/* /usr/local/hadoop
cp -r /tmp/hbase-1.3.3/* /usr/local/hbase
cp -r /tmp/zookeeper-3.4.13/* /usr/local/zookeeper
4.创建hadoop用户,配置环境变量
useradd hadoop
passwd hadoop
su - hadoop
vi ~/.bash_profile
export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin
export HADOOP_HOME=/usr/local/hadoop
export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
export HBASE_HOME=/usr/local/hbase
export PATH=$PATH:$HBASE_HOME/bin
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib"
export PATH
5.ssh互信
所有节点执行:
ssh-keygen -t rsa
master1下执行:
ssh master1 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh master2 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh slave1 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh slave2 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh slave3 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
scp ~/.ssh/authorized_keys master2:~/.ssh/
scp ~/.ssh/authorized_keys slave1:~/.ssh/
scp ~/.ssh/authorized_keys slave2:~/.ssh/
scp ~/.ssh/authorized_keys slave3:~/.ssh/
所有节点执行:
chmod 600 ~/.ssh/authorized_keys
ssh master1
ssh master2
ssh slave1
ssh slave2
ssh slave3
注意:执行完一条命令后,不要忘记exit退出,再执行下一条
6.zookeeper配置
master1:
mkdir /usr/local/zookeeper/data
vi /usr/local/zookeeper/data/myid (每个节点分别执行,第一台myid内容1,第二台为2,以此类推)
1,2,3,4,5
cp /usr/local/zookeeper/conf/zoo_sample.cfg /usr/local/zookeeper/conf/zoo.cfg
编辑zoo.cfg
dataDir=/usr/local/zookeeper/data
server.1=master1:2888:3888
server.2=master2:2888:3888
server.3=slave1:2888:3888
server.4=slave2:2888:3888
server.5=slave3:2888:3888
把文件传到各节点
scp -r /usr/local/zookeeper root@master2:/usr/local/
scp -r /usr/local/zookeeper root@slave1:/usr/local/
scp -r /usr/local/zookeeper root@slave2:/usr/local/
scp -r /usr/local/zookeeper root@slave3:/usr/local/
切换到root用户下:
chown hadoop:hadoop /usr/local/zookeeper -R
各节点启动
zkServer.sh start
7.hadoop配置
master1:
编辑core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://ns1</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/hadoop/tmp</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>master1:2181,master2:2181,slave1:2181,slave2:2181,slave3:2181</value>
</property>
<property>
<name>ipc.client.connect.max.retries</name>
<value>100</value>
</property>
<property>
<name>ipc.client.connect.retry.interval</name>
<value>10000</value>
</property>
</configuration>
编辑hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
<property>
<name>dfs.nameservices</name>
<value>ns1</value>
</property>
<property>
<name>dfs.ha.namenodes.ns1</name>
<value>master1,master2</value>
</property>
<property>
<name>dfs.namenode.rpc-address.ns1.master1</name>
<value>master1:9000</value>
</property>
<property>
<name>dfs.namenode.rpc-address.ns1.master2</name>
<value>master2:9000</value>
</property>
<property>
<name>dfs.namenode.http-address.ns1.master1</name>
<value>master1:50070</value>
</property>
<property>
<name>dfs.namenode.http-address.ns1.master2</name>
<value>master2:50070</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://master1:8485;master2:8485;slave1:8485;slave2:8485;slave3:8485/ns1</value>
</property>
<property>
<name>dfs.ha.automatic-failover.enabled.ns1</name>
<value>true</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/usr/local/hadoop/journalnode</value>
</property>
<property>
<name>dfs.client.failover.proxy.provider.ns1</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/hadoop/.ssh/id_rsa</value>
</property>
<property>
<name>dfs.ha.fencing.ssh.connect-timeout</name>
<value>30000</value>
</property>
</configuration>
编辑mapred-site.xml
cp mapred-site.xml.template mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
编辑yarn-site.xml
<configuration>
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>highgo</value>
</property>
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>master1</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>master2</value>
</property>
<property>
<name>yarn.resourcemanager.ha.id</name>
<value>rm1</value>
</property>
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>master1:2181,master2:2181,slave1:2181,slave2:2181,slave3:2181</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
编辑slaves
slave1
slave2
slave3
把目录传送到各节点
scp -r /usr/local/hadoop/* root@master2:/usr/local/hadoop
(修改yarn-site.xml里的yarn.resourcemanager.ha.id为rm2)
scp -r /usr/local/hadoop/* root@slave1:/usr/local/hadoop
(删除yarn.resourcemanager.ha.id)
scp -r /usr/local/hadoop/* root@slave2:/usr/local/hadoop
(删除yarn.resourcemanager.ha.id)
scp -r /usr/local/hadoop/* root@slave3:/usr/local/hadoop
(删除yarn.resourcemanager.ha.id)
切换到root用户下,修改各节点权限:
chown hadoop:hadoop /usr/local/hadoop -R
8.格式化
格式化之前保证zookeeper是启动的,即各节点zkServer.sh start
hadoop-daemon.sh start journalnode(所有节点执行)
hdfs zkfc -formatZK (master1和master2主节点执行)
hdfs namenode -format(master1执行)
hadoop-daemon.sh start namenode (master1执行)
hdfs namenode -bootstrapStandby (master2执行)
start-all.sh(master1执行)
yarn-daemon.sh start resourcemanager (master2执行)
hadoop-daemon.sh start zkfc (master1和master2执行)
hdfs haadmin -getServiceState master1
hdfs haadmin -getServiceState master2
(master1或master2执行都可以,查看两个主节点状态)
9.hbase配置
master1:
编辑hbase-env.sh
export HBASE_PID_DIR=/usr/local/hbase/pids
export HBASE_MANAGES_ZK=false
编辑hbase-site.xml
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://master1:9000/hbase</value>
</property>
<property>
<name>hbase.master</name>
<value>hdfs://master1:60000</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>master1:2181,master2:2181,slave1:2181,slave2:2181,slave3:2181</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/usr/local/zookeeper</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
</configuration>
编辑regionservers
master1
master2
slave1
slave2
slave3
创建pids文件
mkdir /usr/local/hbase/pids
把目录传送到各节点
scp -r /usr/local/hbase root@master2:/usr/local/
scp -r /usr/local/hbase root@slave1:/usr/local/
scp -r /usr/local/hbase root@slave2:/usr/local/
scp -r /usr/local/hbase root@slave3:/usr/local/
root用户下,各节点修改权限:
chown hadoop:hadoop /usr/local/hadoop -R
10.建议启动顺序
zkServer.sh start(所有节点执行)
hadoop-daemon.sh start journalnode(所有节点执行)
start-all.sh(master1执行))
yarn-daemon.sh start resourcemanager (master2执行)
hadoop-daemon.sh start zkfc(master1和master2执行)
hdfs haadmin -getServiceState master1 (master1或master2执行,查看两个主节点状态)
hdfs haadmin -getServiceState master2
start-hbase.sh (master1执行)
hbase-daemon.sh start master(master2执行)
启动后进程:
master1 | 192.168.80.182 | NameNode,RegionServer,Hmaster,ResourceManager,QuorumPeerMain,JournalNode,DFSZKFailoverController |
master2 | 192.168.80.183 | NameNode,RegionServer,Hmaster,ResourceManager,QuorumPeerMain,JournalNode,DFSZKFailoverController |
slave1 | 192.168.80.184 | DataNode,RegionServer,NodeManager,QuorumPeerMain,JournalNode |
slave2 | 192.168.80.185 | DataNode,RegionServer,NodeManager,QuorumPeerMain,JournalNode |
slave3 | 192.168.80.186 | DataNode,RegionServer,NodeManager,QuorumPeerMain,JournalNode |