(3) 由于Master节点的机器需要ssh无密码登录到所有slave节点,因此所有机器都需要如下配置。
在本文中Hadoop1是Master节点。
打开/etc/ssh/sshd_config文件,确保ssh使用的不是ssh2协议,否则将所有的Protocol 2修改成Protocol 1。
如果修改了该文件,用service sshd restart命令重启一下ssh服务。
键入以下命令
# cd ~/.ssh/
# ssh-keygen -t rsa1 -C "hadoop1" -f /root/.ssh/identity
# cat identity.pub >> authorized_keys
这时本机的公钥文件被存到了authorized_keys文件。
这时ssh localhost命令应该可以不需要输入密码就自动登录本机(如果ssh 本机IP成功,但ssh localhost失败,则可以打开/etc/hosts.allow文件并添加127.0.0.1)。
为了保证master不需要密码直接ssh到slave节点,所有slave机器要rsync下来master机器的/root/.ssh/identity.pub文件,并cat到本机的/root/.ssh/authorized_keys文件。
这时在master节点上用ssh+IP不输入密码直接可以登录slave机器。
(Hadoop需要SSH的无密访问。 Master机器访问Slaves机器)
(4) 修改环境变量
打开/etc/profile文件,在最后添加
export $HADOOP_HOME=/search/hadoop/hadoop
export PATH=$HADOOP_HOME/bin:$PATH
关闭,并运行$ source /etc/profile命令,则环境变量生效。
(5) 修改$HADOOP_HOME/conf/hadoop-env.sh配置文件的两个配置
export JAVA_HOME=配置本机jdk或者jre的路径
(Redhat如果没有jdk,可以yum install java-1.6.0-openjdk-devel,
注意必须是java1.6版本以上,否则hadoop无法正常运行)
#这里设定hadoop占用2G内存,可以根据机器配置来改
export HADOOP_HEAPSIZE=2000
(6) 修改$HADOOP_HOME/conf/hadoop-site.xml文件如下,注意fs.default.name和mapred.job.tracker配置项必须用master节点的机器名而不能IP。
否则运行HIVE时会遇到错误。
<!--[if !supportLists]-->1. <!--[endif]--><?xml version="1.0"?>
<!--[if !supportLists]-->2. <!--[endif]--><?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--[if !supportLists]-->3. <!--[endif]-->
<!--[if !supportLists]-->4. <!--[endif]--><configuration>
<!--[if !supportLists]-->5. <!--[endif]--><property>
<!--[if !supportLists]-->6. <!--[endif]--> <name>fs.default.name</name>
<!--[if !supportLists]-->7. <!--[endif]--> <value>hdfs://hadoop1:9000</value>
<!--[if !supportLists]-->8. <!--[endif]--> <description>The name of the default file system. Either the literal string "local" or a host:port for DFS.</description>
<!--[if !supportLists]-->9. <!--[endif]--></property>
<!--[if !supportLists]-->10. <!--[endif]--><property>
<!--[if !supportLists]-->11. <!--[endif]--> <name>mapred.job.tracker</name>
<!--[if !supportLists]-->12. <!--[endif]--> <value>hadoop1:9001</value>
<!--[if !supportLists]-->13. <!--[endif]--> <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 reduc
<!--[if !supportLists]-->14. <!--[endif]--></property>
<!--[if !supportLists]-->15. <!--[endif]--><property>
<!--[if !supportLists]-->16. <!--[endif]--> <name>hadoop.tmp.dir</name>
<!--[if !supportLists]-->17. <!--[endif]--> <value>/search/hadoop/hadoop/tmp</value>
<!--[if !supportLists]-->18. <!--[endif]--> <description>A base for other temporary directories.</description>
<!--[if !supportLists]-->19. <!--[endif]--></property>
<!--[if !supportLists]-->20. <!--[endif]--><property>
<!--[if !supportLists]-->21. <!--[endif]--> <name>dfs.name.dir</name>
<!--[if !supportLists]-->22. <!--[endif]--> <value>/search/hadoop/hadoop/filesystem/name</value>
<!--[if !supportLists]-->23. <!--[endif]--> <description>Determines where on the local filesystem the DFS name node should store the name table. If this is a comma-delimited list of
<!--[if !supportLists]-->24. <!--[endif]--></property>
<!--[if !supportLists]-->25. <!--[endif]--><property>
<!--[if !supportLists]-->26. <!--[endif]--> <name>dfs.data.dir</name>
<!--[if !supportLists]-->27. <!--[endif]--> <value>/search/hadoop/hadoop/filesystem/data</value>
<!--[if !supportLists]-->28. <!--[endif]--> <description>Determines where on the local filesystem an DFS data node should store its blocks. If this is a comma-delimited list of dire
<!--[if !supportLists]-->29. <!--[endif]--></property>
<!--[if !supportLists]-->30. <!--[endif]--><property>
<!--[if !supportLists]-->31. <!--[endif]--> <name>dfs.replication</name>
<!--[if !supportLists]-->32. <!--[endif]--> <value>1</value>
<!--[if !supportLists]-->33. <!--[endif]--> <description>Default block replication. The actual number of replications can be specified when the file is created. The default is used
<!--[if !supportLists]-->34. <!--[endif]--></property>
<!--[if !supportLists]-->35. <!--[endif]--></configuration>