Linux操作使用指北

Ubuntu 系统 添加交换分区(/swap) 1. 查看交换分区信息 2. 检查硬盘分区上的可用空间 3. 在合适的位置创建 swap 文件 以下操作 swap 文件创建在 /swa...

Ubuntu

系统

  • 添加交换分区(/swap)
    1. 查看交换分区信息

      $ sudo swapon --show # 如果没有任何显示, 说明系统当前没有可用的交换空间
      NAME TYPE SIZE USED PRIO
      $ free -m  					 # -m 表示以MB单位显示 swap row 都为 0表示当前交换分区大小为0
                    total        used        free      shared  buff/cache   available
      Mem:           3793         259        2633           3         899        3481
      Swap:          0           0           0
      
      
    2. 检查硬盘分区上的可用空间

      $ df -h
      Filesystem      Size  Used Avail Use% Mounted on
      udev            1.9G     0  1.9G   0% /dev
      tmpfs           380M  4.0M  376M   2% /run
      /dev/mmcblk0p2   15G  4.7G  9.1G  34% /
      tmpfs           1.9G     0  1.9G   0% /dev/shm
      tmpfs           5.0M     0  5.0M   0% /run/lock
      tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
      /dev/loop0       49M   49M     0 100% /snap/core18/1883
      /dev/loop1       64M   64M     0 100% /snap/lxd/16103
      /dev/loop2       26M   26M     0 100% /snap/snapd/8543
      /dev/mmcblk0p1  253M   96M  157M  38% /boot/firmware
      tmpfs           380M     0  380M   0% /run/user/1000
      
      
    3. 在合适的位置创建 swap 文件 以下操作 swap 文件创建在 /swapfile

      $ sudo fallocate -l 2G /swapfile
      $ ls -lh /swapfile 		# 查看创建出来的 /swapfile 文件信息
      -rw------- 1 root root 2.0G Oct 18 13:58 /swapfile
      
      
    4. 启用交换文件 /swapfile

      $ sudo chmod 600 /swapfile # 授权 /swapfile 文件权限 600
      $ ls -lh /swapfile 				 # 确认分区文件权限信息
      -rw------- 1 root root 2.0G Oct 18 13:58 /swapfile
      
      
    5. 将 /swapfile 标记为交换分区空间

      $ sudo mkswap /swapfile
      Setting up swapspace version 1, size = 2048 MiB (1073737728 bytes)
      no label, UUID=6e965805-2ab9-450f-add9-577e74089dbf
      
      
    6. 启用交换分区空间文件

      $ sudo swapon /swapfile # 标记启用交换文件 系统开始使用该文件作为交换分区空间
      $ sudo swapon --show    # 检查交换分区是否可用
      NAME      TYPE SIZE USED PRIO
      /swapfile file   2G   0B   -2
      $ free -h
                    total        used        free      shared  buff/cache   available
      Mem:          3.7Gi       259Mi       2.6Gi       3.0Mi       899Mi       3.4Gi
      Swap:         2.0Gi          0B       2.0Gi
      
      
    7. 永久使用交换分区文件

      $ sudo cp /etc/fstab /etc/fstab.bak # 备份交换分区配置文件
      $ echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab # 将配置信息写入配置末尾
      
      

软件

树莓派(Ubuntu)

[硬件信息]

树莓派版本: raspberry 4B 4GB

系统版本: Ubuntu 2020.04.1 LTS 64

内存大小: 4G

swap: 2G

磁盘: 16GB

  • 安装 Docker-CE
    1. 下载安装脚本

      $ curl -fsSL <https://get.docker.com> -o ~/get-docker.sh
      
      
    2. 执行安装脚本安装 Docker-CE

      $ sudo sh ~/get-docker.sh --mirror Aliyun
      
      
    3. 可以直接使用 ubuntu 用户直接管理 docker

      $ sudo usermod -aG docker ubuntu # ubuntu 用户管理docker 可以不使用 sudo
      
      
    4. 启动 docker

      $ sudo systemctl enable docker # 开机自启动
      $ sudo systemctl start docker
      $ docker version
      Client: Docker Engine - Community
       Version:           19.03.13
       API version:       1.40
       Go version:        go1.13.15
       Git commit:        4484c46
       Built:             Wed Sep 16 17:03:40 2020
       OS/Arch:           linux/arm64
       Experimental:      false
      
      Server: Docker Engine - Community
       Engine:
        Version:          19.03.13
        API version:      1.40 (minimum version 1.12)
        Go version:       go1.13.15
        Git commit:       4484c46
        Built:            Wed Sep 16 17:02:11 2020
        OS/Arch:          linux/arm64
        Experimental:     false
       containerd:
        Version:          1.3.7
        GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
       runc:
        Version:          1.0.0-rc10
        GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
       docker-init:
        Version:          0.18.0
        GitCommit:        fec3683
      
      
    5. 配置国内镜像

      $ mkdir -p /etc/docker
      $ sudo tee /etc/docker/daemon.json <<-'EOF'
      > {
      >   "registry-mirrors":["<https://docker.mirrors.ustc.edu.cn>"]
      > }
      > EOF
      $ sudo systemctl daemon-reload # 重启 docker 使相关设置生效
      $ sudo systemctl restart docker
      
      
    6. 测试

      $ docker run arm64v8/hello-world
      
      Hello from Docker!
      This message shows that your installation appears to be working correctly.
      
      To generate this message, Docker took the following steps:
       1. The Docker client contacted the Docker daemon.
       2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
          (arm64v8)
       3. The Docker daemon created a new container from that image which runs the
          executable that produces the output you are currently reading.
       4. The Docker daemon streamed that output to the Docker client, which sent it
          to your terminal.
      
      To try something more ambitious, you can run an Ubuntu container with:
       $ docker run -it ubuntu bash
      
      Share images, automate workflows, and more with a free Docker ID:
       <https://hub.docker.com/>
      
      For more examples and ideas, visit:
       <https://docs.docker.com/get-started/>
      
      

      注: 树莓派是 arm 架构,arm 平台不能使用 x86 镜像,查看 Raspbian 可使用镜像请访问 arm64v8