首页 > 编程语言 >使用树梅派搭建Golang、Python、NodeJs的开发服务器

使用树梅派搭建Golang、Python、NodeJs的开发服务器

时间:2024-05-26 12:04:32浏览次数:28  
标签:non https NodeJs Python sudo apt Golang && docker

使用树梅派搭建Golang、Python、NodeJs的开发服务器

安装系统

  1. 安装rpi-imager

    sudo apt install rpi-imager
    
  2. 打开rpi-imager烧写Raspberry Pi OS Lite(64-bit)系统

  3. 设置好用户名、密码、wifi、ssh等信息

  4. 上电

修改镜像源

  1. 备份/etc/apt/sources.list

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    
  2. 修改/etc/apt/sources.list

    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
    
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
    
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
    
    deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
    # deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
    
  3. 修改/etc/apt/sources.list.d/raspi.list

    deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bookworm main
    

    参考:raspberrypi | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

  4. 更新

    sudo apt update && sudo apt dist-upgrade
    

安装docker

  1. 删除旧版本

    for pkg in docker.io docker-doc docker-compose \
     podman-docker containerd runc; \
    do sudo apt-get remove $pkg; done
    
  2. 设置apt 仓库

    # Add Docker's official GPG key:
    sudo apt-get update
    sudo apt-get install ca-certificates curl
    sudo install -m 0755 -d /etc/apt/keyrings
    sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
    sudo chmod a+r /etc/apt/keyrings/docker.asc
    
    # Add the repository to Apt sources:
    echo \
     "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
     https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian \
     $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
     sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt-get update
    
  3. 安装docker

    sudo apt-get install docker-ce docker-ce-cli \
       containerd.io docker-buildx-plugin docker-compose-plugin
    
  4. 验证安装

    sudo docker run hello-world
    
  5. 将用户添加到docker组

    sudo groupadd docker
    sudo usermod -aG docker $USER
    newgrp docker
    

使用docker创建开发服务器

  1. 创建项目文件夹

    mkdir code-server && cd code-server
    
  2. 创建Dockerfile

     FROM codercom/code-server:ubuntu
    
     USER root
     # 修改源
     RUN sed -i 's#http://ports.ubuntu.com/ubuntu-ports/#https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/#g' /etc/apt/sources.list
    
     RUN apt update -y && apt upgrade -y
    
     # 设置时区
     ENV TZ="Asia/Shanghai"
     RUN DEBIAN_FRONTEND=noninteractive apt-get install -yq tzdata && \
         ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && \
         dpkg-reconfigure -f noninteractive tzdata
     USER 1000
    
     ENV USER=coder
    
     WORKDIR /home/coder
    
     RUN sudo apt install build-essential libssl-dev zlib1g-dev \
             libbz2-dev libreadline-dev libsqlite3-dev curl \
             libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev -y
    
     # install python
     RUN curl https://pyenv.run | bash
    
     RUN export PYENV_ROOT="$HOME/.pyenv" \
         && export PATH="$PYENV_ROOT/bin:$PATH" \
         && eval "$(pyenv init -)" \
         && pylatest=$(pyenv install -l | grep -E '^  ([0-9].)([0-9]+.)([0-9]+)$' | tail -n1) \
         && pyenv install $pylatest \
         && pyenv global $pylatest \
         && python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip \
         && pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \
         && echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc \
         && echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc \
         && echo 'eval "$(pyenv init -)"' >> ~/.bashrc
    
     # 安装nodejs
     RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash \
         && export NVM_DIR="$HOME/.nvm" \
         && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" \
         && nvm install $(nvm ls-remote | grep LTS | tail -n1 | awk '{print $1}') \
         && npm config set registry https://registry.npmmirror.com \
         && npm install -g npm
    
     # 安装go
     ENV GO111MODULE=on \
         GOPROXY=https://goproxy.cn,direct
     RUN wget https://go.dev/dl/go1.22.2.linux-arm64.tar.gz \
         && sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.22.2.linux-arm64.tar.gz \
         && export PATH=$PATH:/usr/local/go/bin \
         && echo 'export PATH=$PATH:/usr/local/go/bin' >> .bashrc \
         && rm go1.22.2.linux-arm64.tar.gz 
    
     RUN rm -rf ~/workspace/pyenv
    
     RUN sudo apt install vim tree -y
    
     # 修改提示符显示最后一个文件夹
     RUN sed -i 's/\(PS1.*\)\\w/\1\\W/g' ~/.bashrc
    
  3. 创建docker-comose.yaml

    services:
      code-server:
        build: .
        container_name: code-server
        user: "${UID}:${GID}"
        environment:
          - DOCKER_USER=$USER
        volumes:
          - ./.config:/home/coder/.config
          - ./.local:/home/coder/.local
          - ~/code:/home/coder/workspace
          - ~/.ssh:/home/coder/.ssh
        ports:
          - 8080:8080
        restart: unless-stopped
    
  4. 启动容器

    docker compose up -d
    
  5. 浏览器访问本机的8080端口,即可进入web版的vscode,登陆密码可以在./.config/code-server/config.yaml文件查看

推荐阅读

1. Go语言中局部变量的逃逸分析(从汇编的角度)
2. 使用VS Code调试Go程序

标签:non,https,NodeJs,Python,sudo,apt,Golang,&&,docker
From: https://blog.csdn.net/fuxily/article/details/139212659

相关文章