1. 程式人生 > >linux下通過mount掛載iscsi、ntfs、nfs詳解

linux下通過mount掛載iscsi、ntfs、nfs詳解



通常伺服器本機自帶磁碟空間有限,都需要額外載入磁碟,可以採用mount方式把遠端的共享儲存磁碟載入進來,目前用過的有iscsi、ntfs、nfs三種類型


一,mount掛載iscsi型別
1,查詢下準備掛載的磁碟或者儲存器
[[email protected] /]# 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

[[email protected] /]# 


[[email protected] ~]# 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.
[[email protected] ~]# 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
[[email protected] ~]# 


預設情況下,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,登入節點
[[email protected] ~]# 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.
[[email protected] ~]# 


3,執行fdisk -l檢視節點,如下所示。
[[email protected] ~]# 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


[[email protected] ~]# 

可以看到新掛載的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,格式化裝置
[[email protected] baimo]# mount /dev/sdc /daxxxx
mount: you must specify the filesystem type
[[email protected] baimo]# 
檢視原有的磁碟檔案系統格式:
[[email protected] ~]# 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
[[email protected] ~]# 


看到為ext4格式,如欲將裝置格式化為ext4檔案系統,執行# mkfs.ext4 /dev/sdc,如下所示:
[[email protected] ~]#  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目錄:
[[email protected] ~]# mount /dev/sdc /daxxxx
[[email protected] ~]# 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
[[email protected] ~]# 

看到,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  
[[email protected] ~]# 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...
[[email protected] ~]# 
報錯,去check下看是否可以ping通
[[email protected] /]# 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

[[email protected] /]# 

去檢視網路配置
[[email protected] /]# 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一下
[[email protected] /]# ifconfig eth0  1x.xx.0.107 netmask 255.255.255.0
[[email protected] /]# 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下,已經正常。  
[[email protected] /]# 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
[[email protected] /]#  


二,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


----------------------------------------------------------------------------------------------------------------
<版權所有,允許轉載,但必須以連結方式註明源地址,否則追究法律責任!><