hadoop集群搭建#### 配置虚拟机的ip
1.配置虚拟机的ip
vi /etc/hosts
172.16.219.138 centos138
172.16.219.139 centos139
172.16.219.140 centos140
2.配置虚拟机的主机名
vi /etc/sysconfig/network
# Created by anaconda
NETWORKING=yes
HOSTNAME=centos138
3.关闭防火墙和selinux
1.iptables -F
2.vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
#安全增强型 Linux(Security-Enhanced Linux)简称 SELinux,它是一个 Linux 内核模块,也是 Linux 的一个安全子系统
#SELinux 主要作用就是最大限度地减小系统中服务进程可访问的资源(最小权限原则)。
4.将系统的启动级别改为3
1.centos6修改为
id:3:initdefault
2.Centos7.x
中的默认启动界别已经修改了
修改方法:
#1.查看当前运行级别,
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
[root@centos138 ~]# systemctl get-default
multi-user.target
#2.此处看到默认为3,如果不是那么
systemctl set-default multi-user.target
[root@centos138 ~]# vi /etc/inittab
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#rgets:
# systemd uses 'targets' instead of runlevels. By defaul# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
5.创建普通用户,添加sudoers权限
-
新建普通用户hadoop
[root@centos138 ~]# adduser hadoop [root@centos138 ~]# passwd hadoop 更改用户 hadoop 的密码 。 新的 密码: 无效的密码: 密码少于 8 个字符 重新输入新的 密码: passwd:所有的身份验证令牌已经成功更新。
-
将hadoop用户添加到用户组
[root@centos138 ~]# usermod -a -G hadoop hadoop
-
配置权限
[root@centos138 ~]# vi /etc/sudoers ## Allow root to run any commands anywhere root ALL=(ALL) ALL hadoop ALL=(ALL) ALL ## Allows members of the 'sys' gr
6.配置免密登录
-
生成秘钥,先切换用户,然后生成秘钥
-
发送秘钥 ssh-copy-id 主机名
-
shell:
[root@centos138 ~]# su - hadoop [hadoop@centos138 ~]$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/hadoop/.ssh/id_rsa): Created directory '/home/hadoop/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/hadoop/.ssh/id_rsa. Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub. The key fingerprint is: SHA256:j2R0G2wNPIDYs188O3AQLKlkxR46DZJK0Btmra3lljg hadoop@centos138 The key's randomart image is: +---[RSA 2048]----+ |o. o =.+o+. | | .B * O o.oo | |.+ O * =.o=.. | |. o * +..o=o | | = o .S+.o | | E + o.oo | | o . .. | | | | | +----[SHA256]-----+ [hadoop@centos138 ~]$ cd .ssh/ [hadoop@centos138 .ssh]$ ll 总用量 8 -rw-------. 1 hadoop hadoop 1675 8月 19 01:37 id_rsa -rw-r--r--. 1 hadoop hadoop 398 8月 19 01:37 id_rsa.pub [hadoop@centos138 .ssh]$ ssh-copy-id centos138 /bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/hadoop/.ssh/id_rsa.pub" The authenticity of host 'centos138 (172.16.219.138)' can't be established. ECDSA key fingerprint is SHA256:JMjblYT4PB4D0Vyow/boHAGIOyvzxWdOEfnGeWbwb6k. ECDSA key fingerprint is MD5:91:ae:f5:47:a4:0b:2c:d4:3f:af:88:11:02:46:0a:1e. Are you sure you want to continue connecting (yes/no)? yes /bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys hadoop@centos138's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'centos138'" and check to make sure that only the key(s) you wanted were added. [hadoop@centos138 .ssh]$
7.安装jdk,略
8.时间同步
9.修改配置文件
(hadoop/etc/hadoop目录下为配置文件)
1.修改hadoop_env.sh,导入java环境变量(/usr/local/soft/jdk/)
[hadoop@centos138 .]# cd /hadoop/etc/hadoop
[hadoop@centos138 hadoop]# vi hadoop_env.sh
2.修改core-site.xml
[hadoop@centos138 hadoop]$ vi core-site.xml
<!-- Put site-specific property overrides in this file. -->
#配置的是通信的主节点的url链接
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://centos138:9000</value>
</property>
<!-- 配置操作hdfs的存冲大小 -->
<property>
<name>io.file.buffer.size</name>
<value>4096</value>
</property>
<!-- 配置临时数据存储目录 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/hadoop/hadoop-2.8.5/tmp</value>
</property>
</configuration>
3.修改hdfs-site.xml,配置存储分片数量
[hadoop@centos138 hadoop]$ vi hdfs-site.xml
<!--配置副本数-->
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
<!--hdfs的元数据存储位置-->
<property>
<name>dfs.namenode.name.dir</name>
<value>/opt/hadoop/hadoop-2.8.5/hdfs/name</value>
</property>
<!--hdfs的数据存储位置-->
<property>
<name>dfs.datanode.data.dir</name>
<value>/opt/hadoop/hadoop-2.8.5/hdfs/data</value>
</property>
<!--hdfs的namenode的web ui 地址-->
<property>
<name>dfs.http.address</name>
<value>centos138:50070</value>
</property>
<!--hdfs的snn的web ui 地址-->
<property>
<name>dfs.secondary.http.address</name>
<value>centos138:50090</value>
</property>
<!--是否开启web操作hdfs-->
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
<!--是否启用hdfs权限(acl)-->
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
</configuration>
4.修改yarn-site.xml,yarn负责资源调度
[hadoop@centos138 hadoop]$ vi yarn-site.xml
<configuration>
<!-- Site specific YARN configuration properties -->
<!--指定resourcemanager所启动的服务器主机名-->
<property>
<name>yarn.resourcemanager.hostname</name>
<value>centos138</value>
</property>
<!--指定mapreduce的shuffle-->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<!--指定resourcemanager的内部通讯地址-->
<property>
<name>yarn.resourcemanager.address</name>
<value>centos138:8032</value>
</property>
<!--指定scheduler的内部通讯地址-->
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>centos138:8030</value>
</property>
<!--指定resource-tracker的内部通讯地址-->
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>centos138:8031</value>
</property>
<!--指定resourcemanager.admin的内部通讯地址-->
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>centos138:8033</value>
</property>
<!--指定resourcemanager.webapp的ui监控地址-->
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>centos138:8088</value>
</property>
</configuration>
5.修改mapred-site.xml
[hadoop@centos138 hadoop]$ vi yarn-site.xml
<configuration>
<!--指定maoreduce运行框架-->
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value> </property>
<!--历史服务的通信地址-->
<property>
<name>mapreduce.jobhistory.address</name>
<value>centos138:10020</value>
</property>
<!--历史服务的web ui地址-->
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>centos138:19888</value>
</property>
</configuration>
6.修改slaves–助理配置
[hadoop@centos138 hadoop]$ vi slaves
centos139
centos140
7.格式化
[hadoop@centos138 hadoop]$ sudo chown -R hadoop /usr/local/soft/hadoop-2.8.5/
[hadoop@centos138 hadoop]$ /usr/local/soft/hadoop-2.8.5/bin/./hdfs namenode -format
19/08/22 02:20:34 INFO util.GSet: VM type = 64-bit
19/08/22 02:20:34 INFO util.GSet: 0.029999999329447746% max memory 889 MB = 273.1 KB
19/08/22 02:20:34 INFO util.GSet: capacity = 2^15 = 32768 entries
19/08/22 02:20:34 INFO namenode.FSImage: Allocated new BlockPoolId: BP-1305675377-172.16.219.138-1566411634561
19/08/22 02:20:34 INFO common.Storage: Storage directory /usr/local/soft/hadoop-2.8.5/dfs/name has been successfully formatted.
19/08/22 02:20:34 INFO namenode.FSImageFormatProtobuf: Saving image file /usr/local/soft/hadoop-2.8.5/dfs/name/current/fsimage.ckpt_0000000000000000000 using no compression
19/08/22 02:20:34 INFO namenode.FSImageFormatProtobuf: Image file /usr/local/soft/hadoop-2.8.5/dfs/name/current/fsimage.ckpt_0000000000000000000 of size 322 bytes saved in 0 seconds.
19/08/22 02:20:34 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with txid >= 0
19/08/22 02:20:34 INFO util.ExitUtil: Exiting with status 0
19/08/22 02:20:34 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at centos138/172.16.219.138
************************************************************/
10.启动
- sbin/./start-dfs.sh
- sbin/./start-yarn.sh