Hadoop集群搭建--主机准备
1. 克隆虚拟机
2. 修改克隆虚拟机的静态IP
前面两步参考 《虚拟机的安装》
3. 修改主机名
# 修改文件/etc/sysconfig/network
[root@localhost ~]# vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=hadoop101 # 修改成主机名为hadoop101
同时修改主机映射文件(规划3台主机)
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# 新增Ip和主机映射关系 172.16.9.101 hadoop101 172.16.9.102 hadoop102 172.16.9.103 hadoop103
4. 关闭防火墙
关闭防火墙服务
[root@localhost ~]# service iptables status # 查看防火墙状态 Table: filter Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) num target prot opt source destination 1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) num target prot opt source destination [root@localhost ~]# service iptables stop ## 关闭防火墙 iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] [root@localhost ~]# service iptables status ## 查看防火墙状态 iptables: Firewall is not running.
配置开机自启动为关闭状态
[root@localhost ~]# chkconfig --list iptables ## 查看防火墙自启动状态,不同的运行级别下的状态
iptables 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@localhost ~]# chkconfig iptables off ## 关闭开机自启动
[root@localhost ~]# chkconfig --list iptables ## 查看防火墙自启动状态
iptables 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭 [root@localhost ~]#
关闭 selinux 安全访问策略
[root@localhost ~]# getenforce ##查看selinux 安全访问策略状态
Enforcing
[root@localhost ~]# vi /etc/sysconfig/selinux
# 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 these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
5. 创建bigdata用户
[root@localhost home]# cd /home/ #查看home 下有哪些用户 [root@localhost home]# ll 总用量 0 [root@localhost home]# useradd bigdata # 添加bigdata 用户 [root@localhost home]# passwd bigdata # 给bigdata用户设置密码 更改用户 bigdata 的密码 。 新的 密码: 无效的密码: 过于简单化/系统化 无效的密码: 过于简单 重新输入新的 密码: passwd: 所有的身份验证令牌已经成功更新。 [root@localhost home]# [root@localhost home]# cd /home/ [root@localhost home]# ll ## bigdata 家目录OK 总用量 4 drwx------. 3 bigdata bigdata 4096 3月 7 06:58 bigdata [root@localhost home]#
6. 配置bigdata用户具有root权限
[root@localhost home]# ll /etc/sudoers -r--r-----. 1 root root 3729 12月 8 2015 /etc/sudoers # 只读文件,不能修改 [root@localhost home]# chmod +w /etc/sudoers # 给sudoers 文件添加写权限 [root@localhost home]# ll /etc/sudoers -rw-r-----. 1 root root 3729 12月 8 2015 /etc/sudoers [root@localhost home]# vi /etc/sudoers # 编辑sudoers 文件 ##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
bigdata ALL=(ALL) NOPASSWD: ALL ## 添加该行,让bigdata具有root 权限,并且不用输入密码验证
7.在/opt目录下创建文件夹
[root@localhost home]# cd /opt/ [root@localhost opt]# ll 总用量 4 drwxr-xr-x. 2 root root 4096 3月 26 2015 rh [root@localhost opt]# mkdir modules [root@localhost opt]# mkdir softwares [root@localhost opt]# ll 总用量 12 drwxr-xr-x. 2 root root 4096 3月 7 07:07 modules drwxr-xr-x. 2 root root 4096 3月 26 2015 rh drwxr-xr-x. 2 root root 4096 3月 7 07:08 softwares [root@localhost opt]# chown bigdata:bigdata modules/ # 更改文件所属用户和用户组 [root@localhost opt]# chown bigdata:bigdata softwares/ [root@localhost opt]# ll 总用量 12 drwxr-xr-x. 2 bigdata bigdata 4096 3月 7 07:07 modules drwxr-xr-x. 2 root root 4096 3月 26 2015 rh drwxr-xr-x. 2 bigdata bigdata 4096 3月 7 07:08 softwares [root@localhost opt]#
8. 安装JDK
首先查看系统中是否已安装jdk , 如果已有安装,使用 rpm -e jdk包 命令进行卸载
[root@localhost opt]# rpm -qa | grep java [root@localhost opt]# rpm -qa | grep jdk
使用属主机将jdk压缩包拷贝到 /opt/softwares 下
justin@MacBook-Pro Downloads % scp jdk-8u221-linux-x64.tar.gz bigdata@172.16.9.101:/opt/softwares bigdata@172.16.9.101's password: jdk-8u221-linux-x64.tar.gz 100% 186MB 55.9MB/s 00:03 justin@MacBook-Pro Downloads %
客户机hadoop101 中切换到 bigdata用户下
[root@localhost softwares]# su - bigdata [bigdata@localhost softwares]$ tar -zxvf jdk-8u221-linux-x64.tar.gz -C ../modules/ # 解压到modules目录下
设置java path
[bigdata@localhost jdk1.8.0_221]$ pwd /opt/modules/jdk1.8.0_221 [bigdata@localhost jdk1.8.0_221]$ sudo vi /etc/profile # 使用root 权限修改 /etc/profile文件,在文件最后添加 #JAVA_HOME export JAVA_HOME=/opt/modules/jdk1.8.0_221 export PATH=$PATH:$JAVA_HOME/bin
# 然后使文件立即生效
[bigdata@localhost jdk1.8.0_221]$ source /etc/profile
# 测试jdk是否安装成功
[bigdata@localhost jdk1.8.0_221]$ java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
最后重启系统,让所有的修改项都生效。
然后在克隆两台相同的主机
主机分别命名为 hadoop102, hadoop103。
修改主机名,和网卡设置。
9. 配置无密登录
(1)生成公钥和私钥:
[bigdata@hadoop101 ~]$ ssh-keygen -t rsa
然后敲(三个回车),就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)
然后敲(三个回车),就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥) [bigdata@hadoop101 ~]$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/bigdata/.ssh/id_rsa): Created directory '/home/bigdata/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/bigdata/.ssh/id_rsa. Your public key has been saved in /home/bigdata/.ssh/id_rsa.pub. The key fingerprint is: 85:c6:77:de:88:d0:b6:bb:52:3a:5f:ff:ab:bc:74:35 bigdata@hadoop101 The key's randomart image is: +--[ RSA 2048]----+ | | | . o | | = = . | | . = = o | | S o o .E.| | .. o| | o. .. . | | + oo.. | | +o ++oo| +-----------------+
(2)将公钥拷贝到要免密登录的目标机器上
[bigdata@hadoop101 ~]$ ssh-copy-id hadoop101
[bigdata@hadoop101 ~]$ ssh-copy-id hadoop101 The authenticity of host 'hadoop101 (172.16.9.101)' can't be established. RSA key fingerprint is dc:7a:74:88:a8:35:4e:89:5d:2e:ba:26:5d:46:87:cf. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'hadoop101,172.16.9.101' (RSA) to the list of known hosts. bigdata@hadoop101's password: Now try logging into the machine, with "ssh 'hadoop101'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
接下来同样操作,将公钥拷贝到hadoop102,hadoop103
[bigdata@hadoop101 ~]$ ssh-copy-id hadoop102
[bigdata@hadoop101 ~]$ ssh-copy-id hadoop103
注意:
还需要在hadoop102上采用bigdata账号,配置一下无密登录到hadoop101、hadoop102、hadoop103;
还需要在hadoop103上采用bigdata账号配置一下无密登录到hadoop101、hadoop102、hadoop103服务器上。
10. 时间服务器配置
需使用root用户操作(在hadoop101机器上进行修改)
(1)检查ntp服务是否安装
[root@hadoop101 ~]# rpm -qa | grep ntp fontpackages-filesystem-1.41-1.1.el6.noarch ntpdate-4.2.6p5-10.el6.centos.x86_64 ntp-4.2.6p5-10.el6.centos.x86_64 [root@hadoop101 ~]# service ntpd status ntpd is stopped
(2)修改ntp配置文件
[root@hadoop101 ~]# vi /etc/ntp.conf
修改内容如下
a)修改1(授权172.16.9.0-172.16.9.255网段上的所有机器可以从这台机器上查询和同步时间)
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap为
restrict 172.16.9.0 mask 255.255.255.0 nomodify notrap
b)修改2(集群在局域网中,不使用其他互联网上的时间)
将以下行全部注释掉:
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
c)添加3(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)
server 127.127.1.0
fudge 127.127.1.0 stratum 10
(3)修改/etc/sysconfig/ntpd 文件
[root@hadoop101 ~]# vi /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
SYNC_HWCLOCK=yes
增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes
(4)重新启动ntpd服务
[root@hadoop101 ~]# service ntpd status ntpd is stopped [root@hadoop101 ~]# [root@hadoop101 ~]# service ntpd start Starting ntpd: [ OK ] [root@hadoop101 ~]#
(5)设置ntpd服务开机启动
[root@hadoop101 ~]# chkconfig --list | grep ntpd ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@hadoop101 ~]# chkconfig ntpd on [root@hadoop101 ~]# chkconfig --list | grep ntpd ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@hadoop101 ~]#
2. 其他机器配置(必须root用户)
(1)在其他机器配置10分钟与时间服务器同步一次
## hadoop102机器上设置时间同步定时任务
[root@hadoop102 ~]# crontab -e no crontab for root - using an empty one ## 编写定时任务如下 */10 * * * * /usr/sbin/ntpdate hadoop101
### hadoop103机器上设置同步定时任务
[root@hadoop103 ~]# crontab -e
no crontab for root - using an empty one
## 编写定时任务如下
*/10 * * * * /usr/sbin/ntpdate hadoop101
(2)修改其他任意机器时间
[root@hadoop103 ~]# date -s "2021-3-11 11:11:11"
(3)十分钟后查看机器是否与时间服务器同步
[root@hadoop103桌面]# date
[root@hadoop103 ~]# date Mon Mar 8 22:16:28 CST 2021
说明:测试的时候可以将10分钟调整为1分钟,节省时间。测试通过,能同步hadoop101机器的时间。
至此,完成3台主机的准备工作!

浙公网安备 33010602011771号