您的位置:首页 > 运维架构 > Linux

linux双机互信

2012-11-27 15:45 190 查看
前提:
本配置共有两个测试节点,分别node1.wangzhen.com和node2.wangzhen.com,相的IP地址分别为192.168.0.78和192.168.0.79;
1、准备工作

为了配置一台Linux主机成为HA的节点,通常需要做出如下的准备工作:

1)所有节点的主机名称和对应的IP地址解析服务可以正常工作,且每个节点的主机名称需要跟"uname -n“命令的结果保持一致;因此,需要保证两个节点上的/etc/hosts文件均为下面的内容:

192.168.0.78 node1.wangzhen.com node1
192.168.0.79 node2.wangzhen.com node2

为了使得重新启动系统后仍能保持如上的主机名称,还分别需要在各节点执行类似如下的命令:

Node1:
# sed -i 's@\(HOSTNAME=\).*@\1node1.wangzhen.com@g' /etc/sysconfig/network
# hostname node1.wangzhen.com

Node2:
# sed -i 's@\(HOSTNAME=\).*@\1node2.wangzhen.com@g' /etc/sysconfig/network
# hostname node2.wangzhen.com

2)设定两个节点可以基于密钥进行ssh通信,这可以通过类似如下的命令实现:
Node1:
# ssh-keygen -t rsa
# ssh-copy-id -i ~/.ssh/id_rsa.pub root@node2.wangzhen.com

Node2:
# ssh-keygen -t rsa
# ssh-copy-id -i ~/.ssh/id_rsa.pub root@node1.wangzhen.com

node1操作:

[root@~ ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
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:
ac:82:b8:e5:a9:0f:d0:1b:bd:86:84:3a:44:8d:b9:58 root@node1.wangzhen.com

[root@~ ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.0.79
15
The authenticity of host '192.168.0.79 (192.168.0.79)' can't be established.
RSA key fingerprint is 4e:e9:54:9b:a8:7c:ed:97:81:21:51:e2:58:3d:5e:90.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.79' (RSA) to the list of known hosts.
root@192.168.0.79's password:
Now try logging into the machine, with "ssh 'root@192.168.0.79'", and check in:

.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.

[root@~ ~]# ssh 192.168.0.79 'ifconfig'
node2操作:

[root@ ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
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:
c9:60:62:38:18:af:1a:e0:aa:1a:f0:cc:0a:5e:86:13 root@node2.wangzhen.com

[root@~ ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.0.78
15
The authenticity of host '192.168.0.78 (192.168.0.78)' can't be established.
RSA key fingerprint is 4e:e9:54:9b:a8:7c:ed:97:81:21:51:e2:58:3d:5e:90.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.78' (RSA) to the list of known hosts.
root@192.168.0.78's password:
Now try logging into the machine, with "ssh 'root@192.168.0.78'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[root@~ ~]# ssh 192.168.0.78 'ifconfig'

=============================================================
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux ssh 双机互信 rsa