Redhat 7搭建iscsi存储系统_redhat7ipsan搭建

63 ~]# /etc/init.d/tgtd start
63 ~]# netstat -antup | grep 3260
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN
4067/tgtd
tcp 0 0 :::3260 ::😗 LISTEN
4067/tgtd


实战: 配置一个 IP SAN 存储服务器  
 将 63 配置成 ip san,将 63 上的 sda4 分区,通过 ip san 共享出去。  
 服务器端: target 63  
 客户端:initiator 64  
 63 :  
 安装:



63 Desktop]# yum install -y scsi-target-utils


准备一个磁盘分区: sda4 大小 5G



63 ~]# fdisk /dev/sda #划分出 sda4 分区
WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
switch off the mode (command ‘c’) and change display units to
sectors (command ‘u’).
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000b8b35
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1301 10240000 83 Linux
/dev/sda3 1301 1428 1024000 82 Linux swap / Solaris
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First cylinder (1428-2610, default 1428):
Using default value 1428
Last cylinder, +cylinders or +size{K,M,G} (1428-2610, default 2610): +5G
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
63 ~]#reboot


配置 target ,把 sda4 分区共享出去  
 修改配置文件



63 ~]# vim /etc/tgt/targets.conf #写入以下内容
在参考这段内容并在段内容后,追加以下红色标记内容:
#


注释:



default-driver iscsi #此配置文件默认全部注释,使用 iscsi 驱动


3)启动服务



63 Desktop]#service tgtd restart
63 Desktop]# netstat -antup | grep 3260
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN
3130/tgtd
tcp 0 0 :::3260 ::😗 LISTEN
3130/tgtd


4. 查看状态 tgt-admin --show



63 Desktop]# tgt-admin --show
Target 1: iqn.2015-01.cn.xuegod.www:target_san1
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Readonly: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 5372 MB, Block size: 512
Online: Yes
Removable media: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sda4
Backing store flags:
Account information:
ACL information: #允许哪些客户端可以访问
192.168.1.64


开机启动:



63 Desktop]# chkconfig tgtd on


总结:  
 1、安装服务端软件包  
 2、划分存储空间  
 3、配置 tgtd 服务  
 配置客户端: 64


安装包:



64 ~]# rpm -ivh /mnt/Packages/iscsi-initiator-utils-6.2.0.872-34.el6.x86_64.rpm


启动客户端服务:  
 启动客户端服务:



64 ~]# /etc/init.d/iscsid start #启劢后没有反应


注:需要先发现 target 存储,再启动客户端服务,才有效



64 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.63:3260
Starting iscsid: [ OK ]
192.168.1.63:3260,1 iqn.2015-01.cn.xuegod.www:target_san1
64 ~]# /etc/init.d/iscsid status
iscsid (pid 2607) is running…


target 存储服务器信息在客户端存储的位置:



64 ~]# rpm -ivh /mnt/Packages/tree-1.5.3-2.el6.x86_64.rpm
64 ~]# tree /var/lib/iscsi/
64 ~]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│ └── iqn.2015-01.cn.xuegod.www:target_san1
│ └── 192.168.1.63,3260,1
│ └── default
├── send_targets
│ └── 192.168.1.63,3260
│ ├── iqn.2015-01.cn.xuegod.www:target_san1,192.168.1.63,3260,1,default ->
/var/lib/iscsi/nodes/iqn.2015-01.cn.xuegod.www:target_san1/192.168.1.63,3260,1
│ └── st_config
├── slp
└── static


重新启动:



64 ~]# /etc/init.d/iscsid restart #先启劢 iscsid
64 ~]# /etc/init.d/iscsi restart # 根据/var/lib/iscsi/ 中发现的信息,识别设备

Stopping iscsi: [ OK ]
Starting iscsi: [ OK ]


关闭:



64 ~]# /etc/init.d/iscsi stop
64 ~]# /etc/init.d/iscsid stop


开机自劢启动:



64 ~]# chkconfig iscsi on
64 ~]# chkconfig iscsid on


查看默认开机两个服务的先后顺序:



64 ~]# grep chkconfig: /etc/init.d/iscsid

