赞
踩
目录
5. 配置普通用户具有root权限,方便后期加sudo执行root权限的命令
2.xftp上传JDK8压缩包至/opt/software目录下
1.xftp上传Hadoop压缩包至/opt/software目录下
1.在/opt/module/hadoop-3.1.3目录下新建wcinput文件夹
2.wcinput文件夹下新建word.txt文件并输入内容
8.hadoop102尝试免密登录102、103、104三台机器
2.进入/opt/module/hadoop-3.1.3/etc/hadoop/目录下
虚拟机参数参考:
新建虚拟机参考博文《CentOS7中新建虚拟机详细步骤》
注意:1.选择桌面版安装
2.设置普通用户
虚拟机网络配置参考博文《Linux网关设置》
[root@hadoop100 ~]# yum install -y epel-release
如果你是最小化安装要执行以下命令,桌面版不需要
- [root@hadoop100 ~]# yum install -y net-tools
-
- [root@hadoop100 ~]# yum install -y vim
[root@hadoop100 ~]# vim /etc/sudoers
在%wheel下面添加命令如下图:
[root@hadoop100 ~]# rm -rf /opt/*
- [root@hadoop100 ~]# mkdir /opt/module
- [root@hadoop100 ~]# mkdir /opt/software
- [root@hadoop100 ~]# chown atguigu:atguigu /opt/module
- [root@hadoop100 ~]# chown atguigu:atguigu /opt/software
- [root@hadoop100 ~]# rpm -qa | grep -i java | xargs -n1 rpm -e --nodeps
-
- # 检查是否删除干净
- [root@hadoop100 ~]# rpm -qa | grep -i java
rpm -qa :查询所安装的所有 rpm 软件包grep -i :忽略大小写xargs -n1 :表示每次只传递一个参数rpm -e –nodeps :强制卸载软件
[root@hadoop100 ~]# reboot
模板虚拟机右键→管理→克隆
再克隆两台虚拟机hadoop103和hadoop104
(1)开启这四台虚拟机
(2)修改ip地址
[root@hadoop100 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
(3)修改主机名
[root@hadoop100 ~]# vim /etc/hostname
(4)重启hadoop102
(5)关闭hadoop102的防火墙
- [root@hadoop102 ~]# systemctl stop firewalld
- [root@hadoop102 ~]# systemctl disable firewalld.service
- [root@hadoop102 ~]# systemctl status firewalld
- ● firewalld.service - firewalld - dynamic firewall daemon
- Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
- Active: inactive (dead)
- Docs: man:firewalld(1)
(6)开启network,测试网络连接
[root@hadoop102 network-scripts]# systemctl stop NetworkManager
[root@hadoop102 network-scripts]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
[root@hadoop102 network-scripts]# systemctl restart network
[root@hadoop102 network-scripts]# ping www.baidu.com
[root@hadoop102 network-scripts]# hostname
hadoop102
[root@hadoop102 network-scripts]# ifconfig
- [root@hadoop102 network-scripts]# systemctl stop NetworkManager
- [root@hadoop102 network-scripts]# systemctl disable NetworkManager
- Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
- Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
- Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
- [root@hadoop102 network-scripts]# systemctl restart network
- [root@hadoop102 network-scripts]# ping www.baidu.com
- PING www.a.shifen.com (180.101.50.242) 56(84) bytes of data.
- 64 bytes from 180.101.50.242 (180.101.50.242): icmp_seq=1 ttl=128 time=2.99 ms
- 64 bytes from 180.101.50.242 (180.101.50.242): icmp_seq=2 ttl=128 time=3.26 ms
- ^C
- --- www.a.shifen.com ping statistics ---
- 2 packets transmitted, 2 received, 0% packet loss, time 1001ms
- rtt min/avg/max/mdev = 2.999/3.134/3.269/0.135 ms
- [root@hadoop102 network-scripts]# hostname
- hadoop102
- [root@hadoop102 network-scripts]# ifconfig
- ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 192.168.180.152 netmask 255.255.255.0 broadcast 192.168.180.255
- inet6 fe80::20c:29ff:fec5:2a4e prefixlen 64 scopeid 0x20<link>
- ether 00:0c:29:c5:2a:4e txqueuelen 1000 (Ethernet)
- RX packets 5 bytes 524 (524.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 30 bytes 4235 (4.1 KiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
- lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
- inet 127.0.0.1 netmask 255.0.0.0
- inet6 ::1 prefixlen 128 scopeid 0x10<host>
- loop txqueuelen 1 (Local Loopback)
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
- virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
- inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
- ether 52:54:00:55:4e:cf txqueuelen 1000 (Ethernet)
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
(7)另外两台虚拟机hadoop103和hadoop104重复(1)~(6)操作
(8)《关于Job for network.service failed because the control process exited with error code.》
注意:安装 JDK 前,一定确保提前删除了虚拟机自带的 JDK 。参考一、8
- [lxm@hadoop102 ~]$ rpm -qa | grep -i java | xargs -n1 rpm -e --nodeps
- rpm:未给出要擦除的软件包
- [lxm@hadoop102 module]$ tar -zxvf /opt/software/jdk-8u321-linux-x64.tar.gz -C /opt/module/
- [lxm@hadoop102 module]$ ll
- 总用量 0
- drwxr-xr-x. 8 lxm lxm 273 12月 16 2021 jdk1.8.0_321
- [lxm@hadoop102 module]$ sudo vim /etc/profile.d/my_env.sh
-
- # JAVA_HOME
- export JAVA_HOME=/opt/module/jdk1.8.0_321
- export PATH=$PATH:$JAVA_HOME/bin
- [lxm@hadoop102 module]$ source /etc/profile
- [lxm@hadoop102 module]$ javac
- [lxm@hadoop102 module]$ java -version
- java version "1.8.0_321"
- Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
- Java HotSpot(TM) 64-Bit Server VM (build 25.321-b07, mixed mode)
- [lxm@hadoop102 module]$ sudo vim /etc/profile.d/my_env.sh
-
- # HADOOP_HOME
- export HADOOP_HOME=/opt/module/hadoop-3.1.3
- export PATH=$PATH:$HADOOP_HOME/bin
- export PATH=$PATH:$HADOOP_HOME/sbin
- [lxm@hadoop102 module]$ source /etc/profile
- [lxm@hadoop102 module]$ hadoop version
- Hadoop 3.1.3
- Source code repository https://gitbox.apache.org/repos/asf/hadoop.git -r ba631c436b806728f8ec2f54ab1e289526c90579
- Compiled by ztang on 2019-09-12T02:47Z
- Compiled with protoc 2.5.0
- From source with checksum ec785077c385118ac91aadde5ec9799
- This command was run using /opt/module/hadoop-3.1.3/share/hadoop/common/hadoop-common-3.1.3.jar
[lxm@hadoop102 hadoop-3.1.3]$ mkdir wcinput
- [lxm@hadoop102 hadoop-3.1.3]$ cd ./wcinput/
- [lxm@hadoop102 wcinput]$ vim word.txt
-
- hello world
- hello java
- hello hadoop
[lxm@hadoop102 wcinput]$ hadoop jar /opt/module/hadoop-3.1.3/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar wordcount /opt/module/hadoop-3.1.3/wcinput/ /opt/module/hadoop-3.1.3/wcoutput/
- [lxm@hadoop102 hadoop-3.1.3]$ cat ./wcoutput/part-r-00000
- hadoop 1
- hello 3
- java 1
- world 1
注意:如果第二次提交wordcount命令就要删除/opt/module/hadoop-3.1.3目录下的wcoutput文件。
免密登录就是从一台虚拟机登录另一台虚拟机不需要输入密码
[lxm@hadoop102 ~]$ ssh hadoop103
Are you sure you want to continue connecting (yes/no)? yes
lxm@hadoop103's password:
- [lxm@hadoop103 ~]# exit
- 登出
- Connection to hadoop103 closed.
- [lxm@hadoop102 ~]
- [lxm@hadoop102 ~]$ ll -al
- [lxm@hadoop102 ~]$ cd .ssh
[lxm@hadoop102 .ssh]$ ssh-keygen -t rsa -P ''
回车
- [lxm@hadoop102 .ssh]$ ll
- -rw-------. 1 lxm lxm 1675 2月 12 11:10 id_rsa
- -rw-r--r--. 1 lxm lxm 395 2月 12 11:10 id_rsa.pub
- -rw-r--r--. 1 lxm lxm 561 2月 12 11:11 known_hosts
- [lxm@hadoop102 .ssh]$ ssh-copy-id hadoop102
- /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/lxm/.ssh/id_rsa.pub"
- The authenticity of host 'hadoop102 (192.168.180.152)' can't be established.
- ECDSA key fingerprint is SHA256:GFkoioPRq02rdq9bMm4L+OWi08ZceOxyBAaKGj4pObQ.
- ECDSA key fingerprint is MD5:8f:f8:55:6a:f6:ba:13:a4:81:3e:04:d2:3c:07:1c:a5.
- Are you sure you want to continue connecting (yes/no)? yes
- /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
- lxm@hadoop102's password:
-
- Number of key(s) added: 1
-
- Now try logging into the machine, with: "ssh 'hadoop102'"
- and check to make sure that only the key(s) you wanted were added.
-
- [lxm@hadoop102 .ssh]$ ssh-copy-id hadoop103
- [lxm@hadoop102 .ssh]$ ssh-copy-id hadoop104
- [lxm@hadoop102 .ssh]$ ssh hadoop102
- Last login: Sun Feb 12 10:11:45 2023 from 192.168.180.1
- [lxm@hadoop102 ~]$ exit
- 登出
- Connection to hadoop102 closed.
- [lxm@hadoop102 .ssh]$ ssh hadoop103
- Last login: Sun Feb 12 11:10:15 2023 from 192.168.180.152
- [lxm@hadoop103 ~]$ exit
- 登出
- Connection to hadoop103 closed.
- [lxm@hadoop102 .ssh]$ ssh hadoop104
- Last login: Sun Feb 12 09:57:31 2023 from 192.168.180.1
- [lxm@hadoop104 ~]$ exit
- 登出
- Connection to hadoop104 closed.
注意:
- NameNode和SecondaryNameNode不要安装在同一台服务器;
- ResourceManager也很消耗内存,不要和NameNode、SecondaryNameNode配置在同一台机器上。
- [lxm@hadoop102 hadoop]$ pwd
- /opt/module/hadoop-3.1.3/etc/hadoop
在下面四个xml文件的<configuration></configuration>标签内插入以下内容,注意根据你的主机名更改对应的localhost
- <!-- 指定 NameNode 的地址 -->
- <property>
- <name>fs.defaultFS</name>
- <value>hdfs://hadoop102:8020</value>
- </property>
- <!-- 指定 hadoop 数据的存储目录 -->
- <property>
- <name>hadoop.tmp.dir</name>
- <value>/opt/module/hadoop-3.1.3/data</value>
- </property>
- <!-- 配置 HDFS 网页登录使用的静态用户为 atguigu -->
- <property>
- <name>hadoop.http.staticuser.user</name>
- <value>atguigu</value>
- </property>
- <!-- nn web 端访问地址-->
- <property>
- <name>dfs.namenode.http-address</name>
- <value>hadoop102:9870</value>
- </property>
- <!-- 2nn web 端访问地址-->
- <property>
- <name>dfs.namenode.secondary.http-address</name>
- <value>hadoop104:9868</value>
- </property>
- <!-- 指定 MapReduce 程序运行在 Yarn 上 -->
- <property>
- <name>mapreduce.framework.name</name>
- <value>yarn</value>
- </property>
- <!-- 指定 MR 走 shuffle -->
- <property>
- <name>yarn.nodemanager.aux-services</name>
- <value>mapreduce_shuffle</value>
- </property>
- <!-- 指定 ResourceManager 的地址-->
- <property>
- <name>yarn.resourcemanager.hostname</name>
- <value>hadoop103</value>
- </property>
- <!-- 环境变量的继承 -->
- <property>
- <name>yarn.nodemanager.env-whitelist</name>
- <value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME</value>
- </property>
脚本放在声明了全局环境变量的路径
- [lxm@hadoop102 ~]$ cd /home/lxm
- [lxm@hadoop102 ~]$ mkdir bin
- [lxm@hadoop102 ~]$ cd bin
- [lxm@hadoop102 ~]$ vim xsync
- #!/bin/bash
- #1. 判断参数个数
- if [ $# -lt 1 ]
- then
- echo Not Enough Arguement!
- exit;
- fi
- #2. 遍历集群所有机器
- for host in hadoop102 hadoop103 hadoop104
- 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
[lxm@hadoop102 bin]$ chmod 777 xsync
[lxm@hadoop102 ~]$ xsync /home/lxm/bin
执行成功
[lxm@hadoop102 ~]$ sudo cp xsync /bin/
[lxm@hadoop102 ~]$ xsync /opt/module/
- # 同步环境变量配置
- # 注意:如果用了sudo,那么xsync一定要给它的路径补全。
- [lxm@hadoop102 ~]$ sudo ./bin/xsync /etc/profile.d/my_env.sh
-
- # 刷新环境
- [lxm@hadoop103 ~]$ source /etc/profile
- [lxm@hadoop104 ~]$ source /etc/profile
参考博文《Linux中CentOS7时间与网络时间orWindows同步的方法》
- [lxm@hadoop102 ~]$ vim /opt/module/hadoop-3.1.3/etc/hadoop/workers
- hadoop102
- hadoop103
- hadoop104
[lxm@hadoop102 ~]$ xsync /opt/module/hadoop-3.1.3/etc/hadoop/workers
[lxm@hadoop102 ~]$ hdfs namenode -format
[lxm@hadoop102 ~]$ start-dfs.sh
[lxm@hadoop103 ~]$ start-yarn.sh
http://hadoop102:9870
- <!-- 历史服务器端地址 -->
- <property>
- <name>mapreduce.jobhistory.address</name>
- <value>hadoop102:10020</value>
- </property>
- <!-- 历史服务器 web 端地址 -->
- <property>
- <name>mapreduce.jobhistory.webapp.address</name>
- <value>hadoop102:19888</value>
- </property>
- <!-- 开启日志聚集功能 -->
- <property>
- <name>yarn.log-aggregation-enable</name>
- <value>true</value>
- </property>
- <!-- 设置日志聚集服务器地址 -->
- <property>
- <name>yarn.log.server.url</name>
- <value>http://hadoop102:19888/jobhistory/logs</value>
- </property>
- <!-- 设置日志保留时间为 7 天 -->
- <property>
- <name>yarn.log-aggregation.retain-seconds</name>
- <value>604800</value>
- </property>
[lxm@hadoop102 ~]$ xsync /opt/module/hadoop-3.1.3/etc/hadoop/
- [lxm@hadoop102 ~]$ stop-dfs.sh
-
- [lxm@hadoop103 ~]$ stop-yarn.sh
-
- [lxm@hadoop102 ~]$ start-dfs.sh
-
- [lxm@hadoop103 ~]$ start-yarn.sh
[lxm@hadoop102 hadoop]$ mapred --daemon start historyserver
参考博文《Hadoop之——WordCount案例与执行本地jar包》
- [lxm@hadoop102 bin]$ vim myhadoop.sh
-
- #!/bin/bash
- if [ $# -lt 1 ]
- then
- echo "No Args Input..."
- exit ;
- fi
- case $1 in
- "start")
- echo " =================== 启动 hadoop 集群 ==================="
- echo " --------------- 启动 hdfs ---------------"
- ssh hadoop102 "/opt/module/hadoop-3.1.3/sbin/start-dfs.sh"
- echo " --------------- 启动 yarn ---------------"
- ssh hadoop103 "/opt/module/hadoop-3.1.3/sbin/start-yarn.sh"
- echo " --------------- 启动 historyserver ---------------"
- ssh hadoop102 "/opt/module/hadoop-3.1.3/bin/mapred --daemon start historyserver"
- ;;
- "stop")
- echo " =================== 关闭 hadoop 集群 ==================="
- echo " --------------- 关闭 historyserver ---------------"
- ssh hadoop102 "/opt/module/hadoop-3.1.3/bin/mapred --daemon stop historyserver"
- echo " --------------- 关闭 yarn ---------------"
- ssh hadoop103 "/opt/module/hadoop-3.1.3/sbin/stop-yarn.sh"
- echo " --------------- 关闭 hdfs ---------------"
- ssh hadoop102 "/opt/module/hadoop-3.1.3/sbin/stop-dfs.sh"
- ;;
- *)
- echo "Input Args Error..."
- ;;
- esac
[lxm@hadoop102 bin]$ chmod +x myhadoop.sh
[lxm@hadoop102 ~]$ sudo ./bin/xsync /home/lxm/bin/
- [lxm@hadoop102 bin]$ vim jpsall
-
- #!/bin/bash
- for host in hadoop102 hadoop103 hadoop104
- do
- echo =============== $host ===============
- ssh $host jps
- done
[lxm@hadoop102 bin]$ chmod +x jpsall
[lxm@hadoop102 ~]$ sudo ./bin/xsync /home/lxm/bin/
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。