Hadoop学习笔记二 安装部署(2)

对于本文中的三台机器,首先在dbrg-1上生成密钥对:
[dbrg@dbrg-1:~]$ssh-keygen  -t  rsa
这个命令将为dbrg-1上的用户dbrg生成其密钥对,询问其保存路径时直接回车采用默认路径,当提示要为生成的密钥输入passphrase的时候,直接回车,也就是将其设定为空密码。生成的密钥对id_rsa,id_rsa.pub,默认存储在/home/dbrg/.ssh目录下。然后将id_rsa.pub的内容复制到每个机器(也包括本机)的/home/dbrg/.ssh/authorized_keys文件中,如果机器上已经有authorized_keys这个文件了,就在文件末尾加上id_rsa.pub中的内容,如果没有authorized_keys这个文件,直接cp或者scp就好了,下面的操作假设各个机器上都没有authorized_keys文件。

对于dbrg-1
[dbrg@dbrg-1:.ssh]$cp id_rsa.pub authorized_keys

对于dbrg-2(dbrg-3同dbrg-2的方法)
[dbrg@dbrg-2:~]$mkdir .ssh
[dbrg@dbrg-1:.ssh]$scp authorized_keys dbrg-2:/home/dbrg/.ssh/
此处的scp就是通过ssh进行远程copy,此处需要输入远程主机的密码,即dbrg-2机器上dbrg帐户的密码,当然,你也可以用其他方法将authorized_keys文件拷贝到其他机器上

[dbrg@dbrg-2:.ssh]$chmod 644 authorized_keys
这一步非常关键,必须保证authorized_keys只对其所有者有读写权限,其他人不允许有写的权限,否则SSH是不会工作的。我就曾经在配置SSH的时候郁闷了好久。

[dbrg@dbrg-2:.ssh]ls -la
drwx------ 2 dbrg dbrg .
drwx------ 3 dbrg dbrg ..
 -rw-r--r-- 1 dbrg dbrg authorized_keys
注意每个机器上的.ssh目录的ls -la都应该和上面是一样的

接着,在三台机器上都需要对sshd服务进行配置(其实是可以不用配置的,完成了上面的那些操作了以后SSH就已经可以工作了),在三台机器上修改文件/etc/ssh/sshd_config
#去除密码认证
PasswordAuthentication  no
AuthorizedKeyFile   .ssh/authorized_keys

至此各个机器上的SSH配置已经完成,可以测试一下了,比如dbrg-1向dbrg-2发起ssh连接
[dbrg@dbrg-1:~]$ssh  dbrg-2
如果ssh配置好了,就会出现以下提示信息
The authenticity of host [dbrg-2] can't be established.
Key fingerprint is 1024 5f:a0:0b:65:d3:82:df:ab:44:62:6d:98:9c:fe:e9:52.
Are you sure you want to continue connecting (yes/no)?
OpenSSH告诉你它不知道这台主机,但是你不用担心这个问题,因为你是第一次登录这台主机。键入“yes”。这将把这台主机的“识别标记”加到“~/.ssh/know_hosts”文件中。第二次访问这台主机的时候就不会再显示这条提示信息了。
然后你会发现不需要输入密码就可以建立ssh连接了,恭喜你,配置成功了
不过,别忘了测试本机ssh  dbrg-1


Hadoop环境变量
在/home/dbrg/HadoopInstall/hadoop-conf目录下的hadoop_env.sh中设置Hadoop需要的环境变量,其中JAVA_HOME是必须设定的变量。HADOOP_HOME变量可以设定也可以不设定,如果不设定,HADOOP_HOME默认的是bin目录的父目录,即本文中的/home/dbrg/HadoopInstall/hadoop。我的是这样设置的
export  HADOOP_HOME=/home/dbrg/HadoopInstall/hadoop
export  JAVA_HOME=/usr/java/jdk1.6.0
从这个地方就可以看出前面所述的创建hadoop0.12.0的链接hadoop的优点了,当以后更新hadoop的版本的时候,就不需要在改配置文件,只需要更改链接就可以了。


Hadoop配置文件
如前所述,在hadoop-conf/目录下,打开slaves文件,该文件用来指定所有的从节点,一行指定一个主机名。即本文中的dbrg-2,dbrg-3,因此slaves文件看起来应该是这样的
dbrg-2
dbrg-3
在conf/目录中的hadoop-default.xml中包含了Hadoop的所有配置项,但是不允许直接修改!可以在hadoop-conf/目录下的hadoop-site.xml里面定义我们需要的项,其值会覆盖hadoop-default.xml中的默认值。可以根据自己的实际需要来进行定制。以下是我的配置档:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="https://www.linuxidc.com/configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
  <name>fs.default.name</name>
  <value>dbrg-1:9000</value>
  <description>The name of the default file system. Either the literal string "local" or a host:port for DFS.</description>
</property>
<property>
  <name>mapred.job.tracker</name>
  <value>dbrg-1:9001</value>
  <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>
</property>
<property>
  <name>hadoop.tmp.dir</name>
  <value>/home/dbrg/HadoopInstall/tmp</value>
  <description>A base for other temporary directories.</description>
</property>
<property>
  <name>dfs.name.dir</name>
  <value>/home/dbrg/HadoopInstall/filesystem/name</value>
  <description>Determines where on the local filesystem the DFS name node should store the name table. 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.data.dir</name>
  <value>/home/dbrg/HadoopInstall/filesystem/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>1</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>
</configuration>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/pxxfx.html