Hadoop 一:完美集群搭建设置方法 [复制链接]查看:4677回复:0

Hadoop 一:完美集群搭建

unbuntu-master  namenode|jobtracker
unbuntu-slaveone  datanode|tasktracker
unbuntu-slavetwo  datanode|tasktracker
# NameNode 和 JobTracker 可以是同一台机器,也可以分开;
# Secondary NameNode 在 Hadoop-1.0.3 中被废弃,用 Checkpoint Node 和 Backup Node 来代替;


1. 修改 HOSTS 文件:
$ sudo vi /ect/hosts

# 增加以下行: unbuntu-master unbuntu-slaveone unbuntu-slavetwo

# 其中以下两行名称重复,容易引起异常,可注释第一行;  unbuntu-master unbuntu-master

2. 其他节点同步修改;


Suse 和 Redhat 操作系统可以下载 RPM 格式安装包,使用以下命令直接安装,并且不需要配置环境变量:
$ rpm -ivh jdk-7u6-linux-x64.rpm

1. 下载 JDK 安装包并放入指定位置:

2. 解压并移动到指定位置:
$ tar -zxvf jdk-7u6-linux-x64.tar.gz
$ mv /home/navon/entry/jdk1.7.0_06 /usr/java

3. 配置环境变量:
$ vim ~/.bashrc

# 增加以下行:
export JAVA_HOME=/usr/java/jdk1.7.0_06
export CLASSPATH=.{JAVA_HOME}/lib{JAVA_HOME}/jre/lib
export PATH=${JAVA_HOME}/binPATH

# 使配置生效:
$ source ~/.bashrc

4. 测试安装:
$ java -version

5. 其他节点同步安装;


Suse 和 Redhat 操作系统,可以省略步骤1,SSH 默认已安装;

1. 安装 SSH(Ubuntu):
$ sudo apt-get install ssh

2. 生成密钥:
$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

3. 存储口令:
$ ssh-add

4. 同步到其他节点(其他节点需先安装 SSH):

$ scp ~/.ssh/authorized_keys ubuntu-slaveone/.ssh/
$ scp ~/.ssh/authorized_keys ubuntu-slavetwo/.ssh/

navon@ubuntu-slaveone$ chmod 644 ~/.ssh/authorized_keys
navon@ubuntu-slavetwo$ chmod 644 ~/.ssh/authorized_keys

$ scp ~/.ssh/id_dsa.pub ubuntu-slaveone/.ssh/
$ scp ~/.ssh/id_dsa.pub ubuntu-slavetwo/.ssh/

navon@ubuntu-slaveone$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
navon@ubuntu-slavetwo$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

5. 验证:
navon@ubuntu-master$ ssh ubuntu-slaveone
navon@ubuntu-master$ ssh ubuntu-slavetwo

# 不需要密码连接成功说明配置完成;


1. 下载 Hadoop 安装包并放入指定位置:

2. 解压并移动到指定位置:
$ tar -zxvf hadoop-1.0.3.tar.gz
$ mv /home/navon/entry/hadoop-1.0.3. /usr

3. 配置环境变量(所有节点):
$ vim ~/.bashrc

# 增加以下行:
export HADOOP_HOME=/usr/hadoop-1.0.3

# 使配置生效:
$ source ~/.bashrc

4. 其他节点同步安装;

五、Hadoop 配置(/usr/hadoop-1.0.3/conf):

1. 配置 hadoop-env.sh:
$ vi /usr/hadoop-1.0.3/conf/hadoop-env.sh

# 增加以下行:
export JAVA_HOME=/usr/java/jdk1.7.0_06

# 后面一句表示取消环境变量HADOOP_HOME过时的警告;

2. 配置 core-site.xml:
$ vi /usr/hadoop-1.0.3/conf/core-site.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  <description>A base for other directories.</description>
  <description>A base for other directories.</description>
  <description>A base for other directories.</description>
  <description>The name of the default file system. A URI whose
  scheme and authority determine the FileSystem implementation.
  The uri's scheme determines the config property (fs.SCHEME.impl)
  naming the FileSystem implementation class. The uri's authority is
  used to determine the host, port, etc. for a filesystem.</description>
  <description>A base for other temporary directories.</description>

# 其中 hadoop.local.dir 、hadoop.remote.dir 和 hadoop.other.dir
# 是自定义变量,使用方式:${hadoop.local.dir};
# ${user.name} 返回当前系统用户;

3. 配置 hdfs-site.xml:
$ vi /usr/hadoop-1.0.3/conf/hdfs-site.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  <description>Determines where on the local filesystem the DFS
  name node should store the name table(fsimage). If this is a
  comma-delimited list of directories then the name table is
  replicated in all of the directories, for redundancy. </description>
  <description>Determines where on the local filesystem an DFS
  data node should store its blocks. If this is a comma-delimited
  list of directories, then data will be stored in all named
  directories, typically on different devices. Directories that
  do not exist are ignored. </description>
  <description>Default block replication. The actual number of
  replications can be specified when the file is created. The default
  is used if replication is not specified in create time. </description>

