centos6.3搭建iscsitarget存储服务器

来源:互联网 发布:cs175平台数据查询 编辑:程序博客网 时间:2024/04/30 21:59

实验环境:centos 6.3
软件版本:iscsitarget-1.4.20.2.tar.gz

安装软件:

yum install likernel-headers kernel-devel make gcc gcc-c++ flex patch[root@localhost ~]# tar zxvf iscsitarget-1.4.20.2.tar.gz [root@localhost ~]# cd iscsitarget-1.4.20.2[root@localhost iscsitarget-1.4.20.2]# make[root@localhost iscsitarget-1.4.20.2]# make install

安装完成,开始配置

Iscsitarget安装完毕后,会创建/etc/iet/目录,此目录下有Iscsitarget的相关配置文件
[root@localhost iscsitarget-1.4.20.2]# cd /etc/iet/
[root@localhost iet]# vi ietd.conf
打开ietd.conf文件,首先找到类似如下行:
#Target iqn.2001-04.com.example:storage.disk2.sys1.xyz
此选项表示该iSCSI Target的命名,先将前面的“#”号去掉, Target的命名在同一子网内应该是唯一的,标准命名方式为:
iqn.yyyy-mm.[:identifier]
其中:
iqn:表示“iSCSI Qualified Name”,简称iqn。
yyyy-mm:表示年份-月份。这里是2001-04。
reversed domain name:表示倒过来的域名,这里是com.example。
identifier:表示识别代码,这里是storage.disk2.sys1.xyz。
接下来,就是要设定 LUN(Logical Unit Number),找到类似如下行:
#Lun 0 Path=/dev/sdb,Type=fileio,ScsiId=xyz,ScsiSN=xyz
将前面的“#”号去掉,“Lun 0 Path=/dev/sdb”表示块设备号为0,映射的磁盘为/dev/sdb,
“Type”值fileio是默认的,表示设置设备IO传输类型,有fileio、blockio、nullio。逻辑卷推荐用fileio,分区推荐用blockio。
主要用来对一个磁盘进行存储共享。读者可以根据自己情况将Path改为需要共享的存储分区的设备标识。
这里我们新建一个分区来作为iscsitarget存储的分区
[root@localhost iet]# fdisk /dev/sda
新分区一个分区叫/dev/sda4 大小为512M。
格式化分区
[root@localhost ~]# mkfs.ext4 /dev/sda4
在这里我们的ietd.conf的配置文件为:

Target iqn.2012-07.com.example:yanLun 0 Path=/dev/sda4,Type=blockio,ScsiId=xyz,ScsiSN=xyz

如果是有多块磁盘要映射到initiator上,配置文件如下:

Target iqn.2012-07.com.example:yan1Lun 0 Path=/dev/sda4,Type=blockio,ScsiId=xyz1,ScsiSN=xyz1
Target iqn.2012-07.com.example:yan2Lun 1 Path=/dev/sda5,Type=blockio,ScsiId=xyz2,ScsiSN=xyz2

接下来就可以启动服务了

[root@localhost ~]# /etc/init.d/iscsi-target startStarting iSCSI Target: FATAL: Error inserting crc32c_intel (/lib/modules/2.6.32-279.2.1.el6.x86_64/kernel/arch/x86/crypto/crc32c-intel.ko): No such deviceFATAL: Module iscsi_trgt not found.[确定]

悲剧了,,报错了,,而且还一下报了2个错,,尼玛,坑爹。
万能的google啊,,今天gfw各种抽风,没办法只有翻墙了,,首先解决第二个错误
FATAL: Module iscsi_trgt not found.
解决办法:

mkdir /lib/modules/`uname -r`/kernel/iscsifind / -name “iscsi_trgt.ko”cp iscsi_trgt.ko /lib/modules/`uname -r`/kernel/iscsi把iscsi_trgt.ko模块复制到正确的位置depmod -aq重建一下内核模块的依赖关系

