Hadoop集群搭建——Ⅰ.环境准备
关于虚拟机网络设置可参考:https://www.cnblogs.com/huanongying/p/7061719.html
一、集群时间同步
若是centos8系统,参考:https://www.cnblogs.com/freeweb/p/12980841.html
为保证集群时间不会因为网络情况出现时间异步的情况,将节点1作为时间服务器,同步集群之间时间。
1、集群中所有的机器安装ntp时间同步工具。
sudo yum -y install ntp ntpdaye
2、节点1设置为时间同步服务器
在所有机器上执行以下命令。
sudo systemctl start ntpd #启动时间同步程序
sudo systemctl enable ntpd #允许时间同步程序开机启动
修改节点1中的/etc/ntp.conf文件,添加server设置127.127.1.0为其自身。
sudo vi /etc/ntp.conf
在public servers下面添加
server 127.127.1.0 #设置自己作为时间同步服务器
在access下面添加一个restrict段,此段ip为集群公网ip。
restrict 192.168.0.0
如下图所示:
保存退出,并重启ntp系统服务
sudo systemctl restart ntpd
3、ntp同步客户端设置
编辑除了节点1外其他所有节点的/etc/ntp.conf文件,指定时间服务器。
sudo vim /etc/ntp.conf
在server下面添加时间服务器(既节点1)的ip地址,本例中为192.168.1.101
server 192.168.1.101
如下图所示:
在时间同步客户端(除节点1以外节点)执行以下命令同步时间
sudo ntpdate 192.168.1.101 #如果需要查看调试信息,可以添加参数-d
4、开启时间同步
在所有节点执行时间同步
sudo timedatectl set-ntp yes
二、集群主机名更名
修改主机名有两种方式,一种是临时有效,重启后失效。另一种则永久有效。此处只介绍永久有效的修改方式。
# 编辑/etc/hostname文件
vim /etc/hostname
# 将该文件中的内容改为需要的主机名保存退出即可
# 重启服务器生效
reboot
三、主机映射
# 编辑所有的节点/etc/hosts文件,在文件末尾加入ip 主机名,注意用空格隔开。例如:
192.168.1.101 node1
192.168.1.102 node2
192.168.1.103 node3
测试:
# 在任意一台节点上使用主机名ping其余主机,ping通说明设置成功。若未成功先重启网络服务,再不成功检查网络。
ping node2
# 重启网络指令
systemctl restart network
四、免密登录
为了保证集群之间通信顺畅,可用ssh在集群之间做免密登录
安装ssh服务并启动
yum -y install sshd
systemctl start sshd
1、节点1生成密钥,可以一直回车确认使用默认
CentOS7 默认使用RSA加密算法生成密钥对,保存在~/.ssh目录下的id_rsa(私钥)和id_rsa.pub(公钥)。也可以使用“-t DSA”参数指定为DSA算法,对应文件为id_dsa和id_dsa.pub,密钥对生成过程会提示输入私钥加密密码,可以直接回车不使用密码保护。
[root@node1 ~]# ssh -keygen
Bad escape character 'ygen'.
[root@node1 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): # 可以在这里指定密钥位置
Created directory '/root/.ssh'.
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:4nay9P4Xcad3YBC/YzkLi3syYbdNunbtGyDz6zaSE5E root@node1
The key's randomart image is:
+---[RSA 2048]----+
| .. |
| .. |
| ... |
| E. +o.|
| . S oo=*+ |
| . . oo*+++o|
| = ...o+B.+.|
| o = o=*o+ o|
| ..o.o**=.oo|
+----[SHA256]-----+
[root@node1 ~]# ls /root/.ssh/ # 查看密钥位置
id_rsa id_rsa.pub
2、将公钥发送给其余节点相同目录下
# 将节点1 ~/.ssh目录中的 id_rsa.pub 这个文件拷贝到你要登录的其余节点的~/.ssh目录中
scp ~/.ssh/id_rsa.pub node2:~/.ssh/
# 然后在所有节点运行以下命令来将公钥导入到~/.ssh/authorized_keys这个文件中
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
3、验证免密登录成功
如果想既能从node1免密登录node2,又想从node2免密登录node1,则以后续节点为主,重复上面2的工作,但是要注意密钥位置。详见https://blog.csdn.net/tladagio/article/details/79612795
# 不需要输入密码即可登录node2
[root@node1 ~]# ssh node2
Last login: Tue Mar 24 17:15:30 2020 from 43.248.124.113
Welcome to Alibaba Cloud Elastic Compute Service !
[root@node2 ~]#