Centos6.5下的Hadoop安装

时间:2023-03-09 07:55:36
Centos6.5下的Hadoop安装

开始进行云计算部分的学习,为了存档,写下现在进行过的步骤

需要用到的主要版本:

虚拟机:Vmware Workstation pro 12.5

Linux系统:CentOS6.4 64bit

jdk版本:jdk1.8.0_111

hadoop版本:hadoop-2.5.2

所有的包均可以在官网下载

在此次搭建环境中,主要是搭建了一个主节点,两个从节点,hostname分别是master,slave1,slave2

地址设置为静态ip.图形化处理只需要改变右上角网络,

192.168.66.111 master

192.168.66.112  slave1

192.168.66.113  slave2

一、Vmware Workstation+Centos6.5的安装

1.官网选择,安装版本12.5,输入序列号。

2.安装好虚拟机后,安装centos6.5版本的Linux系统。进行相关的环境设置。主要设置如下:

①需要将网络连接NAT,改成host-only模式,右键centos系统,进行编辑。

②将网络设置成静态IP,以便后来进行相关的编程。

③设置DNS解析:

  使用 vim /etc/sysconfig/network 命令,进行相关更改。  将HOSTNAME的变量给成master

  设置节点映射,vim /etc/hosts.在文本的最后一行追加内容:192.168.66.111 master

  验证配置,执行ping master,如果能够ping通过。则表示,这个配置正确。(需要保证网络连通)

同理,需要在其他节点设置相同。

这一步可以颠倒顺序,先配置单机,再配置集群。或者先配置集群在配置单机。只需要注意克隆的顺序即可。但是均需要在hosts文件中,添加节点IP

④关闭防火墙

  命令setup ,选择firewall configuration,回车,之后进入设置按键,将*中按空格,取消。然后保存退出。

  命令service iptables status 验证防火墙是否关闭,如果提示not running则表示已经关闭。——这一步需要在root权限下进行,否则会没有提示

⑤设置SSH自动登录

  验证是否安装了SSH。命令 rpm -qa |grep ssh   若没有安装,则命令 yum install openssh-server

  配置SSH免密登录(在这个过程花费了很多时间,在这里写出来):

ssh-keygen -t rsa 若有提示信息,直接进行回车,最后生成.ssh文件, 进入密钥目录,~/.ssh,命令:cp id_rsa.pub anthorized_keys 这个命令会生成授权文件:authorized_keys,然后使用 ls 命令,进行查看。

同时,命令  vi /etc/ssh/sshd_config   删除下列文字:

Centos6.5下的Hadoop安装

命令  service sshd restart   对其进行重新启动,以上的命令需要分别在三个机器中都实现

然后输入命令: cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

ssh slave1 cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys

       ssh slave2 cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys

我们需要在ssh目录中查看是否已经配置完成,每个主机上面的公钥和密钥都存放在一个文件夹中,这个很重要,会导致后面的配置是否需要密码。(注:所有的操作均在root权限下进行,也可以新建一个hadoop用户)

  cd ~/.ssh
  cat authorized_keys

Centos6.5下的Hadoop安装

scp authorized_keys root@slave1:/root/.ssh/

scp known_hosts root@slave1:/root/.ssh/

scp known_hosts root@slave2:/root/.ssh/

scp authorized_keys root@slave2:/root/.ssh/

需要将所有的文件拷贝到每个需要配置的节点主机上。

  验证SSH无密码登录:

执行命令   ssh slave1        后面不需要确认,若登录了,需要用命令:exit 进行退出。  再次使用命令ssh slave1之后可以看到登录信息。

二、JDK的安装

  安装jdk文件。

Centos6.5下的Hadoop安装

主要需要注意权限问题,以及目录问题。

主要命令是

1.改变文件的位置:mv,

2.用命令chmod 777 jdk-8u111-linux-x64.rpm修改文件权限,双击它就自动解压安装了,安装完成后,在/usr目录下产生一个新的 java 文件夹

3.设置环境变量

vi打开文件命令:vi /etc/profile

移至文件末尾插入一个空行:输入字母o

输入以下配置信息:(注:这里的分隔符是冒号不是分号)

