離線部署 CDH 5.15.0及使用CDH(2)——ssh免登陸

1. 配置主機(jī)名[1]

3臺(tái)主機(jī)各執(zhí)行一次

hostnamectl set-hostname master
//master、node1、node2

現(xiàn)在有3臺(tái)機(jī)器

master node2 node3
192.168.206.201 192.168.206.202 192.168.206.203

2. SSH免密登陸[2]

  • \color{red}{以下操作如無(wú)特殊說(shuō)明表示在master下執(zhí)行} ($后代表命令)
    1. vim 編輯/etc/hosts, 先清空所有內(nèi)容( 可以用快捷鍵dd刪除 ),加入7個(gè)節(jié)點(diǎn)的ip以及主機(jī)名:
    
    192.168.206.201 master
    192.168.206.202 node1
    192.168.206.203 node2
    
  1. 使用 scp命令拷貝免密登陸文件
    首先,編輯/etc/ssh/ssh_config,去掉以下選項(xiàng)的注釋
    RSAAuthentication yes      
    PubkeyAuthentication yes
    

保存后使用scp拷貝到2-7 node機(jī)器上,按提示輸入yes和密碼

$ vim scp_file.sh


#/bin/bash
if [ -n "$1" ]; then
    echo "scp dir $1"
    for a in {1..2}
    do
     scp $1 node$a:$1
    done
else
    echo "Usage: scp_file [filename]"
fi

$ chmod o+x  scp_file.sh
$./scp_file.sh /etc/ssh/ssh_config
scp_file.png
/etc/hosts同樣拷貝
$ ./scp_file.sh /etc/hosts
  1. 在集群的\color{red}{每一個(gè)節(jié)點(diǎn)}都需要輸入命令 ssh-keygen -t rsa -P '',生成 key,提示出來(lái)按全部都按回車(chē)鍵
    ssh-keygen.png
  1. 將各個(gè)節(jié)點(diǎn)的秘鑰寫(xiě)入master的authorized_keys文件中,master上執(zhí)行
$ vim ops_command.sh


#/bin/bash
if [ -n "$1" ]; then
    echo "exe command $1"
    for a in {1..2}
    do
     ssh root@node$a $1
    done
else
    echo "Usage: ops_command [command]"
fi

---------------------------------------------------------------------

$ vim auth_write.sh


#/bin/bash
for a in {1..2}
do
    ssh root@node$a cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
done

--------------------------------------------------------------------------------
$ chmod o+x  ops_command.sh
$ chmod o+x  auth_write.sh
$ ./auth_write.sh
$ ./scp_file.sh /root/.ssh/authorized_keys
$ systemctl restart sshd
$ ./ops_command.sh 'systemctl restart sshd'
  1. 測(cè)試
//node1上執(zhí)行
ssh root@node2

//各個(gè)機(jī)器上都可以試試
//第一次登陸會(huì)有一個(gè)yes的提示,正常現(xiàn)象

  1. 配置主機(jī)名 ?

  2. SSH免密登陸 ?

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容