Shell 自動化部署免密登陸

1 .配置主機名稱

  參考:Linux 修改主機名 和 ip 映射關係html

2 . 編寫腳本

root.sh 內容bash

#!/bin/bash

SERVERS="hadoop0 hadoop1 hadoop2"
PASSWORD=lg


auto_ssh_copy_id() {
    expect -c "set timeout -1;
        spawn ssh-copy-id $1;
        expect {
            *(yes/no)* {send -- yes\r;exp_continue;}
            *assword:* {send -- $2\r;exp_continue;}
            eof        {exit 0;}
        }";
}

ssh_copy_id_to_all() {
    for SERVER in $SERVERS
    do
        auto_ssh_copy_id $SERVER $PASSWORD
    done
}

ssh_copy_id_to_all
# 將 install.sh 傳到每一個節點

for SERVER in $SERVERS
do
scp install.sh root@$SERVER:/root
ssh root@$SERVER /root/install.sh
donessh

 

 

3. 執行腳本

  sh root.sh  oop

 

本部分屬於一步一步學習大數據系列之 Linux 的章節,歡迎訂閱更多文章學習

更多內容請參考:一步一步學習大數據系列介紹大數據

相關文章
相關標籤/搜索