( 若已有authorized_keys,则执行ssh-copy-id ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@slave1 上面命令的功能ssh-copy-id将pub值写入远程机器的~/.ssh/authorized_key中)
从master中把authorized_keys分发到各个结点上(会提示输入密码,输入slave1相应的密码即可):
scp /usr/hadoop/.ssh/authorized_keys hadoop@slave1:/home/master/.ssh
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
hadoop@slave1's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'hadoop@slave1'" and check to make sure that only the key(s) you wanted were added.
[hadoop@hadoop-master .ssh]$
然后在各个节点对authorized_keys执行(一定要执行该步,否则会报错):chmod 600 authorized_keys
保证.ssh 700,.ssh/authorized_keys 600权限
测试如下(第一次ssh时会提示输入yes/no,输入yes即可):
[hadoop@hadoop-master ~]$ ssh hadoop@slave1
Last login: Fri Feb 23 18:40:10 2018
[hadoop@slave1 ~]$
[hadoop@slave1 ~]$ exit
logout
Connection to slave1 closed.
[hadoop@hadoop-master ~]$
2.4 设置Hadoop的环境变量
Master及slave1都需操作
[root@hadoop-master ~]# su - root
[root@hadoop-master ~]# vi /etc/profile 末尾添加,保证任何路径下可执行hadoop命令
Java_HOME=/usr/java/jdk1.7.0_79
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=/usr/hadoop/hadoop-2.7.5/bin:$JAVA_HOME/bin:$PATH
让设置生效
[root@hadoop-master ~]# source /etc/profile
或者
[root@hadoop-master ~]# . /etc/profile
Master设置hadoop环境
su - hadoop
1 # vi etc/hadoop/hadoop-env.sh 新增以下内容
2 export JAVA_HOME=/usr/java/jdk1.7.0_79
3 export HADOOP_HOME=/usr/hadoop/hadoop-2.7.5
此时hadoop安装已完成,可执行hadoop命令,后续步骤为集群部署
[hadoop@hadoop-master ~]$ hadoop
Usage: hadoop [--config confdir] [COMMAND | CLASSNAME]
CLASSNAME run the class named CLASSNAME
or
where COMMAND is one of:
fs run a generic filesystem user client
version print the version
jar <jar> run a jar file
note: please use "yarn jar" to launch
YARN applications, not this command.
checknative [-a|-h] check native hadoop and compression libraries availability
distcp <srcurl> <desturl> copy file or directories recursively
archive -archiveName NAME -p <parent path> <src>* <dest> create a hadoop archive
classpath prints the class path needed to get the
credential interact with credential providers
Hadoop jar and the required libraries
daemonlog get/set the log level for each daemon
trace view and modify Hadoop tracing settings
Most commands print help when invoked w/o parameters.
[hadoop@hadoop-master ~]$
2.5 Hadoop设定
2.5.0 开放端口50070
注:centos7版本对防火墙进行 加强,不再使用原来的iptables,启用firewall
Master节点:
su - root
firewall-cmd --state 查看状态(若关闭,则先开启systemctl start firewalld)
firewall-cmd --list-ports 查看已开放的端口
开启8000端口:firewall-cmd --zone=public(作用域) --add-port=8000/tcp(端口和访问类型) --permanent(永久生效)
firewall-cmd --zone=public --add-port=1521/tcp --permanent
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=50070/tcp --permanent
firewall-cmd --zone=public --add-port=8088/tcp --permanent
firewall-cmd --zone=public --add-port=19888/tcp --permanent
firewall-cmd --zone=public --add-port=9000/tcp --permanent
firewall-cmd --zone=public --add-port=9001/tcp --permanent
firewall-cmd --reload -重启防火墙
firewall-cmd --list-ports 查看已开放的端口
systemctl stop firewalld.service停止防火墙
systemctl disable firewalld.service禁止防火墙开机启动
关闭端口:firewall-cmd --zone= public --remove-port=8000/tcp --permanent
Slave1节点:
su - root
systemctl stop firewalld.service停止防火墙
systemctl disable firewalld.service禁止防火墙开机启动
2.5.1 在Master节点的设定文件中指定Slave节点
[hadoop@hadoop-master hadoop]$ pwd
/usr/hadoop/hadoop-2.7.5/etc/hadoop
[hadoop@hadoop-master hadoop]$ vi slaves
slave1
2.5.2 在各节点指定HDFS文件存储的位置(默认是/tmp)
Master节点: namenode
创建目录并赋予权限
Su - root
# mkdir -p /usr/local/hadoop-2.7.5/tmp/dfs/name
# chmod -R 777 /usr/local/hadoop-2.7.5/tmp
# chown -R hadoop:hadoop /usr/local/hadoop-2.7.5
Slave节点:datanode
创建目录并赋予权限,改变所有者
Su - root
# mkdir -p /usr/local/hadoop-2.7.5/tmp/dfs/data
# chmod -R 777 /usr/local/hadoop-2.7.5/tmp
# chown -R hadoop:hadoop /usr/local/hadoop-2.7.5
2.5.3 在Master中设置配置文件(包括yarn)
su - hadoop
# vi etc/hadoop/core-site.xml
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://hadoop-master:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/hadoop-2.7.5/tmp</value>
</property>
</configuration>
# vi etc/hadoop/hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
<property>
<name>dfs.name.dir</name>
<value>/usr/local/hadoop-2.7.5/tmp/dfs/name</value>
</property>
<property>
<name>dfs.data.dir</name>
<value>/usr/local/hadoop-2.7.5/tmp/dfs/data</value>
</property>
</configuration>
#cp mapred-site.xml.template mapred-site.xml
# vi etc/hadoop/mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
YARN设定
yarn的组成(Master节点: resourcemanager ,Slave节点: nodemanager)
以下仅在master操作,后面步骤会统一分发至salve1。
# vi etc/hadoop/yarn-site.xml
<configuration>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>hadoop-master</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
2.5.4将Master的文件分发至slave1节点。
cd /usr/hadoop
scp -r hadoop-2.7.5 hadoop@hadoop-master:/usr/hadoop
2.5.5 Master上启动job history server,Slave节点上指定
此步2.5.5可跳过
Mater:
启动jobhistory daemon
# sbin/mr-jobhistory-daemon.sh start historyserver
确认
# jps
访问Job History Server的web页面
:19888/
Slave节点:
# vi etc/hadoop/mapred-site.xml
<property>
<name>mapreduce.jobhistory.address</name>
<value>hadoop-master:10020</value>
</property>
2.5.6 格式化HDFS(Master)
# hadoop namenode -format
Master结果:
2.5.7 在Master上启动daemon,Slave上的服务会一起启动
启动: