Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1095413
  • 博文数量: 80
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 746
  • 用 户 组: 普通用户
  • 注册时间: 2018-06-12 20:01
个人简介

寫写code、调調bug、填填坑,僅此而已。

文章分类

全部博文(80)

文章存档

2019年(30)

2018年(50)

分类: 服务器与存储

2018-07-06 10:57:46

iSCSI Target  ubserver 10.0.66.145
 iSCSI Initiator tesetsrv 10.0.66.191

一、服务器搭建
服务器(ubserver), 10.0.66.145 

1.apt-get -y install iscsitarget iscsitarget-dkms

2.配置相关信息
2.1 在本服务器创建一个硬盘分区用于客户端共享

mkdir /var/iscsi_disks

dd if=/dev/zero of=/var/iscsi_disks/disk01.img count=0 bs=1 seek=10G

2.2 修改配置文件
vi /etc/default/iscsitarget
添加一下几行
#naming rule : [ iqn.yaer-month.domain:any name ]
Target iqn.2018-07.ubserver:target00
  # provided devicce as a iSCSI target
   Lun 0 Path=/var/iscsi_disks/disk01.img,Type=fileio
    # iSCSI Initiator's IP address you allow to connect
    initiator-address 10.0.66.191
    # authentication info ( set anyone you like for "username", "password" )
   incominguser test 123456 
apt-get install open-iscsi
vi /etc/iscsi/iscsid.conf
node.session.auth.username = test
node.session.auth.password = 123456
discovery.sendtargets.auth.username = test
discovery.sendtargets.auth.password = 123456
3.配置文成后重启 服务
systemct restart iscsitarget
4.测试服务是否正常
执行命令:ietadm --op show --tid=1
显示如下:
    Wthreads=8
    Type=0
    QueuedCommands=32
    NOPInterval=0
    NOPTimeout=0
二、客户端的安装配置
1.apt-get install open-iscsi
2.修改客户端配置文件
vi /etc/iscsi/initiatorname.iscsi
    InitiatorName=iqn.2018-07.ubserver:target00
vi /etc/iscsi/iscsid.conf
    node.session.auth.authmethod = CHAP   
    node.session.auth.username = test
   node.session.auth.password = 123456
    discovery.sendtargets.auth.username = test
    discovery.sendtargets.auth.password = 123456

3.重启服务
systemctl restart iscsid open-iscsi

4.按顺序执行如下命令

4.1测试是否发现网络服务器硬盘
iscsiadm -m discovery -t sendtargets -p 10.0.66.145
    10.0.66.145:3260,1 iqn.2018-07.ubserver:target00