# 此处的目录不能预先创建,Hadoop 格式化时会自动创建,如果预先创建反而会有问题;

4. 配置 mapred-site.xml:
$ vi /usr/hadoop-1.0.3/conf/mapred-site.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  <description>The host and port that the MapReduce job tracker
  runs at. If "local", then jobs are run in-process as a single map
  and reduce task. </description>
  <description>The local directory where MapReduce stores
  intermediate data files. May be a comma-separated list of
  directories on different devices in order to spread disk i/o.
  Directories that do not exist are ignored. </description>
  <description>The directory where MapReduce stores control files.
  <description>The maximum number of map tasks that will be
  run simultaneously by a task tracker. </description>
  <description>The maximum number of reduce tasks that will be
  run simultaneously by a task tracker.</description>
  <description>Java opts for the task tracker child processes.
  The following symbol, if present, will be interpolated: @taskid@
  is replaced by current TaskID. Any other occurrences of '@' will
  go unchanged. For example, to enable verbose gc logging to a
  file named for the taskid in /tmp and to set the heap maximum
  to be a gigabyte, pass a 'value'
  of: -Xmx1024m -verbosec -Xloggc:/tmp/@taskid@.gc The
  configuration variable mapred.child.ulimit can be used to control
  the maximum virtual memory of the child processes. </description>

5. 配置 masters:
$ vi /usr/hadoop-1.0.3/conf/masters

# 注意,此处不要设置为:

# 运行 Secondary NameNode 的机器列表(每行一个);

6. 配置 slaves
$ vi /usr/hadoop-1.0.3/conf/slaves

# 增加以下行:

# 运行 DataNode 和 TaskTracker 的机器列表(每行一个);

7. 同步Hadoop配置:

navon@ubuntu-master$ scp -r /usr/hadoop-1.0.3/conf ubuntu-slaveone:/usr/hadoop-1.0.3
navon@ubuntu-master$ scp -r /usr/hadoop-1.0.3/conf ubuntu-slavetwo:/usr/hadoop-1.0.3

8. 测试:
navon@ubuntu-master$ hadoop


1. 格式化一个新的分布式文件系统:
navon@ubuntu-master$ hadoop namenode -format

2. 启动 Hadoop:
navon@ubuntu-master$ start-dfs.sh
navon@ubuntu-master$ start-mapred.sh

# 在主节点上启动 Hadoop,主节点会启动所有从节点的 Hadoop;

# start-all.sh 和 stop-all.sh 这两个脚本在1.03中被废弃,使用
# start-dfs.sh & start-mapred.sh 和 stop-dfs.sh & stop-mapred.sh 来代替;

3. 关闭 Hadoop:
navon@ubuntu-master$ stop-dfs.sh
navon@ubuntu-master$ stop-mapred.sh


1. 日志目录:
navon@ubuntu-master$ cd /usr/hadoop1.0.3/logs/

2. 查看端口占用情况:
navon@ubuntu-master$ netstat -antp | grep 19880

3. Incompatible namespaceIDs 错误:
namespaceIDs 不一致,每次进行文件系统格式化(hadoop namenode -format)会
重新创建一个 namenodeId,存储在 …/dfs/data 目录中,格式化时清空了 NameNode
下的数据,但没有清空 DataNode 下的数据,导致启动时 DataNode 失败!


1. HDFS 浏览:
# NameNode 和 JobTracker 的网络接口,默认地址分别为:

# DataNode 和 TaskTracker 的网络接口,默认地址分别为:

2. 使用 jps(JVM 进程工具)查看进程:
navon@ubuntu-master$ jps
***** NameNode
***** JobTracker
***** jps

navon@ubuntu-slaveone$ jps
***** DataNode
***** TaskTracker
***** jps

3. 将输入文件拷贝到分布式文件系统:
$ hadoop fs -mkdir sample-input
$ hadoop fs -put /usr/hadoop_1.0.3/conf/slaves sample-input

4. 运行发行版提供的示例程序:
$ hadoop jar hadoop-examples-1.0.3.jar grep sample-input sample-output 'sla[a-z.]+'

# 运行示例程序中的 grep(类),HDFS 上的输入目录为 sample-input
,输出目录为 sample-output,查找以 sla 开头的文件;

5. HDFS 常用操作:
#  将 HDFS 的文件拷贝到本地文件系统;
hadoop fs -get output ~/output

# 查看 HDFS 的基本统计信息;
hadoop dfsadmin -report

# 查看当前 HDFS 的副本数;
$ hadoop fsck -locations

# 列出 HDFS 下的文件;
$ hadoop fs -ls

# 列出 HDFS 下 output 目录中文件;
$ hadoop fs -ls output

#  删除 HDFS 上 output 目录;
hadoop fs -rmr output

#  查看 HDFS 上 output 目录中文件的内容;
hadoop fs -cat output/*

分享 转发