暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

华为openGauss 手工建立互信

华为高斯 2020-06-01
2121

openGauss在安装过程中,需要在openGauss中的主机间执行命令,传送文件等操作。因此,在普通用户安装前需要确保互信是连通的。前置脚本中会先建立root用户间的互信,然后创建普通用户,并建立普通用户间的互信。

须知:
root用户互信可能会存在安全隐患,因此建议用户在使用完成后,立即删除各主机上root用户的互信。
单机部署不需要创建互信。

前提条件

  • 确保ssh服务打开。
  • 确保ssh端口不会被防火墙关闭。
  • 确保xml文件中各主机名称和IP配置正确。
  • 确保所有机器节点间网络畅通。
  • 如果为普通用户建立互信,需要提前在各主机创建相同用户并设置密码。
  • 如果各主机安装并启动了SELinux服务,需要确保/root和/home目录安全上下文为默认值(root目录:system_u:object_r:home_root_t:s0,home目录:system_u:object_r:admin_home_t:s0)或者关闭掉SELinux服务。

    检查系统SELinux状态的方法:执行命令getenforce,如果返回结果是Enforcing ,说明SELinux安装并启用。

    检查目录安全上下文的命令:

    ls -ldZ /root | awk '{print $4}'

    ls -ldZ /home | awk '{print $4}'

    恢复目录安全上下文命令:

    restorecon -r -vv /home/

    restorecon -r -vv /root/

使用脚本建立互信

  1. 创建一个执行互信脚本所需要的输入文本,并在此文件中添加openGauss中所有主机IP。

    plat1:/opt/software/openGauss> vim hostfile 192.168.0.1 192.168.0.2 192.168.0.3

  2. 以需要创建互信的用户执行脚本。

  3. 执行下面脚本建立互信。

    plat1:/opt/software/openGauss/script# gs_sshexkey -f /opt/software/hostfile

    /opt/software/hostfile为主机列表,列出所有需要建立互信机器的主机IP。

手工建立互信

如果openGauss各主机的root密码不一致,gs_preinstall脚本无法建立互信,可以手工建立互信。

说明:
建立互信的过程中需要生成如下4个文件:authorized_keys、id_rsa、id_rsa.pub、known_hosts。请勿删除或破坏这些互信相关的文件。

手工建立信任关系,步骤如下,plat1,plat2,plat3是主机名:

  1. 在其中一个主机上,生成root用户的本机授权文件。假设在主机plat1上执行。

    1. 生成密钥。

      ssh-keygen -t rsa

      示例如下:

      plat1:~ # ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. 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: d5:35:46:33:27:22:09:f0:1e:12:a7:87:fa:33:3f:ab root@plat1 The key's randomart image is: +--[ RSA 2048]----+ | o.o.....O .| | * .o + * | | + + . . | | . + o | | . S | | . | | + | | +. | | E.oo | +-----------------+

    2. 生成本机授权文件。

      cat .ssh/id_rsa.pub >> .ssh/authorized_keys

      示例如下:

      plat1:~ # cat .ssh/id_rsa.pub >> .ssh/authorized_keys

  2. 收集所有的待建互信主机的公钥,写入到本机的known_hosts文件中。此步骤需要在步骤1执行的主机上执行。需要收集plat1、plat2、plat3三个主机的公钥。

    1. 收集plat1的公钥,写入到本机known_hosts文件中。

      ssh-keyscan -t rsa plat1 >> ~/.ssh/known_hosts

      示例如下:

      ``` plat1:~ # ssh-keyscan -t rsa plat1 >> ~/.ssh/known_hosts

      ```

    2. 收集plat2的公钥,写入到本机known_hosts文件中。

      ssh-keyscan -t rsa plat2 >> ~/.ssh/known_hosts

      示例如下:

      ``` plat1:~ # ssh-keyscan -t rsa plat2 >> ~/.ssh/known_hosts

      ```

    3. 收集plat3的公钥,写入到本机known_hosts文件中。

      ssh-keyscan -t rsa plat3 >> ~/.ssh/known_hosts

      示例如下:

      ``` plat1:~ # ssh-keyscan -t rsa plat3 >> ~/.ssh/known_hosts

      ```

      说明:
      - 当远程主机的公钥被接受以后,它就会被保存在文件$HOME/.ssh/known_hosts之中。下次再连接这台主机,系统就会认出它的公钥已经保存在本地了,从而跳过警告部分。
      - 如果该主机上known_hosts文件被删除,互信仍然可以使用,但是会有告警提示信息。如果需要规避告警提示信息,请将/etc/ssh/ssh_config配置文件中,StrictHostKeyChecking参数设置为no。

  3. 将互信文件分发到其它所有主机上。在本例中,需要将plat1上的互信文件分发到plat2和plat3上。

    1、将互信文件分发到plat2上。Password输入拷贝目标主机的密码。

    scp -r .ssh plat2:~

    示例如下:

    plat1:~ # scp -r .ssh plat2:~ Password: authorized_keys 100% 796 0.8KB/s 00:00 id_rsa 100% 1675 1.6KB/s 00:00 id_rsa.pub 100% 398 0.4KB/s 00:00 known_hosts 100% 1089 1.1KB/s 00:00

    2、将互信文件分发到plat3上。Password输入拷贝目标主机的密码。

    scp -r .ssh plat3:~

    示例如下:

    plat1:~ # scp -r .ssh plat3:~ Password: authorized_keys 100% 796 0.8KB/s 00:00 id_rsa 100% 1675 1.6KB/s 00:00 id_rsa.pub 100% 398 0.4KB/s 00:00 known_hosts 100% 1089 1.1KB/s 00:00

  4. 查看互信是否建成功,可以互相ssh主机名。输入exit退出。

    plat1:~ # ssh plat2 Last login: Tue Jan 5 10:28:18 2016 from plat1 Huawei's internal systems must only be used for conducting Huawei's business or for purposes authorized by Huawei management.Use is subject to audit at any time by Huawei management. plat2:~ # exit logout Connection to plat2 closed. plat1:~ #

    说明:
    如果三个以上节点,和上述过程类似。假设节点名为plat1、plat2、plat3、......。第一步,需要在plat1上生成root用户的本机授权文件;第二步,需要收集所有待建互信主机(plat1、plat2、plat3、......)的公钥并写入到本机known_hosts文件中;第三步,需要将互信文件分发到除本机外的所有其它主机(plat2、plat3、......)上;第四步,检查互信是否建立成功。

