hadoop1 hadoop2 hadoop3 ip分别为:192.168.56.211,192.168.56.212,192.168.56.213
vi /etc/hosts 分别添加如下内容:
192.168.56.211 hadoop1
192.168.56.212 hadoop2
192.168.56.213 hadoop3
分别配置三台虚拟机的主机名为:hadoop1 hadoop2 hadoop3
vi /etc/hostname
添加主机名
systemctl stop firewalld
systemctl disable firewalld
yum install -y rsync
分别在三台机器上执行:
a ssh-keygen -t rsa 按三次回车 ----生成ssh登录的公钥和私钥
b ssh-copy-hadoop1 输入对应机器的登录密码
ssh-copy-hadoop2 输入对应机器的登录密码
ssh-copy-hadoop3 输入对应机器的登录密码
/myshell 用于存放jpsall、xsync、myhadoop命令脚本,并授权:
chmod 777 jpsall
chmod 777 xsync
chmod 777 myhadoop
jpsall脚本如下:
#!/bin/bash
for host in hadoop1 hadoop2 hadoop3
do
echo ============$host============
ssh $host jps
done
xsync脚本如下:
#!/bin/bash
if [ $# -lt 1 ]
then
echo Not Enough Arguement
exit;
fi
for host in hadoop1 hadoop2 hadoop3
do
echo ======$host=====
for file in $@
do
if [ -e $file ]
then
pdir=$(cd -P $(dirname $file); pwd)
fname=$(basename $file)
ssh $host "mkdir -p $pdir"
rsync -av $pdir/$fname $host:$pdir
else
echo $file does not exits!
fi
done
done
myhadoop脚本如下:
#!/bin/bash
if [ $# -lt 1 ]
then
echo Not Enough Arguement
exit;
fi
case $1 in
"start")
echo "=========启动hadoop集群============="
echo "---------启动hdfs-------------------"
ssh hadoop1 "/soft/hadoop-3.3.1/sbin/start-dfs.sh"
echo "---------启动yarn-------------------"
ssh hadoop2 "/soft/hadoop-3.3.1/sbin/start-yarn.sh"
echo "---------启动hisotryserver----------"
ssh hadoop1 "/soft/hadoop-3.3.1/bin/mapred --daemon start historyserver"
;;
"stop")
echo "=========关闭hadoop集群============="
echo "---------关闭hisotryserver----------"
ssh hadoop1 "/soft/hadoop-3.3.1/bin/mapred --daemon stop historyserver"
echo "---------关闭yarn-------------------"
ssh hadoop2 "/soft/hadoop-3.3.1/sbin/stop-yarn.sh"
echo "---------关闭hdfs-------------------"
ssh hadoop1 "/soft/hadoop-3.3.1/sbin/stop-dfs.sh"
;;
*)
echo "input args error"
esac
jdk-8u321-linux-x64.tar.gz
hadoop-3.3.1.tar.gz
在/etc/profile.d目录下创建 myenv.sh
输入内容如下:
export JAVA_HOME=/soft/jdk1.8.0_321
export PATH=$PATH:$JAVA_HOME/bin
export PATH=$PATH:/soft/hadoop-3.3.1/bin
export PATH=$PATH:/soft/hadoop-3.3.1/sbin
export PATH=$PATH:/mycmd/bin
其中路径根据实际情况填写
source /etc/profile
配置文件目录:/soft/hadoop-3.3.1/etc/hadoop
core-site.xml配置文件在
fs.defaultFS
hdfs://192.168.56.211:8020
hadoop.tmp.dir
/soft/hadoop-3.3.1/data
hadoop.http.staticuser.user
root
hdfs-site.xml配置文件在
dfs.namenode.http-address
192.168.56.211:9870
dfs.namenode.secondary.http-address
192.168.56.213:9868
yarn-site.xml配置文件在
yarn.nodemanager.aux-services
mapreduce_shuffle
yarn.resourcemanager.hostname
hadoop2
yarn.nodemanager.env-whitelist
JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME
yarn.log-aggregation-enable
true
yarn.log.server.url
http://192.168.56.211:19888
yarn.log-aggregation.retain-seconds
640800
mapred-site.xml配置文件在
mapreduce.framework.name
yarn
mapreduce.jobhistory.address
192.168.56.211:10020
mapreduce.jobhistory.webapp.address
192.168.56.211:19888
修改workers文件内容为:注意前后不要有空格,不要有空行
hadoop1
hadoop2
hadoop3
分别修改/soft/hadoop-3.3.1/bin目录下:
start-dfs.sh stop-dfs.sh
在文件最前方添加如下:
HDFS_DATANODE_USER=root
HADOOP_SECURE_DN_USER=hdfs
HDFS_NAMENODE_USER=root
HDFS_SECONDARYNAMENODE_USER=root
修改start-yarn.sh stop-yarn.sh
在文件最前方添加如下:
YARN_RESOURCEMANAGER_USER=root
HADOOP_SECURE_DN_USER=yarn
YARN_NODEMANAGER_USER=root
xsync /soft/hadoop-3.3.1/
xsync /soft/jdk1.8.0_321/
xsync /etc/profile.d/myenv.sh
xsync /myshell/
并分别到hadoop2、hadoop3上执行source /etc/profile
第一次启动时格式化,后续启动hadoop不要格式化
hdfs namenode -format
myhadoop start --启动hadoop集群
jspall
查看到类似如下内容表示启动成功
============hadoop1============
19490 DataNode
19907 JobHistoryServer
20422 Jps
19773 NodeManager
19326 NameNode
============hadoop2============
15920 ResourceManager
15735 DataNode
16061 NodeManager
16861 Jps
============hadoop3============
13089 DataNode
13797 Jps
13270 NodeManager
13193 SecondaryNameNode