server:192.168.1.190
client:192.168.1.200
1、通过fdisk工具,划分出四个区域
sdb1,sdb2,sdb3,sdb4,sdb5(sdb4为扩展总分区,此分区不可用)
sdc1,sdc2
------------------------------
[root@chen-190 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help):
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-522, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): +500M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (63-522, default 63):
Using default value 63
Last cylinder or +size or +sizeM or +sizeK (63-522, default 522): +500M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (125-522, default 125):
Using default value 125
Last cylinder or +size or +sizeM or +sizeK (125-522, default 522): +1000M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First cylinder (248-522, default 248):
Using default value 248
Last cylinder or +size or +sizeM or +sizeK (248-522, default 522):
Using default value 522
Command (m for help): n
First cylinder (248-522, default 248):
Using default value 248
Last cylinder or +size or +sizeM or +sizeK (248-522, default 522): +1000M
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 62 497983+ 83 Linux
/dev/sdb2 63 124 498015 83 Linux
/dev/sdb3 125 247 987997+ 83 Linux
/dev/sdb4 248 522 2208937+ 5 Extended
/dev/sdb5 248 370 987966 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
-----------------------
2、把划分出来的区域,格式化成linux可识别的EXT3格式。
mkfs -t ext3 -c /dev/sdb1
mkfs -t ext3 -c /dev/sdb2
mkfs -t ext3 -c /dev/sdb3
mkfs -t ext3 -c /dev/sdb5
mkfs -t ext3 -c /dev/sdc1
mkfs -t ext3 -c /dev/sdc2
3、创建文件夹。然后把四个区域挂载到相应的文件夹
[root@chen-190 /]# mount /dev/sdb1 /share1
[root@chen-190 /]# mount /dev/sdb2 /share2
[root@chen-190 /]# mount /dev/sdb3 /share3
[root@chen-190 /]# mount /dev/sdb5 /share4
[root@chen-190 /]# mount /dev/sdc1 /share5
[root@chen-190 /]# mount /dev/sdc2 /share6
[root@chen-190 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
5.8G 2.8G 2.7G 51% /
/dev/sda1 99M 11M 83M 12% /boot
tmpfs 544M 0 544M 0% /dev/shm
/dev/sdb1 471M 412M 35M 93% /share1
/dev/sdb2 471M 412M 35M 93% /share2
/dev/sdb3 950M 869M 34M 97% /share3
/dev/sdb5 950M 869M 34M 97% /share4
/dev/sdc1 1.9G 35M 1.8G 2% /share5
/dev/sdc2 3.1G 69M 2.9G 3% /share6
4、设置刚才的分区开机自动挂载,修改/etc/fstab表:
server端/etc/fstab添加以下内容:
/dev/sdb1 /share1 ext3 defaults 0 0
/dev/sdb2 /share2 ext3 defaults 0 0
/dev/sdb3 /share3 ext3 defaults 0 0
/dev/sdb5 /share4 ext3 defaults 0 0
/dev/sdc1 /share5 ext3 defaults 0 0
/dev/sdc2 /share6 ext3 defaults 0 0
client端、etc/fstab;
192.168.1.190:/share1 /share1 nfs defaults 0 0
192.168.1.190:/share2 /share2 nfs defaults 0 0
192.168.1.190:/share3 /share3 nfs defaults 0 0
192.168.1.190:/share4 /share4 nfs defaults 0 0
192.168.1.190:/share5 /share5 nfs defaults 0 0
192.168.1.190:/share6 /share6 nfs defaults 0 0
client端/etc/rc.local:
mount -o soft,intr,retry=1s -t nfs 192.168.1.190:/share1 /share1
mount -o soft,intr,retry=1s -t nfs 192.168.1.190:/share2 /share2
mount -o soft,intr,retry=1s -t nfs 192.168.1.190:/share3 /share3
mount -o soft,intr,retry=1s -t nfs 192.168.1.190:/share4 /share4
mount -o soft,intr,retry=1s -t nfs 192.168.1.190:/share5 /share5
mount -o soft,intr,retry=1s -t nfs 192.168.1.190:/share6 /share6
注意:在关在nfs目录时,最好添加soft选项,以防止nfs服务端万一出现异常,而导致客户端的挂死。
5、设置nfs与portmap自动启动,在server端/etc/rc.local中添加以下:
service nfs start
exportfs -rv
service portmap start
6、修改server端/etc/exports 配置文件,添加以下内容:
/share1 192.168.1.200/24(rw)
/share2 192.168.1.200/24(rw)
/share3 192.168.1.200/24(rw)
/share4 192.168.1.200/24(rw)
/share5 192.168.1.200/24(rw)
/share6 192.168.1.200/24(rw)
7、启动挂载NFS所需的进程
server端:
加载exports目录
exportfs -rv
启动portmap服务:
service portmap start[restart]
启动NFS服务:
service nfs start[restart]
client 端
创建挂载目录
mkdir /share1
mkdir /share2
mkdir /share3
mkdir /share4
mkdir /share5
mkdir /share6
启动portmap服务:
service portmap start[restart]
挂载服务器端的共享目录(假设服务器端192.168.1.190):
[root@chen-200 /]# mount -o soft,intr,retry=1s -t nfs 192.168.1.190:/share2 /share2
[root@chen-200 /]# mount -o soft,intr,retry=1s -t nfs 192.168.1.190:/share1 /share1
[root@chen-200 /]# mount -o soft,intr,retry=1s -t nfs 192.168.1.190:/share3 /share3
[root@chen-200 /]# mount -o soft,intr,retry=1s -t nfs 192.168.1.190:/share4 /share4
此时,如果服务器端的防火墙有开着的话,将会提示错误,如:
mount: mount to NFS server '192.168.0.10' failed: System Error: No route to host.
查看防火墙状态:service iptables status
停止防火墙:service iptables stop
提示:nfs的停止和卸载有严格的顺序,千万不能弄错。
在停止nfs服务端之前,务必先umount所有客户端的挂载,否在在服务端停止后,客户端中所有涉及到挂载目录的命令都将会hang住,直至服务器端恢复正常,并且服务器停止的时间越长,客户端恢复的时间也越长。
在hang 住期间无法umount,lsof ,fuser
如果出现客户端无法正常卸载,命令均hang的状况,可参考以下方法:
方法一:修改/etc/mtab文件,把mount nfs 那一行记录删除,命令即可恢复正常,但实际上后台nfs进程仍在尝试挂载,此方法只是临时性解决方法;
方法二:重启客户端服务器,如果想更好更快的解决此问题,就只能重启客户端服务器,重启后nfs mount 进程即停止;
方法三:重启服务器端的nfs进程,然后等待客户端自动恢复
转载于:https://blog.51cto.com/ccchencheng/890970