手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux双机互信

[日期:2012-11-27] 来源:Linux社区  作者:wz102 [字体:大 中 小]

前提:

本配置共有两个测试节点,分别node1.linuxidc.com和node2.linuxidc.com,相的IP地址分别为192.168.0.78和192.168.0.79;

1、准备工作

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

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

192.168.0.78              node1.linuxidc.com node1

192.168.0.79              node2.linuxidc.com node2

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

Node1:

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

# hostname node1.linuxidc.com

Node2:

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

# hostname node2.linuxidc.com

2)设定两个节点可以基于密钥进行ssh通信,这可以通过类似如下的命令实现:

Node1:

# ssh-keygen -t rsa

# ssh-copy-id -i ~/.ssh/id_rsa.pub root@node2.linuxidc.com

Node2:

# ssh-keygen -t rsa

# ssh-copy-id -i ~/.ssh/id_rsa.pub root@node1.linuxidc.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.linuxidc.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.linuxidc.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
相关资讯       节点  Linux双机 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款