文章目錄
- 一.背景說明
- 二.磁盤分區
- 2.1 安裝分區工具
- 2.2 檢視是否存在資料盤
- 2.3 使用Parted工具為資料盤進行分區
- 2.4 系統重讀分區表
- 2.5 為/dev/vdb1分區建立檔案系統
- 2.6 挂載磁盤
- 三、安裝docker
- 3.1 解除安裝舊版本
- 3.2 使用 yum 安裝
- 3.3 使用官方安裝腳本自動安裝
- 3.4 啟動并加入開機啟動
一.背景說明
AWS塊存儲支援的分區格式包括MBR和GPT。其中,MBR隻支援處理不大于2 TB的容量,且隻支援劃分4個主區。如果需要使用大于2 TB的資料盤,必須采用GPT格式。
大于2 TB的資料盤請采用下表中描述的分區工具、分區格式和檔案系統。
作業系統 | 分區工具 | 分區格式 | 檔案系統 |
Linux | parted | GPT | ext4 |
二.磁盤分區
此示例中說明如何在Linux執行個體上使用Parted工具和e2fsprogs工具分區并格式化一個大容量資料盤
- 系統:centos 7.7
- 盤空間:3T
- 裝置名:/dev/nvme1n1
2.1 安裝分區工具
前提條件:請确認您的Linux執行個體上已經安裝了Parted工具和e2fsprogs工具。
- 安裝Parted工具:
yum install -y parted
- 令安裝e2fsprogs工具:
yum install -y e2fsprogs
2.2 檢視是否存在資料盤
運作以下指令:
fdisk -l
運作結果如下所示,應包含資料盤資訊。如果沒有,表示未挂載資料盤。
Disk /dev/nvme1n1: 3328.6 GB, 3328599654400 bytes, 6501171200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
2.3 使用Parted工具為資料盤進行分區
- 開始分區
parted /dev/nvme1n1
- 将預設的MBR分區格式轉為GPT分區格式
mklabel gpt
- 劃分一個主分區,并設定分區的開始位置和結束位置
mkpart primary 1 100%
- 檢查分區是否對齊
align-check optimal 1
運作結果如下所示:
1 aligned
注:如果傳回的是 1 not aligned,說明分區未對齊,需要進行檢查。
- 檢視分區表
print
- 退出Parted工具
quit
Parted工具分區結果如下所示
# arted /dev/nvme1n1
GNU Parted 3.1
Using /dev/nvme1n1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt //将預設的MBR分區格式轉為GPT分區格式
(parted) mkpart primary 1 100% //劃分一個主分區,并設定分區的開始位置和結束位置
(parted) align-check optimal 1 //檢查分區是否對齊
1 aligned
(parted) print //檢視分區表
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 4398GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 3329GB 3329GB primary
(parted) quit //退出Parted工具
Information: You may need to update /etc/fstab.
2.4 系統重讀分區表
使系統重讀分區表。
partprobe
2.5 為/dev/vdb1分區建立檔案系統
- 建立一個ext4檔案系統
mkfs -t ext4 /dev/nvme1n1
2.6 挂載磁盤
- 将分區/dev/nvme1n1挂載到/opt
mount /dev/nvme1n1 /opt
- 檢視目前磁盤空間和使用情況
df -h
如果傳回結果裡出現建立檔案系統的資訊,說明挂載成功,可以進行使用了
/dev/nvme1n1 3.0T 89M 2.9T 1% /opt
- 設定開機自動挂載
在/etc/fstab檔案中寫入新分區資訊,啟動開機自動挂載分區
- 備份etc/fstab。
cp /etc/fstab /etc/fstab.bak
- 向/etc/fstab裡寫入新分區資訊
echo `blkid /dev/nvme1n1 | awk '{print $2}' | sed 's/\"//g'` /opt ext4 defaults 0 0 >> /etc/fstab
- 檢視/etc/fstab的資訊
cat /etc/fstab
如果傳回結果裡出現了寫入的新分區資訊,說明寫入成功。
至此,已經成功分區并格式化了一個3 TB資料盤。
三、安裝docker
3.1 解除安裝舊版本
舊版本的 Docker 稱為 docker 或者 docker-engine,可以使用如下指令解除安裝:
# yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
3.2 使用 yum 安裝
- 1)安裝依賴包
# yum install -y yum-utils
-
2)配置安裝源
國内源:
# yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
$ sudo sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
官方源:
# yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
- 3)安裝 Docker
# yum install docker-ce docker-ce-cli containerd.io
3.3 使用官方安裝腳本自動安裝
指定使用國内源進行安裝
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
curl -sSL https://get.daocloud.io/docker | sh
3.4 啟動并加入開機啟動
# systemctl start docker
# systemctl enable docker