續上一篇文章:4. Hadoop集群搭建-克隆虛擬機/從機-基于CentOS7-【連載中】
目錄
- 前言
- 正文
- 配置hosts檔案
- 配置免密
- 驗證免密是否成功
- 更改主機名
- 臨時變更用戶名例:
- 永久變更用戶名例:
- 相關文章:
前言
- 請確保三臺主機可以互相Ping通
- 盡量去做”快照“備份,以免發生故障后及時恢復,避免造成更大的損失,
- 本次使用軟體:Xshell 6:藍奏下載,百度網盤下載Xshell6 - 提取碼: x2f3
- Xshell使用技巧請參閱:Hadoop集群搭建-Xshell小技巧-基于CentOS7-【連載中】
正文
配置hosts檔案
- Xshell連接三臺主機,步驟詳見:5.2 Hadoop集群搭建-Xshell新建會話連接圖解-基于CentOS7-【連載中】
- 將三臺主機頁面設定為”瓷磚排列“,詳見:Hadoop集群搭建-Xshell小技巧-基于CentOS7-【連載中】
- 在Master視窗輸入
vim /etc/hosts(需要提前安裝vim彩色代碼命令:yum install -y vim) - 在最后一行輸入IP地址空格后輸入主機名,每個主機IP和主機名后要回車,也就是每個主機各占一行

- 保存后發送到其他兩臺主機(需要輸入其他兩臺主機的密碼,需要輸入”yes“時請輸入”yes“):
scp /etc/hosts root@slave1:/etc/
[root@localhost ~]# scp /etc/hosts root@slave1:/etc/
The authenticity of host 'slave1 (192.168.***.***)' can't be established.
ECDSA key fingerprint is SHA256:1uOH6LWY9vqqbkbz93f6fbsHV/jKPEN8I0Zm37qb1ZU.
ECDSA key fingerprint is MD5:05:d2:b6:50:5f:32:f1:38:92:d9:c2:8e:df:42:e6:dc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'slave1,192.168.**.***' (ECDSA) to the list of known hosts.
root@slave1's password:
hosts 100% 224 217.8KB/s 00:00
[root@localhost ~]# scp /etc/hosts root@slave2:/etc/
The authenticity of host 'slave2 (192.168.**.***)' can't be established.
ECDSA key fingerprint is SHA256:1uOH6LWY9vqqbkbz93f6fbsHV/jKPEN8I0Zm37qb1ZU.
ECDSA key fingerprint is MD5:05:d2:b6:50:5f:32:f1:38:92:d9:c2:8e:df:42:e6:dc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'slave2,192.168.***.****' (ECDSA) to the list of known hosts.
root@slave2's password:
hosts 100% 224 154.8KB/s 00:00
配置免密
- 三臺主機都要輸入:
ssh-keygen -t rsa生成密鑰- 解釋:
Enter file in which to save the key (/root/.ssh/id_rsa):(/root/.ssh/id_rsa)
密鑰的生成路徑保存的位置為(/root/.ssh/id_rsa),如果默認即回車,不默認即在冒號后方輸入自己的路徑
/root/.ssh/id_rsa already exists.
Overwrite (y/n)?出現這個是因為之前配置過(生成過)密鑰,詢問是否覆寫,y是覆寫,n是不覆寫,
Enter passphrase (empty for no passphrase):輸入密鑰的密碼,不需要直接回車
Enter same passphrase again:再次輸入相同的密碼(和上一步一樣,跳過,如果上一步輸入了密碼這一步就要輸入同樣的密碼,)
回車密鑰生成
- 在撰寫欄中一路回車(建議參閱5.1 Hadoop集群搭建-Xshell小技巧-基于CentOS7-【連載中】后使用更流暢):

- 撰寫欄輸入(也就是三臺主機都要輸入)
ssh-copy-id master將密鑰發送給master主機:
[root@localhost ~]# ssh-copy-id master
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'master (192.168.**.***)' can't be established.
ECDSA key fingerprint is SHA256:1uOH6LWY9vqqbkbz93f6fbsHV/jKPEN8I0Zm37qb1ZU.
ECDSA key fingerprint is MD5:05:d2:b6:50:5f:32:f1:38:92:d9:c2:8e:df:42:e6:dc.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@master's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'master'"
and check to make sure that only the key(s) you wanted were added.
- 轉到master輸入:
cd /root/.ssh/使用ls查看該目錄下檔案:
[root@localhost ~]# cd /root/.ssh/
[root@localhost .ssh]# ls
authorized_keys id_rsa id_rsa.pub known_hosts
- 將
authorized_keys檔案發送到其他兩臺從機:scp authorized_keys root@slave1:/root/.ssh/
[root@localhost .ssh]# scp authorized_keys root@slave1:/root/.ssh/
root@slave1's password:
authorized_keys 100% 1224 1.0MB/s 00:00
[root@localhost .ssh]# scp authorized_keys root@slave2:/root/.ssh/
root@slave2's password:
authorized_keys 100% 1224 1.1MB/s 00:00
驗證免密是否成功
- 在撰寫欄輸入:
ssh master連接master查看是否需要密碼,如不需要即為配置免密成功(若詢問yes/no,請輸入yes) - 在撰寫欄輸入:
exit退出連接 - 之后再在撰寫欄輸入:
ssh slave1連接slave1查看是否需要密碼,如不需要即為配置免密成功 - 在撰寫欄輸入:
exit退出連接(若詢問yes/no,請輸入yes) - 之后再在撰寫欄輸入:
ssh slave2連接slave2查看是否需要密碼,如不需要即為配置免密成功 - 在撰寫欄輸入:
exit退出連接(若詢問yes/no,請輸入yes)
更改主機名
說白了,更改主機名就是為了讓用戶(自己)區分哪一臺是主機哪一臺是從機
| 臨時變更主機名(重啟失效) | hostname 主機名(例:hostname master) |
|---|---|
| 永久變更主機名 (重啟不失效) | hostnamectl set-hostname 主機名 (例: hostname set-hostname master) |
| 臨時或永久變更用戶名后重繪 | bash |
臨時變更用戶名例:
[root@localhost ~]# hostname master
[root@localhost ~]# bash
[root@master ~]#
永久變更用戶名例:
[root@localhost ~]# hostnamectl set-hostname slave1
[root@localhost ~]# bash
[root@slave1 ~]#
相關文章:
5.1 Hadoop集群搭建-Xshell小技巧-基于CentOS7-【連載中】
5.2 Hadoop集群搭建-Xshell新建會話連接圖解-基于CentOS7-【連載中】
下一篇文章:6. Hadoop集群搭建 - 關閉防火墻 - 基于CentOS7 -【連載中】
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/292894.html
標籤:其他
