将编写好的xsync脚本文件放在/home/atguigu/bin目录下,因为这个路径已经在path变量里面了。之后可以随便在哪个目录下执行xsync命令
增加xsync脚本文件的执行权
chmod +x xsync
在任何位置敲击xsy,之后按一下tab键,就可以自动打出xsync

分布式模式集群的规划

第一步:配置core-site.xml,操作hadoop102,之后分发





<!-- 指定NameNode的地址 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop102:9820</value>
</property>
<!-- 指定hadoop数据的存储目录
官方配置文件中的配置项是hadoop.tmp.dir ,用来指定hadoop数据的存储目录,此次配置用的hadoop.data.dir是自己定义的变量, 因为在hdfs-site.xml中会使用此配置的值来具体指定namenode 和 datanode存储数据的目录
-->
<property>
<name>hadoop.data.dir</name>
<value>/opt/module/hadoop-3.1.3/data</value>
</property>
<!-- 下面是兼容性配置,先跳过 -->
<!-- 配置该atguigu(superUser)允许通过代理访问的主机节点 -->
<property>
<name>hadoop.proxyuser.atguigu.hosts</name>
<value>*</value>
</property>
<!-- 配置该atguigu(superuser)允许代理的用户所属组 -->
<property>
<name>hadoop.proxyuser.atguigu.groups</name>
<value>*</value>
</property>
<!-- 配置该atguigu(superuser)允许代理的用户-->
<property>
<name>hadoop.proxyuser.atguigu.users</name>
<value>*</value>
</property>
2、配置hdfs-site.xml文件
<!-- 指定NameNode数据的存储目录 -->
<property>
<name>dfs.namenode.name.dir</name>
<value>file://${hadoop.data.dir}/name</value>
</property>
<!-- 指定Datanode数据的存储目录 -->
<property>
<name>dfs.datanode.data.dir</name>
<value>file://${hadoop.data.dir}/data</value>
</property>
<!-- 指定SecondaryNameNode数据的存储目录 -->
<property>
<name>dfs.namenode.checkpoint.dir</name>
<value>file://${hadoop.data.dir}/namesecondary</value>
</property>
<!-- 兼容配置,先跳过 -->
<property>
<name>dfs.client.datanode-restart.timeout</name>
<value>30</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>



/opt/module/hadoop-3.1.3/data



3、配置yarn-site.xml
<configuration>
<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>
</configuration>


4、配置mapred-site.xml文件
<configuration>
<!--指定MapReduce程序运行在Yarn上 -->
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>

所有在102上配置的东西全部分发一下
直接分发hadoop目录/opt/module/hadoop-3.1.3/etc/hadoop


这里我们就已经配置好所有的文件了
单点启动集群:
因为,集群是新搭建的,需要在第一次启动的时候先在namenode所在的节点去格式化一下
hdfs namenode -formate
在/opt/module/hadoop-3.1.3目录下去格式化,格式化之后会在这个目录下生成一个data目录



1、在hadoop102上启动namenode
hdfs --daemon start namenode
查看浏览器页面
输入hadoop102:9870



2、在hadoop104上启动secondarynode
hdfs --daemon start secondarynamenode


2nn页面我们一般不会去访问这个web页面。没意义在hadoop102 103 104分别启动datanode
hdfs --daemon start dateanode





这个时候就已经成功实现了单点启动hdfs