前言
云服务器共享分析服务器是一类专业服务器,已经配置好分析环境,安装好各种生信研究所需软件及R/Python包,购买即可开始使用。 当我们购买了云服务器(华为、阿里、腾讯)之后,可以登陆服务器提供商的网站查看IP地址及用户和密码,下载FinalShell或MobaXterm工具进行远程登录服务器进行配置及使用。 FinalShell打开后显示界面如下,点击中间的文件夹按钮, 打开连接管理器。
编辑后保存,在连接管理器中点击你想登录的服务器即可转到命令台输入用户名及密码登录,注意密码不会以明文显示,尽管输入即可。
|
1 2 3 4 5 |
sudo useradd 用户名 sudo usermod –aG sudo 用户名 #设置该用户为管理员 su 用户名 passwd #回车之后设置密码 |
宝塔安装
Linux服务器管理如果仅通过ssh连接shell在命令行下进行对新手来说并不友好,劝退新手。面对这种困境,可以安装可视化面板工具如宝塔面板、1Panel面板来帮助运维。 可以Bing/百度搜索宝塔进入其官网,复制一键安装命令:
|
1 2 3 |
wget –O install.sh https://download.bt.cn/install/install_lts.sh sudo bash ./install.sh |
利用FinalShell或MobaXterm通过开启SSH服务的端口(默认是22)登陆服务器,黏贴上面的一键安装命令,按回车执行:
安装与部署 RStudio Server
安装必要依赖
确保安装了必要的依赖:
|
1 2 3 |
sudo apt update sudo apt install –y gdebi–core libssl–dev |
安装 R 和 RStudio Server
- 安装 R:
|
1 2 3 4 5 6 |
sudo apt–key adv —keyserver keyserver.ubuntu.com —recv–keys E298A3A825C0D65DFD57CBB651716619E084DAB9 sudo apt install —no–install–recommends software–properties–common dirmngr sudo add–apt–repository "deb [arch=amd64] https://cloud.r–project.org/bin/linux/ubuntu $(lsb_release –cs)–cran40/" sudo apt update sudo apt install r–base r–base–dev |
- 下载并安装 RStudio Server:
|
1 2 3 |
wget https://download2.rstudio.org/server/jammy/amd64/rstudio–server–2024.09.1–394–amd64.deb sudo gdebi rstudio–server–2024.09.1–394–amd64.deb |
- 启动 RStudio Server 服务:
|
1 2 3 |
sudo systemctl start rstudio–server sudo systemctl enable rstudio–server |
RStudio Server 将在 http://your_server_ip:8787 提供服务,用户可以用他们的 Linux 用户名和密码登录。 请注意,由于网站的转义问题,这里的代码我不用好看的样式标识,它会把单引号换成中文的影响运行效果:
if(!require(‘BiocManager’)) install.packages(‘BiocManager’,update = F,ask = F)
设置CRAN的镜像源为北外
options(repos = c(CRAN = ‘https://mirrors.bfsu.edu.cn/CRAN/’))
设置Bioconductor的镜像源为北外
options(BioC_mirror=‘https://mirrors.bfsu.edu.cn/bioconductor’) cran_packages=c(‘magrittr’, ‘dplyr’, ‘tibble’, ‘ggpubr’, ‘stringr’, ‘reshape2’, ‘psych’, ‘limma’, ‘circlize’, ‘grid’, ‘fmsb’, ‘survival’, ‘survminer’, ‘forestplot’, ‘pROC’, ‘ggplot2’, ‘patchwork’, ‘ggsci’, ‘RColorBrewer’, ‘pheatmap’)
Biocductor_packages=c(‘edgeR’, ‘org.Hs.eg.db’, ‘clusterProfiler’, ‘enrichplot’, ‘ComplexHeatmap’, ‘GSVA’) Biocductor_packages=c( ‘org.Mm.eg.db’, ‘Seurat’, ‘monocle’ )
install packages in CRAN
for (pkg in cran_packages){ if (!require(pkg,character.only=T)){ install.packages(pkg,ask = F,update = F) require(pkg,character.only=T) } }
install packages in Biocductor
for (pkg in Biocductor_packages){ if (!require(pkg,character.only=T)) { BiocManager::install(pkg,ask = F,update = F) require(pkg,character.only=T) } }
安装 Mambaforge
3.1 下载并安装 Mambaforge
- 下载 Mambaforge:
|
1 2 |
wget https://github.com/conda–forge/miniforge/releases/latest/download/Mambaforge–Linux–x86_64.sh |
- 安装 Mambaforge:
|
1 2 |
bash Mambaforge–Linux–x86_64.sh –b –p /opt/mambaforge |
● -b 选项表示静默安装 ● -p /opt/mambaforge 指定安装路径
3.3 创建共享虚拟环境 你可以为所有用户创建一个共享虚拟环境,供所有人使用:
|
1 2 |
conda create –n myenv python=3.9 –y |
然后激活该环境:
|
1 2 |
source ~/bin/mambaforge/bin/activate myenv |
- 部署 Jupyter Lab 4.1 安装 Jupyter Lab 在已经创建的共享虚拟环境中安装 Jupyter Lab:
|
1 2 |
conda install –n shared_env jupyterlab –y |
4.2 配置 Jupyter Lab 服务 为了让 Jupyter Lab 能作为一个服务运行,我们需要创建一个 systemd 服务文件。
- 创建 Jupyter Lab 服务文件 /etc/systemd/system/jupyterlab.service:
|
1 2 |
sudo nano /etc/systemd/system/jupyterlab.service |
- 在文件中添加以下内容:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[Unit] Description=Jupyter Lab [Service] Type=simple PIDFile=/run/jupyterlab.pid ExecStart=/home/liuyuchen/.conda/envs/scenv/bin/jupyter–lab —no–browser —port=8888 —ip=0.0.0.0 User=nobody Group=nogroup WorkingDirectory=/opt/mambaforge/envs/shared_env Restart=always RestartSec=10 [Install] WantedBy=multi–user.target |
- 启动并启用 Jupyter Lab 服务:
|
1 2 3 4 |
sudo systemctl daemon–reload sudo systemctl start jupyterlab sudo systemctl enable jupyterlab |
Jupyter Lab 将在 http://your_server_ip:8888 提供服务。可以为每个用户生成单独的访问 token 来控制访问权限。
- 端口与防火墙设置 确保开放 RStudio Server 和 Jupyter Lab 所需的端口:
|
1 2 3 4 |
sudo ufw allow 8787 sudo ufw allow 8888 sudo ufw enable |
- 总结 ● 用户只能访问自己的 home 目录。 ● 将 Mambaforge 的路径和共享虚拟环境添加到 /etc/profile.d/mambaforge.sh,确保每个用户登录时自动加载。 ● RStudio Server 运行在端口 8787,Jupyter Lab 运行在端口 8888。 ● 可以使用frp进行内网穿透,通过外网服务器访问内部资源
|
1 2 |
wget https://github.com/fatedier/frp/releases/download/v0.60.0/frp_0.60.0_linux_amd64.tar.gz |
以下是服务器端和客户端的设置演示。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
假设服务器端IP: IPXXX 编辑服务器配置文件内容(frps.toml): bindPort = 8024 # 可以自定义,记得在安全组打开访问权限 vhostHTTPPort = 28416 # 可以自定义 vhostHTTPSPort = 1443 # 可以自定义 客户端配置文件(frpc.toml): serverAddr = "IPXXX" # 填写服务器的ip地址 serverPort = 8024 # 上述的bindPort [[proxies]] # 用于ssh链接 name = ‘ssh’ type = ‘tcp’ localIP = ‘127.0.0.1’ localPort = 22 remotePort = 6000 # 可以自定义 [[proxies]] name = ‘rstudio’ type = ‘http’ localIP = ‘127.0.0.1’ localPort = 8787 customDomains = [‘119.45.13.149’] |
在服务器用 nohup ./frps -c frps.toml & 命令启动服务器端
在客户端用 nohup ./frpc -c frpc.toml & 启动客户端,查看nohup文件看到正确的输出后
用IPXXX:6000进行ssh访问,用IPXXX:8787访问Rstudio

发表回复