ssh免密登录
-
生成ssh免登陆密钥
cd /root/.ssh
如果没有.ssh目录,执行下
ssh localhost
执行完这个命令后(四个回车),会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥) -
将公钥拷贝到要免密登陆的目标机器上
ssh-copy-id root@hadoop02
-
ssh登录测试
[root@hadoop01 .ssh]# ssh root@hadoop02
Last login: Tue Sep 18 18:18:36 2018 from hadoop01
#退出
[root@hadoop02 ~]# exit -
自动化免密配置及jdk安装脚本
#!/bin/bash SERVERS="hadoop01 hadoop02" PASSWORD=123456 BASE_SERVER=172.16.203.100 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 for SERVER in $SERVERS do scp install.sh root@$SERVER:/root ssh root@$SERVER /root/install.sh done
-
install.sh脚本
#!/bin/bash BASE_SERVER=172.16.203.100 yum install -y wget wget $BASE_SERVER/soft/jdk-7u45-linux-x64.tar.gz tar -zxvf jdk-7u45-linux-x64.tar.gz -C /usr/local cat >> /etc/profile << EOF export JAVA_HOME=/usr/local/jdk1.7.0_45 export PATH=\$PATH:\$JAVA_HOME/bin EOF