大数据

hadoop搭建[单机模式+伪分布式]

2018-11-01  本文已影响0人  57山本无忧

环境准备

主机名称 IP地址
hadoop-master 192.168.200.100
echo "192.168.200.100 hadoop-master">>/etc/hosts

其他信息:

[root@hadoop-master ~]# uname -r
2.6.32-358.el6.x86_64
[root@hadoop-master ~]# uname -m
x86_64
[root@hadoop-master ~]# cat /etc/redhat-release 
CentOS release 6.4 (Final)
[root@hadoop-master ~]# getenforce 
Disabled

一、安装JDK

请参考:Linux下快速安装JDK

二、安装hadoop

useradd hadoop && echo 123456 | passwd --stdin hadoop
wget --no-check-certificate https://mirrors.cnnic.cn/apache/hadoop/common/hadoop-2.9.0/hadoop-2.9.0.tar.gz
mkdir /application && tar zxf /usr/local/src/hadoop-2.9.0.tar.gz -C /application/&&ln -s /application/hadoop-2.9.0 /application/hadoop&&chown -R hadoop:hadoop /application/hadoop*&&ll /application/
##################Hadoop环境变量配置#############
export HADOOP_HOME=/application/hadoop
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib"
export PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
hadoop version

三、配置Hadoop

3.1 单机模式(standalone)

测试

hdfs dfs -ls /

3.2 伪分布模式

修改配置文件

export JAVA_HOME=/usr/local/jdk
<configuration>
<property>
     <name>hadoop.tmp.dir</name>
     <value>file:/application/hadoop/tmp</value>
</property>
<property>
     <name>fs.defaultFS</name>
     <value>hdfs://hadoop-master:9000</value>
</property>
</configuration>
<configuration>
        <property>
             <name>dfs.replication</name>
             <value>1</value>
        </property>
        <property>
             <name>dfs.namenode.name.dir</name>
             <value>file:/application/hadoop/tmp/dfs/name</value>
        </property>
        <property>
             <name>dfs.datanode.data.dir</name>
             <value>file:/application/hadoop/tmp/dfs/data</value>
        </property>
</configuration>
<configuration>
        <property>
             <name>mapreduce.framework.name</name>
             <value>yarn</value>
        </property>
</configuration>
<configuration>
    <property>
         <name>yarn.nodemanager.aux-services</name>
         <value>mapreduce_shuffle</value>
    </property>
</configuration>

配置SSH免密登陆

检查是否安装了ssh相关软件包(openssh-server openssh-clients openssh)
yum list installed | grep ssh
检查是否启动了sshd进程
ps -Af | grep sshd
su - hadoop
在客户端生成密钥对
ssh-keygen -t dsa
将公钥追加到服务端的认证库(本机)
cat .ssh/id_dsa.pub >> .ssh/authorized_keys
检查authorized_keys的权限是否为644,不是的话,需要修改为644

格式化文件系统

hdfs namenode -format

成功字样:has been successfully formatted
Existing with status 0

启动

[hadoop@hadoop-master ~]start-dfs.sh
[hadoop@hadoop-master ~]$ jps
8880 Jps
8593 DataNode
8769 SecondaryNameNode
8454 NameNode
[hadoop@hadoop-master ~]$ start-yarn.sh
[hadoop@hadoop-master ~]$ jps
8593 DataNode
9041 NodeManager
8769 SecondaryNameNode
8454 NameNode
9338 Jps
8939 ResourceManager

测试

浏览器访问:
http://192.168.200.100:50070

测试往HDFS写文件:

echo "123456" >>/home/hadoop/1.txt
bin/hdfs dfs -appendToFile /home/hadoop/1.txt  hdfs://hadoop-master:9000/1.txt
bin/hdfs dfs -ls hdfs://hadoop-master:9000/

四、三种模式共存

配置hadoop,让其三种模式共存,方便切换

  1. 分别复制${HADOOP_HOME}/etc/hadoop文件夹3次,分别更名为local、pseudo、full
  2. 删除${HADOOP_HOME}/etc/hadoop文件夹
  3. 创建对应软连接ln -s
上一篇下一篇

猜你喜欢

热点阅读