删除root用户互信

为了避免Root用户互信可能存在的安全隐患,因此建议用户在使用完成后,立即删除各主机上root用户的互信。

  1. 删除openGauss数据库各节点上的互信相关文件/root/.ssh。

    rm –rf \~/.ssh

  2. 查看互信是否删除成功,可以互相ssh主机名,提示不能互信,互信删除成功。

    plat1:\~ # ssh plat2

    he authenticity of host ' plssat2 (plat2)' can't be established.

    ECDSA key fingerprint is SHA256:Q4DPRedFytsjsJSKf4l2lHKuzVw4prq3bIUCNVKIa7M.

    ECDSA key fingerprint is MD5:e2:77:6c:aa:4c:43:5f:f2:c4:58:ec:d5:53:de:7c:fc.

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

示例

root用户建立互信示例:

plat1:~ # gs_sshexkey -f /opt/software/hostfile -W Gauss_234 Checking network information. All nodes in the network are Normal. Successfully checked network information. Creating SSH trust. Creating the local key file. Successfully created the local key files. Appending local ID to authorized_keys. Successfully appended local ID to authorized_keys. Updating the known_hosts file. Successfully updated the known_hosts file. Appending authorized_key on the remote node. Successfully appended authorized_key on all remote node. Checking common authentication file content. Successfully checked common authentication content. Distributing SSH trust file to all node. Successfully distributed SSH trust file to all node. Verifying SSH trust on all hosts. Successfully verified SSH trust on all hosts. Successfully created SSH trust.

普通用户建立互信示例:

gaussdb@plat1:~ > gs_sshexkey -f /opt/software/hostfile -W Gauss_234 Checking network information. All nodes in the network are Normal. Successfully checked network information. Creating SSH trust. Creating the local key file. Successfully created the local key files. Appending local ID to authorized_keys. Successfully appended local ID to authorized_keys. Updating the known_hosts file. Successfully updated the known_hosts file. Appending authorized_key on the remote node. Successfully appended authorized_key on all remote node. Checking common authentication file content. Successfully checked common authentication content. Distributing SSH trust file to all node. Successfully distributed SSH trust file to all node. Verifying SSH trust on all hosts. Successfully verified SSH trust on all hosts. Successfully created SSH trust.

安全模式下建立互信示例,需要用户根据提示,手动输入建立互信的用户密码(建议使用安全模式):

plat1:~ # gs_sshexkey -f /opt/software/hostfile Please enter password for current user[root]. Password: Checking network information. All nodes in the network are Normal. Successfully checked network information. Creating SSH trust. Creating the local key file. Appending local ID to authorized_keys. Successfully appended local ID to authorized_keys. Updating the known_hosts file. Successfully updated the known_hosts file. Appending authorized_key on the remote node. Successfully appended authorized_key on all remote node. Checking common authentication file content. Successfully checked common authentication content. Distributing SSH trust file to all node. Successfully distributed SSH trust file to all node. Verifying SSH trust on all hosts. Successfully verified SSH trust on all hosts. Successfully created SSH trust.

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

文集目录
暂无数据