一、存储概述
- 应用场景:存放用户上传的内容
- 数据库:常用于文字内容,账号信息
- 为何拆分存储,使用独立存储服务器/存储集群
二、存储服务选型
| 存储选型 | 说明 |
|---|---|
| 硬件存储 | 存储服务器 |
| 开源软件 | 单点的:NFS(最经典,最简单,性能ok) 分布式存储:Ceph,Minio,FastDFS… |
| 云产品 | 云存储,分布式云存储…. |
三、环境准备与nfs极速上手
3.1环境准备
| 环境 | ip | 主机名 |
|---|---|---|
| nfs服务端 | 10.0.0.31/172.16.1.31 | nfs01 |
| nfs客户端 | 10.0.0.7/172.16.1.7 | web01 |
| nfs客户端 | 10.0.0.8/172.16.1.8 | web02 |
安装:
yum install -y nfs-utils rpcbind
yum install -y nfs-utils rpcbind
安装:
yum install -y nfs-utils rpcbind
注:web服务器安装即可无需启动,仅提供nfs文件系统类型支持
yum install -y nfs-utils rpcbind
注:web服务器安装即可无需启动,仅提供nfs文件系统类型支持
3.2nfs极速上手指南
3.2.1nfs服务端
启动:
systemctl enable –now nfs rpcbind.service
检查:
rpcinfo -p
showmount -e
systemctl enable –now nfs rpcbind.service
检查:
rpcinfo -p
showmount -e
例:
#1.创建文件系统目录
mkdir -p /nfsdata/
#2.修改用户与用户组
chown -R nobody.nobody /nfsdata/
#3.进入/etc/exports
vim /etc/exports
#4.添加内容
##1.共享 /nfsdata/目录
/nfsdata/ 172.16.1.0/24(rw)
#5.重新启动nfs服务
systemctl restart nfs
#6.检查(服务端与客户端都要检查)
showmount -e nfs01
#效果:
Export list for nfs01:
/nfsdata 172.16.1.0/24
#1.创建文件系统目录
mkdir -p /nfsdata/
#2.修改用户与用户组
chown -R nobody.nobody /nfsdata/
#3.进入/etc/exports
vim /etc/exports
#4.添加内容
##1.共享 /nfsdata/目录
/nfsdata/ 172.16.1.0/24(rw)
#5.重新启动nfs服务
systemctl restart nfs
#6.检查(服务端与客户端都要检查)
showmount -e nfs01
#效果:
Export list for nfs01:
/nfsdata 172.16.1.0/24
#1.临时挂载
mount -t nfs 172.16.1.31:/nfsdata /mnt/
#2.查看是否挂载成功
df -h /mnt
#3.在/mnt目录下创建文件(cs.txt)
touch /mnt/cs.txt
#4.查看在/nfsdata目录下是否有该文件
ll /nfsdata/
#5.取消挂载
umount -t nfs 172.16.1.31:/nfsdata /mnt/
mount -t nfs 172.16.1.31:/nfsdata /mnt/
#2.查看是否挂载成功
df -h /mnt
#3.在/mnt目录下创建文件(cs.txt)
touch /mnt/cs.txt
#4.查看在/nfsdata目录下是否有该文件
ll /nfsdata/
#5.取消挂载
umount -t nfs 172.16.1.31:/nfsdata /mnt/
3.2.2nfs客户端
- 客户端/upload/目录连接到nfs共享目录
- nfs共享目录挂载到客户端/uplpad/
#1.检查
showmount -e nfs01
#效果:
Export list for nfs01:
/nfsdata 172.16.1.0/24
#2.创建要挂载的目录
mkdir -p /upload
#3.挂载
mount -t nfs 172.16.1.31:/nfsdata /upload/
#4.检查是否挂载
#5.在/upload目录下创建文件
#6.在服务端的/nfsdata目录下查看是否创建成功
#7.永久挂载
vim /etc/fstab
添加
172.16.1.31:/nfsdata /upload nfs defaults 0 0
showmount -e nfs01
#效果:
Export list for nfs01:
/nfsdata 172.16.1.0/24
#2.创建要挂载的目录
mkdir -p /upload
#3.挂载
mount -t nfs 172.16.1.31:/nfsdata /upload/
#4.检查是否挂载
#5.在/upload目录下创建文件
#6.在服务端的/nfsdata目录下查看是否创建成功
#7.永久挂载
vim /etc/fstab
添加
172.16.1.31:/nfsdata /upload nfs defaults 0 0
四、nfs用户映射
| nfs服务端选项 | 说明 |
|---|---|
| root_squash | 客户端是root用户,则压缩为匿名用户 |
| no_all_squash | root其他用户是否进行压缩,不进行压缩 |
| all_squash | root其他用户是否进行压缩,进行压缩 |
| anonuid | 用于指定匿名用户(uid),默认是65534 |
| anongid | 用于指定匿名用户(gid),默认是65534 |
cat /var/lib/nfs/etab
groupadd -g 1999 www
useradd -u 1999 -g www -s /sbin/nologin -M www
useradd -u 1999 -g www -s /sbin/nologin -M www
过程与3.2.1和3.2.2相差不多
不同:
1.文件系统目录不同
2.修改文件系统目录的用户与用户组为www.www
3.在/etc/exports中添加/nfs/blog/ 172.16.1.0/24(rw,all_squash,anonuid=1999,anongid=1999)
4.永久挂载中添加172.16.1.31:/nfs/blog /app/code/blog/wp-content/uploads/ nfs defaults 0 0
不同:
1.文件系统目录不同
2.修改文件系统目录的用户与用户组为www.www
3.在/etc/exports中添加/nfs/blog/ 172.16.1.0/24(rw,all_squash,anonuid=1999,anongid=1999)
4.永久挂载中添加172.16.1.31:/nfs/blog /app/code/blog/wp-content/uploads/ nfs defaults 0 0
五、实现存储迁移
scp 文件/目录 root@10.0.0.8:/app/code/blog/
其他内容与上面内容一样