
Một môi trường huấn luyện Nextflow dùng được cả trên laptop lẫn trên cụm HPC rất thuận tiện cho một nhóm cùng làm các bài tập giống nhau. code-server chạy VS Code trong trình duyệt và có thể được khởi động như một job Slurm trên một compute node, nên học viên chỉ cần một trình duyệt và một kết nối SSH thay vì cài đặt cục bộ.
Hướng dẫn này trình bày cách khởi chạy code-server như một job Slurm, cách truy cập từ máy cục bộ qua một SSH tunnel, cách cài các extension VS Code cần thiết, và cách xác nhận rằng Nextflow, Singularity, nf-core và nf-test đã sẵn sàng.
Để có phần giới thiệu về Pixi và quản lý gói, xem bài viết của chúng tôi về Pixi, trình quản lý gói dựa trên conda.
Code-server chạy VS Code trong trình duyệt, giúp dùng được trên một cụm mà không cần cài trình soạn thảo cục bộ. Ở đây nó được cài qua Pixi để phiên bản công cụ được quản lý cùng với các công cụ khác.
Code-server chạy VS Code trong trình duyệt, mang lại giao diện quen thuộc khi làm việc trên một hệ thống từ xa. Điều này phù hợp với:
Pixi là một trình quản lý gói có thể cài các công cụ như Nextflow và Singularity. Chi tiết thêm về Pixi có trong bài viết của chúng tôi về Pixi, trình quản lý gói dựa trên conda.
Trong hướng dẫn này, Pixi quản lý code-server, Nextflow, Singularity và các công cụ nf-core bên trong một job SLURM.
Gửi code-server như một batch job của Slurm giúp cấp phát tài nguyên cần thiết và giữ nó chạy trên một compute node.
Tạo một script job Slurm để cài và khởi động code-server:
# Create sbatch scriptcat > ~/code-server-job.sh << 'EOF'#!/bin/bash#SBATCH --job-name=code-server#SBATCH --time=24:00:00#SBATCH --cpus-per-task=2#SBATCH --mem=4GB#SBATCH --output=%x-%j.log
# Install Pixi (one time per node)curl -fsSL https://pixi.sh/install.sh | bashexport PATH="$HOME/.pixi/bin:$PATH"
# Install code-server and all tools using Pixipixi global install code-server open-jdk nextflow singularity nf-core nf-test
# Create code-server configuration directorymkdir -p ~/.config/code-server
# Create configuration filecat > ~/.config/code-server/config.yaml << 'CONFIGEOF'bind-addr: 127.0.0.1:8080auth: passwordpassword: your-secure-passwordcert: falseCONFIGEOF
# Start code-serverecho "Starting code-server on $HOSTNAME:8080"echo "Job ID: $SLURM_JOB_ID"echo "Node: $SLURM_NODENAME"
code-server --bind-addr 0.0.0.0:8080EOF
# Make script executablechmod +x ~/code-server-job.sh
# Submit the jobsbatch ~/code-server-job.shKiểm tra trạng thái job và tìm node mà nó đang chạy:
# Check running jobssqueue -u $USER
# You should see output like:# JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)# 12345 gpu code-serv user R 0:15 1 compute-node-05
# Check the log file for connection detailscat code-server-12345.log
Code-server đang chạy trên một compute node qua job Slurm. Để truy cập từ máy cục bộ, một SSH tunnel được tạo qua login node tới compute node đó.
Trước tiên, xác định compute node mà job code-server đang chạy:
# SSH into HPC login nodessh user@hpc.server.edu
# Check your running jobssqueue -u $USER
# Output example:# JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)# 12345 multi code-serv user R 5:30 1 worker-01
# Note the node name (worker-01 in this example)
# Verify code-server is runningssh worker-01 'curl http://localhost:8080' 2>/dev/null | head -5Cấu hình chuyển tiếp cổng từ máy cục bộ qua login node tới compute node đang chạy code-server:
# Replace worker-01 with your actual node name# This creates a tunnel: local:8080 → login node → worker-01:8080ssh -L 8080:worker-01:8080 user@hpc.server.edu
# Keep this terminal open while using code-server# Open browser and navigate to: http://localhost:8080# Enter password: your-secure-password (from sbatch script)Định dạng lệnh tunnel là:
ssh -L local_port:compute_node:remote_port user@login_nodeTrong đó:
local_port: cổng trên máy cục bộ (8080)compute_node: tên node từ squeue (ví dụ worker-01)remote_port: cổng mà code-server lắng nghe (8080)login_node: login node HPC của bạn (hpc.server.edu)Để có một tunnel tồn tại lâu dài mà không cần giữ terminal mở:
# Run tunnel in backgroundssh -L 8080:worker-01:8080 user@hpc.server.edu -N -f
# To close the tunnel laterkillall sshkillall ssh kết thúc mọi tiến trình ssh thuộc người dùng hiện tại, có thể đóng cả những phiên khác. Nên đóng đúng tunnel cần đóng thay vì dùng lệnh này.
Để truy cập lặp lại dễ dàng hơn, thêm host HPC vào ~/.ssh/config trên máy cục bộ:
Host hpc-dev HostName hpc.server.edu User your_username LocalForward 8080 localhost:8080 ServerAliveInterval 60 ServerAliveCountMax 3Sau đó kết nối bằng:
ssh hpc-dev# Port 8080 is now forwarded to your HPC's code-serverLưu ý: cách dùng SSH config này chuyển tiếp tới localhost:8080 trên login node. Với thiết lập trên compute node SLURM, hãy dùng lệnh trực tiếp với hostname của compute node.
Khi tunnel đã hoạt động, mở trình duyệt và truy cập:
http://localhost:8080Nhập mật khẩu từ cấu hình code-server. Màn hình chào mừng của VS Code sẽ hiện ra.
Khi code-server đã truy cập được từ máy cục bộ, bước tiếp theo là cài các extension cần thiết và kiểm tra các công cụ.
Trước tiên, xác nhận rằng các công cụ đã được cài trong job code-server:
# In the code-server terminal (access via http://localhost:8080)# Check installed tools
nextflow -vsingularity --versionnf-core --versionnf-test --versionNếu thiếu một công cụ, có thể cài ngay từ cùng terminal:
# Install any missing toolspixi global install nextflow singularity nf-core nf-testCó thể cài extension trực tiếp trong code-server:
Khi công cụ và extension đã có, chạy một kiểm tra đơn giản:
# In the code-server terminal, run a simple testnextflow run hello-world.nf
Với các buổi huấn luyện định kỳ, một vài script nhỏ giúp thiết lập thuận tiện hơn.
Để huấn luyện thường xuyên, một alias hoặc script giúp việc gửi job gọn hơn:
# Add to ~/.bashrcalias submit-code-server='sbatch ~/code-server-job.sh && sleep 5 && squeue -u $USER | grep code-server'
# Now you can easily submit with:submit-code-serverMột script cũng có thể tự động thiết lập tunnel:
# Save as ~/tunnel-to-code-server.sh on your LOCAL machine#!/bin/bash
# SSH to HPC and check code-server jobNODE=$(ssh user@hpc.server.edu "squeue -u \$USER --format=%N --noheader | grep compute" | head -1)
if [ -z "$NODE" ]; then echo "No compute node found. Submit code-server job first!" exit 1fi
echo "Found code-server on node: $NODE"echo "Creating tunnel to http://localhost:8080"echo "Press Ctrl+C to close tunnel"
ssh -L 8080:$NODE:8080 user@hpc.server.eduCấp quyền thực thi và dùng nó:
chmod +x ~/tunnel-to-code-server.sh~/tunnel-to-code-server.shconfig.yamlScript Slurm ví dụ cấp phát:
Có thể điều chỉnh:
# For heavier computation (running larger workflows)#SBATCH --cpus-per-task=4#SBATCH --mem=8GB
# For shorter sessions (testing)#SBATCH --time=4:00:00
# To use GPU (if available)#SBATCH --gres=gpu:1Kết quả là một môi trường huấn luyện Nextflow với:
Hạ tầng:
Công cụ và framework:
Cấu hình:
local → login node → compute node) truy cập code-server mà không lộ hệ thống HPC.# Step 1: Submit code-server job (one time)sbatch ~/code-server-job.sh
# Step 2: Find compute nodesqueue -u $USER
# Step 3: Create SSH tunnel (from local machine)ssh -L 8080:worker-01:8080 user@hpc.server.edu
# Step 4: Access in browserhttp://localhost:8080
# Step 5: Run workflowsnextflow run main.nf -profile singularitynf-core đơn giảnnf-core createsqueue, sacct, sinfo)cat code-server-*.logssh user@hpc.server.edu ssh worker-01 hostnamepixi global install nextflow singularity nf-core nf-test

