0. 安装环境
安装系统版本,集群IP列表
- ubunut 16.04 server
192.168.24.128 ubuntu-master
192.168.24.129 ubuntu-slave1
192.168.24.130 ubuntu-slave2
1. 创建用户 和用户组(hadoop 用户的密码也是hadoop 方便记忆)
useradd hadoop
passwd hadoop
groupadd bigdata
usermod -a -G bigdata hadoop
mkdir /home/hadoop
chown -R hadoop:bigdata /home/hadoop
2. 更改hosts 文件以及对应的机器hostname
host文件 /etc/hosts
hostname文件 /etc/hostname
cat /etc/hosts
192.168.24.128 ubuntu-master
192.168.24.129 ubuntu-slave1
192.168.24.130 ubuntu-slave2
在这里要注意,我安装的集群是用虚拟机创建的,机器之间是直接复制虚拟机的方式,这时有一个问题就是机器的hostname都是一样的,这样一来,即使修改了hosts 文件,但是每台机器的hostname 并没有生效,需要修改各自的hostname保持和上述文件中一样的对应关系。
3. 无密码登陆
在每台虚拟机上分别执行以下命令
ssh-keygen -t rsa -P ""
cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
执行
ssh localhost
可以发现此时无需输入密码
集群之间的无密码ssh 通信
以192.168.24.128/129/130 三台机为例
登录192.168.24.128
ssh-copy-id -i $HOME/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i $HOME/.ssh/id_rsa.pub [email protected]
5. 设置环境变量
安装jdk,并设置环境变量,我的.bashrc文件的相关内容如下
#set oracle jdk environment
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_79 ## 这里要注意目录要换成自己解压的jdk 目录
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
5. 上传hadoop压缩包到指定目录并解压
$ ls
hadoop-2.6.2 hadoop-2.6.2.tar.gz
6. 修改相应的配置文件
需要修改的文件列表如下
~/hadoop/etc/hadoop/hadoop-env.sh
~/hadoop/etc/hadoop/yarn-env.sh
~/hadoop/etc/hadoop/slaves
~/hadoop/etc/hadoop/core-site.xml
~/hadoop/etc/hadoop/hdfs-site.xml
~/hadoop/etc/hadoop/mapred-site.xml
~/hadoop/etc/hadoop/yarn-site.xml
- 以下两个文件设置的内容为JAVA_HOME环境变量
~/hadoop/etc/hadoop/hadoop-env.sh
~/hadoop/etc/hadoop/yarn-env.sh
- 设置slave机器的列表
cat ~/hadoop/etc/hadoop/slaves
192.168.24.129
192.168.24.130
- ~/hadoop/etc/hadoop/core-site.xml
hadoop.tmp.dir
/home/hadoop/bigdata/hadoop/tmp
fs.default.name
hdfs://192.168.24.128:9000
- hdfs-site.xml
dfs.http.address
192.168.24.128:50070
dfs.namenode.secondary.http-address
192.168.24.128:50090
dfs.replication
1
- mapred-site.xml
mapred.job.tracker
192.168.24.128:9001
mapred.map.tasks
2
mapred.reduce.tasks
2
mapreduce.framework.name
yarn
mapreduce.jobhistory.address
192.168.24.128:10020
mapreduce.jobhistory.webapp.address
192.168.24.128:19888
- yarn-site.xml
yarn.resourcemanager.address
192.168.24.128:8032
yarn.resourcemanager.scheduler.address
192.168.24.128:8030
yarn.resourcemanager.webapp.address
192.168.24.128:8088
yarn.resourcemanager.resource-tracker.address
192.168.24.128:8031
yarn.resourcemanager.admin.address
192.168.24.128:8033
yarn.nodemanager.aux-services
mapreduce_shuffle
yarn.nodemanager.aux-services.mapreduce.shuffle.class
org.apache.hadoop.mapred.ShuffleHandler
按照上面的配置之后应该来说就可以了,但是在之前安装的过程中,我遇到过任务hang住的情况,查找资料发现是内存不够的原因,由于是自己电脑跑的虚拟机,内存有限,于是针对内存情况增加如下配置:
mapred-site.xml
mapreduce.map.memory.mb
230
mapreduce.reduce.memory.mb
460
mapreduce.map.java.opts
-Xmx184m
mapreduce.reduce.java.opts
-Xmx368m
yarn.app.mapreduce.am.resource.mb
460
yarn.app.mapreduce.am.command-opts
-Xmx368m
yarn-site.xml
yarn.nodemanager.resource.memory-mb
700
yarn.scheduler.minimum-allocation-mb
230
yarn.scheduler.maximum-allocation-mb
700
7. 启动
首次启动需要先在 Master 节点执行 NameNode 的格式化:
./hdfs namenode -format
进入~/hadoop/sbin目录
./start-dfs.sh
./start-yarn.sh
./mr-jobhistory-daemon.sh start historyserver
查看进程
hadoop@ubuntu-master:~$ jps
6193 ResourceManager
5863 NameNode
6051 SecondaryNameNode
6476 JobHistoryServer
6937 Jps
hadoop@ubuntu-slave1:~$ jps
3536 Jps
2884 NodeManager
2771 DataNode
hadoop@ubuntu-slave2:~$ jps
2937 NodeManager
2826 DataNode
3653 Jps
登录192.168.24.128:50070可以看到hadoop集群基本信息
8. 运行测试例子
进入 ~/hadoop/bin目录
./hdfs dfs -mkdir -p /user/hadoop
./hdfs dfs -mkdir input
./hdfs dfs -put /home/hadoop/bigdata/hadoop/etc/hadoop/*.xml input
./hadoop jar /home/hadoop/bigdata/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-*.jar grep input output 'dfs[a-z.]+'
运行程序部分结果如下:
17/01/13 23:45:14 INFO client.RMProxy: Connecting to ResourceManager at /192.168.24.128:8032
17/01/13 23:45:17 WARN mapreduce.JobResourceUploader: No job jar file set. User classes may not be found. See Job or Job#setJar(String).
17/01/13 23:45:17 INFO input.FileInputFormat: Total input paths to process : 9
17/01/13 23:45:18 INFO mapreduce.JobSubmitter: number of splits:9
17/01/13 23:45:19 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1484322039697_0001
17/01/13 23:45:20 INFO mapred.YARNRunner: Job jar is not present. Not adding any jar to the list of resources.
17/01/13 23:45:21 INFO impl.YarnClientImpl: Submitted application application_1484322039697_0001
17/01/13 23:45:22 INFO mapreduce.Job: The url to track the job: http://ubuntu-master:8088/proxy/application_1484322039697_0001/
17/01/13 23:45:22 INFO mapreduce.Job: Running job: job_1484322039697_0001
17/01/13 23:45:53 INFO mapreduce.Job: Job job_1484322039697_0001 running in uber mode : false
17/01/13 23:45:53 INFO mapreduce.Job: map 0% reduce 0%
17/01/13 23:46:22 INFO mapreduce.Job: map 11% reduce 0%
17/01/13 23:46:43 INFO mapreduce.Job: map 22% reduce 0%
17/01/13 23:47:08 INFO mapreduce.Job: map 33% reduce 0%
17/01/13 23:47:09 INFO mapreduce.Job: map 44% reduce 0%
17/01/13 23:47:10 INFO mapreduce.Job: map 56% reduce 0%
17/01/13 23:47:11 INFO mapreduce.Job: map 67% reduce 0%
17/01/13 23:47:59 INFO mapreduce.Job: map 78% reduce 0%
17/01/13 23:48:03 INFO mapreduce.Job: map 100% reduce 0%
17/01/13 23:48:24 INFO mapreduce.Job: map 100% reduce 50%
17/01/13 23:48:46 INFO mapreduce.Job: map 100% reduce 100%
17/01/13 23:48:47 INFO mapreduce.Job: Job job_1484322039697_0001 completed successfully
... ...
9. 后记
- 之前也零零散散装过几次hadoop,但是没有记录笔记,之前安装的虚拟机也被删除了,这此就重新整理了一下,以便以后参考。
- 安装的过程并不顺利,中间遇到了磕磕绊绊的小问题,之后会整理单独一个遇到问题的笔记,暂时就这样