JAVA_HOME=/usr/java/jdk1.8.0_111

PATH=$JAVA_HOME/bin:$PATH

CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export JAVA_HOME

export PATH

export CLASSPATH

先按Esc退出编辑模式,再保存退出输入 :wq ! (冒号也要输入)

至此,新的JDK环境设置完毕。

4.卸载原JDK

终端输入,查看gcj的版本号:rpm -qa|grep jdk

得到结果:

jdk-1.7.0_04-fcs.x86_64

java-1.6.0-openjdk-1.6.0.0-1.49.1.11.4.el6_3.x86_64

终端输入,卸载:yum -y remove java java-1.6.0-openjdk-1.6.0.0-1.49.1.11.4.el6_3.x86_64

等待系统自动卸载,最终终端显示 Complete,卸载完成

5.让系统配置立即生效,不用重启系统

终端输入命令:source /etc/profile

6.验证是否安装完好

输入命令java -version

Centos6.5下的Hadoop安装

注意:如果出现以下错误信息

      • bash: /usr/java/jdk1.7.0_04/lib/dt.jar: 权限不够
      • bash: /usr/java/jdk1.7.0_04/lib/tools.jar: 权限不够
  • 错误原因:分隔符不能用;(分号),要用:(冒号)
  • CLASSPATH=.;$JAVA_HOME/lib/tools.jar;$JAVA_HOME/lib/dt.jar
  • 这样写是不对滴,要这样写:
  • CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
  • PATH = $PATH;$JAVA_HOME/bin;也一样,通通用冒号分隔。

三、安装Hadoop

1.安装版本2.5.2版本,一定要下载rpm结尾的版本,进行相关的配置,也许其他也可以,但是没有找到配置文件

2.解压文件。命令:tar -xzvf 文件名

3.设置文件环境变量。 命令  vim /etc/profile    在文件的最后一行,命令 O 换行插入,增加以下内容:

export HADOOP_HOME=/usr/program/hadoop-2.5.2
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_YARN_HOME=$HADOOP_HOME
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HADOOP_HOME/lib
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib"

执行命令   source /etc/profile

4.验证Hadoop是否安装完好。

  命令 hadoop version   若出现如下语句,则说明安装成功。

Centos6.5下的Hadoop安装

5.进行修改Hadoop的配置文件————有一点需要注意,Hadoop2.5.2与Hadoop1.0其他的版本不同地方在于,2.5的配置文件都在etc/hadoop文件中,而1.0版本的Hadoop的配置文件是在conf中。同时,后面需要改进的的mapred-site.xml.template文件,就是原来的mapred-site.xml文件。其他的地方就是后面的包的位置不同,以后用到的时候再说。

①.修改hadoop-env.sh及yarn-env.sh中的JAVA_HOME,与环境变量中的路径相同即可

②. cd /usr/program/hadoop-2.5.2/etc/hadoop

进入配置路径,进行文件的配置   文件的打开方式 均用vi ,cat查看。而且首先需要在hadoop-2.5.2文件下创建一个目录,tmp,hdfs/data,hdfs/name,用来存储临时文件数据,和计算路径

  core-site.xml 

<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://master:9000</value>
<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>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/program/hadoop-2.5.2/tmp</value>
<description>A base for other temporary directories.</description>
</property>
<!-- i/o properties -->
<property>
<name>io.file.buffer.size</name>
<value>131072</value>
<description>The size of buffer for use in sequence files.
The size of this buffer should probably be a multiple of hardware
page size (4096 on Intel x86), and it determines how much data is
buffered during read and write operations.</description>
</property>
</configuration>

  hdfs-site.xml

<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>/usr/program/hadoop-2.5.2/hdfs/name</value>
<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>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/usr/program/hadoop-2.5.2/hdfs/data</value>
<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>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
<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>
</property>
<property>
<name>dfs.blocksize</name>
<value>134217728</value>
<description>
The default block size for new files, in bytes.
You can use the following suffix (case insensitive):
k(kilo), m(mega), g(giga), t(tera), p(peta), e(exa) to specify the size (such as 128k, 512m, 1g, etc.),
Or provide complete size in bytes (such as 134217728 for 128 MB).
</description>
</property>
<property>
<name>dfs.namenode.handler.count</name>
<value>10</value>
<description>The number of server threads for the namenode.</description>
</property>
</configuration>

  mapred-site.xml.template

