How to build a network disk server on Linux

环境准备

  1. 准备好Linux服务器,本地或线上均可,本文以centos8为例。(推荐阿里云的共享计算实例,性价比较高,自己家里有网络条件搞本地服务器当然更好)

  2. 安装好 docker-cedocker-compose, Reference: How to Install Docker CE on CentOS 8 / RHEL 8

  # Step1: Enable Docker CE Repository
  dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

  # Step2: Install Docker CE using dnf command
  dnf install docker-ce --nobest -y
  systemctl start docker
  systemctl enable docker

  # Step3: Install Docker Compose
  curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  chmod +x /usr/local/bin/docker-compose
  ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

  # Setp4: Modify Docker registry mirrors to use 163 registry mirrors
  vim /etc/docker/daemon.json
  {
    "registry-mirrors": ["http://hub-mirror.c.163.com"]
  }
  systemctl restart docker.service
  1. 安装 ownCloud, Reference: Installing ownCloud with Docker

    # Create a new project directory
    mkdir owncloud-docker-server
    
    cd owncloud-docker-server
    
    # Copy docker-compose.yml from the GitHub repository
    wget https://raw.githubusercontent.com/owncloud/docs/master/modules/admin_manual/examples/installation/docker/docker-compose.yml
    
    # Create the environment configuration file
    cat << EOF > .env
    OWNCLOUD_VERSION=10.4
    OWNCLOUD_DOMAIN=localhost
    ADMIN_USERNAME=admin
    ADMIN_PASSWORD=admin
    HTTP_PORT=8080
    EOF
    
    # Build and start the container
    docker-compose up -d
    
  1. 挂载阿里云OSS到服务器,当做硬盘来存储网盘中的数据

    • 在阿里云上创建一个OSS的Bucket,和ECS选择同区域,存储类型选标准存储,读写权限私有,服务器端加密设置为AES256加密,其余设置默认。
    • 需要创建一个只能使用OSS的用户,来通过API访问OSS中的文件,RAM访问控制,创建时设置为只允许编程访问,并授予AliyunOSSFullAccess权限。
    • 安装ossfs来挂载oss到服务器
    
     [root@test]# df -h | grep -v '/var/lib/docker'
      Filesystem      Size  Used Avail Use% Mounted on
      devtmpfs        1.9G     0  1.9G   0% /dev
      tmpfs           1.9G     0  1.9G   0% /dev/shm
      tmpfs           1.9G  684K  1.9G   1% /run
      tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
      /dev/vda1        20G  4.6G   16G  23% /
      tmpfs           379M     0  379M   0% /run/user/0
      ossfs           256T     0  256T   0% /data/ossfs
    

    https://help.aliyun.com/document_detail/32196.html