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'
=============================================================
本配置共有两个测试节点,分别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 查看corefile文件所在路径
- Linux下动态库查看方法
- MD5校验码 (Linux/Windows)
- linux下vim配置
- Linux下的正则表达式
- linux 查看文件编码以及修改编码
- linux远程管理工具:putty
- Linux Top命令
- 编译OpenCV for arm-linux (转)
- 详解Linux运维工程师必备技能
- UNIX/Linux进程间通信IPC系列(一)总论
- Linux面试题1
- [极客]每个极客都应该知道的Linux技巧 (1)
- use of Linux0.11 emulator
- linux下QT编程学习笔记——配置文件的读写
- 1.菜鸟的linux学习之路------linux初体验
- Linux kernel coding style
- linux下configure配置参数
- linux /sys目录下各个子目录的具体说明
- 基于Linux的ARM与上位机文件传输