一、首先说一下,Hadoop有三种运行模式。 第一个是独立(或本地)运行模式:无需运行任何守护进程,所有程序都在一个同一个JVM上执行。 第二个是伪分布模式:Hadoop守护进程运行在本地机器上,模拟一个小规模的集群。 第三个是全分布模式,也就是通常所说的完全分布式模式:Hadoop守护进程运行在一个集群上。 下面简单介绍下完全分布式的配置: 首先准备三台机器,系统公共配置部分: 系统信息: [[email protected] ~]# cat /etc/redhat-release CentOS release 6.7 (Final) [[email protected] ~]$ uname -r 2.6.32-573.el6.x86_64 [[email protected] ~]# uname -m x86_64 公共操作用户:centos centos用户在/etc/sudoers中的公共配置: [[email protected] ~]# grep centos /etc/sudoers centos ALL=(ALL) NOPASSWD: ALL 环境变量如下: [[email protected] ~]# tail -16 /etc/profile #java JAVA_HOME=/home/centos/download/jdk PATH=$JAVA_HOME/bin:$PATH CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME export CLASSPATH #hadoop HADOOP_HOME=/home/centos/download/hadoop PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin export PATH 主机IP域名映射如下: [[email protected] ~]# cat /etc/hosts 10.0.0.101 hadoop1 10.0.0.102 hadoop2 10.0.0.103 hadoop3 主节点IP为: [[email protected] ~]# ifconfig | awk -F ‘[ :]+‘ ‘NR==2{print $4}‘ 10.0.0.101 从节点IP分别为: [[email protected] ~]# ifconfig | awk -F ‘[ :]+‘ ‘NR==2{print $4}‘ 10.0.0.102 [[email protected] ~]# ifconfig | awk -F ‘[ :]+‘ ‘NR==2{print $4}‘ 10.0.0.103 Java版本 [[email protected] ~]# java -version java version "1.8.0_65" Java(TM) SE Runtime Environment (build1.8.0_65-b17) Java HotSpot(TM) 64-Bit Server VM (build25.65-b01, mixed mode) Hadoop版本 [[email protected] ~]# hadoop version Hadoop 2.7.3 Subversionhttps://git-wip-us.apache.org/repos/asf/hadoop.git -r baa91f7c6bc9cb92be5982de4719c1c8af91ccff Compiled by root on 2016-08-18T01:41Z Compiled with protoc 2.5.0 From source with checksum2e4ce5f957ea4db193bce3734ff29ff4 This command was run using/home/centos/download/hadoop-2.7.3/share/hadoop/common/hadoop-common-2.7.3.jar 二、配置ssh 首先在三台机器上的家目录分别执行下述生成密钥对脚本,这样的话,三台机器的centos之间就可以免密码登录、免密码传输文件等操作。 [[email protected] ~]$ ll createssh.sh -rwxr-xr-x 1 centos centos 51 May 14 11:05createssh.sh [[email protected] ~]$ cat createssh.sh #!/bin/sh ssh-keygen -t rsa -P ‘‘ -f ~/.ssh/id_rsa 然后在三台机器上的家目录分别执行下述分发公钥 [[email protected] ~]$ ll fen.sh -rwxr-xr-x 1 centos centos 142 May 14 12:14fen.sh [[email protected] ~]$ cat fen.sh #!/bin/sh ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] #上述只是在执行的时候会输入yes和系统用户密码,其他在执行的时候就不会再次输入密码了。执行SSH的目的是,比如在配置好完全分布式的时候,主节点会自动吊起从节点的日志并且往里面写入数据,此时SSH的密钥对就起作用了。 #经常碰到的坑,要配置三台机器家目录中.ssh的权限为700,而且要配置家目录中.ssh目录中的authorized_keys权限为644. [[email protected] ~]$ chmod 700 .ssh [[email protected] ~]$ chmod 644 .ssh/authorized_keys 三、重点的配置文件内容 #三台机器共同配置 [[email protected] ~]$ grep JAVA_HOME download/hadoop/etc/hadoop/hadoop-env.sh # The only required environment variable isJAVA_HOME. All others are # set JAVA_HOME in this file, so that it iscorrectly defined on export JAVA_HOME=/home/centos/download/jdk #JAVA环境变量要在这再配置一下 [[email protected] ~]$ cat download/hadoop/etc/hadoop/core-site.xml <?xml version="1.0"?> <configuration> <property> <name>fs.defaultFS</name> <value>hdfs://hadoop1</value> </property> </configuration> [[email protected] ~]$ cat download/hadoop/etc/hadoop/hdfs-site.xml <?xml version="1.0"?> <configuration> <property> <name>dfs.replication</name> <value>2</value>#副本数,对应从节点数 </property> </configuration> [[email protected] ~]$ cat download/hadoop/etc/hadoop/mapred-site.xml <?xml version="1.0"?> <configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> </configuration> [[email protected] ~]$ cat download/hadoop/etc/hadoop/yarn-site.xml <?xml version="1.0"?> <configuration> <property> <name>yarn.resourcemanager.hostname</name> <value>hadoop1</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> </configuration> #注意这里只配置从节点的域名 [[email protected] ~]$ cat download/hadoop/etc/hadoop/slaves hadoop2 hadoop3 四、启动hadoop #下述命令只在主节点hadoop1中执行! #首先执行格式化命令 [[email protected] ~]$ hadoop namenode -format #然后启动hadoop [[email protected] ~]$ start-all.sh #查看启动进程 #主节点执行,名称节点只会存在于主节点中,包括文件名称等内容。 [[email protected] ~]$ jps 2736 SecondaryNameNode 2961 Jps 2889 ResourceManager 2539 NameNode #从节点执行,数据节点只会存在于从节点,是真正存放数据的地方。 [[email protected] ~]$ jps 2322 NodeManager 2234 DataNode 2380 Jps [[email protected] ~]$ jps 2481 DataNode 2646 Jps 2569 NodeManager #临时文件都生成在了根目录下的/tmp目录下 [[email protected] ~]$ ll /tmp/ total 32 drwxrwxr-x 3 centos centos 4096 May 1414:05 hadoop-centos -rw-rw-r-- 1 centos centos 5 May 14 14:06 hadoop-centos-namenode.pid -rw-rw-r-- 1 centos centos 5 May 14 14:06hadoop-centos-secondarynamenode.pid drwxr-xr-x 2 centos centos 4096 May 1414:06 hsperfdata_centos drwxrwxr-x 3 centos centos 4096 May 1414:06 Jetty_0_0_0_0_50070_hdfs____w2cu08 drwxrwxr-x 3 centos centos 4096 May 1414:06 Jetty_0_0_0_0_50090_secondary____y6aanv drwxrwxr-x 4 centos centos 4096 May 1414:06 Jetty_hadoop1_8088_cluster____.jtly5k -rw-rw-r-- 1 centos centos 5 May 14 14:06yarn-centos-resourcemanager.pid
时间: 2024-11-05 13:31:47