任务:
1.安装nfs服务
修改配置文件
挂载文件到指定位置
2.安装samba服务
修改配置文件
挂载文件到指定位置
1.yum install -y nfs-utils
#安装nfs服务
yum install -y rpcbind
#安装rpc服务
systemctl start rpcbind #先启动rpc服务
systemctl enable rpcbind #设置开机启动
systemctl start nfs-server nfs-secure-server
#启动nfs服务和nfs安全传输服务
systemctl enable nfs-server nfs-secure-server
mkdir /public
#创建public共享目录
vi /etc/exports
/public 192.168.128.129(insecure,rw,sync,no_root_squash)
systemctl reload nfs
#重新加载NFS服务,使配置文件生效
NFS客户端挂载配置
[root@localhost public]# showmount -e 192.168.254.21
Export list for 192.168.128.129:
/public 192.168.128.129
[root@localhost ~]# mkdir /mnt/public
[root@localhost ~]# mkdir /mnt/data
[root@localhost ~]# vim /etc/fstab
#在该文件中挂载,使系统每次启动时都能自动挂载
192.168.128.129:/public /mnt/public nfs defaults 0 0
[root@localhost ~]# mount -a #是文件/etc/fstab生效
[root@localhost public]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 23G 4.1G 19G 18% /
devtmpfs devtmpfs 475M 0 475M 0% /dev
tmpfs tmpfs 489M 84K 489M 1% /dev/shm
tmpfs tmpfs 489M 7.1M 482M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 xfs 297M 144M 154M 49% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
tmpfs tmpfs 98M 20K 98M 1% /run/user/42
192.168.128.129:/public nfs4 50G 5.7G 45G 12% /mnt/public
服务器端
1、下载工具
yum -y install nfs-utils rpcbind
2、编辑vim /etc/exports
/home/lnntest 192.168.128.0/24(rw)
3、启动
[root@localhost ~]# systemctl start rpcbind nfs
[root@localhost ~]# systemctl is-active rpcbind nfs
查看是不是active
active
4、新建
mkdir /home/lnntest
5、复制
cp /etc/passwd /etc/hosts /home/lnntest
6、[root@localhost ~]# ls /home/lnntest
hosts passwd
7、重启
[root@localhost ~]# systemctl restart rpcbind nfs
[root@localhost ~]# systemctl is-active rpcbind nfs
8、挂载自己
[root@localhost ~]# showmount -e 192.168.128.132
Export list for 192.168.128.132:
/home/lnntest 192.168.128.0/24
客户端
1、下载工具
yum -y install nfs-utils rpcbind
2、[root@localhost ~]# mount 192.168.128.132:/home/lnntest /nfs/
3、查看最后一行
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root 38770180 1152804 37617376 3% /
devtmpfs 920380 0 920380 0% /dev
tmpfs 932652 0 932652 0% /dev/shm
tmpfs 932652 9816 922836 2% /run
tmpfs 932652 0 932652 0% /sys/fs/cgroup
/dev/sda1 1038336 145260 893076 14% /boot
tmpfs 186532 0 186532 0% /run/user/0
192.168.128.132:/home/lnntest 38770432 1227264 37543168 4% /nfs
echo 123456 > /nfs/wp.txt
cat /nfs/wp.txt
[root@localhost ~]# cd /nfs
[root@localhost nfs]# ll
total 16
-rw-r--r--. 1 nfsnobody nfsnobody 7 Oct 6 10:43 ap.txt
-rwxrwxrwx. 1 root root 158 Oct 6 10:17 hosts
-rwxrwxrwx. 1 root root 1034 Oct 6 10:17 passwd
-rw-r--r--. 1 nfsnobody nfsnobody 7 Oct 6 10:44 wp.txt
服务器:
[root@localhost home]# cd test
[root@localhost test]# ll
total 16
-rw-r--r--. 1 nfsnobody nfsnobody 7 Oct 6 10:43 ap.txt
-rwxrwxrwx. 1 root root 158 Oct 6 10:17 hosts
-rwxrwxrwx. 1 root root 1034 Oct 6 10:17 passwd
-rw-r--r--. 1 nfsnobody nfsnobody 7 Oct 6 10:44 wp.txt