一、安装nfs服务组件:
 1、安装
 yum install rpcbind nfs-utils
 2、创建共享目录,并模拟生成web服务器所需的静态资源,如html页面
 mkdir /share
 echo "hello nfs-server and http-server" > /share/index.html
 3、向指定的服务器web-server发布当前的共享目录/share
 vi /etc/exports
 4、启动nfs服务并验证端口是否在监听客户端请求
 systemctl start nfs.service
 systemctl status nfs.service
 5、启动远程过程调用服务以传输数据
 systemctl start rpcbind
 systemctl status rpcbind
 6、设置nfs服务及rpcbind服务开机自启动
 systemctl enable rpcbind
 systemctl enable nfs
 7、查看nfs服务的监听端口
 netstat -nltpu | grep rpcbind
 8、rpc端口是否生效
 rpcinfo -p
 9、查看共享目录在本机是否可以被挂载
 showmount -e localhost二、Web-server服务器
 1、安装Apache服务
 rpm -qa|grep httpd
 (1)配置yum源:
 mount /dev/sr0 /media/CentOS/
 mount: /dev/sr0 写保护,将以只读方式挂载
 yum clean all
 yum repolist
 yum makecache
 yum install -y httpd
 2、安装nfs服务客户端程序,帮助httpd从nfs-server读取共享目录数据
 yum install -y rpcbind
 3、启动httpd服务并设置为开机自启动
 systemctl start httpd
 systemctl enable httpd
 Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
 4、启动rpcbind服务并设置为开机自启动
 systemctl start rpcbind
 systemctl enable rpcbind
 5、测试httpd服务是否可用,在Windows的浏览器输入当前web-server的IP地址
 6、在web-server上挂载nfs-server的共享目录
 (1)停止httpd服务
 systemctl stop httpd
 (2)挂载共享目录
 (3)安装nfs服务相关的工具包
 yum -y install nfs-utils nfs-utils-lib nfs4-acl-tools
 mount -t nfs 192.168.100.240:/share /var/www/html/
 (4)查看当前系统已挂载的设备
 df -h
 文件系统                 容量  已用  可用 已用% 挂载点
 192.168.100.240:/share 17G 1.3G 16G 8% /var/www/html
 7、验证文件共享
 (1)启动httpd服务
 systemctl start httpd
 (2)在windows浏览器中测试静态资源访问是否正常
 (3)在CentOS系统中使用elink工具进行测试
 A、安装elink工具
 yum install -y elinks
 elinks http://192.168.100.200三、inotify+rsync实现nfs-server共享目录的数据实时备份
 1、安装文件系统监测inotify工具
 (1)创建源代码安装软件的目录
 mkdir /soft
 cd /soft
  ll
 总用量 352
 -rw-r--r-- 1 root root 358772 8月   6 14:39 inotify-tools-3.14.tar.gz (2)对源码包解包解压缩
  tar -zxf inotify-tools-3.14.tar.gz
  ls
 inotify-tools-3.14  inotify-tools-3.14.tar.gz
  cd inotify-tools-3.14
 安装C编译器
  yum install -y gcc
 配置安装信息
  ./configure
 编译源码包
  make
 安装编译后的源码包
  make install2、编写inotify与rsync实时备份静态数据的脚本
 vi rsync.sh
 cat rsync.sh
 #!/bin/bash
 /usr/local/bin/inotifywait -mrq -e modify,delete,create,attrib,move /share | while read events
 do
         rsync -a --delete /share 192.168.10.20:/backup/
         echo "`date +%F\ %T`出现事件$events" >> /var/log/rsync.log 2>&1
 done3、脚本权限设置
 ll rsync.sh
 -rw-r--r-- 1 root root 234 8月   6 15:08 rsync.sh
 chmod a+x rsync.sh
 ll rsync.sh
 -rwxr-xr-x 1 root root 234 8月   6 15:08 rsync.sh5、在back-server服务器上创建备份文件的目录/backup
