如何在需要ssh身份验证的远程群集上运行并行计算

时间:2019-05-20 12:28:28

标签: python-3.x multiprocessing ssh-tunnel pathos

我想在远程集群上运行并行功能,但我只能在本地集群上运行

我有3个不同的群集,其中包含3个不同的主机地址。 我试图使用pathos包在所有3个群集上一起运行计算。但是我只设法只使用本地集群。 所有3个集群都需要使用user_name和password进行ssh身份验证。 我找不到将远程集群的用户名和密码传递给pathos api的方法。

我什至尝试打开从localhost:special_port到远程集群之一的隧道,并在server = localhost:special_port上运行pathos,但是它不起作用(pathos仍然仅在本地集群上运行)。

什么是执行上述操作的正确方法?

from pathos.pools import ParallelPool as ppool
import sshtunnel
import paramiko

    with sshtunnel.open_tunnel(
            (remote_host, 22),
        ssh_username=ssh_username,
        ssh_password=ssh_password,
        remote_bind_address=(remote_host, 22),
        local_bind_address=('', 12345)) as tunnel:
        client = paramiko.SSHClient()
        client.load_system_host_keys()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        client.connect("127.0.0.1", 12345, username=ssh_username, password=ssh_password)
p = ppool(processes=80, servers=("132.67.140.121:22",), )


        x = [i for i in range(10000)]
        print(p.servers)
        y = p.amap(inc, x)

        z = y.get()
        client.close()
def inc(x):
    time.sleep(0.1)
    return x**2

0 个答案:

没有答案