RHEL5/centos5上安裝配置iscsi server
本博文介紹將介紹如何在rhel5/centos5的環境下安裝配置iscsi服務。
測試環境:
iscsi server: 192.168.0.210 server210.example.com
iscsi client: 192.168.0.200 client200.example.com
兩臺機器的操作系統都是rhel5.4 32, 該配置方法同樣適用於64位的操作系統。
一:iscsi server的具體配置步驟:
1.安裝軟件包
a.iscsi server需要安裝的包爲:
[root@server210 ~]# yum list|grep -i scsi-target
This system is not registered with RHN.
RHN support will be disabled.
scsi-target-utils.i386 0.0-5.20080917snap.el5 ClusterStorage
b.檢查server210是否已經安裝了scsi-target軟件包,如果已經安裝,請忽略本步驟。
[root@server210 ~]# rpm -qa scsi-target-utils.i386
c.如果沒有安裝,在配置完yum後運行如下命令以完成軟件包的安裝.該命令會自動安裝scsi-target-utils.i386和perl-Config-General.noarch兩個包.所以你也可以使用rpm -ivh ****.rpm來安裝。
[root@server210 ~]# yum -y install scsi-target-utils.i386
2.創建兩個lv分區來做共享盤。(不一定非要用lv,如入你用硬盤,邏輯分區,還可以用dd if來創建一個鏡像文件,等等都可以用來做共享盤)
[root@server210 ~]# lvcreate -L 1G -n scsi1 vol0
Logical volume "scsi1" created
[root@server210 ~]# lvcreate -L 1G -n scsi2 vol0
Logical volume "scsi2" created
[root@server210 ~]# lvscan
ACTIVE '/dev/vol0/root' [8.00 GB] inherit
ACTIVE '/dev/vol0/home' [480.00 MB] inherit
ACTIVE '/dev/vol0/lv.vcracker' [2.00 GB] inherit
ACTIVE '/dev/vol0/lv.vserver' [3.00 GB] inherit
ACTIVE '/dev/vol0/scsi1' [1.00 GB] inherit
ACTIVE '/dev/vol0/scsi2' [1.00 GB] inherit
3.修改配置文件,添加如下內容,該配置的目的是:共享出兩個分區vol0-scsi1和vol0-scsi2,命名爲iqn.20012-05.com.example:mydisk,並且只允許192.168.0.200這臺主機能夠訪問.如果你需要共享給某個網段可以這麼寫: 192.168.0.0/24,具體的配置可以根據自己的實際要求來設置,我這麼寫只是爲了演示其功能。
<target iqn.20012-05.com.example:mydisk>
# List of files to export as LUNs
backing-store /dev/mapper/vol0-scsi1
backing-store /dev/mapper/vol0-scsi2
# Authentication :
# if no "incominguser" is specified, it is not used
#incominguser backup secretpass12
# Access control :
# defaults to ALL if no "initiator-address" is specified
initiator-address 192.168.0.200 192.168.0.199
</target>
4.重啓服務並且添加到開機啓動,確保下次重啓後iscsi服務能自動啓動。
[root@server210 ~]# /etc/init.d/tgtd restart
Stopping SCSI target daemon: [ OK ]
Starting SCSI target daemon: [ OK ]
[root@server210 ~]# chkconfig tgtd on
[root@server210 ~]# chkconfig --list|grep tgtd
tgtd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5.如果你配置了iptables防火牆,那麼你需要在添加一條規則,如下:
[root@server210 ~]# iptables -A INPUT -p tcp -s 192.168.0.200 --dport 3260 -j ACCEPT
[root@server210 ~]# iptables -L -nv
Chain INPUT (policy ACCEPT 6522 packets, 2879K bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- * * 192.168.0.200 0.0.0.0/0 tcp dpt:3260
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 5957 packets, 814K bytes)
pkts bytes target prot opt in out source destination
6.在服務器端查看共享的狀態是否正常,如果能正常的現實如下信息說明已經配置ok。
[root@server210 ~]# tgt-admin -s
Target 1: iqn.20012-05.com.example:mydisk
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: deadbeaf1:0
SCSI SN: beaf10
Size: 0 MB
Online: Yes
Removable media: No
Backing store: No backing store
LUN: 1
Type: disk
SCSI ID: deadbeaf1:1
SCSI SN: beaf11
Size: 1074 MB
Online: Yes
Removable media: No
Backing store: /dev/mapper/vol0-scsi1
LUN: 2
Type: disk
SCSI ID: deadbeaf1:2
SCSI SN: beaf12
Size: 1074 MB
Online: Yes
Removable media: No
Backing store: /dev/mapper/vol0-scsi2
Account information:
ACL information:
192.168.0.200
[root@server210 ~]#
二:iscsi client的具體配置步驟:
1.安裝iscsi client的軟件包
a.iscsi server需要安裝的包爲:
[root@client200 ~]# yum list|grep -i iscsi-initiator-utils
This system is not registered with RHN.
RHN support will be disabled.
iscsi-initiator-utils.i386 6.2.0.871-0.10.el5 base
b.查看iscsi client的安裝包是否應安裝,如果已經安裝,請忽略本步驟。
[root@client200 ~]# rpm -qa iscsi-initiator-utils
c.如果沒有安裝,在配置完yum後運行如下命令以完成軟件包的安裝.
[root@client200 ~]# yum -y install iscsi-initiator-utils
2.啓動服務並且添加到開機啓動,確保服務在下次系統重啓後能夠自動啓動。
[root@client200 ~]# /etc/init.d/iscsid restart
Stopping iSCSI daemon:
Turning off network shutdown. Starting iSCSI daemon: [ OK ]
[ OK ]
[root@client200 ~]# chkconfig iscsid on
[root@client200 ~]# chkconfig --list|grep iscsid
iscsid 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3.運行下面的命令發現並且登陸到server共享的分區
[root@client200 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.0.210
192.168.0.210:3260,1 iqn.20012-05.com.example:mydisk
[root@client200 ~]# iscsiadm -m node -T iqn.20012-05.com.example:mydisk -p 192.168.0.210 -l
Logging in to [iface: default, target: iqn.20012-05.com.example:mydisk, portal: 192.168.0.210,3260]
Login to [iface: default, target: iqn.20012-05.com.example:mydisk, portal: 192.168.0.210,3260]: successful
4.查看下共享的兩個分區是否已經正常掛在到了client端。
[root@client200 ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2308 18434587+ 8e Linux LVM
/dev/sda3 2309 2373 522112+ 82 Linux swap / Solaris
Disk /dev/sdb: 1073 MB, 1073741824 bytes
34 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 2074 * 512 = 1061888 bytes
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/sdc: 1073 MB, 1073741824 bytes
34 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 2074 * 512 = 1061888 bytes
Disk /dev/sdc doesn't contain a valid partition table
5.然後你就可以格式化分區,就像使用自己本機的應該一樣了。
[root@client200 ~]# mkfs.ext3 /dev/sdb 把共享的一個分區格式化爲ext3的文件系統
mke2fs 1.39 (29-May-2006)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
131072 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@client200 ~]# mkdir /mnt/myiscsi 創建一個掛載點
[root@client200 ~]# partprobe /dev/sdb
[root@client200 ~]# mount /dev/sdb /mnt/myiscsi/ 掛載到/mnt/myiscsi
[root@client200 ~]# df -h 查看是否正常掛在
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vol0-root
7.8G 2.1G 5.3G 28% /
/dev/mapper/vol0-home
465M 11M 431M 3% /home
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 252M 0 252M 0% /dev/shm
/dev/sdb 1008M 34M 924M 4% /mnt/myiscsi
6.通過/etc/fstab文件中添加如下條目來實現開機自動掛載,千萬記得添加_netdev參數,否則client重啓後將無法正常掛在。因爲os在啓動時會掛在文件系統,這個時候我們的iscsid的服務還沒有啓動,所以就會掛在失敗,應對的方法就是在options上添加_netdev參數。
[root@client200 ~]# cat /etc/fstab
/dev/vol0/root / ext3 defaults 1 1
/dev/vol0/home /home ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda3 swap swap defaults 0 0
/dev/sdb /mnt/myiscsi ext3 defaults,_netdev 0 0
7.運行如下命令,如果你想login out共享的分區。
a.卸載文件系統
[root@client200 ~]# umount /mnt/myiscsi/
b.login out共享的分區
[root@client200 ~]# iscsiadm -m node -T iqn.20012-05.com.example:mydisk -p 192.168.0.210 -u
Logging out of session [sid: 1, target: iqn.20012-05.com.example:mydisk, portal: 192.168.0.210,3260]
Logout of [sid: 1, target: iqn.20012-05.com.example:mydisk, portal: 192.168.0.210,3260]: successful
c.查看是否已經login out.
[root@client200 ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2308 18434587+ 8e Linux LVM
/dev/sda3 2309 2373 522112+ 82 Linux swap / Solaris
d.注意:如果只運行上面命令,共享的分區將會在iscsid服務重啓後自動掛在,那麼如何實現永久login out呢?你可以通過下面命令實現。
[root@client200 ~]# iscsiadm -m node -T iqn.20012-05.com.example:mydisk -p 192.168.0.210 -o delete
說明:本實驗只做了對client IP的限制,並沒有設置user/password的認證功能,如何實現這個功能呢?大家可以看下系統中的man手冊,這裏就不在贅述了。
測試環境:
iscsi server: 192.168.0.210 server210.example.com
iscsi client: 192.168.0.200 client200.example.com
兩臺機器的操作系統都是rhel5.4 32, 該配置方法同樣適用於64位的操作系統。
一:iscsi server的具體配置步驟:
1.安裝軟件包
a.iscsi server需要安裝的包爲:
[root@server210 ~]# yum list|grep -i scsi-target
This system is not registered with RHN.
RHN support will be disabled.
scsi-target-utils.i386 0.0-5.20080917snap.el5 ClusterStorage
b.檢查server210是否已經安裝了scsi-target軟件包,如果已經安裝,請忽略本步驟。
[root@server210 ~]# rpm -qa scsi-target-utils.i386
c.如果沒有安裝,在配置完yum後運行如下命令以完成軟件包的安裝.該命令會自動安裝scsi-target-utils.i386和perl-Config-General.noarch兩個包.所以你也可以使用rpm -ivh ****.rpm來安裝。
[root@server210 ~]# yum -y install scsi-target-utils.i386
2.創建兩個lv分區來做共享盤。(不一定非要用lv,如入你用硬盤,邏輯分區,還可以用dd if來創建一個鏡像文件,等等都可以用來做共享盤)
[root@server210 ~]# lvcreate -L 1G -n scsi1 vol0
Logical volume "scsi1" created
[root@server210 ~]# lvcreate -L 1G -n scsi2 vol0
Logical volume "scsi2" created
[root@server210 ~]# lvscan
ACTIVE '/dev/vol0/root' [8.00 GB] inherit
ACTIVE '/dev/vol0/home' [480.00 MB] inherit
ACTIVE '/dev/vol0/lv.vcracker' [2.00 GB] inherit
ACTIVE '/dev/vol0/lv.vserver' [3.00 GB] inherit
ACTIVE '/dev/vol0/scsi1' [1.00 GB] inherit
ACTIVE '/dev/vol0/scsi2' [1.00 GB] inherit
3.修改配置文件,添加如下內容,該配置的目的是:共享出兩個分區vol0-scsi1和vol0-scsi2,命名爲iqn.20012-05.com.example:mydisk,並且只允許192.168.0.200這臺主機能夠訪問.如果你需要共享給某個網段可以這麼寫: 192.168.0.0/24,具體的配置可以根據自己的實際要求來設置,我這麼寫只是爲了演示其功能。
<target iqn.20012-05.com.example:mydisk>
# List of files to export as LUNs
backing-store /dev/mapper/vol0-scsi1
backing-store /dev/mapper/vol0-scsi2
# Authentication :
# if no "incominguser" is specified, it is not used
#incominguser backup secretpass12
# Access control :
# defaults to ALL if no "initiator-address" is specified
initiator-address 192.168.0.200 192.168.0.199
</target>
4.重啓服務並且添加到開機啓動,確保下次重啓後iscsi服務能自動啓動。
[root@server210 ~]# /etc/init.d/tgtd restart
Stopping SCSI target daemon: [ OK ]
Starting SCSI target daemon: [ OK ]
[root@server210 ~]# chkconfig tgtd on
[root@server210 ~]# chkconfig --list|grep tgtd
tgtd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5.如果你配置了iptables防火牆,那麼你需要在添加一條規則,如下:
[root@server210 ~]# iptables -A INPUT -p tcp -s 192.168.0.200 --dport 3260 -j ACCEPT
[root@server210 ~]# iptables -L -nv
Chain INPUT (policy ACCEPT 6522 packets, 2879K bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- * * 192.168.0.200 0.0.0.0/0 tcp dpt:3260
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 5957 packets, 814K bytes)
pkts bytes target prot opt in out source destination
6.在服務器端查看共享的狀態是否正常,如果能正常的現實如下信息說明已經配置ok。
[root@server210 ~]# tgt-admin -s
Target 1: iqn.20012-05.com.example:mydisk
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: deadbeaf1:0
SCSI SN: beaf10
Size: 0 MB
Online: Yes
Removable media: No
Backing store: No backing store
LUN: 1
Type: disk
SCSI ID: deadbeaf1:1
SCSI SN: beaf11
Size: 1074 MB
Online: Yes
Removable media: No
Backing store: /dev/mapper/vol0-scsi1
LUN: 2
Type: disk
SCSI ID: deadbeaf1:2
SCSI SN: beaf12
Size: 1074 MB
Online: Yes
Removable media: No
Backing store: /dev/mapper/vol0-scsi2
Account information:
ACL information:
192.168.0.200
[root@server210 ~]#
二:iscsi client的具體配置步驟:
1.安裝iscsi client的軟件包
a.iscsi server需要安裝的包爲:
[root@client200 ~]# yum list|grep -i iscsi-initiator-utils
This system is not registered with RHN.
RHN support will be disabled.
iscsi-initiator-utils.i386 6.2.0.871-0.10.el5 base
b.查看iscsi client的安裝包是否應安裝,如果已經安裝,請忽略本步驟。
[root@client200 ~]# rpm -qa iscsi-initiator-utils
c.如果沒有安裝,在配置完yum後運行如下命令以完成軟件包的安裝.
[root@client200 ~]# yum -y install iscsi-initiator-utils
2.啓動服務並且添加到開機啓動,確保服務在下次系統重啓後能夠自動啓動。
[root@client200 ~]# /etc/init.d/iscsid restart
Stopping iSCSI daemon:
Turning off network shutdown. Starting iSCSI daemon: [ OK ]
[ OK ]
[root@client200 ~]# chkconfig iscsid on
[root@client200 ~]# chkconfig --list|grep iscsid
iscsid 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3.運行下面的命令發現並且登陸到server共享的分區
[root@client200 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.0.210
192.168.0.210:3260,1 iqn.20012-05.com.example:mydisk
[root@client200 ~]# iscsiadm -m node -T iqn.20012-05.com.example:mydisk -p 192.168.0.210 -l
Logging in to [iface: default, target: iqn.20012-05.com.example:mydisk, portal: 192.168.0.210,3260]
Login to [iface: default, target: iqn.20012-05.com.example:mydisk, portal: 192.168.0.210,3260]: successful
4.查看下共享的兩個分區是否已經正常掛在到了client端。
[root@client200 ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2308 18434587+ 8e Linux LVM
/dev/sda3 2309 2373 522112+ 82 Linux swap / Solaris
Disk /dev/sdb: 1073 MB, 1073741824 bytes
34 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 2074 * 512 = 1061888 bytes
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/sdc: 1073 MB, 1073741824 bytes
34 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 2074 * 512 = 1061888 bytes
Disk /dev/sdc doesn't contain a valid partition table
5.然後你就可以格式化分區,就像使用自己本機的應該一樣了。
[root@client200 ~]# mkfs.ext3 /dev/sdb 把共享的一個分區格式化爲ext3的文件系統
mke2fs 1.39 (29-May-2006)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
131072 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@client200 ~]# mkdir /mnt/myiscsi 創建一個掛載點
[root@client200 ~]# partprobe /dev/sdb
[root@client200 ~]# mount /dev/sdb /mnt/myiscsi/ 掛載到/mnt/myiscsi
[root@client200 ~]# df -h 查看是否正常掛在
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vol0-root
7.8G 2.1G 5.3G 28% /
/dev/mapper/vol0-home
465M 11M 431M 3% /home
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 252M 0 252M 0% /dev/shm
/dev/sdb 1008M 34M 924M 4% /mnt/myiscsi
6.通過/etc/fstab文件中添加如下條目來實現開機自動掛載,千萬記得添加_netdev參數,否則client重啓後將無法正常掛在。因爲os在啓動時會掛在文件系統,這個時候我們的iscsid的服務還沒有啓動,所以就會掛在失敗,應對的方法就是在options上添加_netdev參數。
[root@client200 ~]# cat /etc/fstab
/dev/vol0/root / ext3 defaults 1 1
/dev/vol0/home /home ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda3 swap swap defaults 0 0
/dev/sdb /mnt/myiscsi ext3 defaults,_netdev 0 0
7.運行如下命令,如果你想login out共享的分區。
a.卸載文件系統
[root@client200 ~]# umount /mnt/myiscsi/
b.login out共享的分區
[root@client200 ~]# iscsiadm -m node -T iqn.20012-05.com.example:mydisk -p 192.168.0.210 -u
Logging out of session [sid: 1, target: iqn.20012-05.com.example:mydisk, portal: 192.168.0.210,3260]
Logout of [sid: 1, target: iqn.20012-05.com.example:mydisk, portal: 192.168.0.210,3260]: successful
c.查看是否已經login out.
[root@client200 ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2308 18434587+ 8e Linux LVM
/dev/sda3 2309 2373 522112+ 82 Linux swap / Solaris
d.注意:如果只運行上面命令,共享的分區將會在iscsid服務重啓後自動掛在,那麼如何實現永久login out呢?你可以通過下面命令實現。
[root@client200 ~]# iscsiadm -m node -T iqn.20012-05.com.example:mydisk -p 192.168.0.210 -o delete
說明:本實驗只做了對client IP的限制,並沒有設置user/password的認證功能,如何實現這個功能呢?大家可以看下系統中的man手冊,這裏就不在贅述了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.