vi /etc/hostname
root@ubuntu:~# vi /etc/hosts
192.168.189.1 master
192.168.189.2 worker1
192.168.189.3 worker2
192.168.189.4 worker3
192.168.189.5 worker4
192.168.189.6 worker5
192.168.189.7 worker6
192.168.189.8 worker7
192.168.189.9 worker8
root@ubuntu:~# reboot now
2.每一个台设备改名字 master worker1-8
3.脚本更新hosts文件
root@master:/usr/local# mkdir setup_scripts
root@master:/usr/local# cd setup_scripts
root@master:/usr/local/setup_scripts# ls
root@master:/usr/local/setup_scripts#
root@master:/usr/local/setup_scripts# vi host_scp.sh
#!/bin/sh
for i in 2 3 4 5 6 7 8 9
do
scp -rq /etc/hosts
[email protected].$i:/etc/
done
root@master:/usr/local/setup_scripts# chmod u+x host_scp.sh
root@master:/usr/local/setup_scripts# ./host_scp.sh
4.各台设备hosts复制分发成功
5.免ssh登录
1.每一台客户机执行
cd /root/.ssh
ssh-keygen -t rsa -P ''
root@worker4:~# cd /root/.ssh
root@worker4:~/.ssh# ssh-keygen -t rsa -P ''
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
27:05:2f:50:08:b3:3c:85:a2:d8:57:92:20:d9:5b:03 root@worker4
The key's randomart image is:
+--[ RSA 2048]----+
|.oEoo+ooo |
|..o.*+o. o |
|.o +++ . o |
|o o .. o |
| . S . |
| o |
| |
| |
| |
+-----------------+
cat /root/.ssh/id_rsa.pub >>/root/.ssh/authorized_keys.8对应的客户机数字
scp -rq /root/.ssh/authorized_keys.8
[email protected]:/root/.ssh/authorized_keys.8 对应的客户机数字
root@master:~/.ssh# ls
authorized_keys authorized_keys.2 authorized_keys.4 authorized_keys.6 authorized_keys.8 id_rsa.pub
authorized_keys.1 authorized_keys.3 authorized_keys.5 authorized_keys.7 id_rsa known_hosts
root@master:~/.ssh#
2在master上汇总各客户端的公钥
cat /root/.ssh/authorized_keys.8 >>authorized_keys 8要修改的
cat /root/.ssh/id_rsa.pub >>authorized_keys
root@master:~/.ssh# cat /root/.ssh/authorized_keys.1 >>authorized_keys
root@master:~/.ssh# cat /root/.ssh/authorized_keys.2 >>authorized_keys
root@master:~/.ssh# cat /root/.ssh/authorized_keys.3 >>authorized_keys
root@master:~/.ssh# cat /root/.ssh/authorized_keys.4 >>authorized_keys
root@master:~/.ssh# cat /root/.ssh/authorized_keys.5 >>authorized_keys
root@master:~/.ssh# cat /root/.ssh/authorized_keys.6 >>authorized_keys
root@master:~/.ssh# cat /root/.ssh/authorized_keys.7 >>authorized_keys
root@master:~/.ssh# cat /root/.ssh/authorized_keys.8 >>authorized_keys
root@master:~/.ssh#
3.汇总公钥分发给客户机
scp -rq /root/.ssh/authorized_keys
[email protected]:/root/.ssh/authorized_keys
root@master:/usr/local/setup_scripts# cat ./ssh_scp.sh
#!/bin/sh
for i in 2 3 4 5 6 7 8 9
do
scp -rq /root/.ssh/authorized_keys
[email protected].$i:/root/.ssh/authorized_keys
done
root@master:/usr/local/setup_scripts#
4.校验问题
root@worker4:~/.ssh# ssh worker8
The authenticity of host 'worker8 (192.168.189.9)' can't be established.
ECDSA key fingerprint is d4:99:48:60:05:96:3f:74:8e:84:e8:70:20:eb:86:47.
Are you sure you want to continue connecting (yes/no)? yes
问题解决
修改/etc/ssh/ssh_config
将其中的# StrictHostKeyChecking ask 改成 StrictHostKeyChecking no
重启
sudo /etc/init.d/ssh stop
sudo /etc/init.d/ssh start
5.分发脚本
root@master:/usr/local/setup_scripts# cat ssh_config.sh
#!/bin/sh
for i in 2 3 4 5 6 7 8 9
do
scp -rq /etc/ssh/ssh_config
[email protected].$i:/etc/ssh/ssh_config
done
root@master:/usr/local/setup_scripts#
root@master:/usr/local/setup_scripts# ./ssh_config.sh
6.彻底搞定ssh免密码登录