1.VM虚拟机下载
官网下载即可。
密钥:百度搜索一下有很多。
2.CentOs下载(用我这里即可)
通过百度网盘分享的文件:CentOS-8.5.2111-x86_64-dvd1.iso
链接:https://pan.baidu.com/s/1GJEkExhcERXzN6ZnGhXr0Q?pwd=w3qm
提取码:w3qm
--来自百度网盘超级会员V3的分享
注意:自己下载也可以,但是需要在centos7及以上。
3.新建虚拟机设置
3.1 新建虚拟机
完全跟着教程做。

注意下一步,命名中不要带有汉字和空格。
3.2虚拟机文件配置
点击编译虚拟机,修改至完全一样。
3.3 启动虚拟机配置
(1)配置语言。
(2)以太网打开!!!!(这里没开一切从来)
(3)配置root密码
(4)选择软件配置
(5)选择上海时间
最后确认等待
4.静态IP设置
4.1 同意协议,设置用户
4.1 查看联网情况
ping www.baidu.com
这是没问题的ctrl+c退出
4.2 查看网络配置
命令
ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.129 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fe59:8bdc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:59:8b:dc txqueuelen 1000 (Ethernet)
RX packets 3476 bytes 2163297 (2.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1230 bytes 103153 (100.7 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 1000 (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:ef:0b:01 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
4.3 修改虚拟机设置
4.4 修改wondows本地设置
(1)打开Window11控制面板
(2) 配置网络
4.5 修改虚拟机网络
(1)切换到root用户,安装vim和net-tools,我给的源基本都有应该不用安装。
[sh@localhost ~]$ su
密码:
[root@localhost sh]# yum -y install vim*
[root@localhost sh]# yum -y install net-tools
systemctl stop firewalld.service
(3)设置卡机不自启
systemctl disable firewalld.service
(4)检查防火墙状态
systemctl status firewalld.service
(5)打开/etc/sysconfig/network-scripts查看端口名字有些是ens33但不是全部,修改前一定要先看看,万一错了,你寄了,谁也不知道为啥。
[root@localhost sh]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# ll
总用量 4
-rw-r--r--. 1 root root 248 9月 9 15:42 ifcfg-ens160
[jyd@hadoop100 network-scripts]$ vim ifcfg-ens160
(6)文件内容设置如下:
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=ens160
UUID=aa7c134e-8d1c-4b80-9524-c562d2d9b43f
DEVICE=ens160
ONBOOT=yes
#静态ip值,根据需要设置
IPADDR=192.168.10.104
GATEWAY=192.168.10.2
DNS1=192.168.10.2
PREFIX=24
(7)重启网络服务
systemctl restart NetworkManager
(8)若查看网络配置显示没有改变,reboot重启便可,重启后查看如下:
ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.104 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::de1c:281c:b338:211d prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:59:8b:dc txqueuelen 1000 (Ethernet)
RX packets 119 bytes 22478 (21.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 119 bytes 12910 (12.6 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 1000 (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:ef:0b:01 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
(9)关闭NetworkManager,并取消开机自启,防止冲突
systemctl stop NetworkManager
systemctl disable NetworkManager
(10)关闭防火墙和取消开机自启
systemctl stop firewalld
systemctl disable firewalld.service
注意:后面开机后可能无法连接网络,输入sudo systemctl start NetworkManager 打开 NetworkManager 便可以。
(11)测试网络:宿主机和虚拟机分别输入ping 192.168.10.104,如下便是正常。
[root@localhost sh]# ping 192.168.10.104
PING 192.168.10.104 (192.168.10.104) 56(84) bytes of data.
64 bytes from 192.168.10.104: icmp_seq=1 ttl=64 time=0.082 ms
64 bytes from 192.168.10.104: icmp_seq=2 ttl=64 time=0.063 ms
64 bytes from 192.168.10.104: icmp_seq=3 ttl=64 time=0.083 ms
64 bytes from 192.168.10.104: icmp_seq=4 ttl=64 time=0.084 ms
64 bytes from 192.168.10.104: icmp_seq=5 ttl=64 time=0.079 ms
64 bytes from 192.168.10.104: icmp_seq=6 ttl=64 time=0.073 ms
64 bytes from 192.168.10.104: icmp_seq=7 ttl=64 time=0.066 ms
^Z
[2]+ 已停止 ping 192.168.10.104
PS C:\Users\86130> ping 192.168.10.104
正在 Ping 192.168.10.104 具有 32 字节的数据:
来自 192.168.10.104 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.104 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.104 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.10.104 的回复: 字节=32 时间<1ms TTL=64
192.168.10.104 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
4.5 修改主机名
(1)hostnamectl set-hostname 主机名1
hostnamectl set-hostname hd01
hostname
(2)修改/etc/hosts和映射关系
vim /etc/hosts
(3)加入如下内容:主机名和ip要一一对应
192.168.10.104 hd01
192.168.10.105 hd02
192.168.10.106 hd03
(4)完成后reboot重启查看
(5) ping查看是否能用,下面是正常的。
[root@hd01 sh]# ping hd01
PING hd01 (192.168.10.104) 56(84) bytes of data.
64 bytes from hd01 (192.168.10.104): icmp_seq=1 ttl=64 time=0.082 ms
64 bytes from hd01 (192.168.10.104): icmp_seq=2 ttl=64 time=0.070 ms
64 bytes from hd01 (192.168.10.104): icmp_seq=3 ttl=64 time=0.068 ms
64 bytes from hd01 (192.168.10.104): icmp_seq=4 ttl=64 time=0.098 ms
^Z
[2]+ 已停止 ping hd01
[root@hd01 sh]#
PS C:\Users\86130> ping hd01
正在 Ping hd01.local [fe80::de1c:281c:b338:211d%15] 具有 32 字节的数据:
来自 fe80::de1c:281c:b338:211d%15 的回复: 时间<1ms
来自 fe80::de1c:281c:b338:211d%15 的回复: 时间<1ms
来自 fe80::de1c:281c:b338:211d%15 的回复: 时间<1ms
来自 fe80::de1c:281c:b338:211d%15 的回复: 时间<1ms
fe80::de1c:281c:b338:211d%15 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
PS C:\Users\86130>
5.Xshell配置(免费)
(1)下载网址如下:
(2)直接全部确认,第一次登录输入用户名跟邮箱号,打开邮箱确认即可。按照官方指引即可。
(3)安图配置
点击新建
配置连接会话:1是连接名 2可以填配置好的主机名,也可以填ip地址
用root和root密码连接
完成后接受确认即可
6.Xftp配置(免费)
(1)下载网址如下:
(2)直接全部确认,第一次登录输入用户名跟邮箱号,打开邮箱确认即可。按照官方指引即可。
7.虚拟机中java配置
7.1 下载文件(下载我的即可,官网还麻烦)
通过百度网盘分享的文件:jdk-8u421-linux-x64.tar.gz
链接:https://pan.baidu.com/s/1zj4XzO35KtD3JORd50MFeg?pwd=ylkg
提取码:ylkg
--来自百度网盘超级会员V3的分享
7.2 查询虚拟机本身java
1. 首先切换到root用户,输入以下命令。
yum install -y epel-release
2.一般来说会报错(centos8百分百报错,主要是centos8停止更新了)
错误一: 一直加载百分之0,不动.
原因:第一个原因,网络没配置好,或者没网。第二个原因就是公司网校园网,没有vpn无法访问外网。
解决:1.ping www.baidu.com测试,正常的话下一步换网络
2.测试不正常重新配置网络。
错误二:
[root@hd01 ~]# yum install -y epel-release
CentOS Linux 8 - AppStream 0.0 B/s | 0 B 02:01
Errors during downloading metadata for repository 'appstream':
- Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]
错误:为仓库 'appstream' 下载元数据失败 : Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]
原因:源已经改变,改变源即可。
解决:
sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
第一个命令会在 /etc/yum.repos.d/
目录下的所有以 CentOS-
开头的文件中,将 mirrorlist=
行注释掉(即在前面加上 #
)。这样做的目的是禁用镜像列表,以避免因无法解析镜像列表而导致的错误。
第二个命令会在同样的文件中,将注释掉的 baseurl=http://mirror.centos.org
行取消注释,并将其更改为 baseurl=http://vault.centos.org
。CentOS Vault 是一个存档,提供旧版本的 CentOS 软件包。
[root@hd01 ~]# sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
[root@hd01 ~]# sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
[root@hd01 ~]# sudo yum install -y epel-release
CentOS Linux 8 - AppStream 334 kB/s | 8.4 MB 00:25
CentOS Linux 8 - BaseOS 434 kB/s | 4.6 MB 00:10
CentOS Linux 8 - Extras 3.7 kB/s | 10 kB 00:02
依赖关系解决。
===================================================================================================================================================================================================
软件包 架构 版本 仓库 大小
===================================================================================================================================================================================================
安装:
epel-release noarch 8-11.el8 extras 24 k
事务概要
===================================================================================================================================================================================================
安装 1 软件包
总下载:24 k
安装大小:35 k
下载软件包:
epel-release-8-11.el8.noarch.rpm 12 kB/s | 24 kB 00:01
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 12 kB/s | 24 kB 00:01
CentOS Linux 8 - Extras 1.6 MB/s | 1.6 kB 00:00
导入 GPG 公钥 0x8483C65D:
Userid: "CentOS (CentOS Official Signing Key) <[email protected]>"
指纹: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
来自: /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : epel-release-8-11.el8.noarch 1/1
运行脚本: epel-release-8-11.el8.noarch 1/1
验证 : epel-release-8-11.el8.noarch 1/1
已安装:
epel-release-8-11.el8.noarch
完毕!
3.java -version 查看虚拟机中是否有Java
[root@hd01 ~]# java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)
这种情况说明有openjdk,需要手动删除。
删除命令: rpm -qa | grep openjdk | xargs rpm -e --nodeps
检查:java -version
[root@hd01 ~]# java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)
[root@hd01 ~]# rpm -qa | grep openjdk | xargs rpm -e --nodeps
[root@hd01 ~]# java -version
-bash: /usr/bin/java: 没有那个文件或目录
7.3 安装java
1.新建文件夹 mkdir /opt/software/
2.点击上方红框,把windows和linux拉到相应文件夹,把下载的相应Java和hadoop安装包上传。
3.解压java文件夹
转到相应文件夹:cd /opt/software/
新建文件夹:mkdir /opt/module
解压到相应板块:tar -zxvf jdk-8u421-linux-x64.tar.gz -C /opt/module/
7.4 配置java
转到相应文件夹: cd /opt/module
查看解压名:ll
重命名:mv jdk1.8.0_421 jdk
接下来我们新建⼀个 /etc/profile.d/my_env.sh⽂件:vim /etc/profile.d/my_env.sh
在该⽂件中添加如下内容:
#JAVA_HOME
export JAVA_HOME=/opt/module/jdk
export PATH=$PATH:$JAVA_HOME/bin
保存退出: :wq
重置环境变量:source /etc/profile 注意:重置换环境变量命令,只能在虚拟机实现。
查看是否成功: java -version
8.虚拟机中hadoop配置
8.1 下载文件(下载我的即可,官网还麻烦)
通过百度网盘分享的文件:hadoop-3.3.3.tar.gz
链接:https://pan.baidu.com/s/1GF01P2jfXeEIaOw_T5Ao2w?pwd=lhma
提取码:lhma
--来自百度网盘超级会员V3的分享
8.2 安装hadoop
1.同刚才上传Java重复
2.解压hadoop
进入文件夹:cd /opt/software
解压:tar -zxvf hadoop-3.3.3.tar.gz -C /opt/module/
进入文件夹:cd /opt/module
查看:ll
重命名:mv hadoop-3.3.3 hadoop
查看是否成功:ll
[root@hd01 software]# cd /opt/module
[root@hd01 module]# ll
总用量 4
drwxr-xr-x. 10 1024 1024 215 5月 10 2022 hadoop-3.3.3
drwxr-xr-x. 8 root root 4096 9月 10 22:56 jdk
[root@hd01 module]# mv hadoop-3.3.3 hadoop
[root@hd01 module]# ll
总用量 4
drwxr-xr-x. 10 1024 1024 215 5月 10 2022 hadoop
drwxr-xr-x. 8 root root 4096 9月 10 22:56 jdk
8.3 配置hadoop
打开配置文件,在原后面添加:vim /etc/profile.d/my_env.sh
#HADOOP_HOME
export HADOOP_HOME=/opt/module/hadoop
export PATH=$PATH:$HADOOP_HOME/bin
export PATH=$PATH:$HADOOP_HOME/sbin
重新编译文件:source /etc/profile
查看:hadoop version
[root@hd01 module]# source /etc/profile
[root@hd01 module]# hadoop version
Hadoop 3.3.3
Source code repository https://github.com/apache/hadoop.git -r d37586cbda38c338d9fe481addda5a05fb516f71
Compiled by stevel on 2022-05-09T16:36Z
Compiled with protoc 3.7.1
From source with checksum eb96dd4a797b6989ae0cdb9db6efc6
This command was run using /opt/module/hadoop/share/hadoop/common/hadoop-common-3.3.3.jar
[root@hd01 module]#
9.hadoop运行测试
9.1 进入hadoop,查看节后目录
cd hadoop
ll
[root@hd01 module]# cd hadoop
[root@hd01 hadoop]# ll
总用量 88
drwxr-xr-x. 2 1024 1024 203 5月 10 2022 bin
drwxr-xr-x. 3 1024 1024 20 5月 10 2022 etc
drwxr-xr-x. 2 1024 1024 106 5月 10 2022 include
drwxr-xr-x. 3 1024 1024 20 5月 10 2022 lib
drwxr-xr-x. 4 1024 1024 288 5月 10 2022 libexec
-rw-rw-r--. 1 1024 1024 23472 5月 10 2022 LICENSE-binary
drwxr-xr-x. 2 1024 1024 4096 5月 10 2022 licenses-binary
-rw-rw-r--. 1 1024 1024 15217 5月 10 2022 LICENSE.txt
-rw-rw-r--. 1 1024 1024 29473 5月 10 2022 NOTICE-binary
-rw-rw-r--. 1 1024 1024 1541 4月 22 2022 NOTICE.txt
-rw-rw-r--. 1 1024 1024 175 4月 22 2022 README.txt
drwxr-xr-x. 3 1024 1024 4096 5月 10 2022 sbin
drwxr-xr-x. 4 1024 1024 31 5月 10 2022 share
9.2 演示案例1-统计单词数量
1.在hadoop安装⽬录下新建⼀个⽂件夹wcinput,并在该⽬录中随便存放⼀个⽂本⽂件 word.txt,之后我们会对word.txt⾥的单词数量进⾏统计。
# 创建⼀个⽬录,然后将若⼲个存储单词的⽂件放⼊这个⽬录
[root@hd01 hadoop]# mkdir wcinput
# 进⼊wcinput⽬录下
[root@hd01 hadoop]# cd wcinput
# 创建word.txt⽂件
[root@hd01 wcinput]# vim word.txt
2.在该⽂件中输⼊如下内容:
hadoop yarn
hadoop mapreduce
root
root
jiayadong
3.切换到hadoop⽬录: cd ..
4.执⾏wordcount命令: hadoop jar $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.3.jar wordcount wcinput wcoutput
5.查看结果:cat wcoutput/part-r-00000
10.克隆虚拟机(要克隆两台)
10.1 克隆
1.首先关闭克隆机,然后点击要克隆的虚拟机,然后右键,点击管理键,管理下有克隆按钮。
2.选择完整克隆。
3.选择文件位置,文件夹和主机名必须相同!!!!!!!
一定要克隆两台!!!!
10.2 修改其他两台克隆的虚拟机
1.修改其他克隆机的配置
[root@hd01 sh]# cd /etc/sysconfig/network-scripts
[root@hd01 network-scripts]# vim ifcfg-ens160
将将文件中的IPADDR改为:
IPADDR=192.168.10.105
前面已经添加了映射
192.168.10.104 hd01
192.168.10.105 hd02
192.168.10.106 hd03
这里修改时对应这里的,这里克隆是完全一样的不用修改。
hostnamectl set-hostname hd02
hostname
重启便可.
2.充分修改其他克隆机的配置
IPADDR=192.168.10.106
hostnamectl set-hostname hd03
3.新建两个xshell连接
4.修改图
11.ssh配置无密登录
11.1 安装SSH
# 安装SSH服务器
sudo yum install -y openssh-server
# 启动SSH服务
sudo systemctl start sshd
# 设置SSH服务开机⾃启动
sudo systemctl enable sshd
11.2 ssh基本使用
ssh [⽤户名]@[⽬标IP地址]
例子在hd01上ssh访问ha02 :
ssh [email protected]
我们现在hd01中,也可以通过如下命令连接到hd02中:ssh hd02
如果出现如下内容: Are you sure you want to continue connecting (yes/no)? 只需要输⼊yes,并回⻋即可,连接之后,我们可以通过exit命令退回到hd01
[root@hd01 ~]# ssh hd02
The authenticity of host 'hd02 (192.168.10.105)' can't be established.
ECDSA key fingerprint is SHA256:eccXezTm/Ag/cu+yakp/HkufU3o7TZpdf2s6beLSl88.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'hd02' (ECDSA) to the list of known hosts.
root@hd02's password:
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Thu Sep 12 10:32:58 2024 from 192.168.10.1
[root@hd02 ~]# exit
注销
11.3 免密登录配置

# 切换到.ssh⽬录下
cd /root/.ssh
# ⽣成密钥对
ssh-keygen -t rsa
[root@hd01 ~]# cd /root/.ssh
[root@hd01 .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:olkdty3m5Ntp8LvffDIM0heNDfn411L6bIu4c/EVLkc root@hd01
The key's randomart image is:
注意: 在⽣成密钥对时,我们不⽤设置⾃⼰的密码,直接连敲三个回⻋即可,就会⽣成两个⽂件:id_rsa 私钥、id_rsa.pub公钥。
3.后我们将⽣成的公钥拷⻉到要免密登录的⽬标机器上。
ssh-copy-id hd01
ssh-copy-id hd02
ssh-copy-id hd03
ssh hd02
exit
ssh hd03
exit
12.编写集群分发脚本xsync
12.1 安装rsync
1.⾸先我们要在3台虚拟机中都安装rsync
yum -y install rsync
[root@hd01 ~]# yum -y install rsync
上次元数据过期检查:2:27:20 前,执行于 2024年09月12日 星期四 11时06分14秒。
软件包 rsync-3.1.3-12.el8.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
[root@hd01 ~]#
2.测试
rsync -av /opt/module/hadoop/wcinput/ root@hd02:/opt/module/hadoop/wcinput/
[root@hd01 ~]# rsync -av /opt/module/hadoop/wcinput/ root@hd02:/opt/module/hadoop/wcinput/
sending incremental file list
sent 61 bytes received 12 bytes 146.00 bytes/sec
total size is 49 speedup is 0.67
[root@hd01 ~]#
12.2 创建xsync⽂件
cd /root
vim xsync
2.修改xsync文件内容。
#!/bin/bash
# 1. 判断参数个数
if [ $# -lt 1 ]; then
echo "Not Enough Arguments!"
exit 1
fi
# 2. 遍历集群所有机器
for host in hd01 hd02 hd03; 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 exist!"
fi
done
done
3.增加执⾏权限
chmod +x xsync
4.测试脚本
./xsync /root/xsync
12.3 同步脚本文件
cp /root/xsync /bin/
2.同步环境变量配置
xsync /etc/profile.d/my_env.sh
3.让环境变量生效:
source /etc/profile
4.在三台机器都环境变量生效:
source /etc/profile