Loading

day31 文件服务器层

文件服务器

NFS主-----rsync-----NFS备

ceph
NFS
Gluster

网络存储

  1. 文件存储
    对外提供的文件,例如NFS
  2. 块存储
    对外提供一个块设备(一个硬盘),例如ceph
  3. 对象存储
    存储单位是对象

NFS(Network File System)(小集群可用,屎上雕花)

安装 NFS 服务

在服务器端和客户端都需要安装 NFS 服务。在 Linux 系统中,可以使用包管理工具来安装,如在 CentOS 上使用yum install nfs-utils命令,在 Ubuntu 上使用sudo apt-get install nfs-kernel-server命令。

配置服务器端

编辑 NFS 配置文件,通常是/etc/exports。在该文件中,指定要共享的目录以及允许访问该目录的客户端列表,例如/data *(rw,sync,no_root_squash)表示将/data目录共享给所有客户端,客户端具有读写权限,同步写入磁盘,并且不限制根用户权限。
启动 NFS 服务,并设置开机自启。在 CentOS 上可以使用systemctl start nfs-server和systemctl enable nfs-server命令,在 Ubuntu 上使用sudo service nfs-kernel-server start和sudo update-rc.d nfs-kernel-server enable命令。

vim /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash)

挂载后可读可写,all_squash:将所有访问用户(包括 root)映射为匿名用户(nfsnobody),增强安全性(避免客户端以 root 权限操作共享目录)。

统一用户

添加用户

[root@web01 ~]# groupadd www -g 666
[root@web01 ~]# useradd www -u 666 -g 666
 
[root@web02 ~]# groupadd www -g 666
[root@web02 ~]# useradd www -u 666 -g 666
 
[root@nfs ~]# groupadd www -g 666
[root@nfs ~]# useradd www -u 666 -g 666

将NFS共享文件夹改为www组www用户

[root@nfs ~]# vim /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
 
#授权/data目录
[root@nfs ~]# chown -R www.www /data/
 
#重启服务
[root@nfs ~]# systemctl restart nfs-server.service
 
#验证启动用户
[root@nfs ~]# cat /var/lib/nfs/etab/data
172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=666,anongid=666,sec=sys,rw,secure,root_squash,all_squash)

永久挂载NFS

vi /etc/fstab

# 创建挂载点
mkdir -p /mnt/nfs_data

# 编辑 fstab
vi /etc/fstab
# 添加:
192.168.1.100:/data    /mnt/nfs_data    nfs    rw,sync,all_squash,anonuid=1000,anongid=1000    0    0

# 测试挂载
mount -a
mount | grep nfs_data  # 验证输出

配置客户端

在客户端上,使用showmount -e <server_ip>命令来查看服务器端共享的目录,其中<server_ip>是 NFS 服务器的 IP 地址。
创建一个本地目录,用于挂载 NFS 共享目录,例如mkdir /mnt/nfs。
使用mount -t nfs <server_ip>:/shared_dir /mnt/nfs命令将服务器端的共享目录挂载到本地目录,其中<server_ip>是服务器的 IP 地址,/shared_dir是服务器端共享的目录,/mnt/nfs是本地挂载点。

制作NFS的备份

  1. rsync + inotify
    inotifty 检测文件夹下变动
    rsync 同步变动到远程备份机

  2. sersync=rsync + inotidy

1.2有缺点:故障切换要人手动完成
(DRBD+HeartBeat+NFS)高可用服务器集群

rsync

与scp、cp命令用法相同,但rsync是增量拷贝,还支持断点续传
yum install rsync -y
服务端:
systemctl start rsyncd
兼容服务端的sshd

用法:
/a.txt 虚拟账号@1.1.1.1::xxx
xxx为模块名

posted @ 2025-03-25 23:27  xbule  阅读(46)  评论(0)    收藏  举报