nfs挂载:
客户端服务器端安装nfs:
yum install -y nfs-utils
服务器端操作:
启动nfs和rpcbind:
systemctl start nfs & systemctl enable nfs
systemctl start rpcbind & systemctl enable rpcbind
创建需要共享的目录(例如):
mkdir /home/mnt/question/
设置nfs共享目录权限:
vim /etc/exports
添加(红色ip为nfs服务端ip),:wq保存退出
/home/mnt/question 192.168.1.30/24(rw,sync)
此处rw表示可读写,sync表示文件同时写入硬盘和内存
设置权限
chmod -R 777 /home/mnt/question
重启nfs服务
systemctl restart nfs & systemctl restart rpcbind
客户端操作:
创建需要挂载nfs的目录(例如):
mkdir /home/attachments
添加挂载目录:
mount -t nfs 192.168.1.30:/home/mnt/question /home/attachments/
测试是否挂载成功:
客户端操作:
cd /home/attachments
mkdir test
服务器端操作:
cd /home/mnt/question
ls查看能看到test文件夹证明挂载成功
如果挂载不成功的话请关闭nfs服务器的防火墙
firewall-cmd --state
systemctl stop firewalld
systemctl disable firewalld
开机自启动nfs:
因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以需要赋予其可执行权
chmod +x /etc/rc.d/rc.local
编写自启动脚本
红色所代表的ip是platform所在机器对应的ip
vim /usr/local/sbin/nfsboot.sh
往脚本填写一下内容:
#! /bin/bash ## This is nfs自启动 shell script. ## Writen by Luyouzhi 2020-04-03. date mount -t nfs 192.168.1.30:/home/mnt/question /home/attachments/ echo "nfs自启动 success!!"
赋予脚本可执行权限
chmod +x /usr/local/sbin/nfsboot.sh
打开/etc/rc.d/rc.local文件,在末尾增加如下内容
/usr/local/sbin/nfsboot.sh