r如何远程登录linux,在 Linux 上设置远程 R 服务 - Visual Studio | Microsoft Docs

适用于 Linux 的远程 R 服务Remote R Service for Linux

12/04/2017

本文内容

适用于 Linux 的远程 R 服务当前打包为 rtvs-daemon。Remote R Service for Linux is currently packaged as rtvs-daemon. Ubuntu 16.04、16.10 LTS 桌面、服务器和适用于 Linux 的 Windows 子系统(运行 Ubuntu)系统上支持守护程序,并在系统上对守护程序进行了测试。The daemon is supported and tested on Ubuntu 16.04, 16.10 LTS desktop, server, and Windows Subsystem for Linux running Ubuntu. 本文的大量篇幅提供了在这些不同系统上设置远程 R 服务的说明。The bulk of this article provides instructions for setting up Remote R Service on these different systems.

配置远程计算机后,以下步骤将针对 Visual Studio 的 R 工具 (RTVS) 连接到该服务:Once you've configured the remote machine, the following steps connect the R Tools for Visual Studio (RTVS) to that service:

选择“R 工具” > “窗口” > “工作区”,打开“工作区”窗。Select R Tools > Windows > Workspaces to open the Workspaces window.

选择“添加连接” 。Select Add Connection.

为连接命名并提供其 URL,例如 https://localhost:5444(适用于 Linux 的 Windows 子系统)或 https://public-ip:5444(Azure 容器)。Give the connect a name and provide its URL, such as https://localhost:5444 (Windows Subsystem for Linux) or https://public-ip:5444 (Azure container). 完成后,选择“保存” 。Select Save when complete.

选择连接图标或双击连接项。Select the connection icon or double-click the connection item.

提供登录凭据。Provide login credentials. 用户名的前缀必须为 <>\,如 <>\ruser1(所有与Linux 远程计算机的连接都有此要求)。The username must be prefixed with <>\ as in <>\ruser1 (as required for all connections to Linux remote computers).

如果在使用自签名证书,可能会看到一条警告。If you are using self-signed certificate, you may see a warning. 该消息提供了更正警告的说明。The message provides instructions to correct the warning.

设置远程 R 服务Set up Remote R Service

本节介绍下列选项:This section describes the following options:

在每种情况下,远程计算机上必须至少安装一个下列 R 解释器:In each case, the remote computer must have one of the following R interpreters installed:

物理 Ubuntu 计算机Physical Ubuntu computer

登录计算机后,下载 rtvs-daemon tarball:Once logged into the computer, download the rtvs-daemon tarball:

wget -O rtvs-daemon.tar.gz https://aka.ms/r-remote-services-linux-binary-current

tar -xvzf rtvs-daemon.tar.gz

运行安装脚本:Run the install script:

sudo ./rtvs-install

要实现无提示自动化,请使用 sudo ./rtvs-install -s。For a silent automation, use sudo ./rtvs-install -s.

启用并启动服务:Enable and start the service:

sudo systemctl enable rtvsd

sudo systemctl start rtvsd

配置 SSL 证书(生产所需)。Configure the SSL certificate (required for production). 默认情况下,rtvs-daemon 使用 ssl-cert 包生成的 ssl-cert-snakeoil.pem 和 ssl-cert-snakeoil.pem。By default, rtvs-daemon uses the ssl-cert-snakeoil.pem and ssl-cert-snakeoil.pem generated by the ssl-cert package. 安装期间,它们合并为 ssl-cert-snakeoil.pfx。During installation, they're combined into ssl-cert-snakeoil.pfx. 如果要用于生产目的,请使用管理员提供的 SSL 证书。For production purposes, use the SSL certificate provided by your administrator. 可通过在 /etc/rtvs/rtvsd.config.json 中提供 .pfx 文件和可选导入密码配置 SSL 证书 。The SSL certificate can be configured by providing a .pfx file and optional import password in: /etc/rtvs/rtvsd.config.json.

(可选)检查服务正在运行:(Optional) Check that the service is running:

ps -A -f | grep rtvsd

如果发现进程未在用户名 rtvssvc 下运行,If you don’t see a process running under the user name rtvssvc. 请使用以下命令启动它:Start it using the following command:

sudo systemctl start rtvsd

要进一步配置 rtvs-daemon,请参阅 man rtvsd。To further configure the rtvs-daemon, see man rtvsd.

Ubuntu 服务器 VM 或 Azure 上的数据科学 VMUbuntu Server VM or Data Science VM on Azure

创建 VMCreate a VM

导航到虚拟机,然后选择“添加” 。Navigate to Virtual Machines, then select Add.

在可用 VM 映像列表中,搜索并选择以下选项之一:In the list of available VM images, search for and select one of the following:

Ubuntu 服务器:Ubuntu Server 16.04 LTSUbuntu Server: Ubuntu Server 16.04 LTS

数据科学 VM:Linux Data Science(请参阅数据科学虚拟机了解详细信息)Data Science VM: Linux Data Science (see Data Science Virtual Machines for details)

将部署模型设置为Resource manager,并选择“创建” 。Set the deployment model to Resource manager and select Create.

