L028-老男孩實效教育-nfs網路檔案系統企業級優化實戰-12節
通過命令:mount -t nfs -o nosuid,noexec,nodev,rw 10.0.0.7:data/ /mnt 將mnt掛載。
掛載的時候因為加了noexec引數,雖然有x許可權,但是也會會導致指令碼不能正常執行。
加了sh之後就可以執行了。
echo一個檔案,往當前目錄echo,去掉了mnt目錄,這時候加上x許可權就可以執行了。
exec作用:使本身帶有執行許可權的檔案執行不了,但是如果加上sh之類的直譯器exec就不會在起作用。
suid作用:
第二幅圖的real時間比第一幅圖的real時間縮短了十倍,用第四幅圖的wsize也相當於第一幅圖wsize的十倍。所以提高rsize,wsize就可以提高效率。
綜上:非效能的引數越多,速度會越慢。
把檔案/proc/sys/net/core/rmem_default和檔案/proc/sys/net/core/rmem_default的值改大,可以提高NFS的效率。
通過命令:vim /etc/sysctl.conf向檔案中輸入
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
然後儲存,再通過命令sysctl -p可檢視。
有關NFS的引數優化就寫到這裡。瞭解就行。
有關exportfs命令的介紹:
exportfs的兩大功能:
載入生效:
exporefs -rv:載入配置生效。
關於命令的使用。是要和/etc/exports檔案中的內容相一致的。
不用配置檔案而達到共享目錄的效果:
通過:exportfs -o rw,sync,all_squash 10.0.0.100(客戶端ip)/24:/data在服務端可以實現在配置檔案修改的功能,方便之處是在命令列就可以修改。然後進到客戶端,通過命令showmount -e 10.0.0.10可檢視。
通過命令:/etc/init.d/nfs stop把nfs服務關閉,rpc服務重啟,這時候輸入命令rpcinfo -p localhost檢視。就沒有nfs服務的顯示。
再次啟動NFS服務,就顯示正常。
NFS故障及解決方法:
在服務端重啟nfs服務,關閉rpc服務,然後在服務端掛載,會顯示掛在不上去。
Pnr(簡寫):程式沒有註冊。這個時候在服務端重啟nfs服務,就正常了。
所以學習的時候要先把路走通,然後自己再去多變通。
在服務端通過命令:cd /var/lib/nfs,進入到目錄中可以查目錄下的子檔案,etab中可以看到我們配置的許可權以及預設許可權。
NFS相關知識小結:
1.命令:mount(-t:指定系統檔案型別。-o:引數選項。-a:掛載所有的檔案系統。上圖所示。),umount(-l,-f:主要用於解除安裝和強制解除安裝。),showmount(-e:顯示NFS伺服器的輸出清單。),exportfs(-rv:r 重新掛載/etc/exports 裡面的設定,也同步的更新/etc/exports和/var/lib/nfs/xtab裡面的內容,v 在export的時候,將分享的目錄顯示到熒屏上。-o:後接選項。),,rpcinfo(-p)。如果出錯了,可以用ping(-c,-t:連續ping),telnet:不需要引數。檢查。
2.配置檔案:/etc/fstab,/etc/exports,/var/lib/nfs/etab,/proc/mounts,/etc/mtab。
autofs:作用是當你想訪問nfs目錄時,系統通過autofs讓nfs提前掛載在了mnt下,也可以設定在多長時間內沒有訪問這個目錄時系統自動解除安裝。實現了一個自動掛載的功能。在工作中一般不會用到autofs,優點缺點都有。價值不高,不要求掌握。
在這個需要注意:建議總結一下關於fstab的知識。
yum不能用作刪除檔案,可以安裝,查詢,等操作。禁止用yum remove刪除檔案,否則系統會出現很多問題。
關於autofs的自動掛載:
1.在服務端進行一個共享目錄的設定,我們所用的目錄是/data。授予許可權(rw,sync)。
2.在客戶端首先進行autofs的安裝命令:yum install autofs -y。安裝之後,使用命令:/etc/init.d/autofs start。讓autofs服務啟動。
啟動之後,在/etc下會生成一個auto.misc檔案和auto.master檔案。
進入/etc/auto.master檔案,設定/mnt掛載點(mnt是定義的自動mount的掛載點, /etc/auto.misc是定義了mount的動作.)
進入/etc/auto.misc檔案,服務端下的data共享目錄掛載到nfsdata目錄裡面去:
# nfsdata目錄,不需要自己建立,啟動autofs時會自動建立(如下圖):
在客戶端建立一個檔案sfgasg,在服務端的共享目錄下能檢視到。,如果規定時間不進入,就會自動斷開,預設是300秒。
關於autofs的一篇文件(和上邊的過程是一樣的,只不過是以文件的形式發出來):
【
前提:
在服務端和客戶端都要有autofs服務。安裝命令:yum install autofs -y。
啟動命令:/etc/init.d/autofs reatart。服務端和客戶端都要執行。可能rpcbind服務和nfs服務也會影響,修改完配置檔案之後無關乎在啟動一次rpcbind和nfs服務。
正解:
服務端:
1.
安裝rpcbind,nfs,autofs服務。
2.
[[email protected] ~]# cat /etc/exports
/root/test_nfs_root 10.0.0.100/24(rw,sync,insecure,no_root_squash)
/data 10.0.0.100/24(rw,sync,insecure,no_root_squash)
[[email protected] ~]#
客戶端:
1.
安裝rpcbind,nfs,autofs服務。
2.
進入到mnt目錄下執行以下命令。
[[email protected] mnt]# vim /etc/auto.master
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc /etc/auto.misc
/mnt /etc/auto.misc(PS:我們手動配置的)(mnt是定義的自動掛載的掛載點,/etc/auto.misc是定義了掛載的動作)
#
# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"
# options are explicitly given.
#
/net -hosts
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
/mnt /etc/auto.nfs
[[email protected] mnt]# vim /etc/auto.misc
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
# the following entries are samples to pique your imagination
#linux -ro,soft,intr ftp.example.org:/pub/linux
#boot -fstype=ext2 :/dev/hda1
#floppy -fstype=auto :/dev/fd0
#floppy -fstype=ext2 :/dev/fd0
#e2floppy -fstype=ext2 :/dev/fd0
#jaz -fstype=ext2 :/dev/sdc1
#removable -fstype=ext2 :/dev/hdd
nfsdata -fstype=nfs 10.0.0.10:/data(我們手動配置的)(10.0.0.10服務端下的data共享目錄掛載到服務端的nfsdata目錄裡面去)( nfsdata目錄,不需要自己建立,啟動autofs時會自動建立)
[[email protected] mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_sys-lv_root
8.3G 5.3G 3.0G 64% /
tmpfs 491M 84K 491M 1% /dev/shm
/dev/sda1 477M 36M 416M 8% /boot
/dev/sr0 1.9G 1.9G 0 100% /media/CentOS-6.9-x86_64-LiveDVD
[[email protected] mnt]# /etc/init.d/autofs restart
停止 automount: [確定]
正在啟動 automount: [確定]
[[email protected] mnt]# ll /data
總用量 0
[[email protected] mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_sys-lv_root
8.3G 5.3G 3.0G 64% /
tmpfs 491M 84K 491M 1% /dev/shm
/dev/sda1 477M 36M 416M 8% /boot
/dev/sr0 1.9G 1.9G 0 100% /media/CentOS-6.9-x86_64-LiveDVD
[[email protected] mnt]# cd /mnt
[[email protected] mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_sys-lv_root
8.3G 5.3G 3.0G 64% /
tmpfs 491M 84K 491M 1% /dev/shm
/dev/sda1 477M 36M 416M 8% /boot
/dev/sr0 1.9G 1.9G 0 100% /media/CentOS-6.9-x86_64-LiveDVD
[[email protected] mnt]# ll
總用量 0
[[email protected] mnt]# cd nfsdata
[[email protected] nfsdata]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_sys-lv_root
8.3G 5.3G 3.0G 64% /
tmpfs 491M 84K 491M 1% /dev/shm
/dev/sda1 477M 36M 416M 8% /boot
/dev/sr0 1.9G 1.9G 0 100% /media/CentOS-6.9-x86_64-LiveDVD
10.0.0.10:/data 8.3G 5.5G 2.8G 67% /mnt/nfsdata
[[email protected] nfsdata]# touch sfgasg
檢視客戶端的建立檔案:
[[email protected] nfsdata]# ll
總用量 8
-rw-r--r-- 1 root root 0 4月 20 2018 a.txt
-rw-r--r-- 1 root root 0 4月 20 2018 dir
crw-r--r-- 1 root root 5, 1 4月 20 2018 hsp
brw-r--r-- 1 root root 5, 1 4月 20 2018 hsp1
drwxr-xr-x 2 root root 4096 4月 25 2018 oldboy
-rw-r--r-- 1 root root 0 11月 8 17:09 sfgasg
-rw-r--r-- 1 root root 112 6月 13 19:12 www_2018-06-13.tar.gz
[[email protected] nfsdata]# pwd
/mnt/nfsdata
[[email protected] nfsdata]#
檢視服務端的建立檔案:
[[email protected] ~]# ll /data
total 8
-rw-r--r--. 1 root root 0 Apr 20 2018 a.txt
-rw-r--r--. 1 root root 0 Apr 20 2018 dir
crw-r--r--. 1 root root 5, 1 Apr 20 2018 hsp
brw-r--r--. 1 root root 5, 1 Apr 20 2018 hsp1
drwxr-xr-x. 2 root root 4096 Apr 25 2018 oldboy
-rw-r--r-- 1 root root 0 Nov 8 17:09 sfgasg
-rw-r--r-- 1 root root 112 Jun 13 19:12 www_2018-06-13.tar.gz
[[email protected] ~]#
】
考試題一:
考試題二:
考試題三:
考試題四:
通過命令:rpm -i nfs-utils-1.0.9-42.el5.rpm實現。
考試題五:
第一個叫用來決定哪一個檔案系統需要執行dump操作(dump執行ext2的檔案系統的備份操作),1就是需要,0就是不需要。
第二個是系統重啟時fsck程式檢測磁碟(fsck檢測和修復檔案系統)的順序號,0表示該檔案系統不被檢測,1是root檔案系統,2是別的檔案系統。fsck按序號檢測磁碟。
考試題六:
使用命令umount -lf強制解除安裝。
考試題七:
[[email protected] ~]# tail -1 /etc/exports
/data 10.0.0.100/24(rw,sync)
考試題八:
[[email protected] ~]# tail -1 /etc/exports
/data 10.0.0.100/24(ro,sync)
考試題九:
考試題十:
/etc/init.d/protmapstart
/etc/init.d/rpcstart
/etcinit.d/nfsstart
考試題十一:
/etc/init.d/protmapstart
/etc/init.d/rpcstart
考試題十二:
[[email protected] ~]# df -h
考試題十三:
優點
a.節省本地儲存空間將常用的資料存放在一臺伺服器可以通過網路訪問
b.簡單容易上手
c.方便部署非常快速,維護十分簡單
缺點
a.侷限性容易發生單點故障,及server機宕機了所有客戶端都不能訪問
b.在高併發下NFS效率/效能有限
c.客戶端沒用使用者認證機制,且資料是通過明文傳送,安全性一般(一般建議在區域網內使用)
d.NFS的資料是明文的,對資料完整性不做驗證
e.多臺機器掛載NFS伺服器時,連線管理維護麻煩
考試題十四:
[[email protected] ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9797468
Device Boot Start End Blocks Id System
/dev/sdb1 1 501 4024251 83 Linux
Command (m for help): d
Selected partition 1
Command (m for help): d
No partition is defined yet!
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +200M
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9797468
Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (27-2610, default 27):
Using default value 27
Last cylinder, +cylinders or +size{K,M,G} (27-2610, default 2610): +200M
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9797468
Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 52 208845 83 Linux
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 3
First cylinder (53-2610, default 53):
Using default value 53
Last cylinder, +cylinders or +size{K,M,G} (53-2610, default 2610):
Using default value 2610
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9797468
Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 52 208845 83 Linux
/dev/sdb3 53 2610 20547135 5 Extended
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (53-2610, default 53):
Using default value 53
Last cylinder, +cylinders or +size{K,M,G} (53-2610, default 2610): +300M
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9797468
Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 52 208845 83 Linux
/dev/sdb3 53 2610 20547135 5 Extended
/dev/sdb5 53 91 313236 83 Linux
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (92-2610, default 92):
Using default value 92
Last cylinder, +cylinders or +size{K,M,G} (92-2610, default 2610):
Using default value 2610
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf9797468
Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 52 208845 83 Linux
/dev/sdb3 53 2610 20547135 5 Extended
/dev/sdb5 53 91 313236 83 Linux
/dev/sdb6 92 2610 20233836 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]# mkfs.ext4 /dev/sdb6
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1264800 inodes, 5058459 blocks
252922 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
155 block groups
32768 blocks per group, 32768 fragments per group
8160 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[[email protected] ~]# tune2fs -c -1 /dev/sdb6(不讓系統做磁碟檢查)
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
[[email protected] ~]# mkdir /oldboy1(前提是oldboy檔案裡邊有東西)
[[email protected] ~]# mount /dev/sdb6 /oldboy1
[[email protected] ~]# cp -a /oldboy/* /oldboy1
[[email protected] ~]# ll /oldboy1
total 28
drwxr-xr-x 3 root root 4096 May 24 19:43 ett
drwx------ 2 root root 16384 Nov 10 20:22 lost+found
drwxr-xr-x 2 root root 4096 May 27 18:14 newdir
-rw-r--r-- 1 root root 0 May 27 18:14 newfile
-rw-r--r-- 1 oldboy incahome 0 May 27 17:13 s
-rw-r--r-- 1 root root 0 May 28 18:36 sudo
drwxrw-r-x 3 oldboy incahome 4096 May 27 17:40 test
-rw-r--r-- 1 root root 0 May 28 19:25 test.sh
---------- 1 root root 0 May 28 18:26 test.txt
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_hsp-lv_root
8.3G 5.5G 2.8G 67% /
tmpfs 491M 72K 491M 1% /dev/shm
/dev/sda1 477M 36M 416M 8% /boot
/dev/sdc 9.8G 23M 9.2G 1% /mnt
/dev/sdb6 19G 44M 18G 1% /oldboy1
[[email protected] ~]# umount /oldboy1
[[email protected] ~]# mount /dev/sdb6 /oldboy
[[email protected] ~]# ll /oldboy
total 28
drwxr-xr-x 3 root root 4096 May 24 19:43 ett
drwx------ 2 root root 16384 Nov 10 20:22 lost+found
drwxr-xr-x 2 root root 4096 May 27 18:14 newdir
-rw-r--r-- 1 root root 0 May 27 18:14 newfile
-rw-r--r-- 1 oldboy incahome 0 May 27 17:13 s
-rw-r--r-- 1 root root 0 May 28 18:36 sudo
drwxrw-r-x 3 oldboy incahome 4096 May 27 17:40 test
-rw-r--r-- 1 root root 0 May 28 19:25 test.sh
---------- 1 root root 0 May 28 18:26 test.txt
[[email protected] ~]# vim /etc/fstab
[[email protected] ~]# tail -1 /etc/fstab
/dev/sdb6 /oldboy ext4 defaults 0 0
[[email protected] ~]# mount -a(檢查掛載的有沒有錯誤,沒有提示就沒有錯誤)
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_hsp-lv_root
8.3G 5.5G 2.8G 67% /
tmpfs 491M 72K 491M 1% /dev/shm
/dev/sda1 477M 36M 416M 8% /boot
/dev/sdc 9.8G 23M 9.2G 1% /mnt
/dev/sdb6 19G 44M 18G 1% /oldboy
[[email protected] ~]# ll /oldboy
total 28
drwxr-xr-x 3 root root 4096 May 24 19:43 ett
drwx------ 2 root root 16384 Nov 10 20:22 lost+found
drwxr-xr-x 2 root root 4096 May 27 18:14 newdir
-rw-r--r-- 1 root root 0 May 27 18:14 newfile
-rw-r--r-- 1 oldboy incahome 0 May 27 17:13 s
-rw-r--r-- 1 root root 0 May 28 18:36 sudo
drwxrw-r-x 3 oldboy incahome 4096 May 27 17:40 test
-rw-r--r-- 1 root root 0 May 28 19:25 test.sh
---------- 1 root root 0 May 28 18:26 test.txt
[[email protected] ~]#
上機考試;
1.使用linuxrescue(救援模式)修復/etc/fstab(可以把fstab移動到/tmp目錄,然後重啟系統)
2.root忘記密碼了,想重新獲取root密碼,怎麼做?
在grub選項選單按e進入編輯模式
(按e)編輯kernel那行新增/init1(或/single)或空格1
按B重啟
進入後執行下列命令
#passwdroot