使用centos7.5 DVD
环境虚拟机 VMware
jdk1.8
hadoop 3.1.3
ip地址 192.168.【吉祥数】.1
子网掩码 255.255.255.0
默认网关 192.168.【吉祥数】.2
首选DNS 192.168.【吉祥数】.2
吉祥数是10,实际根据环境判断,避免占用
yum install -y epel-release yum install -y vim yum install -y net-tools yum install -y ntp
vim /etc/sudoers
需要增加在 %wheel ALL=(ALL) ALL 后面
注意:user这一行不要直接放到root行下面,因为所有用户都属于wheel组,你先配置了user具有免密功能,但是程序执行到%wheel行时,该功能又被覆盖回需要密码。所以user要放到%wheel这行下面。
#找到 %wheel ALL=(ALL) ALL 添加在该行下面 user ALL=(ALL) NOPASSWD:ALL
vim /etc/hostname
hadoop11
vim /etc/hosts
192.168.10.11 hadoop11 192.168.10.12 hadoop12 192.168.10.13 hadoop13
systemctl stop firewalld systemctl disable firewalld.service
rpm -qa:查询所安装的所有rpm软件包
grep -i:忽略大小写
xargs -n1:表示每次只传递一个参数
rpm -e –nodeps:强制卸载软件
rpm -qa | grep -i java | xargs -n1 rpm -e --nodeps
vim /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO=“static”
IPADDR=192.168.10.11
GATEWAY=192.168.10.2
DNS1=192.168.10.2
TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="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="ens33" UUID="ec201efe-1f94-46ab-b276-50022ceee6e8" DEVICE="ens33" ONBOOT="yes" IPADDR=192.168.10.11 GATEWAY=192.168.10.2 DNS1=192.168.10.2
保存后重启
reboot
mkdir /opt/module mkdir /opt/software
tar -zxvf jdk-8u212-linux-x64.tar.gz -C /opt/module/ tar -zxvf hadoop-3.1.3.tar.gz -C /opt/module/
vim /etc/profile
vim /etc/profile.d/my_env.sh
#JAVA_HOME export JAVA_HOME=/opt/module/jdk1.8.0_212 export PATH=$PATH:$JAVA_HOME/bin #HADOOP_HOME export HADOOP_HOME=/opt/module/hadoop-3.1.3 export PATH=$PATH:$HADOOP_HOME/bin export PATH=$PATH:$HADOOP_HOME/sbin
source /etc/profile
jps java -version
192.168.10.11 hadoop11是主节点
192.168.10.12 hadoop12是Yarn节点
192.168.10.13 hadoop13是从节点
cd /opt/module/hadoop-3.1.3/etc/hadoop
vim core-site.xml
fs.defaultFS hdfs://hadoop11:8020 hadoop.tmp.dir /opt/module/hadoop-3.1.3/data hadoop.http.staticuser.user ocken
vim hdfs-site.xml
dfs.namenode.http-address hadoop11:9870 dfs.namenode.secondary.http-address hadoop13:9868
vim yarn-site.xml
yarn.nodemanager.aux-services mapreduce_shuffle yarn.resourcemanager.hostname hadoop12 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://hadoop11:19888/jobhistory/logs yarn.log-aggregation.retain-seconds 604800
vim mapred-site.xml
mapreduce.framework.name yarn mapreduce.jobhistory.address hadoop11:10020 mapreduce.jobhistory.webapp.address hadoop11:19888
vim workers
hadoop11 hadoop12 hadoop13
vim /etc/hostname vim /etc/sysconfig/network-scripts/ifcfg-ens33
ssh-keygen -t rsa ssh-copy-id hadoop11 ssh-copy-id hadoop12 ssh-copy-id hadoop13
scp -r $pdir/$fname $user@$host:$pdir/$fname
命令 递归 要拷贝的文件路径/名称 目的地用户@主机:目的地路径/名称
rsync -av $pdir/$fname $user@$host:$pdir/$fname
命令 选项参数 要拷贝的文件路径/名称 目的地用户@主机:目的地路径/名称
sudo vim /home/bin/xsync
#!/bin/bash #1. 判断参数个数 if [ $# -lt 1 ] then echo Not Enough Arguement! exit; fi #2. 遍历集群所有机器 for host in hadoop11 hadoop12 hadoop13 do echo ==================== $host ==================== #3. 遍历所有目录,挨个发送 for file in $@ do #4. 判断文件是否存在 if [ -e $file ] then #5. 获取父目录 pdir=$(cd -P $(dirname $file); pwd) #6. 获取当前文件的名称 fname=$(basename $file) ssh $host "mkdir -p $pdir" rsync -av $pdir/$fname $host:$pdir else echo $file does not exists! fi done done
【user】替换成你服务器用户名称
sudo chmod 777 xsync
cd /home/【user】/bin sudo vim myhadoop.sh
#!/bin/bash if [ $# -lt 1 ] then echo "No Args Input..." exit ; fi case in "start") echo " =================== 启动 hadoop集群 ===================" echo " --------------- 启动 hdfs ---------------" ssh hadoop11 "/opt/module/hadoop-3.1.3/sbin/start-dfs.sh" echo " --------------- 启动 yarn ---------------" ssh hadoop12 "/opt/module/hadoop-3.1.3/sbin/start-yarn.sh" echo " --------------- 启动 historyserver ---------------" ssh hadoop11 "/opt/module/hadoop-3.1.3/bin/mapred --daemon start historyserver" ;; "stop") echo " =================== 关闭 hadoop集群 ===================" echo " --------------- 关闭 historyserver ---------------" ssh hadoop11 "/opt/module/hadoop-3.1.3/bin/mapred --daemon stop historyserver" echo " --------------- 关闭 yarn ---------------" ssh hadoop12 "/opt/module/hadoop-3.1.3/sbin/stop-yarn.sh" echo " --------------- 关闭 hdfs ---------------" ssh hadoop11 "/opt/module/hadoop-3.1.3/sbin/stop-dfs.sh" ;; *) echo "Input Args Error..." ;; esac
sudo chmod +x myhadoop.sh
-设置查询hadoop脚本
sudo vim jpsall
#!/bin/bash for host in hadoop11 hadoop12 hadoop13 do echo =============== $host =============== ssh $host jps done
sudo chmod 777 jpsall
在分发xsync的时候,一定到bin目录下,避免同步.ssh文件🥸
xsync /home/【user】/bin/*
使用linux【user】用户进行一下操作
hdfs namenode -format
#启动服务器 myhadoop.sh start #停止服务器 myhadoop.sh stop #查看服务器 jpsall #输出一下内容就OK了 =============== hadoop11 =============== 5379 JobHistoryServer 4915 DataNode 5204 NodeManager 4760 NameNode 5448 Jps =============== hadoop12 =============== 7282 ResourceManager 7747 Jps 7592 NodeManager 7098 DataNode =============== hadoop13 =============== 5040 NodeManager 5147 Jps 4843 DataNode 4956 SecondaryNameNode
例如
#创建文件夹 hadoop fs -mkdir /input #将jdk移入input hadoop fs -put /opt/software/jdk-8u212-linux-x64.tar.gz /input
本文依据尚硅谷大数据Hadoop教程,hadoop3.x搭建到集群调优,百万播放内容整理,感谢感谢感谢海哥