在搭建大数据集群时,机子创建好后,第一步需要做的就是进行ssh免密登录的配置。
进行ssh免密登录之前,我们先在每个机子上进行IP映射。
1、修改每台机子的hosts文件:
vim /etc/hosts
2、在文件最后加上IP,机子名称。
192.168.xx.xx node1
192.168.xx.xx node2
192.168.xx.xx node3
这样就完成了IP与机子名称的映射。
关闭防火墙
每台机子都需要关闭防火墙,以及关闭防火墙自启
# 关闭
systemctl stop firewalld
# 禁止开机自启
systemctl disable firewalld
#查看状态
systemctl status firewalld
以下命令也是可以的
#关闭
service firewalld stop
#查看状态
service firewalld status
接下来做的就是进行ssh免密登录配置:
1、在机器node1上输入以下命令,一直按回车,若有(y/n)则选择y,得到密钥对。
ssh-keygen
2、会得到类似于以下的一个东西:
+---[RSA 3072]----+
| |
| o . |
| o . + |
| + = + + o . |
| . = o S + O + |
|.o.+ + + = o |
|+o+.oE. . = o |
|.+oo. =. + . . |
| o+. ..o++o.. |
+----[SHA256]-----+
到这里密钥对就生成成功了。密钥对包括了公钥和私钥。
在root目录下会生成一个隐藏目录 .ssh。可以用以下命令查看。
id_rsa 文件是私钥
id_rsa.pub 文件是公钥
[root@node1 ~]# cd /root/.ssh
[root@node1 .ssh]# ll
3、执行以下命令,将公钥文件传输给另外两台主机,并输入对应的机子密码。
ssh-copy-id -i /root/.ssh/id_rsa.pub root@node1
ssh-copy-id -i /root/.ssh/id_rsa.pub root@node2
ssh-copy-id -i /root/.ssh/id_rsa.pub root@node3
注意:这里需要对本机也进行ssh-copy-id。
执行完成后,可以进行ssh验证
在每个机子上分别对本机以及另外两台机子进行ssh连接,若不用输入密码则配置成功。
验证如下则配置成功:
配置完ssh后,还需进行三台机子之间的时间同步
(保证虚拟机集群配置的过程正常)
查看所有节点 ntpd开机自启动状态和服务状态
#查看是否开机自启
systemctl is-enabled ntpd
#查看状态
systemctl status ntpd
修改/etc/ntp.conf文件
进行如下修改
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
关闭ntpd服务
systemctl stop ntpd
#或者 service ntpd stop (上面的查看状态命令同理)
在node2和node3机器上配置定时任务,一分钟同步一次时间
crontab -e
#然后输入
*/1 * * * * /usr/sbin/ntpdate node1
等待一段时间,在node2上和node3上分别使用 date 命令查看时间,若时间同步了则成功。
在node1上进行ntpd开机自启,以及ntpd服务重启。
在node2、node3上进行ntpd关闭开机自启,以及关闭ntpd服务。
#开机自启
systemctl enable ntpd
#关闭开机自启
systemctl disable ntpd
#查看状态
systemctl status ntpd
#开启ntpd
systemctl start ntpd
#关闭ntpd
systemctl stop ntpd
以上过程若有不对,欢迎评论指正😀