且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

RAC中的ssh用户等价

更新时间:2022-08-22 10:37:49

所谓的用户等价,就是以oracle用户从一个节点连接到另一个节点时,不需要输入密码。Clusterware和Database的安装过程都是先在一个节点安装,然后安装程序自动把本地安装好的内容复制到远程相同的目录,这是一个后台拷贝过程,安装人员没有机会输入密码进行验证,因此必须配置用户等价。

oracle允许使用两种用户等价RSH和SSH。推荐使用SSH,因为更安全。

配置步骤:

以在redhat5上安装oracle10gR2的rac为例:

生成 SSH 的公共密钥和专用密钥

[root@rac1 ~]$mkdir ~/.ssh

[root@rac1 ~]$chmod 755 ~/.ssh

[[root@rac1 ~]$cd  ~/.ssh

[root@rac1 ~]$/usr/bin/ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key(/home/oracle/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in/home/oracle/.ssh/id_rsa.

Your public key has been saved in/home/oracle/.ssh/id_rsa.pub.

The key fingerprint is:

e8:ad:d2:94:7b:dc:d7:30:ac:23:c9:0e:d3:fd:e4:c4oracle@rac1

这里一路按回车选择默认就行

[root@rac1 ~]$ /usr/bin/ssh-keygen -t dsa

Generating public/private dsa key pair.

Enter file in which to save the key(/home/oracle/.ssh/id_dsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in/home/oracle/.ssh/id_dsa.

Your public key has been saved in/home/oracle/.ssh/id_dsa.pub.

The key fingerprint is:

87:92:54:42:4b:23:b0:22:ba:e2:31:4a:1f:65:04:c9oracle@rac1

这里一路按回车选择默认就行

将公共密钥文件拷贝到其他节点,并合并成一个。。

现在,必须将每个主机上的公共密钥文件 id_rsa.pub 和 id_dsa.pub 的内容复制到其他每个主机的 ~/.ssh/authorized_keys 文件中。

使用ssh将每个文件的内容复制到 ~/.ssh/authorized_keys文件。请注意,当您使用ssh第一次访问远程主机时,其 RSA 密钥将是未知的,从而将提示您确认是否希望连接该主机。SSH 将记录该远程主机的 RSA 密钥,并在以后连接该主机时不再做出相关提示。

只需在第一个主机上,以oracle 用户身份登录(复制本地帐户的密钥,以便连接本地主机的 ssh 能够起作用):

(如果您要剪切和粘贴这些命令,则分别运行它们。 SSH 每次会提示输入 oracle的口令,如果同时粘贴这些命令,则第一个命令在提示输入口令之前刷新输入缓冲区,从而导致其他命令将会丢失。)

[root@rac1 ~]cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys

[root@rac1 ~] cat ~/.ssh/id_dsa.pub>> ~/.ssh/authorized_keys

 

上面扯了这么多,又执行了这两个命令,其实就是要你把那俩.pub文件合成一个,然后拷贝到其他每个主机的 ~/.ssh/authorized_keys文件中(可以直接这么干就行):

[oracle@rac1.ssh]$ cat *.pub > authorized_keys

 

现在进入另一台主机rac2进行上面的操作!!!!!

 

现在,我们把所有节点的authorized_key文件合并成一个:

 

[oracle@rac1 .ssh]$ scp authorized_keys rac2:/home/oracle/.ssh/key_rac1

The authenticity of host 'rac2(192.168.15.102)' can't be established.

RSA key fingerprint is0e:fe:c3:42:a2:65:64:d7:77:6e:1c:31:e0:ff:d6:4f.

Are you sure you want to continueconnecting (yes/no)? yes

Warning: Permanently added'rac2,192.168.15.102' (RSA) to the list of known hosts.

oracle@rac2's password:(这里输入你的rac2oracle用户的密码,我的密码是ora123

 

authorized_keys                               100%  994    1.0KB/s   00:00

现在已经把rac1上的authorized_keys文件拷到了rac2上(已经被命名为:key_rac1),我们接下来把此文件和rac2原有的那个authorized_keys合并起来。

 

[oracle@rac2 .ssh]$ catkey_rac1 >> authorized_keys

 

 [oracle@rac2.ssh]$ scp authorized_keysrac1:/home/oracle/.ssh/.

The authenticity of host 'rac1(192.168.15.101)' can't be established.

RSA key fingerprint is0e:fe:c3:42:a2:65:64:d7:77:6e:1c:31:e0:ff:d6:4f.

Are you sure you want to continueconnecting (yes/no)? yes

Warning: Permanently added'rac1,192.168.15.101' (RSA) to the list of known hosts.

oracle@rac1's password: (这里输入你的rac1oracle用户的密码,我的密码是ora123

authorized_keys                               100% 1988     1.9KB/s  00:00   

 

如果是多台主机做rac集群的话要对第二,第三,第四个主机做同样的处理。请注意,这次有的SSH不会提示您输入oracle的口令。这是因为第一个主机(dbrac01)现在知道了第二个主机的公共密钥,而SSH现在使用的是一种不同的认证协议。

最后,在每个节点上ssh一下所有结点(包括自己)

验证等效性配置

[root@rac1 ~] ssh rac2 date

The authenticity of host 'dbrac02 (10.49.9.100)'can't be established.

RSA key fingerprint is 8f:a3:19:76:ca:4f:71:85:42:c2:7a:da:eb:53:76:85.

Are you sure you want to continue connecting(yes/no)? yes

Sun Jun 27 19:07:19 CDT 2004

 

该消息只有在远程节点上第一次执行操作时才会出现,因此通过测试连通性,您不仅确保了远程操作的正常运行,还完成了初始的安全密钥交换。

 

我们也可以ssh登录其他节点看看:

[oracle@rac1 .ssh]$ssh rac2

Last login: Tue Sep  3 22:31:02 2013 from rac1-priv

[oracle@rac1 .ssh]$ ssh rac2-priv

Last login: Tue Sep  3 22:36:44 2013 from rac1

同样可以试验在rac2上登录rac1