首先需要获取Hadoop程序,可以去到Apache Hadoop官网进行下载:http://hadoop.apache.org/releases.html。
1、配置SSH无密码登录:
[user@localhost ~]$ cd[user@localhost ~]$ ssh-keygen -t rsa
// 省略部分内容,中间一直按回车键继续就可以了
[user@localhost ~]$ cd .ssh/
[user@localhost .ssh]$ ll
total 20
-rw-r--r--. 1 user user 1682 Dec 2 17:21 authorized_keys
-rw-------. 1 user user 1675 Feb 9 2015 id_rsa
-rw-r--r--. 1 user user 412 Feb 9 2015 id_rsa.pub
-rw-r--r--. 1 user user 7240 Dec 2 17:18 known_hosts
[user@localhost .ssh]$ cat id_rsa.pub >> authorized_keys
2、将下载的Hadoop程序上传到服务器:
[user@localhost .ssh]$ cp hadoop-2.7.1.tar.gz /usr/local/
[user@localhost .ssh]$ cd /usr/local/
[user@localhost local]$ tar xzf hadoop-2.7.1.tar.gz
[user@localhost local]$ mv hadoop-2.7.1 hadoop
[user@localhost local]$ rm -f hadoop-2.7.1.tar.gz
3、如果你的ssh服务的端口修改过,不是22,需要在配置文件中修改:
[user@localhost local]$ cd hadoop/etc/hadoop/
[user@localhost hadoop]$ vi hadoop-env.sh
按住SHIFT + G,进入文件内容末尾,增加一行:
export HADOOP_SSH_OPTS="-p 1122"
将1122改为你自己的ssh端口
4、修改core-site.xml文件,增加下面配置内容:
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
<property>
<name>io.native.lib.available</name>
<value>true</value>
<description>Controls whether to use native libraries for bz2 and zlib
compression codecs or not. The property does not control any other native
libraries.
</description>
</property>
需要确保你的9000端口未被占用,如被占用,改为其他未被占用的端口号。
5、启动hdfs:
/usr/local/hadoop/sbin/start-dfs.sh
启动hdfs后可以使用ps fax | grep java查看系统进程,如果发现下面三个进程,则表示启动成功:
/usr/local/jdk/bin/java -Dproc_datanode -Xmx1000m -Djava.net.preferIPv4Stack=true -Dhadoop
/usr/local/jdk/bin/java -Dproc_namenode -Xmx1000m -Djava.net.preferIPv4Stack=true -Dhadoop
/usr/local/jdk/bin/java -Dproc_secondarynamenode -Xmx1000m -Djava.net.preferIPv4Stack=true
6、关闭hdfs:
/usr/local/hadoop/sbin/stop-dfs.sh
7、查看hdfs文件系统:
刚刚安装启动的hdfs文件系统中并没有内容,可以先新建一个目录查看是否可用:
[user@localhost local]$ hadoop fs -mkdir /home
16/01/01 23:45:00 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
[user@localhost local]$
[user@localhost local]$
[user@localhost local]$ hadoop fs -ls /
16/01/01 23:45:04 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Found 1 items
drwxr-xr-x - user supergroup 0 2016-01-01 23:45 /home
[user@localhost local]$
8、上面可以看到警告内容:Unable to load native-hadoop library for your platform
如果想要去掉该警告,可以在core-site.xml中,将io.native.lib.available改为false,即可去除该警告。不过这样做会让速度变慢,最好
加载本地库,现在还没成功加载,下次再介绍怎么加载。