先切换用户
su - hadoop
设置hadoop环境
cd /usr/local/hadoop/hadoop-2.7.1/etc/hadoop
vim hadoop-env.sh
export JAVA_HOME=/usr/local/jdk1.7.0_79
配置hadoop
vim core-site.xml
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/hadoop/tmp</value>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://master:9000</value>
</property>
</configuration>
创建数据存放文件夹
mkdir /usr/local/hadoop/tmp
mkdir -p /usr/local/hadoop/dfs/name
mkdir -p /usr/local/hadoop/dfs/data
配置hdfs
vim hdfs-site.xml
<property>
<name>dfs.name.dir</name>
<value>/usr/local/hadoop/dfs/name</value>
</property>
<property>
<name>dfs.data.dir</name>
<value>/usr/local/hadoop/dfs/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
根据实际情况,配置dfs.replication,代表需要在dfs中保存的副本数
配置从节点配置文件
vim slaves
slave1
slave2
同步
将配置好的hadoop同步 到 slave1 和 slave2
rsync -avz /usr/local/hadoop/hadoop-2.7.1 slave1:/usr/local/hadoop/
rsync -avz /usr/local/hadoop/hadoop-2.7.1 slave2:/usr/local/hadoop/
格式化hdfs
cd /usr/local/hadoop/hadoop-2.7.1/bin
./hdfs namenode -format
启动dfs文件系统
cd /usr/local/hadoop/hadoop-2.7.1/sbin
./start-dfs.sh
检查进程
使用jps命令,正常会看到一NameNode, 和2个DataNode
[hadoop@master sbin]$ jps
8959 SecondaryNameNode
8754 NameNode
[hadoop@slave1 bin]$ jps
5817 DataNode
[hadoop@slave2 bin]$ jps
5787 DataNode