为 VM 选择一个名字、提供用户名和密码(必须提供密码的,因为不支持 SSH 公钥登录)。Choose a name for the VM, provide a username and password (password is required, as SSH public key login isn't supported).

对 VM 配置进行任何其他所需更改。Make any other desired changes to the VM configuration.

选择 VM 大小,验证配置,然后选择“创建” 。Choose a VM size, verify the configuration, and select Create. 创建 VM 后,继续下一节。Once the VM is created, proceed to the next section.

配置 VMConfigure the VM

在 VM 的“网络”部分中,将 5444 添加为允许的入站端口 。In the VM's Networking section, add 5444 as an allowed inbound port. 要使用不同端口,请更改 RTVS 守护程序配置文件 (/etc/rtvs/rtvsd.config.json ) 中的设置。To use a different port, change the setting in the RTVS daemon config file (/etc/rtvs/rtvsd.config.json).

(可选)设置 DNS 名称,也可以使用 IP 地址。(Optional) Set a DNS name; you can also use the IP address.

使用 SSH 客户端(如适用于 Windows 的 PuTTY)连接到 VM。Connect to the VM using an SSH client, such as PuTTY for WIndows.

Follow the instructions for a Physical Ubuntu computer above.

适用于 Linux 的 Windows 子系统 (WSL)Windows Subsystem for Linux (WSL)

Follow the WSL installation instructions for either Windows 10 or Windows Server.

在 Windows 上启动 bash,并按照之前物理 Ubuntu 计算机中的说明操作,但其中一个步骤例外。Start bash on Windows and follow the earlier instructions a Physical Ubuntu computer with one exception. 对于步骤 3,改用命令 rtvsd 启动服务,因为 WSL 当前不支持 systemd/systemctl 接口。For step 3, start the service using the command rtvsdinstead because WSL currently does not support the systemd/systemctl interfaces.

本地或远程 Docker 容器(干净的生成)Local or remote Docker container (clean build)

使用以下内容创建 Docker 文件,安装远程 R 服务守护程序和最新版本的 R。注意:此脚本创建名为“ruser1”、密码为“foobar”的用户,可在最后两个 RUN 语句中根据需要更改用户名和密码。Create a Docker file with the contents below, which installs the Remote R service daemon and the latest version of R. Note: this script creates a user called "ruser1" with the password "foobar", which you can modify as desired in the final two RUN statements.

FROM ubuntu:16.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update \

&& apt-get install -y software-properties-common python-software-properties \

&& apt-get install -y apt-transport-https \

&& rm -rf /var/lib/apt/lists/*

RUN sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list' \

&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893 \

&& sh -c 'echo "deb https://cran.revolutionanalytics.com/bin/linux/ubuntu xenial/" > /etc/apt/sources.list.d/cran-r.list' \

&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 \

&& rm -rf /var/lib/apt/lists/* \

&& apt-get clean

RUN apt-get update --fix-missing && apt-get update \

&& apt-get install -y dotnet-dev-1.0.4 libexplain51 libzip4 libc6 git lshw ssl-cert wget \

&& rm -rf /var/lib/apt/lists/*

# install R

RUN apt-get update && apt-get install -y r-base-dev

RUN apt upgrade -y

# install rtvs-daemon

RUN wget -O rtvs-daemon.tar.gz https://aka.ms/r-remote-services-linux-binary-current && tar -xvzf rtvs-daemon.tar.gz && ./rtvs-install -s

RUN useradd --create-home ruser1

RUN echo "ruser1:foobar" | chpasswd

EXPOSE 5444

生成并运行 Docker 文件:Build and run the docker file:

docker build -t myrimage .

docker run -p 5444:5444 myrimage rtvsd

要从 RTVS 连接到容器,请使用 https://localhost:5444 作为路径,并使用 <>\ruser1 作为用户名、foobar 作为密码。To connect to the contains from RTVS, use https://localhost:5444 as the path, username <>\ruser1, and password foobar. 如果容器在远程计算器上运行,则改用 https://remote-host-name:5444 作为路径。If the container is running on a remote computer, use https://remote-host-name:5444 as the path instead. 可以通过更新 /etc/rtvs/rtvsd.config.json 来更改端口。The port can be changed by updating /etc/rtvs/rtvsd.config.json.

在 Azure 容器实例上运行的容器Container running on Azure Container Instances

将容器推送到 Docker 中心或 Azure Container Repository。Push the container to Docker hub or Azure Container Repository.

启动 Azure CLI 并使用 az login 命令登录。Start the Azure CLI and sign in using the az login command.

使用 az container create 命令创建容器,如果尚未将容器设置为将 rtvsd 作为 systemd 服务运行,则使用 --command-line "rtvsd"。Use the az container create command to create the container, using --command-line "rtvsd" if you have not set up the container to run rtvsd as a systemd service. 在以下命令中,映像应位于 Docker 中心。In the command below, the image is expected to be on Docker hub. 还可以通过将 Container Repository 凭据参数添加到命令行来使用 Azure Container Repository。You can also use Azure Container Repository by adding Container Repository credential arguments to the command line.

az container create --image myimage:latest --name myaz-container --resource-group myaz-container-res --ip-address public --port 5444 --cpu 2 --memory 4 --command-line "rtvsd"

使用 az container list 命令检查状态。Use the az container list command to check the status. 查找 provisioningState:Succeeded。Look for provisioningState: Succeeded.

如果预配成功,则现在可以连接到容器。If the provisioning succeeded, you can now connect to the container. 在 ipAddress 字段中查找公共 IP 地址,此 IP 地址与 docker 文件中的凭据配合使用,可用于从 RTVS 连接到容器。Look for the public IP address, in the ipAddress field, which you use with the credentials in the docker file to connect to the container from RTVS.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值