城市里的游牧民族

Menu

ubuntu iscsi 安装以及挂载SAN资源步骤

ubuntu iscsi 安装以及挂载SAN资源步骤

在操作一下步骤前请事先在存储上配置好SAN资源,SANZ客户端,创建target,并将SAN资源分配给SAN客户端,保证ubuntu服务到存储业务网络能ping通。最好ubuntu服务器能上网,这样方便后面安装一些软件包。
本次试验设备H3C IX3000、ubuntu服务器。

第一步:安装open-iscsi即Linux Open-iSCSI Initiator。
命令如下:
sudo apt-get install open-iscsi

第二步:修改参数。
1、修改InitiatorName、保证InitiatorName和存储上的Initiator名称一致。
用vi编辑/etc/iscsi/initiatorname.iscsi文件,文件内容如下
InitiatorName=iqn.20111128.com.h3c:linux
2、设置在开机后自动登录Target。
用vi编辑/etc/iscsi/iscsi.conf文件
找到#node.startup = automatic去掉前面的注释符#,
找到node.startup = manual在前面加上注释符#
最后如下
node.startup = automatic   表示自动登录(默认是automatic),
#node.startup = manual     表示需手动登录。
3、如果存储的target上启用了CHAP认证,则还需要配置CAHP认证
用vi编辑/etc/iscsi/iscsi.conf文件
node.session.auth.authmethod = CHAP
node.session.auth.username = xxxxxx      ――CHAP认证用户名
node.session.auth.password = xxxxxx      ――CHAP认证密码(至少12个字符)
4、设置iSCSI发生错误以后,返回应用程序的超时时间。
用vi编辑/etc/iscsi/iscsi.conf文件
node.session.timeo.replacement_timeout = 120  表示120秒
第三步:修改好参数后,需要重启open-iscsi服务。
命令如下:
sudo service open-iscsi restart

重启好了后我们可以通过下面的命令查看iscsi运行状态
命令如下:
sudo service iscsi status

第四步:在ubuntu上执行target发现

首先要安装 iscsiadm ,如果该命令已经安装请跳过此步。
命令如下:
sudo apt-get install iscsiadm
安装好后执行target发现,
命令如下:
sudo iscsiadm -m discovery -t sendtargets -p 200.200.10.200:3260
我们这里是先在存储上做好分配了,所以正常情况下直接由如下提示,表示发现了。
我们也可以先通过发现,然后再去存储上分配都是一样,结果一样。
iscsiadm: unexpected SendTargets data:
200.200.10.200:3260,1 iqn.2007-04.acme.com:h3c:200realm.rhel5
此时发现了一个新的target,target名称为iqn.2007-04.acme.com:h3c:200realm.rhel5
第五步:登陆target
命令如下:
sudo iscsiadm -m node -T iqn.2007-04.acme.com:h3c:200realm.rhel5 -p 200.200.10.200:3260 –l

这里-T后面跟target名称,最后的-l(英文字母中小写的L),是login的意思。
可以使用iscsiadm -m node --loginall=all一次登录所有的targets。
sudo iscsiadm -m node --loginall=all

第六步:对新发现的磁盘进行分区并创建文件系统
1、先用fdisk –l查看新的磁盘名称
命令如下:
sudo fdisk -l

会有如下提示,这里我们发现了一个100GB的磁盘,设备名为/dev/sdb
Disk /dev/sdb: 107.3 GB, 107373133824 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table
2、用fdisk /dev/sdb进行分区,本例中我们把整个磁盘分成一个主分区/dev/sdb1
命令如下:
sudo 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.
The number of cylinders for this disk is set to 13054.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-13054, default 1):     ――此处回车,使用默认值1
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-13054, default 13054):   ――此处回车使用默认值13054
Using default value 13054

Command (m for help): w
The partition table has been altered!
3、用mkfs命令在/dev/sdb1上创建ext3文件系统
命令如下:
sudo mkfs.ext3 /dev/sdb1

mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
13107200 inodes, 26214055 blocks
1310702 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
800 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: //这里直接回车
done

This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

4、用tune2fs修改文件系统的属性,去掉自动检查的属性
命令如下:
sudo tune2fs -c -1 -i 0 /dev/sdb1    //-1为负一

Linux上的ext3文件系统有一个特性,对某个分区mount、umount很多次后或者隔一个固定的时间后,系统会对该分区进行检测,这就会导致硬盘反映速度很慢,影响业务,本操作的目的就是去掉文件系统自动检查的属性。
tune2fs 1.39 (29-May-2006)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds

第七步:设定文件系统的自动挂载
本例中我们将要把/dev/sdb1挂载到/data目录下
1、手动创建一个目录/data
命令如下:
sudo mkdir /data

2、用tune2fs查看文件系统的UUID
命令如下:
sudo tune2fs -l /dev/sdb1

tune2fs 1.39 (29-May-2006)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          3f0a00b7-4939-4ad2-a592-0821bb79f7c6
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal resize_inode dir_index filetype sparse_super large_file
3、用vi编辑/etc/fstab文件,设置自动挂载:
/dev/VolGroup00/LogVol00  /                    ext3    defaults        1 1
LABEL=/boot             /boot                ext3    defaults        1 2
devpts                  /dev/pts               devpts  gid=5,mode=620  0 0
tmpfs                   /dev/shm               tmpfs   defaults        0 0
proc                    /proc                  proc    defaults        0 0
sysfs                   /sys                   sysfs   defaults        0 0
/dev/VolGroup00/LogVol01 swap                  swap    defaults        0 0
UUID=3f0a00b7-4939-4ad2-a592-0821bb79f7c6    /data     ext3    _netdev   0 0
4、用mount –a挂载文件系统
sudo mount –a

5、用df查看文件系统已经挂载成功
sudo df –Th
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
              ext3     65G  2.4G   59G   4% /
/dev/sda1     ext3     99M   12M   82M  13% /boot
tmpfs        tmpfs    471M     0  471M   0% /dev/shm
/dev/sdb1     ext3     99G  188M   94G   1% /data

6、条件允许的话,重启一下操作系统,使用df命令确认系统重启后文件系统能够自动挂载上来。

 

 

— 于 共写了5146个字
— 文内使用到的标签:
本作品采用知识共享署名-非商业性使用-禁止演绎 3.0 中国大陆许可协议进行许可。

发表评论

电子邮件地址不会被公开。 必填项已用*标注