IP | 主机名 |
---|---|
192.168.100.101 | Hadoop1 |
192.168.100.102 | Hadoop2 |
192.168.100.103 | Hadoop3 |
计划好以后将以上表格内的内容写入/etc/hosts中(每个都要写)
echo '192.168.100.101 Hadoop1' >>/etc/hosts
echo '192.168.100.102 Hadoop2' >>/etc/hosts
echo '192.168.100.103 Hadoop3' >>/etc/hosts
修改主机名(每个主机都要改):
vim /etc/hostname
将hostname中的内容改为Hadoop1, (第二个就是Hadoop2)
修改ip地址(每个主机都要改)
vi /etc/sysconfig/network-scripts/ifcfg-ens*
# -----修改如下-----
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no # --> no
BOOTPROTO=static # --> static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens32
UUID=45400454-c60e-46f0-bd60-5faa1e7fe8f4
DEVICE=ens32
ONBOOT=yes # --> yes
# -----以下内容为新增-----
IPADDR=192.168.100.101 # Hadoop2就是102
GATEWAY=192.168.100.2
DNS1=192.168.100.2
NETMASK=255.255.255.0
修改完成后执行 reboot
重启三台主机
实验环境中关闭防火墙,防止后续查看web页面访问受阻。
systemctl stop firewalld # 关闭防火墙
systemctl disable firewalld # 禁止开机启动
在所有虚拟机中分别执行
ssh-keygen -t rsa # 连续三次回车生成密钥
在Hadoop1中生成认证的公钥key,再用下面的命令分发给各个节点
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
scp /root/.ssh/id_rsa.pub root@Hadoop2:/root/.ssh/authorized_keys
scp /root/.ssh/id_rsa.pub root@Hadoop3:/root/.ssh/authorized_keys
给所有虚报机上的authorized_keys添加权限
chmod 644 /root/.ssh/authorized_keys
测试免密登录
ssh root@Hadoop3 # 不需输入密码即为成功
exit # 退出ssh
mkdir -p /usr/local/java
tar -zxvf jdk-8u191-linux-x64.tar.gz -C /usr/local/java/
mv /usr/local/java/jdk1.8.1_91 /usr/local/java/jdk1.8
vi /etc/profile
# 在配置文件的最后添加如下配置
JAVA_HOME=/usr/local/java/jdk1.8
JRE_JOME=/usr/local/java/jdk1.8/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_JOME CLASS_PATH PATH
保存退出后,执行 source /etc/profile
刷新环境变量java -version
mkdir -p /usr/local/hadoop
tar -zxvf hadoop-3.1.1.tar.gz -C /usr/local/hadoop/
vi /etc/profile
# 在配置文件最后一行添加如下配置
# HADOOP
export HADOOP_HOME=/usr/local/hadoop/hadoop-3.1.1
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
source /etc/profile
刷新环境变量hadoop version
# 在/usr/local/hadoop目录下创建目录
cd /usr/local/hadoop/
mkdir tmp
mkdir var
mkdir dfs
mkdir dfs/name
mkdir dfs/data
cd /usr/local/hadoop/hadoop-3.1.1/etc/hadoop
vim workers
删除localhost
添加从节点主机名,例如:
Hadoop2
Hadoop3
找到 # JAVA_HOME=/usr/java/testing hdfs dfs -ls一行, 在下面添加如下代码
export JAVA_HOME=/usr/local/java/jdk1.8.0_65
export HADOOP_HOME=/usr/local/hadoop/hadoop-3.1.1
export HDFS_NAMENODE_USER=root
export HDFS_DATANODE_USER=root
export HDFS_SECONDARYNAMENODE_USER=root
export YARN_RESOURCEMANAGER_USER=root
export YARN_NODEMANAGER_USER=root
<property>
<name>fs.defaultFSname>
<value>hdfs://192.168.100.101:9000value>
property>
<property>
<name>hadoop.tmp.dirname>
<value>/usr/local/hadoop/tmpvalue>
property>
<property>
<name>dfs.name.dirname>
<value>/usr/local/hadoop/dfs/namevalue>
<description>Path on the local filesystem where theNameNode stores the namespace and transactions logs persistently.description>
property>
<property>
<name>dfs.data.dirname>
<value>/usr/local/hadoop/dfs/datavalue>
<description>Comma separated list of paths on the localfilesystem of a DataNode where it should store its blocks.description>
property>
<property>
<name>dfs.namenode.http-addressname>
<value>192.168.100.101:50070value>
property>
<property>
<name>dfs.namenode.secondary.http-addressname>
<value>192.168.100.101:50090value>
property>
<property>
<name>dfs.replicationname>
<value>2value>
property>
<property>
<name>dfs.permissionsname>
<value>falsevalue>
<description>need not permissionsdescription>
property>
hadoop classpath
,并将返回的地址复制,在配置下面的yarn-site.xml时会用到。<property>
<name>yarn.resourcemanager.hostnamename>
<value>Hadoop1value>
property>
<property>
<name>yarn.nodemanager.aux-servicesname>
<value>mapreduce_shufflevalue>
property>
<property>
<name>yarn.application.classpathname>
<value>输入刚才返回的Hadoop classpath路径value>
property>
<property>
<name>mapred.job.trackername>
<value>Hadoop1:49001value>
property>
<property>
<name>mapred.local.dirname>
<value>/usr/local/hadoop/varvalue>
property>
<property>
<name>mapreduce.framework.namename>
<value>yarnvalue>
property>
scp -r /usr/local/java Hadoop2:/usr/local/java
scp -r /usr/local/hadoop Hadoop2:/usr/local/hadoop
scp -r /etc/profile Hadoop2:/etc/
scp -r /usr/local/java Hadoop3:/usr/local/java
scp -r /usr/local/hadoop Hadoop3:/usr/local/hadoop
scp -r /etc/profile Hadoop3:/etc/
source /etc/profile
hdfs namenode -format
运行之后不报错,并在倒数第五六行有successfully即为格式化节点成功
start-all.sh
,启动hadoop集群的服务在浏览器上输入 http://192.168.100.101:8088 (前者为主节点ip地址,后者为hdfs的web进程对应的端口号)