配置要求每台主机的名字(uname -n )要一致!
主机信息
192.168.10.10 node1.zzx.com
192.168.10.11 node2.zzx.com
192.168.10.12 Console.zzx.com (控制台)
分别配置主机域名
hostname node1.zzx.com
hostname node2.zzx.com
hostname Console.zzx.com
分别修改配置 vim /etc/sysconfig/network
修改 HOSTNAME=node1.zzx.com
HOSTNAEM=node2.zzx.com
HOSTNAME=Console.zzx.com
vim /etc/hosts
添加 192.168.10.10 node1.zzx.com node1
192.168.10.11 node2.zzx.com node2
192.168.10.11 Console.zzx.com Console
切换su
创建配置nod1node2主机的ssh 互信
1.生成sshd 的秘钥
[root@node1 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
Generating public/private rsa key pair.
Created directory '/root/.ssh'.
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:
b7:76:48:4f:ac:f8:e7:5e:d8:89:51:e4:ff:b7:c8:7c root@node1.zzx.com
2.拷贝node1主机的秘钥到node2(同时node2秘钥主机到node1主机)
[root@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node2
15
The authenticity of host '192.168.10.11 (192.168.10.11)' can't be established.
RSA key fingerprint is 2e:ec:e9:b9:34:2c:c4:46:84:bf:85:ad:e9:22:17:3c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.11' (RSA) to the list of known hosts.
root@192.168.10.11's password:
Now try logging into the machine, with "ssh 'root@192.168.10.11'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
5.Console(192.168.10.12)控制台同样把生成的ssh秘钥分别复制到node和node2
ssh-copy-id -i .ssh/id_rsa.pub root@node1
ssh-copy-id -i .ssh/id_rsa.pub root@node2
6.测试访问
ssh node1 (链接无需输入密码)
ssh node2 (链接无需输入密码)
7. Console (控制台)使用for循环现实文件复制删除和创建以及软件的安装
(1)软件安装这里需要首先配置好yum源
(2)我们这里使用for循环,这里使用的alias(别名操作)
别名: alias zzx='for I in {1..2}; do'
别名长期生效
vim /.bashrc
alias zzx='for I in {1..2}; do'
使用别名复制
[root@Console ~]# zzx scp /root/2.txt node$I:/root/;done
删除文件
[root@Console ~]# zzx ssh node$I 'rm -rf /root/2.txt'; done
启动服务
[root@Console ~]# zzx ssh node$I 'service httpd restart'; done
有充足的时间写一个人性化的脚本了!
如果有新发现后续会更新的!
转载于:https://blog.51cto.com/zzxtbl/1554446