一、NFS永久挂载
服务端 nfs rpcbind 开机自启动
[root@nfs01 ~]# systemctl is-active rpcbind nfs
active
active
[root@nfs01 ~]# systemctl is-enabled rpcbind nfs
enabled
enabled
- 方法1 /etc/rc.local
chmod +x /etc/rc.d/rc.local
- 方法2 /etc/fstab 通过/etc/fstab 实现nfs开机自动挂载
172.16.1.31:/nfs /nfs nfs defaults 0 0
二、NFS相关命令和文件
- 命令
rpcinfo
查询rpc服务注册表
-p 指定ip 如果不指定就查看当前服务器rpc信息
showmount
mount 挂载
-t 指定文件系统类型
-o 指定挂载参数
umount 卸载
-lf 强制卸载
- 文件
/etc/export
nfs服务端配置文件
/proc/mounts
nfs 客户端挂载后 参数信息
/var/lib/nfs/etab
exports table nfs 服务器共享列表 (nfs服务端 共享信息)
三、nfs 挂载的参数
rsize
wsize
nosuid
nodev
noexec
noatime
nodiratime
四、nfs优化
nfs客户端挂载优化配置命令
mount -o rsize=131072,wsize=131072,nosuid,noexec,nodev 172.16.1.31:/nfs /nfs
对内核进行优化
cat >>/etc/sysctl.conf <<EOF
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
EOF
执行sysctl -p 生效
五、故障案例:read only filesystem磁盘只读
1.如何进入光盘救援模式
troubleshooting
resuce installed system 进入救援模式
选择1 continue
选择3 skip to shell
2.磁盘故障或/etc/fstab故障
开机进入维护模式(紧急模式)
变为可以读写模式
mount -o remount,rw /
修改文件
六、错误集合:
- /nfs is busy or already mounted
nfs已经挂载
解决办法:先强制卸载,umount -lf /nfs 然后重新挂载
[root@web01 ~]# mount 172.16.1.31:/nfs /nfs
mount.nfs: /nfs is busy or already mounted
[root@web01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 99G 1.7G 98G 2% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 14M 473M 3% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 98M 0 98M 0% /run/user/0
- Stale file handle
文件句柄错误
df -h 没有挂载这个 nfs
grep /nfs /proc/mounts 已经挂载
解决:强制卸载 /nfs
[root@web01 ~]# cp /bin/ls /nfs
cp: failed to access ‘/nfs’: Stale file handle
[root@web01 ~]# cp /bin/ls /nfs/
cp: failed to access ‘/nfs/’: Stale file handle
[root@web01 ~]# cd /nfs/
-bash: cd: /nfs/: Stale file handle
[root@web01 ~]# mkdir -p /nfs/
mkdir: cannot create directory ‘/nfs/’: File exists
[root@web01 ~]# rm -r /nfs/
rm: cannot remove ‘/nfs/’: Stale file handle
3.an incorrect mount option was specified
不正确的 挂载参数
指定了1个错误的挂载参数
[root@web01 ~]# mount -t nfs -o nosiud,nodev,noexec 172.16.1.31:/data /mnt
mount.nfs: an incorrect mount option was specified
4.read-only file system
文件系统只读
touch: cannot touch ‘/root/alex.txt’: Read-only file system
解决方法:
mount -o rw,remount /
进入光盘救援模式
troubeshooting ---->rescue
continue 自动把磁盘的上面的根分区挂载到 /mnt/sysimage
shell 手动进行挂载
fdisk -l
mount /dev/sda3 /mnt/sysimage
chroot /mnt/sysimage #把当前系统的根目录设置为 从 /mnt/sysimage
vim /etc/fstab #修改磁盘上面的文件
重启