这个时候再启动服务的时候
[root@localhost ~]# /etc/init.d/iscsi-target start
Starting iSCSI Target: FATAL: Error inserting crc32c_intel (/lib/modules/2.6.32-279.2.1.el6.x86_64/kernel/arch/x86/crypto/crc32c-intel.ko): No such device
还是会报一个错,但是我们查看服务的时候,发现iscsiatrget服务已经正常启动了

[root@localhost ~]# netstat -tnlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   tcp        0      0 0.0.0.0:53350               0.0.0.0:*                   LISTEN      1198/rpc.statd      tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1180/rpcbind              tcp        0      0 0.0.0.0:3260                0.0.0.0:*                   LISTEN      1738/ietd                tcp        0      0 :::22                       :::*                        LISTEN      1407/sshd                tcp        0      0 :::3260                     :::*                        LISTEN      1738/ietd

可以看出ietd服务已经正常启动了,但是为什么启动的时候会报
Starting iSCSI Target: FATAL: Error inserting crc32c_intel (/lib/modules/2.6.32-279.2.1.el6.x86_64/kernel/arch/x86/crypto/crc32c-intel.ko): No such device
各种google,终于找到了原因,链接地址:http://old.nabble.com/FATAL%3A-Error-inserting-crc32c_intel-td33228335.html
因为现在我用的是centos6.3,内核版本为2.6.32-279.2.1.el6.x86_64
在这个内核下面使用iscsitarget,已经不需要crc32c-intel.ko模块了,所以虽然报了这个错,但是不影响使用的,如果不想看到这个错,可以修改iscsiatrget的启动脚本
vi /etc/init.d/iscsi-target
注释或者删掉这么一行
modprobe -q crc32c
保存退出,然后我们来重启一下iscsi-target服务,看会不会报错
[root@localhost ~]# /etc/init.d/iscsi-target restart
Stopping iSCSI Target: [确定]
Starting iSCSI Target: [确定]
好了,至此,iscsi-target服务端安装完成。

下面来安装客户端,这里只介绍一下客户端工具的简单使用。

在客户端的机器上安装iscsi的客户端yum -y install iscsi-initiator-utils安装完成后,执行如下命令发现服务端[root@localhost ~ ]# iscsiadm -m discovery -t sendtargets -p 192.168.207.128192.168.207.128:3260,1 iqn.2012-07.com.example:yan登入服务端[root@localhost ~ ]# iscsiadm -m node -T iqn.2012-07.com.example:yan -p 192.168.207.128 -lLogging in to [iface: default, target: iqn.2012-07.com.example:yan, portal: 192.168.207.128,3260] (multiple)Login to [iface: default, target: iqn.2012-07.com.example:yan, portal: 192.168.207.128,3260] successful.

如果有多块磁盘映射则需要执行多次login命令。

如果需要将某块磁盘的映射关系删除,执行logout命令:

iscsiadm -m node -T iqn.2012-07.com.example:yan -p 192.168.207.128 --logout


然后可以看到系统信息里面显示检测到了sdb这块硬盘

[root@localhost ~ ]#dmesgsd 3:0:0:0: [sdb] 1050935 512-byte logical blocks: (538 MB/513 MiB)sd 3:0:0:0: [sdb] Write Protect is offsd 3:0:0:0: [sdb] Mode Sense: 77 00 00 08sd 3:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA sdb: unknown partition tablesd 3:0:0:0: [sdb] Attached SCSI disk用fdisk可以看到sdb这块硬盘
[root@localhost ~ ]# fdisk -lDisk /dev/sdb: 538 MB, 538078720 bytes17 heads, 61 sectors/track, 1013 cylindersUnits = cylinders of 1037 * 512 = 530944 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

然后新建一个目录,把这块硬盘挂载上。
mkdir /data
mount /dev/sdb /data/

[root@localhost ~]# cd /data/[root@localhost data]# ll总用量 16drwx------. 2 root root 16384  726 2012 lost+found

写入一个文件看看

[root@localhost data]# mkdir a[root@localhost data]# touch b[root@localhost data]# ll总用量 20drwxr-xr-x. 2 root root  4096  722 22:25 a-rw-r--r--. 1 root root     0  722 22:25 bdrwx------. 2 root root 16384  726 2012 lost+found

测试正常。

原创粉丝点击