Day35-集群NFS后端存儲應(yīng)用與實踐-深入講解2

為什么fstab無法實現(xiàn)nfs掛載?

回顧:開機(jī)啟動流程:

1、磁盤先啟動/etc/fstab

2、防火墻在前。

3、網(wǎng)卡

NFS網(wǎng)絡(luò)文件系統(tǒng),通過網(wǎng)絡(luò)掛載,網(wǎng)絡(luò)沒起如何掛載?

又想在fstab里實現(xiàn)掛載、就用一個服務(wù),延遲啟動。

[root@nfs01 /data1]# systemctl start remote-fs.target?

[root@nfs01 /data1]# systemctl enable remote-fs.target?

Created symlink from /etc/systemd/system/multi-user.target.wants/remote-fs.target to /usr/lib/systemd/system/remote-fs.target.

[root@nfs01 /data1]# systemctl status remote-fs.target?

● remote-fs.target - Remote File Systems

? ?Loaded: loaded (/usr/lib/systemd/system/remote-fs.target; enabled; vendor preset: enabled)

? ?Active: active since 四 2019-04-18 10:17:57 CST; 18s ago

? ? ?Docs: man:systemd.special(7)

4月 18 10:17:57 nfs01 systemd[1]: Reached target Remote File Systems.

C6:netfs服務(wù)

C7:remote-fs.target

3)()權(quán)限?

? ?rw 可讀寫 read write

? ?ro 只讀 read only

? ?sync 寫到磁盤才算完成,安全 慢

? ?async 異步寫到遠(yuǎn)程緩沖區(qū),快 不安全

?一會再說。

? ?all_squash※ 不管客戶端什么用戶,到服務(wù)端都是nfsnobody

? ?anonuid=匿名用戶的UID

? ?anongid=匿名用戶的GID


[root@nfs01 ~]# cat /etc/exports

#oldboy shared dir at time

#/data 172.16.1.0/24(rw,sync) 10.0.0.0/24(ro)

/data 172.16.1.0/24(rw,sync)

/data1 10.0.0.0/24(ro)

[root@nfs01 ~]# cat /var/lib/nfs/etab?

/data1 10.0.0.0/24(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,ro,secure,root_squash,no_all_squash)

/data 172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,secure,root_squash,no_all_squash)

更改默認(rèn)NFS默認(rèn)用戶

項目實踐2:

? ?NFS共享的匿名用戶用www,使得客戶端上傳的圖片都是www用戶,而不是匿名的nfsnobody。

? ?web01 backup客戶端實現(xiàn)掛載到nfs

? ?NFS下面共享/backup ,允許web01 backup客戶端(/backup)可讀寫.

? ?web01上傳圖片,backup上可以刪除web01上傳的圖片。

? ? ? NFS下面共享/data1,允許 web01 backup客戶端10網(wǎng)段只讀(data1)

? ?實現(xiàn)開機(jī)自動掛載

1)nfs01服務(wù)端NFS、以及所有客戶端:

[root@nfs01 ~]# useradd -u 1111 www

[root@nfs01 ~]# id www

uid=1111(www) gid=1111(www) 組=1111(www)

2)服務(wù)端NFS特殊配置

[root@nfs01 ~]# tail -2 /etc/exports

/data 172.16.1.0/24(rw,sync,all_squash,anonuid=1111,anongid=1111)

/data1 10.0.0.0/24(ro)

[root@nfs01 ~]# chown -R www.www /data

[root@nfs01 ~]# ls -ld /data

drwxr-xr-x 2 www www 70 4月 ?18 10:05 /data

3)服務(wù)端NFS重啟

[root@nfs01 ~]# systemctl reload nfs

4)每個客戶端

mount -t nfs 172.16.1.31:/data /data

[root@web01 ~]# df -h

文件系統(tǒng) ? ? ? ? ? 容量 ?已用 ?可用 已用% 掛載點

172.16.1.31:/data ? 19G ?1.8G ? 18G ? 10% /data

[root@web01 /data]# touch new_web01.txt

[root@web01 /data]# ls -l

總用量 0