chkconfig: 345 7 89

64 ~]# grep chkconfig: /etc/init.d/iscsi

chkconfig: 345 13 89


查看发现到新硬盘:



64 ~]# ll /dev/sdb
brw-rw---- 1 root disk 8, 16 Jul 30 19:11 /dev/sdb


例 2: 卸载,挂载存储设备  
 卸载



64 ~]# iscsiadm -m node -T iqn.2015-01.cn.xuegod.www:target_san1 -u
Logging out of session [sid: 1, target: iqn.2015-01.cn.xuegod.www:target_san1, portal:
192.168.1.63,3260]
Logout of [sid: 1, target: iqn.2015-01.cn.xuegod.www:target_san1, portal: 192.168.1.63,3260]
successful.
64 ~]# ls /dev/sdb
ls: cannot access /dev/sdb: No such file or directory


登录存储存储设备



64 ~]# iscsiadm -m node -T iqn.2015-01.cn.xuegod.www:target_san1 -l
Logging in to [iface: default, target: iqn.2015-01.cn.xuegod.www:target_san1, portal:
192.168.1.63,3260] (multiple)
Login to [iface: default, target: iqn.2015-01.cn.xuegod.www:target_san1, portal:
192.168.1.63,3260] successful.
64 ~]# ls /dev/sdb
/dev/sdb


卸载方法二:



64 ~]# /etc/init.d/iscsi stop
Stopping iscsi: [ OK ]
[root@xuegod64 ~]# ls /dev/sdb
ls: cannot access /dev/sdb: No such file or directory


登录方法二:



64 ~]# /etc/init.d/iscsi restart


彻底退出:



64 ~]# /etc/init.d/iscsi stop
64 ~]# rm -rf /var/lib/iscsi/*


实例 1: 在 64 上对识别出来的硬盘,分区格式化,挂载使用。



64 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.63:3260 #发现存储设备登录存储

64 ~]# /etc/init.d/iscsid restart
64 ~]# /etc/init.d/iscsi restart
64 ~]# ls /dev/sdb #发现 sdb
/dev/sdb


分区格式化,挂载使用。



64 ~]# fdisk /dev/sdb 划分一个分区。 sdb1
64 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x6d23a932.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
switch off the mode (command ‘c’) and change display units to
sectors (command ‘u’).
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1019, default 1):

Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1019, default 1019): #直接回车使用所有可以使用
的空间。
Using default value 1019
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@xuegod64 ~]# ll /dev/sdb*
brw-rw---- 1 root disk 8, 16 Jul 30 21:44 /dev/sdb
brw-rw---- 1 root disk 8, 17 Jul 30 21:44 /dev/sdb1
[root@xuegod64 ~]# mkfs.ext4 /dev/sdb1


例 5: 在 target 服务端,再添加一个存储客户端:  
 添加如下内容:



63 ~]# vim /etc/tgt/targets.conf


![在这里插入图片描述](https://img-blog.csdnimg.cn/20201128165537862.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwOTA3OTc3,size_16,color_FFFFFF,t_70)



63 ~]# /etc/init.d/tgtd restart
Stopping SCSI target daemon: initiators still connected [FAILED]
Starting SCSI target daemon: [FAILED]


解决:客户端退出一下



64 ~]# umount /opt/
64 ~]# /etc/init.d/iscsi stop


客户端退出后,再测试启动:



63 ~]# /etc/init.d/tgtd restart
Stopping SCSI target daemon: [ OK ]
Starting SCSI target daemon: [ OK ]


测试: 64 和 62 都挂载上硬盘,数据同步



64 ~]#/etc/init.d/iscsi start
64 ~]# ls /dev/sdb*
/dev/sdb /dev/sdb1
64 ~]# ls /dev/sdb*
/dev/sdb /dev/sdb1
64 ~]# mount /dev/sdb1 /opt/
64 ~]# cp /etc/passwd /opt/ #复制一些数据


测试:62 是否数据同步



62 ~]# rpm -ivh
/mnt/Packages/iscsi-initiator-utils-6.2.0.872-34.el6.x86_64.rpm
62 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.63:3260

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值