在部署hadoop2.6之前的前置任务:
1、禁止selinux
setenforce 0
修改vi /etc/selinux/config的参数如下:
SELINUX=disabled
2、关闭防火墙
iptables -F
service iptables save
service iptables stop
chkconfig --level 2345 iptables off
########################################################
一:配置域名解析
-------------------------------------------------------
分别在三台机器上的/etc/hosts文件最后添加如下信息:
------------------------------------------------
128.230.5.113 hbase01
128.230.5.114 hbase02
128.230.5.115 hbase03
二、添加hadoop的管理账号
[root@hbase01 ~]# groupadd -g 1000 hadoop
[root@hbase01 ~]# useradd -u 1000 -g 1000 hadoop
三、设置互信机制
[root@hbase01 ~]# su - hadoop
[hadoop@hbase01 ~]$ ssh-keygen -t rsa
scp id_rsa.pub hadoop@ip2:~/.ssh/authorized_keys
scp id_rsa.pub hadoop@ip2:~/.ssh/authorized_keys
如果互信无法成功请修改如下文件的权限即可
chmod 700 .ssh
chmod 0600 authorized_keys
四、配置环境变量
#vim /home/hadoop/.bash_profile --设置环境变量
export JAVA_HOME=/usr/java/jdk1.8.0_40
export JAR_HOME=/usr/java/jdk1.8.0_40/jre
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAR_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
export HADOOP_HOME=/usr/local/hadoop-2.6.0
export HBASE_HOME=/usr/local/hbase-0.98.9-hadoop2
export PATH=$JAVA_HOME/bin:$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:/usr/local/hbase-0.98.9-hadoop2/bin
export HADOOP_HOME=/usr/local/hadoop-2.6.0
export HBASE_HOME=/usr/local/hbase-0.98.9-hadoop2
export PATH=$JAVA_HOME/bin:$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:/usr/local/hbase-0.98.9-hadoop2/bin
export PATH
五、测试hadoop环境变量生效
hadoop version
六、配置hadoop集群
######################################################################################################
1、配置core-site.xml文件
------------------------------------------------------------------------------------------------------
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://hbase01:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/hadoopdata/tmp</value>
</property>
<property>
<name>io.file.buffer.size</name>
<value>4096</value>
</property>
<property>
<name>hadoop.native.lib</name>
<value>true</value>
</property>
</configuration>
2、配置vim hadoop-env.sh文件
------------------------------------------------------------------------------------------------------
export JAVA_HOME=/usr/java/jdk1.8.0_40
3、配置vim hdfs-site.xml
------------------------------------------------------------------------------------------------------
<configuration>
<property>
<name>dfs.nameservices</name>
<value>hadoop-cluster1</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>hbase01:50090</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:///usr/local/hadoopdata/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:///usr/local/hadoopdata/dfs/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
</configuration>
4、配置vim mapred-site.xml
------------------------------------------------------------------------------------------------------
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobtracker.http.address</name>
<value>hbase01:50030</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>hbase01:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>hbase01:19888</value>
</property>
</configuration>
5、格式化namenode的namespace和dataspace
------------------------------------------------------------------------------------------------------
hadoop namenode -format
6、创建相关目录
------------------------------------------------------------------------------------------------------
mkdir -p /usr/local/hadoopdata/dfs/data
mkdir -p /usr/local/hadoopdata/dfs/name
mkdir -p /usr/local/hadoopdata/dfs/tmp
chown -R hadoop:hadoop /usr/local/hadoopdata
7、启动hadoop集群
------------------------------------------------------------------------------------------------------
#su -hadoop
#start-all.sh
若在namenode显示如下信息:
[hadoop@hbase01 dfs]$ jps
16393 NameNode
16906 Jps
16622 ResourceManager
在datanode显示如下信息:
29697 DataNode
29911 Jps
29805 NodeManager
请直接跳到最后访问hadoop集群的web控制台即可管理和监视hadoop集群的运行
8、输入jps发现hadoop集群没有成功被启动只有jps进程
------------------------------------------------------------------------------------------------------
9、分析诊断日志
------------------------------------------------------------------------------------------------------
tail -f hadoop-hadoop-namenode-hbase01.log
发现端口被占用,通过ps发现另一hadoop进程已经被root账号启用kill掉相关hadoop进程,重新启动hadoop集群
#stop-all.sh
#start-all.sh
再次执行jps发现此次比上次多了一个java进程,离成功更接近了一步。我们再次通过分析日志发现对hadoop的分布式文件系统没有写权限
14848 Jps
14595 ResourceManager
/usr/local/hadoopdata/dfs/name
10、解决方法:停止hadoop集群
------------------------------------------------------------------------------------------------------
stop-all.sh
11、解决方法:创建相关目录并赋权
------------------------------------------------------------------------------------------------------
mkdir -p /usr/local/hadoopdata/dfs/data
mkdir -p /usr/local/hadoopdata/dfs/name
chown -R hadoop:hadoop /usr/local/hadoopdata
12、访问hadoop的web页面,验证hadoop集群是否成功搭建完成
------------------------------------------------------------------------------------------------------
http://128.230.5.113:50070/dfshealth.html#tab-overview
#http://192.168.1.110:50070/dfshealth.html#tab-overview
--转自