-rw-r--r-- 1 www www 0 4月 ?16 10:24 ddddf

-rw-r--r-- 1 www www 0 4月 ?16 10:23 dddfff

-rw-r--r-- 1 www www 0 4月 ?18 11:01 new_web01.txt

-rw-r--r-- 1 www www 0 4月 ?17 11:59 oldboy.txt

-rw-r--r-- 1 www www 0 4月 ?17 12:30 oldgirl.txt

[root@nfs01 ~]# cat /etc/fstab?

#

# /etc/fstab

# Created by anaconda on Mon Mar ?4 11:15:16 2019

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=3a3a295f-88f8-456d-94dc-1a3eeb517c02 / ? ? ? ? ? ? ? ? ? ? ? xfs ? ? defaults ? ? ? ?0 0

UUID=fd2e0ca7-32be-425f-86a2-85c02b9ec5ea /boot ? ? ? ? ? ? ? ? ? xfs ? ? defaults ? ? ? ?0 0

UUID=79a3924b-739e-48dc-ab0c-0444b9ac6591 swap ? ? ? ? ? ? ? ? ? ?swap ? ?defaults,_netdev ? 0 0

man mount

_netdev

? ? ? ? ? ? ? The ?filesystem ?resides on a device that requires network access (used to prevent the ?system from attempting to mount these filesystems until the network has ?been ?enabled ?on the system).

自學(xué):fstab被破壞了如何修復(fù)?

[root@web01 ~]# cat /etc/fstab?

# /etc/fstab

# Created by anaconda on Mon Mar ?4 11:15:16 2019

UUID=3a3a295f-88f8-456d-94dc-1a3eeb517c02 / ? ? ? ? ? ? ? ? ? ? ? xfs ? ? defaults ? ? ? ?0 0

UUID=fd2e0ca7-32be-425f-86a2-85c02b9ec5ea /boot ? ? ? ? ? ? ? ? ? xfs ? ? defaults ? ? ? ?0 0

UUID=79a3924b-739e-48dc-ab0c-0444b9ac6591 swap ? ? ? ? ? ? ? ? ? ?swap ? ?defaults ? ? ? ?0 0

172.16.1.31:/data ? ? ? ? ? ? ? ? ? ? ? ? /data ? ? ? ? ? ? ? ? ? nfs ? ? defaults,soft ? ? ? ?0 0

172.16.1.31:/data ? ? ? ? ? ? ? ? ? ? ? ? /data ? ? ? ? ? ? ? ? ? nfs ? ? defaults,hard,intr ? ? ? ?0?

mount -t nfs -o hard,intr,rsize=131072,wsize=131072 172.16.1.31:/data/ /mnt

NFS服務(wù)器出問題時候,客戶端重啟依然能夠啟動,可以用如下列兩個方法:

defaults,soft

defaults,hard,intr?

#/etc/fstab

客戶端掛載深入

[root@web01 ~]# cat /proc/mounts?

debugfs /sys/kernel/debug debugfs rw,relatime 0 0

hugetlbfs /dev/hugepages hugetlbfs rw,relatime 0 0

/dev/sda1 /boot xfs rw,relatime,attr2,inode64,noquota 0 0

sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0

10.0.0.31:/data1 /mnt nfs4 rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.0.0.7,local_lock=none,addr=10.0.0.31 0 0

172.16.1.31:/data /data nfs rw,relatime,vers=3,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=172.16.1.31,mountvers=3,mountport=20048,mountproto=udp,local_lock=none,addr=172.16.1.31 0 0

rsize=131072,wsize=131072

hard

proto=tcp

tcp安全穩(wěn)定 udp無連接 FTP服務(wù)

Linux正在工作呢,文件系統(tǒng)只讀。

企業(yè)生產(chǎn)案例文件系統(tǒng)只讀故障/fstab故障。

自己找一下:

1、救援模式修復(fù)。

2、單用戶,mount -o remount,rw /

2)安全加優(yōu)化的掛載方式如下:

mount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,intr,rsize=131072,wsize=131072 172.16.1.31:/data /mnt

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容