创建用户hadoop
$ sudo adduser hadoop
需要输入shiyanlou的密码。并按照提示输入hadoop用户的密码。
将hadoop用户添加进sudo用户组
$ sudo usermod -G sudo hadoop
$ sudo apt-get update
$ sudo apt-get install openssh-server rsync
$ sudo service ssh restart
$ sudo apt-get install openjdk-7-jdk
$ java -version
切换到hadoop用户,需要输入添加hadoop用户时配置的密码。后续步骤都将在hadoop用户的环境中执行。
$ su -l hadoop
配置ssh环境免密码登录。
$ ssh-keygen -t rsa -P ""
在/home/hadoop/.ssh目录下生成了id_rsa(私钥)和id_rsa.pub(公钥)两个文件,将公钥追加到authorized_keys中,该文件保存所有允许以当前用户身份登录到ssh客户端用户的公钥内容。
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
验证登录本机是否还需要密码,配置正确的话是可以不需密码登录的。
$ ssh localhost
在hadoop用户登录的环境中进行下列操作:
$ wget http://labfile.oss.aliyuncs.com/hadoop-2.6.0.tar.gz
$ tar zxvf hadoop-2.6.0.tar.gz
$ sudo mv hadoop-2.6.0 /usr/local/hadoop
$ sudo chmod 774 /usr/local/hadoop
$ vim /home/hadoop/.bashrc
在/home/hadoop/.bashrc文件末尾添加下列内容:
#HADOOP START
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export HADOOP_INSTALL=/usr/local/hadoop
export PATH=$PATH:$HADOOP_INSTALL/bin
export PATH=$PATH:$HADOOP_INSTALL/sbin
export HADOOP_MAPRED_HOME=$HADOOP_INSTALL
export HADOOP_COMMON_HOME=$HADOOP_INSTALL
export HADOOP_HDFS_HOME=$HADOOP_INSTALL
export YARN_HOME=$HADOOP_INSTALL
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_INSTALL/lib"
#HADOOP END
保存退出后,激活新加的环境变量
$ source ~/.bashrc
至此,Hadoop单机模式安装完成,可以通过下述步骤的测试来验证安装是否成功。
创建输入的数据,暂时采用/etc/protocols文件作为测试
$ cd /usr/local/hadoop
$ sudo mkdir input
$ sudo cp /etc/protocols ./input
执行Hadoop WordCount应用(词频统计)
$ bin/hadoop jar share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-2.6.0-sources.jar org.apache.hadoop.examples.WordCount input output
查看生成的单词统计数据
$ cat output/*
注意:如果要继续下一节“伪分布式部署”实验,请勿停止本实验环境,直接点击文档上方的“下一个实验”按钮进入,因为伪分布式部署模式需要在单机模式基础上进行配置。
本实验中介绍了Hadoop单机模式的安装方法,并运行wordcount进行基本测试。
创建用户hadoop
$ sudo adduser hadoop
需要输入shiyanlou的密码。并按照提示输入hadoop用户的密码。
将hadoop用户添加进sudo用户组
$ sudo usermod -G sudo hadoop
$ sudo apt-get update
$ sudo apt-get install openssh-server rsync
$ sudo service ssh restart
$ sudo apt-get install openjdk-7-jdk
$ java -version
切换到hadoop用户,需要输入添加hadoop用户时配置的密码。后续步骤都将在hadoop用户的环境中执行。
$ su -l hadoop
配置ssh环境免密码登录。
$ ssh-keygen -t rsa -P ""
在/home/hadoop/.ssh目录下生成了id_rsa(私钥)和id_rsa.pub(公钥)两个文件,将公钥追加到authorized_keys中,该文件保存所有允许以当前用户身份登录到ssh客户端用户的公钥内容。
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
验证登录本机是否还需要密码,配置正确的话是可以不需密码登录的。
$ ssh localhost
在hadoop用户登录的环境中进行下列操作:
$ wget http://labfile.oss.aliyuncs.com/hadoop-2.6.0.tar.gz
$ tar zxvf hadoop-2.6.0.tar.gz
$ sudo mv hadoop-2.6.0 /usr/local/hadoop
$ sudo chmod 774 /usr/local/hadoop
$ vim /home/hadoop/.bashrc
在/home/hadoop/.bashrc文件末尾添加下列内容:
#HADOOP START
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export HADOOP_INSTALL=/usr/local/hadoop
export PATH=$PATH:$HADOOP_INSTALL/bin
export PATH=$PATH:$HADOOP_INSTALL/sbin
export HADOOP_MAPRED_HOME=$HADOOP_INSTALL
export HADOOP_COMMON_HOME=$HADOOP_INSTALL
export HADOOP_HDFS_HOME=$HADOOP_INSTALL
export YARN_HOME=$HADOOP_INSTALL
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_INSTALL/lib"
#HADOOP END
保存退出后,激活新加的环境变量
$ source ~/.bashrc
至此,Hadoop单机模式安装完成,可以通过下述步骤的测试来验证安装是否成功。
创建输入的数据,暂时采用/etc/protocols文件作为测试
$ cd /usr/local/hadoop
$ sudo mkdir input
$ sudo cp /etc/protocols ./input
执行Hadoop WordCount应用(词频统计)
$ bin/hadoop jar share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-2.6.0-sources.jar org.apache.hadoop.examples.WordCount input output
查看生成的单词统计数据
$ cat output/*
注意:如果要继续下一节“伪分布式部署”实验,请勿停止本实验环境,直接点击文档上方的“下一个实验”按钮进入,因为伪分布式部署模式需要在单机模式基础上进行配置。
本实验中介绍了Hadoop单机模式的安装方法,并运行wordcount进行基本测试。
shiyanlou:~/ $ sudo adduser hadoop [20:05:33]
\u6b63\u5728\u6dfb\u52a0\u7528\u6237"hadoop"...
\u6b63\u5728\u6dfb\u52a0\u65b0\u7ec4"hadoop" (1000)...
\u6b63\u5728\u6dfb\u52a0\u65b0\u7528\u6237"hadoop" (1000) \u5230\u7ec4"hadoop"...
\u521b\u5efa\u4e3b\u76ee\u5f55"/home/hadoop"...
\u6b63\u5728\u4ece"/etc/skel"\u590d\u5236\u6587\u4ef6...
\u8f93\u5165\u65b0\u7684 UNIX \u5bc6\u7801\uff1a
\u91cd\u65b0\u8f93\u5165\u65b0\u7684 UNIX \u5bc6\u7801\uff1a
passwd\uff1a\u5df2\u6210\u529f\u66f4\u65b0\u5bc6\u7801
\u6b63\u5728\u6539\u53d8 hadoop \u7684\u7528\u6237\u4fe1\u606f
\u8bf7\u8f93\u5165\u65b0\u503c\uff0c\u6216\u76f4\u63a5\u6572\u56de\u8f66\u952e\u4ee5\u4f7f\u7528\u9ed8\u8ba4\u503c
\u5168\u540d []: usermod
\u623f\u95f4\u53f7\u7801 []: 104
\u5de5\u4f5c\u7535\u8bdd []: 1383838388
\u5bb6\u5ead\u7535\u8bdd []: 288888
\u5176\u5b83 []: no
\u8fd9\u4e9b\u4fe1\u606f\u662f\u5426\u6b63\u786e\uff1f [Y/n] y
shiyanlou:~/ $ sudo usermod -G sudo hadoop [20:07:11]
shiyanlou:~/ $ sodu apt-get update [20:07:23]
zsh: command not found: sodu
shiyanlou:~/ $ sudo yum update [20:07:35]
sudo\uff1ayum: command not found
shiyanlou:~/ $ sudo apt-get update [20:07:44]
\u5ffd\u7565 http://mirrors.aliyuncs.com trusty InRelease
\u83b7\u53d6\uff1a1 http://mirrors.aliyuncs.com trusty-updates InRelease [65.9 kB]
\u83b7\u53d6\uff1a2 http://mirrors.aliyuncs.com trusty-security InRelease [65.9 kB]
\u547d\u4e2d http://mirrors.aliyuncs.com trusty Release.gpg
\u547d\u4e2d http://mirrors.aliyuncs.com trusty Release
\u83b7\u53d6\uff1a3 http://mirrors.aliyuncs.com trusty-updates/main Sources [470 kB]
\u83b7\u53d6\uff1a4 http://mirrors.aliyuncs.com trusty-updates/restricted Sources [5,217 B]
\u83b7\u53d6\uff1a5 http://mirrors.aliyuncs.com trusty-updates/universe Sources [201 kB]
\u83b7\u53d6\uff1a6 http://mirrors.aliyuncs.com trusty-updates/main amd64 Packages [1,096 kB]
\u83b7\u53d6\uff1a7 http://mirrors.aliyuncs.com trusty-updates/restricted amd64 Packages [23.5 kB]
\u83b7\u53d6\uff1a8 http://mirrors.aliyuncs.com trusty-updates/universe amd64 Packages [474 kB]
\u83b7\u53d6\uff1a9 http://mirrors.aliyuncs.com trusty-security/main Sources [150 kB]
\u83b7\u53d6\uff1a10 http://mirrors.aliyuncs.com trusty-security/restricted Sources [3,920 B]
\u83b7\u53d6\uff1a11 http://mirrors.aliyuncs.com trusty-security/universe Sources [44.1 kB]
\u83b7\u53d6\uff1a12 http://mirrors.aliyuncs.com trusty-security/main amd64 Packages [638 kB]
\u83b7\u53d6\uff1a13 http://mirrors.aliyuncs.com trusty-security/restricted amd64 Packages [20.2 kB]
\u83b7\u53d6\uff1a14 http://mirrors.aliyuncs.com trusty-security/universe amd64 Packages [170 kB]
\u547d\u4e2d http://mirrors.aliyuncs.com trusty/main Sources
\u547d\u4e2d http://mirrors.aliyuncs.com trusty/restricted Sources
\u547d\u4e2d http://mirrors.aliyuncs.com trusty/universe Sources
\u547d\u4e2d http://mirrors.aliyuncs.com trusty/multiverse Sources
\u547d\u4e2d http://mirrors.aliyuncs.com trusty/main amd64 Packages
\u547d\u4e2d http://mirrors.aliyuncs.com trusty/restricted amd64 Packages
\u547d\u4e2d http://mirrors.aliyuncs.com trusty/universe amd64 Packages
\u547d\u4e2d http://mirrors.aliyuncs.com trusty/multiverse amd64 Packages
\u4e0b\u8f7d 3,428 kB\uff0c\u8017\u65f6 8\u79d2 (402 kB/s)
\u6b63\u5728\u8bfb\u53d6\u8f6f\u4ef6\u5305\u5217\u8868... \u5b8c\u6210
shiyanlou:~/ $ sudo apt-get install openssh-server rsync [20:08:13]
\u6b63\u5728\u8bfb\u53d6\u8f6f\u4ef6\u5305\u5217\u8868... \u5b8c\u6210
\u6b63\u5728\u5206\u6790\u8f6f\u4ef6\u5305\u7684\u4f9d\u8d56\u5173\u7cfb\u6811
\u6b63\u5728\u8bfb\u53d6\u72b6\u6001\u4fe1\u606f... \u5b8c\u6210
\u5c06\u4f1a\u5b89\u88c5\u4e0b\u5217\u989d\u5916\u7684\u8f6f\u4ef6\u5305\uff1a
openssh-client
\u5efa\u8bae\u5b89\u88c5\u7684\u8f6f\u4ef6\u5305\uff1a
ssh-askpass libpam-ssh keychain monkeysphere rssh molly-guard ufw
\u63a8\u8350\u5b89\u88c5\u7684\u8f6f\u4ef6\u5305\uff1a
ncurses-term ssh-import-id
\u4e0b\u5217\u3010\u65b0\u3011\u8f6f\u4ef6\u5305\u5c06\u88ab\u5b89\u88c5\uff1a
rsync
\u4e0b\u5217\u8f6f\u4ef6\u5305\u5c06\u88ab\u5347\u7ea7\uff1a
openssh-client openssh-server
\u5347\u7ea7\u4e86 2 \u4e2a\u8f6f\u4ef6\u5305\uff0c\u65b0\u5b89\u88c5\u4e86 1 \u4e2a\u8f6f\u4ef6\u5305\uff0c\u8981\u5378\u8f7d 0 \u4e2a\u8f6f\u4ef6\u5305\uff0c\u6709 171 \u4e2a\u8f6f\u4ef6\u5305\u672a\u88ab\u5347\u7ea7\u3002
\u9700\u8981\u4e0b\u8f7d 1,169 kB \u7684\u8f6f\u4ef6\u5305\u3002
\u89e3\u538b\u7f29\u540e\u4f1a\u6d88\u8017\u6389 657 kB \u7684\u989d\u5916\u7a7a\u95f4\u3002
\u60a8\u5e0c\u671b\u7ee7\u7eed\u6267\u884c\u5417\uff1f [Y/n] y
\u83b7\u53d6\uff1a1 http://mirrors.aliyuncs.com/ubuntu/ trusty-updates/main openssh-server amd64 1:6.6p1-2ubuntu2.7 [322 kB]
\u83b7\u53d6\uff1a2 http://mirrors.aliyuncs.com/ubuntu/ trusty-updates/main openssh-client amd64 1:6.6p1-2ubuntu2.7 [564 kB]
\u83b7\u53d6\uff1a3 http://mirrors.aliyuncs.com/ubuntu/ trusty-updates/main rsync amd64 3.1.0-2ubuntu0.2 [284 kB]
\u4e0b\u8f7d 1,169 kB\uff0c\u8017\u65f6 0\u79d2 (1,326 kB/s)
\u6b63\u5728\u9884\u8bbe\u5b9a\u8f6f\u4ef6\u5305 ...
(\u6b63\u5728\u8bfb\u53d6\u6570\u636e\u5e93 ... \u7cfb\u7edf\u5f53\u524d\u5171\u5b89\u88c5\u6709 74090 \u4e2a\u6587\u4ef6\u548c\u76ee\u5f55\u3002)
\u6b63\u51c6\u5907\u89e3\u5305 .../openssh-server_1%3a6.6p1-2ubuntu2.7_amd64.deb ...
\u6b63\u5728\u5c06 openssh-server (1:6.6p1-2ubuntu2.7) \u89e3\u5305\u5230 (1:6.6p1-2ubuntu2.3) \u4e0a ...
\u6b63\u51c6\u5907\u89e3\u5305 .../openssh-client_1%3a6.6p1-2ubuntu2.7_amd64.deb ...
\u6b63\u5728\u5c06 openssh-client (1:6.6p1-2ubuntu2.7) \u89e3\u5305\u5230 (1:6.6p1-2ubuntu2.3) \u4e0a ...
\u6b63\u5728\u9009\u4e2d\u672a\u9009\u62e9\u7684\u8f6f\u4ef6\u5305 rsync\u3002
\u6b63\u51c6\u5907\u89e3\u5305 .../rsync_3.1.0-2ubuntu0.2_amd64.deb ...
\u6b63\u5728\u89e3\u5305 rsync (3.1.0-2ubuntu0.2) ...
\u6b63\u5728\u5904\u7406\u7528\u4e8e ureadahead (0.100.0-16) \u7684\u89e6\u53d1\u5668 ...
\u6b63\u5728\u5904\u7406\u7528\u4e8e man-db (2.6.7.1-1ubuntu1) \u7684\u89e6\u53d1\u5668 ...
\u6b63\u5728\u8bbe\u7f6e openssh-client (1:6.6p1-2ubuntu2.7) ...
\u6b63\u5728\u8bbe\u7f6e openssh-server (1:6.6p1-2ubuntu2.7) ...
invoke-rc.d: policy-rc.d denied execution of restart.
\u6b63\u5728\u8bbe\u7f6e rsync (3.1.0-2ubuntu0.2) ...
Removing any system startup links for /etc/init.d/rsync ...
update-rc.d: warning: default stop runlevel arguments (0 1 6) do not match rsync Default-Stop values (none)
Adding system startup for /etc/init.d/rsync ...
/etc/rc0.d/K20rsync -> ../init.d/rsync
/etc/rc1.d/K20rsync -> ../init.d/rsync
/etc/rc6.d/K20rsync -> ../init.d/rsync
/etc/rc2.d/S20rsync -> ../init.d/rsync
/etc/rc3.d/S20rsync -> ../init.d/rsync
/etc/rc4.d/S20rsync -> ../init.d/rsync
/etc/rc5.d/S20rsync -> ../init.d/rsync
invoke-rc.d: policy-rc.d denied execution of restart.
\u6b63\u5728\u5904\u7406\u7528\u4e8e ureadahead (0.100.0-16) \u7684\u89e6\u53d1\u5668 ...
shiyanlou:~/ $ [20:09:01]
shiyanlou:~/ $ sudo apt-get install openssh-server rsync [20:09:37]
\u6b63\u5728\u8bfb\u53d6\u8f6f\u4ef6\u5305\u5217\u8868... \u5b8c\u6210
\u6b63\u5728\u5206\u6790\u8f6f\u4ef6\u5305\u7684\u4f9d\u8d56\u5173\u7cfb\u6811
\u6b63\u5728\u8bfb\u53d6\u72b6\u6001\u4fe1\u606f... \u5b8c\u6210
openssh-server \u5df2\u7ecf\u662f\u6700\u65b0\u7684\u7248\u672c\u4e86\u3002
rsync \u5df2\u7ecf\u662f\u6700\u65b0\u7684\u7248\u672c\u4e86\u3002
\u5347\u7ea7\u4e86 0 \u4e2a\u8f6f\u4ef6\u5305\uff0c\u65b0\u5b89\u88c5\u4e86 0 \u4e2a\u8f6f\u4ef6\u5305\uff0c\u8981\u5378\u8f7d 0 \u4e2a\u8f6f\u4ef6\u5305\uff0c\u6709 171 \u4e2a\u8f6f\u4ef6\u5305\u672a\u88ab\u5347\u7ea7\u3002
shiyanlou:~/ $ [20:10:03]