6、设置nfs-server中的root用户到本机、back-server备份服务器免密登录
 (1)生成nfs-server服务器的root用户对应密钥对
 ssh-keygen
 (2)将公钥复制到本机及backup-server
 ssh-copy-id 192.168.100.240
 Are you sure you want to continue connecting (yes/no)? yes
 root@192.168.100.240's password:
 ssh-copy-id 192.168.100.250
 Are you sure you want to continue connecting (yes/no)? yes
 root@192.168.100.240's password:
 (3)测试免密登录
 ssh 192.168.100.240
 Last login: Fri Aug  6 09:02:50 2021 from 192.168.100.190
 exit
 登出
 Connection to 192.168.100.240 closed.
 ssh 192.168.100.250
 Last login: Fri Aug  6 14:22:12 2021 from 192.168.100.190
 [root@backup-server ~]# exit
 登出
 Connection to 192.168.100.250 closed.7、让rsync.sh运行于后台模式
 ./rsync.sh &
 [1] 17799
 fg 1  将任务切换到前台
 8、实时备份验证,在nfs-server共享目录/share,创建新文件
 cd /share
 mkdir aaa
 touch test{1..5}
 ls
 aaa index.html rsync.sh  test1  test2  test3  test4  test5
 6、到backup-server上查询/backup中是否备份了文件[root@nfs-server share]# 9、查看rsync进行实时数据备份的日志文件
 [root@nfs-server share]# tail -f /var/log/rsync.log四、Smaba文件共享服务安装:
 1、安装smaba服务
 (1)查看是否安装了samba软件
 rpm -qa | grep smaba
 (2)查看smb安装包名称
 yum search samba
 (3)查看安装源中软件包版本
 yum list | grep samba
 (4)安装samba软件包
 yum install -y samba
 (5)查看软件包安装是否成功
 rpm -qa | grep samba
 samba-common-4.7.1-6.el7.noarch
 samba-common-libs-4.7.1-6.el7.x86_64
 samba-client-libs-4.7.1-6.el7.x86_64
 samba-libs-4.7.1-6.el7.x86_64
 samba-4.7.1-6.el7.x86_64
 samba-common-tools-4.7.1-6.el7.x86_64
 (6)查看安装了哪些samba软件的组件
 rpm -ql samba
 [root@smb-server ~]#2、配置samba服务
 (1)创建共享目录/samba/share
 mkdir -p /samba/share
 ll -d /samba/share
 drwxr-xr-x 2 root root 6 8月   7 09:40 /samba/share
 (2)增加所用对共享目录写权限
 chmod -R a+w /samba/share/
 ll -d /samba/share
 drwxrwxrwx 2 root root 6 8月   7 09:40 /samba/share
 (3)编辑配置文件
 vi /etc/samba/smb.conf
 [global]
         workgroup = LENOVO
 [samba_share]
         path = /samba/share
         public = no
         writable = yes3、创建一个本地用户并且加入到samba数据库里
 (1)创建供客户端远程访问共享目录的本地用户
 useradd user01
 echo 1|passwd --stdin user01
 更改用户 user01 的密码 。
 passwd:所有的身份验证令牌已经成功更新。
 (2)查看samba数据库
 which smbpasswd
 /usr/bin/smbpasswd
 (3)查看samba-common的版本
 rpm -qf /usr/bin/smbpasswd
 samba-common-tools-4.7.1-6.el7.x86_64
 (4)在smaba服务中为用户user01设置访问共享目录的验证密码
 smbpasswd -a user01
 New SMB password:
 Retype new SMB password:
 Added user user01.
 (5)查看是否将用户user01添加到smbpasswd中
 pdbedit -L
 user01:1000:4、启动samba服务
 systemctl start nmb
 systemctl start smb
 5、Samba服务器共享目录的验证测试
 6、在Windows系统验证共享目录及user01用户家目录
 (1)win+r,在运行对话框中输入Linux samba服务器的IP地址:\\192.168.100.180
 (2)登录验证对话框输入用户及密码:user01/smbpasswd中为user01设置的密码;
 (3)进行文件的上传及下载;
 7、在Linux系统进行smb-server服务器的共享难:
 (1)在Linux客户端系统安装smbclient软件
 yum list | grep samba
 yum install -y samba-client
 (2)查看smb-server服务器中共享目录名称:
 smbclient -L 192.168.10.10 -U user01
 (3)进入目录:
 smbclient //192.168.10.10/samba_share -U user01
 (4)使用get命令、put命令进行共享目录文件的下载及上传操作。