4.2确认发现的硬盘状态
iscsiadm -m node -o show
     BEGIN RECORD 2.0-873
    node.name = iqn.2018-07.ubserver:target00
    node.tpgt = 1
    node.startup = manual
    node.leading_login = No
    iface.hwaddress =
    iface.ipaddress =
    iface.iscsi_ifacename = default
    iface.net_ifacename =
    iface.transport_name = tcp
    iface.initiatorname =
    iface.bootproto =
    iface.subnet_mask =
    iface.gateway =
    iface.ipv6_autocfg =
    iface.linklocal_autocfg =
    iface.router_autocfg =
    iface.ipv6_linklocal =
    iface.ipv6_router =
    iface.state =
    iface.vlan_id = 0
    iface.vlan_priority = 0
    iface.vlan_state =
    iface.iface_num = 0
    iface.mtu = 0
    iface.port = 0
    node.discovery_address = 10.0.66.145
    node.discovery_port = 3260
    node.discovery_type = send_targets
    node.session.initial_cmdsn = 0
    node.session.initial_login_retry_max = 8
    node.session.xmit_thread_priority = -20
    node.session.cmds_max = 128
    node.session.queue_depth = 32
    node.session.nr_sessions = 1
    node.session.auth.authmethod = CHAP
    node.session.auth.username = test
    node.session.auth.password = ********
    node.session.auth.username_in =
    node.session.auth.password_in =
    node.session.timeo.replacement_timeout = 120
    node.session.err_timeo.abort_timeout = 15
    node.session.err_timeo.lu_reset_timeout = 30
    node.session.err_timeo.tgt_reset_timeout = 30
    node.session.err_timeo.host_reset_timeout = 60
    node.session.iscsi.FastAbort = Yes
    node.session.iscsi.InitialR2T = No
    node.session.iscsi.ImmediateData = Yes
    node.session.iscsi.FirstBurstLength = 262144
    node.session.iscsi.MaxBurstLength = 16776192
    node.session.iscsi.DefaultTime2Retain = 0
    node.session.iscsi.DefaultTime2Wait = 2
    node.session.iscsi.MaxConnections = 1
    node.session.iscsi.MaxOutstandingR2T = 1
    node.session.iscsi.ERL = 0
    node.conn[0].address = 10.0.66.145
    node.conn[0].port = 3260
    node.conn[0].startup = manual
    node.conn[0].tcp.window_size = 524288
    node.conn[0].tcp.type_of_service = 0
    node.conn[0].timeo.logout_timeout = 15
    node.conn[0].timeo.login_timeout = 15
    node.conn[0].timeo.auth_timeout = 45
    node.conn[0].timeo.noop_out_interval = 5
    node.conn[0].timeo.noop_out_timeout = 5
    node.conn[0].iscsi.MaxXmitDataSegmentLength = 0
    node.conn[0].iscsi.MaxRecvDataSegmentLength = 262144
    node.conn[0].iscsi.HeaderDigest = None
    node.conn[0].iscsi.DataDigest = None
    node.conn[0].iscsi.IFMarker = No
    node.conn[0].iscsi.OFMarker = No
    # END RECORD

4.3登陆网络硬盘服务器

iscsiadm -m node --login

    Logging in to [iface: default, target: iqn.2018-07.ubserver:target00, portal: 10.0.66.145,3260] (multiple)
    Login to [iface: default, target: iqn.2018-07.ubserver:target00, portal: 10.0.66.145,3260] successful.

4.4 确认分区(sdb)

cat /proc/partitions 

    major minor  #blocks  name
      11        0    1048575 sr0
       8        0   89128960 sda
       8        1     498688 sda1
       8        2          1 sda2
       8        5   88627200 sda5
     252        0   82235392 dm-0
     252        1    6389760 dm-1
       8       16   10485760 sdb
    
fdisk -l  (发现新的分区)

    ...
    Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
 parted --script /dev/sdb "mklabel msdos"

parted --script /dev/sdb "mkpart primary 0% 100%"

fdisk -l
    ...
    Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0x58b228dc
    Device     Boot Start      End  Sectors Size Id Type
    /dev/sdb1        2048 20971519 20969472  10G 83 Linux
格式化新的分区
 mkfs.ext4 /dev/sdb1
    mke2fs 1.42.13 (17-May-2015)
    Creating filesystem with 2621184 4k blocks and 655360 inodes
    Filesystem UUID: a2489a15-59de-48b7-9f0b-d29946020b41
    Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done 

fdisk -l
    Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0x58b228dc
    Device     Boot Start      End  Sectors Size Id Type
    /dev/sdb1        2048 20971519 20969472  10G 83 Linux
    
挂在分区
mount /dev/sdb1 /mnt
    ...
    tmpfs                        tmpfs     606M     0  606M   0% /run/user/0
    /dev/sdb1                    ext4      9.8G   23M  9.2G   1% /mnt
    
4.5断开登陆
iscsiadm -m node --logout
    Logging out of session [sid: 1, target: iqn.2018-07.ubserver:target00, portal: 10.0.66.145,3260]
    Logout of [sid: 1, target: iqn.2018-07.ubserver:target00, portal: 10.0.66.145,3260] successful.
    













阅读(4257) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~