Greenplum启动时 SSH 22端口连接拒绝,修改默认通信端口

最近在使用GP数据库时,由于安全规则问题,GP数据库所在机器开启了防火墙,导致GP数据库无法启动。

通过查看GP数据库的日志发现,GP启动需要SSH 22端口。

这是由于GP属于分布式数据库,大部分是集群安装使用,all_hosts_file文件是集群中所有主机的主机名。gpssh-exkeys 命令主要是用各主机间权限互通,用于免密登录。默认是使用linux的ssh服务,其中走的就是默认22端口。

由于GP所在机器的安全规则限制,服务器ssh默认端口改了,无奈只能修改GP的gpssh-exkeys命令的脚本了。

gpssh-exkeys脚本文件,需要修改以下几个部分(加入 服务器当前的SSH 端口 6233):

def testAccess(hostname):
    '''
    Ensure the proper password-less access to the remote host.
    Using ssh here also allows discovery of remote host keys *not*
    reported by ssh-keyscan.
    '''
    errfile = os.path.join(tempDir, 'sshcheck.err')
    cmd = 'ssh -p 6233-o "BatchMode=yes" -o "StrictHostKeyChecking=no" %s true 2>%s' % (hostname, errfile)
    if GV.opt['-v']: print '[INFO %s]: %s' % (hostname, cmd)
    rc = os.system(cmd)
    if rc != 0:
        print >> sys.stderr, '[ERROR %s] authentication check failed:' % hostname
        with open(errfile) as efile:
            for line in efile:
                print >> sys.stderr, '    ', line.rstrip()
        return False
 
    return True
######################
    #  step 0
    #
    #    Ensure the local host can password-less ssh into each remote host
    for remoteHost in GV.allHosts:
        cmd = ['ssh','-p','6233', 'gpadmin@'+remoteHost.host(), '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=yes',  'true']
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = p.communicate()
        if p.returncode:
            print >> sys.stderr, '[ERROR]: Failed to ssh to %s. %s' % (remoteHost.host(), stderr)
            print >> sys.stderr, '[ERROR]: Expected passwordless ssh to host %s' % remoteHost.host()
            sys.exit(1)
cmd = ('scp -P 6233-q -o "BatchMode yes" -o "NumberOfPasswordPrompts 0" ' +
                       '%s %s %s %s %s:.ssh/ 2>&1'
                       % (remoteAuthKeysFile,
                          remoteKnownHostsFile,
                          remoteIdentity,
                          remoteIdentityPub,
                          canonicalize(h.host())))
                h.popen(cmd)
for h in GV.newHosts:
            cmd = ('scp -P 6233-q -o "BatchMode yes" -o "NumberOfPasswordPrompts 0" ' +
                   '%s %s %s %s %s:.ssh/ 2>&1'
                   % (GV.authorized_keys_fname,
                      GV.known_hosts_fname,
                      GV.id_rsa_fname,
                      GV.id_rsa_pub_fname,
                      canonicalize(h.host())))
            h.popen(cmd)

我在这四个地方加了 -p 6233的参数进去。保存退出。

此外还需要修改     /usr/local/greenplum-db-6.6.0/lib/python/gppylib/commands/base.py      脚本文件。在ssh 后面加 -p 6233参数即可。

def execute(self, cmd):
        # prepend env. variables from ExcecutionContext.propagate_env_map
        # e.g. Given {'FOO': 1, 'BAR': 2}, we'll produce "FOO=1 BAR=2 ..."
        self.__class__.trail.add(self.targetHost)
 
        # also propagate env from command instance specific map
        keys = sorted(cmd.propagate_env_map.keys(), reverse=True)
        for k in keys:
            cmd.cmdStr = "%s=%s && %s" % (k, cmd.propagate_env_map[k], cmd.cmdStr)
 
        # Escape " for remote execution otherwise it interferes with ssh
        cmd.cmdStr = cmd.cmdStr.replace('"', '\\"')
        cmd.cmdStr = "ssh -p 6233 -o StrictHostKeyChecking=no -o ServerAliveInterval=60 " \
                     "{targethost} \"{gphome} {cmdstr}\"".format(targethost=self.targetHost,
                                                                 gphome=". %s/greenplum_path.sh;" % self.gphome,
                                                                 cmdstr=cmd.cmdStr)

在执行GP的启动命令,GP数据库就可以正常启动了。

  总结:这应该也是greenplum官方的一个bug,在执行gpssh-exkeys,gpinitsystem命令时没有提供一个-p 端口的配置参数。或许就轻松多了,哎折腾好久。

原文地址:https://www.cnblogs.com/guoxiangyue/p/15581210.html