<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
<description>The runtime framework for executing MapReduce jobs.
Can be one of local, classic or yarn.
</description>
</property>
<!-- jobhistory properties -->
<property>
<name>mapreduce.jobhistory.address</name>
<value>master:10020</value>
<description>MapReduce JobHistory Server IPC host:port</description>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>master:19888</value>
<description>MapReduce JobHistory Server Web UI host:port</description>
</property>
</configuration>

  yarn-site.xml

configuration>
<!-- Site specific YARN configuration properties -->
<property>
<description>The hostname of the RM.</description>
<name>yarn.resourcemanager.hostname</name>
<value>master</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>${yarn.resourcemanager.hostname}:8032</value>
<description>The address of the applications manager interface in the RM.</description>
</property>
<property>
<description>The address of the scheduler interface.</description>
<name>yarn.resourcemanager.scheduler.address</name>
<value>${yarn.resourcemanager.hostname}:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>${yarn.resourcemanager.hostname}:8031</value>
</property>
<property>
<description>The address of the RM admin interface.</description>
<name>yarn.resourcemanager.admin.address</name>
<value>${yarn.resourcemanager.hostname}:8033</value>
</property>
<property>
<description>The http address of the RM web application.</description>
<name>yarn.resourcemanager.webapp.address</name>
<value>${yarn.resourcemanager.hostname}:8088</value>
</property>
<property>
<description>The minimum allocation for every container request at the RM,
in MBs. Memory requests lower than this won't take effect,
and the specified value will get allocated at minimum.
default is 1024
</description>
<name>yarn.scheduler.minimum-allocation-mb</name>
<value>512</value>
</property>
<property>
<description>The maximum allocation for every container request at the RM,
in MBs. Memory requests higher than this won't take effect,
and will get capped to this value.
default value is 8192</description>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>2048</value>
</property>
<property>
<description>Amount of physical memory, in MB, that can be allocated
for containers.default value is 8192</description>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>2048</value>
</property>
<property>
<description>Whether to enable log aggregation. Log aggregation collects
each container's logs and moves these logs onto a file-system, for e.g.
HDFS, after the application completes. Users can configure the
"yarn.nodemanager.remote-app-log-dir" and
"yarn.nodemanager.remote-app-log-dir-suffix" properties to determine
where these logs are moved to. Users can access the logs via the
Application Timeline Server.
</description>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
</property>
</configuration>

 vi slaves   编辑从节点,可以将主节点也作为从节点进行编辑。

输入:master,slave1,slave2

在保存完所有的设置后,我们需要同样配置其他从节点。可以硬复制,也可以将文件进行拷贝,从master到slave1,slave2

输入命令:scp -r  /usr/program/hadoop-2.5.2/etc/hadoop/  root@slave1:~/hadoop/hadoop-2.5.2/etc/

scp -r  /usr/program/hadoop-2.5.2/etc/hadoop/  root@slave2:~/hadoop/hadoop-2.5.2/etc/

scp -r  /etc/profile  root@slave1:/etc/profile

scp -r  /etc/profile  root@slave2:/etc/profile

完成情况如下所示:

Centos6.5下的Hadoop安装

所有的情况都已经配置完毕

现在首先需要对Hadoop进行系列的格式化:

hadoop namenode -format  格式化namenode,

start-dfs.sh

Centos6.5下的Hadoop安装

start-yarn.sh

Centos6.5下的Hadoop安装

成功搭建单机模式

Centos6.5下的Hadoop安装

Centos6.5下的Hadoop安装

Daemon Web Interface Notes
NameNode http://nn_host:port/ Default HTTP port is 50070.
ResourceManager http://rm_host:port/ Default HTTP port is 8088.
MapReduce JobHistory Server http://jhs_host:port/ Default HTTP port is 19888.

这样基本搭建已经完成,形成节点之间的连接。接下来开始配置hadoop和eclipse之间的联系,同时会解决遇到的困难。进行相关的配置问题