linux下通过mount挂载iscsi、ntfs、nfs详解

时间:2023-01-26 22:25:08


通常服务器本机自带磁盘空间有限,都需要额外加载磁盘,可以采用mount方式把远程的共享存储磁盘加载进来,目前用过的有iscsi、ntfs、nfs三种类型


 
一,mount挂载iscsi类型
1,查找下准备挂载的磁盘或者存储器
[root@localhost /]# iscsiadm -m discovery -t st -p 1x.xx.0.22:3260
1x.xx.0.22:3260,1 iqn.2001-05.com.equallogic:0-8a0906-6dac38009-c1b1cac2d434efec-pddata
1x.xx.0.22:3260,1 iqn.2001-05.com.equallogic:0-8a0906-4061f7f09-29d248cfaed54b9d-daxxxx
[root@localhost /]# 


[root@localhost ~]# iscsiadm -m iqn.2001-05.com.equallogic:0-8a0906-4061f7f09-29d248cfaed54b9d-daxxxx -T /daxxxx -p 1x.xx.0.22:3260 -l
Try `iscsiadm --help' for more information.
[root@localhost ~]# iscsiadm --help
iscsiadm -m discoverydb [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -Dl ] ] | [ [ -p ip:port -t type] [ -o operation ] [ -n name ] [ -v value ] [ -lD ] ] 
iscsiadm -m discovery [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -l ] ] | [ [ -p ip:port ] [ -l | -D ] ] 
iscsiadm -m node [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -L all,manual,automatic ] [ -U all,manual,automatic ] [ -S ] [ [ -T targetname -p ip:port -I ifaceN ] [ -l | -u | -R | -s] ] [ [ -o  operation  ] [ -n name ] [ -v value ] ]
iscsiadm -m session [ -hV ] [ -d debug_level ] [ -P  printlevel] [ -r sessionid | sysfsdir [ -R | -u | -s ] [ -o operation ] [ -n name ] [ -v value ] ]
iscsiadm -m iface [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -I ifacename | -H hostno|MAC ] [ [ -o  operation  ] [ -n name ] [ -v value ] ] [ -C ping [ -a ip ] [ -b packetsize ] [ -c count ] [ -i interval ] ]
iscsiadm -m fw [ -l ]
iscsiadm -m host [ -P printlevel ] [ -H hostno|MAC ] [ [ -C chap [ -o operation ] [ -v chap_tbl_idx ] ] | [ -C flashnode [ -o operation ] [ -A portal_type ] [ -x flashnode_idx ] [ -n name ] [ -v value ] ] ]
iscsiadm -k priority
[root@localhost ~]# 


默认情况下,iscsi发起方和目标方之间通过端口3260连接。假设已知iscsi的目标方IP是192.xxx.1.1,运行下列命令:

iscsiadm -m node -T  iqn.2001-05.com.equallogic:0-8a0906-4061f7f09-29d248cfaed54b9d-daxxxx   -p 1x.xx.0.22:3260 -l
如果要在系统启动时自动登入 
iscsiadm -m node –T iqn.1997-05.com.test:raid -p 192.xxx.1.1:3260 --op update -n node.startup -v automatic

2,登录节点
[root@localhost ~]# iscsiadm -m node -T  iqn.2001-05.com.equallogic:0-8a0906-4061f7f09-29d248cfaed54b9d-daxxxx   -p 1x.xx.0.22:3260 -l
Logging in to [iface: iscsi_eth0, target: iqn.2001-05.com.equallogic:0-8a0906-4061f7f09-29d248cfaed54b9d-daxxxx, portal: 1x.xx.0.22,3260] (multiple)
Login to [iface: iscsi_eth0, target: iqn.2001-05.com.equallogic:0-8a0906-4061f7f09-29d248cfaed54b9d-daxxxx, portal: 1x.xx.0.22,3260] successful.
[root@localhost ~]# 


3,运行fdisk -l查看节点,如下所示。
[root@localhost ~]# fdisk -l


WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.




Disk /dev/sda: 146.0 GB, 145999527936 bytes
255 heads, 63 sectors/track, 17750 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: 0x00000000


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1       17751   142577663+  ee  GPT


Disk /dev/mapper/VolGroup-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x00000000




Disk /dev/mapper/VolGroup-lv_swap: 9487 MB, 9487515648 bytes
255 heads, 63 sectors/track, 1153 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: 0x00000000




Disk /dev/mapper/VolGroup-lv_home: 82.1 GB, 82086723584 bytes
255 heads, 63 sectors/track, 9979 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: 0x00000000




Disk /dev/sdb: 1099.5 GB, 1099526307840 bytes
255 heads, 63 sectors/track, 133676 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: 0xcb8879db


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      133676  1073752438+  83  Linux


Disk /dev/sdc: 1099.5 GB, 1099526307840 bytes
255 heads, 63 sectors/track, 133676 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: 0x00000000


[root@localhost ~]# 

可以看到新挂载的Disk /dev/sdc: 1099.5 GB, 1099526307840 bytes


4,登入需验证码的节点:

开启认证
iscsiadm -m node -T iqn.2001-05.com.equallogic:0-8a0906-4061f7f09-29d248cfaed54b9d-daxxxx -o update -name node.session.auth.authmethod -value=CHAP
*.使用-o同--op


5,格式化设备
[root@localhost baimo]# mount /dev/sdc /daxxxx
mount: you must specify the filesystem type
[root@localhost baimo]# 
查看原有的磁盘文件系统格式:
[root@localhost ~]# df -T
文件系统    类型         1K-块      已用      可用 已用% 挂载点
/dev/mapper/VolGroup-lv_root
              ext4    51606140  30446060  18538640  63% /
tmpfs        tmpfs     9261428   3099716   6161712  34% /dev/shm
/dev/sda2     ext4      495844     77683    392561  17% /boot
/dev/sda1     vfat      204580       260    204320   1% /boot/efi
/dev/mapper/VolGroup-lv_home
              ext4    78904232  72142868   2753224  97% /home
/dev/sdb1     ext4   1056902612 730470180 272744812  73% /data
[root@localhost ~]# 


看到为ext4格式,如欲将设备格式化为ext4文件系统,运行# mkfs.ext4 /dev/sdc,如下所示:
[root@localhost ~]#  mkfs.ext4 /dev/sdc
mke2fs 1.41.12 (17-May-2010)
/dev/sdc is entire device, not just one partition!
无论如何也要继续? (y,n) y
Discarding device blocks: failed - 输入/输出错误
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
67117056 inodes, 268439040 blocks
13421952 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
8193 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
102400000, 214990848



6,开始挂接设备
在/mnt下创建iscsi目录
mkdir -p /daxxxx
运行mount命令:
# mount -t /dev/sdc /daxxxx

针对iscsi设备的特殊mount选项,运行df –h可以看到/daxxxx目录:
[root@localhost ~]# mount /dev/sdc /daxxxx
[root@localhost ~]# df -h
文件系统     容量  已用  可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
                       50G   30G   18G  63% /
tmpfs                 8.9G  3.0G  5.9G  34% /dev/shm
/dev/sda2             485M   76M  384M  17% /boot
/dev/sda1             200M  260K  200M   1% /boot/efi
/dev/sdc             1008G  200M  957G   1% /daxxxx
[root@localhost ~]# 

看到,iscsi设备被成功挂接,可以当作常规存储设备使用了。
如果要在系统启动时自动挂接
编辑/etc/fstab加入一行:
/dev/sdc /daxxxx ext4 default 0 0


7,登出节点
首先解除挂接
#umount /mnt/iscsi
登出
# iscsiadm -m node –T iqn.2001-05.com.equallogic:0-8a0906-4061f7f09-29d248cfaed54b9d-daxxxx -p 1x.xx.0.22:3260 –u


8,报错问题记录
ifconfig eth0 192.xxx.0.1 netmask 255.255.255.0 up  
[root@localhost ~]# iscsiadm -m discovery -t st -p 1x.xx.0.22:3260
iscsiadm: connect to 1x.xx.0.22 timed out
iscsiadm: connect to 1x.xx.0.22 timed out
iscsiadm: connect to 1x.xx.0.22 timed out
^Ciscsiadm: caught SIGINT, exiting...
[root@localhost ~]# 
报错,去check下看是否可以ping通
[root@localhost /]# ping 1x.xx.0.22
PING 1x.xx.0.22 (1x.xx.0.22) 56(84) bytes of data.
^C
--- 1x.xx.0.22 ping statistics ---
172 packets transmitted, 0 received, 100% packet loss, time 171475ms

[root@localhost /]# 

去查看网络配置
[root@localhost /]# ifconfig
eth0      Link encap:Ethernet  HWaddr 5C:F3:FC:1B:73:B4  
          inet6 addr: fe80::5ef3:fcff:fe1b:73b4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:27910750 errors:0 dropped:243 overruns:0 frame:0
          TX packets:4909669 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2068014537 (1.9 GiB)  TX bytes:409283724 (390.3 MiB)


eth1      Link encap:Ethernet  HWaddr 5C:F3:FC:1B:73:B6  
          inet addr:192.xxx.1xx.107  Bcast:192.xxx.1xx.255  Mask:255.255.255.0
          inet6 addr: fe80::5ef3:fcff:fe1b:73b6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:37927936 errors:0 dropped:1563 overruns:0 frame:0
          TX packets:41504235 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:21039621446 (19.5 GiB)  TX bytes:34187439193 (31.8 GiB)


lo        Link encap:Local Loopback  
 
原来eth0的网络ip没有配置,只配置了eth1的,所以需要ifconfg一下
[root@localhost /]# ifconfig eth0  1x.xx.0.107 netmask 255.255.255.0
[root@localhost /]# ifconfig
eth0      Link encap:Ethernet  HWaddr 5C:F3:FC:1B:73:B4  
          inet addr:1x.xx.0.107  Bcast:1x.xx.0.255  Mask:255.255.255.0
          inet6 addr: fe80::5ef3:fcff:fe1b:73b4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:27913798 errors:0 dropped:243 overruns:0 frame:0
          TX packets:4910226 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2068233906 (1.9 GiB)  TX bytes:409330163 (390.3 MiB)


eth1      Link encap:Ethernet  HWaddr 5C:F3:FC:1B:73:B6  
          inet addr:192.xxx.1xx.107  Bcast:192.xxx.1xx.255  Mask:255.255.255.0
          inet6 addr: fe80::5ef3:fcff:fe1b:73b6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:38546864 errors:0 dropped:1563 overruns:0 frame:0
          TX packets:42148624 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:21287430291 (19.8 GiB)  TX bytes:34555423236 (32.1 GiB)
查看到ifconfig已经正常,然后去ping下,已经正常。 
[root@localhost /]# ping 1x.xx.0.22
PING 1x.xx.0.22 (1x.xx.0.22) 56(84) bytes of data.
64 bytes from 1x.xx.0.22: icmp_seq=1 ttl=255 time=1.00 ms
64 bytes from 1x.xx.0.22: icmp_seq=2 ttl=255 time=0.082 ms
64 bytes from 1x.xx.0.22: icmp_seq=3 ttl=255 time=0.150 ms
^C
--- 1x.xx.0.22 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2334ms
rtt min/avg/max/mdev = 0.082/0.411/1.003/0.419 ms
[root@localhost /]#  


二,mount挂载ntfs类型
1,安装软件Fuse以及Ntfs-3g

从http://fuse.sourceforge.net上下载源代码
wget http://easynews.dl.sourceforge.net/sourceforge/fuse/fuse-2.7.1.tar.gz
解压缩源代码:
tar zxf fuse-2.7.1.tar.gz
编译和安装fuse源代码
cd fuse-2.7.1
./configure --exec-prefix=/; make; make install
Ntfs-3g安装
从网站http://www.tuxera.com/community/ntfs-3g-download/上下载源代码包:
wget http://tuxera.com/opensource/ntfs-3g_ntfsprogs-2011.4.12.tgz 
解压缩安装:
 tar zxf ntfs-3g_ntfsprogs-2011.4.12.tgz
编译和安装ntfs-3g源代码。
 cd ntfs-3g_ntfsprogs-2011.4.12
 ./configure
 make
 make install

2,挂载
如果在安装过程中没有出现错误,NTFS卷可以mount到Linux上,并且具有读写权限。
 fdisk -l | grep NTFS
 (/dev/sdb1               2    62016256  1953512032+   7  HPFS/NTFS)
 mount -t ntfs-3g /dev/sdb1 /data/oracle


三,mount挂载nfs磁盘类似
1,在linux上安装nfs软件
yum -y install nfs-utils portma
yum install nfs -y
/etc/rc.d/init.d/nfs status
/etc/rc.d/init.d/nfs start|stop|restart
2,挂载windows的共享磁盘
先测试下挂载的服务器
showmount -e 192.168.1.225
再进行挂载操作
mount   -o   username=administrator  //1xx.xx.180.252/backdate/baimo   /home/baimo
3,挂载linux下的共享磁盘
mount -t nfs 1xx.xx.0.231:/nfs/frank /mnt/oracle
4,挂载USB移动硬盘:
mount -t ntfs /dev/sdc1 /root/usb
5,解除挂载
umount /mnt/oracle


  ----------------------------------------------------------------------------------------------------------------
<版权所有,允许转载,但必须以链接方式注明源地址,否则追究法律责任!>
原博客地址:     http://blog.itpub.net/26230597/viewspace-1413077/
原作者:黄杉 (mchdba)
----------------------------------------------------------------------------------------------------------------