Ubuntu 20.04 从零开始
Table of Contents
趁着这次更换服务器的系统, 打算完整记录一下操作流程
实例:突发性能实例 t5系列 IV1核 1GB –> 5年642元
创建用户
刚创建的服务器只有root用户, 使用了密钥对的方式登录
注意: 不要开放密码登录的方式到公网
# 先用root用户登录 sudo adduser saul sudo mkdir -p /home/saul/.ssh sudo cp /root/.ssh/authorized_keys /home/saul/.ssh sudo chown -R saul.saul /home/saul/.ssh # 后续就可以用普通账户登录了
修改hostname
# 使用root执行 hostnamectl set-hostname myubuntu
添加 swap
https://itsfoss.com/swap-size/
Ubuntu has an entirely different perspective on the swap size as it takes hibernation into consideration. If you need hibernation, a swap of the size of RAM becomes necessary for Ubuntu. Otherwise, it recommends: If RAM is less than 1 GB, swap size should be at least the size of RAM and at most double the size of RAM If RAM is more than 1 GB, swap size should be at least equal to the square root of the RAM size and at most double the size of RAM If hibernation is used, swap size should be equal to size of RAM plus the square root of the RAM size
# https://medium.com/analytics-vidhya/how-to-add-swap-space-on-ubuntu-ff9af2820adc # Since the server in our example has 1G of RAM, we will create a 1G file in this guide. Adjust this to meet the needs of your own server: sudo fallocate -l 1G /swapfile # Make the file only accessible to root by typing: sudo chmod 600 /swapfile # We can now mark the file as swap space by typing: sudo mkswap /swapfile # After marking the file, we can enable the swap file, allowing our system to start utilising it: sudo swapon /swapfile # Back up the /etc/fstab file in case anything goes wrong: sudo cp /etc/fstab /etc/fstab.bak # Add the swap file information to the end of your /etc/fstab file by typing: echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
软件安装
docker
https://docs.docker.com/engine/install/ubuntu/
# Add Docker’s official GPG key: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg # Use the following command to set up the stable repository. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below. echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null # Install Docker Engine sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io # 给普通用户权限 sudo usermod -G docker -a saul
redis (3MiB)
version: '2' services: redis: image: redis:latest restart: always ports: - 6379:6379 volumes: - ./data:/data
mysql (200MiB)
version: "3" services: db: image: mysql/mysql-server:5.7 restart: always environment: MYSQL_ROOT_PASSWORD: password ports: - 3306:3306 volumes: - ./data:/var/lib/mysql
docker-nginx-auto-ssl (8MiB)
version: '2' services: nginx: image: valian/docker-nginx-auto-ssl restart: on-failure network_mode: "host" ports: - 80:80 - 443:443 volumes: - ./data:/etc/resty-auto-ssl - ./conf.d:/etc/nginx/conf.d environment: ALLOWED_DOMAINS: '([a-z]+.)?osaul.com' SITES: 'example.osaul.com=172.22.0.1:8080'
node
https://github.com/nodesource/distributions
# Node.js LTS (v16.x): # Using Ubuntu curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs
frp
https://github.com/fatedier/frp/releases/
下载最新版本的 linux_amd64
wget https://github.com/fatedier/frp/releases/download/v0.39.1/frp_0.39.1_linux_amd64.tar.gz tar -zxvf frp_0.39.1_linux_amd64.tar.gz
openresty
http://openresty.org/en/linux-packages.html#ubuntu
sudo apt-get -y install --no-install-recommends wget gnupg ca-certificates wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add - echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" \ | sudo tee /etc/apt/sources.list.d/openresty.list sudo apt-get update sudo apt-get -y install openresty
额外配置
user nobody; => user saul; worker_processes 1; => worker_processes 2;