iscsi 部署

环境准备:
主机: os/ip/hostname
host1:centos7.8     192.168.92.72   target72
host2:centos7.8     192.168.92.71   init71
host3: centos7.8     192.168.92.70   init70

一:部署target端:
1 准备磁盘
    1.1 host1 新增两块10g硬盘
    1.2 将两块10g硬盘作成lv

    #fidsk -l
    Disk /dev/sdb: 10.7 GB, 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

    Disk /dev/sdc: 10.7 GB, 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

    1.2.1 创建pv
    # pvcreat /dev/sdb
    # pvcreat /dev/sdc
 
    # pvdisplay

    "/dev/sdb" is a new physical volume of "10.00 GiB"
    --- NEW Physical volume ---
    PV Name               /dev/sdb
    VG Name
    PV Size               10.00 GiB

    "/dev/sdc" is a new physical volume of "10.00 GiB"
    --- NEW Physical volume ---
    PV Name               /dev/sdc
    VG Name
    PV Size               10.00 GiB

    1.2.2 创建vg
    #vgcreat vg1 /dev/sdb
        Volume group "vg1" successfully created
    #vgextend vg1 /dev/sdc
        Volume group "vg1" successfully extended
    # vgdisplay

    --- Volume group ---
    VG Name               vg1
    System ID
    Format                lvm2
    Metadata Areas        2
    Metadata Sequence No  2
    VG Access             read/write
    VG Status             resizable
    MAX LV                0
    Cur LV                0
    Open LV               0
    Max PV                0
    Cur PV                2
    Act PV                2
    VG Size               19.99 GiB
    PE Size               4.00 MiB
    Total PE              5118
    Alloc PE / Size       0 / 0
    Free  PE / Size       5118 / 19.99 GiB
    VG UUID               KmRdJa-908o-bUHa-Nz3g-5onb-5Lhc-EIhxAk

    # pvdisplay
    
    --- Physical volume ---
    PV Name               /dev/sdb
    VG Name               vg1
    PV Size               10.00 GiB / not usable 4.00 MiB
    Allocatable           yes
    PE Size               4.00 MiB
    Total PE              2559
    Free PE               2559
    Allocated PE          0
    PV UUID               2sy2lT-egJA-rwJ1-4SfS-YDGV-odP4-3S8FcK

    --- Physical volume ---
    PV Name               /dev/sdc
    VG Name               vg1
    PV Size               10.00 GiB / not usable 4.00 MiB
    Allocatable           yes
    PE Size               4.00 MiB
    Total PE              2559
    Free PE               2559
    Allocated PE          0
    PV UUID               bxxKlg-cf2H-d06O-z8F0-NiBd-fvFB-uPDGPL

    1.2.3 创建lv,创建15g吧
    lvcreate -L 15g vg1 -n lv1
        Logical volume "lv1" created.
    # lvdisplay
    
    --- Logical volume ---
    LV Path                /dev/vg1/lv1
    LV Name                lv1
    VG Name                vg1
    LV UUID                9Pkzbf-MzOA-bpWS-RkKR-3f0P-vod2-7TptVd
    LV Write Access        read/write
    LV Creation host, time c72, 2020-08-03 04:22:07 -0400
    LV Status              available
    # open                 0
    LV Size                15.00 GiB
    Current LE             3840
    Segments               2
    Allocation             inherit
    Read ahead sectors     auto
    - currently set to     8192
    Block device           253:2

    #fidsk -l
    
    Disk /dev/mapper/vg1-lv1: 16.1 GB, 16106127360 bytes, 31457280 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


2 安装程序包
    # yum install targetcli.noarch


3 创建块存储
    //查看当前tartget配置
    /> ls
    o- / ............................................................................................... [...]
    o- backstores .................................................................................... [...]
    | o- block ........................................................................ [Storage Objects: 0]
    | o- fileio ....................................................................... [Storage Objects: 0]
    | o- pscsi ........................................................................ [Storage Objects: 0]
    | o- ramdisk ...................................................................... [Storage Objects: 0]
    o- iscsi .................................................................................. [Targets: 0]
    o- loopback ............................................................................... [Targets: 0]

    3.1 创3 创建块存储
    /> backstores/block create test-b-1 /dev/vg1/lv1
    Created block storage object test-b-1 using /dev/vg1/lv1.

    //查看当前tartget配置
    /> ls
    o- / ............................................................................................... [...]
    o- backstores .................................................................................... [...]
    | o- block ........................................................................ [Storage Objects: 1]
    | | o- test-b-1 ........................................ [/dev/vg1/lv1 (15.0GiB) write-thru deactivated]
    | |   o- alua ......................................................................... [ALUA Groups: 1]
    | |     o- default_tg_pt_gp ............................................. [ALUA state: Active/optimized]
    | o- fileio ....................................................................... [Storage Objects: 0]
    | o- pscsi ........................................................................ [Storage Objects: 0]
    | o- ramdisk ...................................................................... [Storage Objects: 0]
    o- iscsi .................................................................................. [Targets: 0]
    o- loopback ............................................................................... [Targets: 0]

4 创建iscsi target iqn

    /> iscsi/ create iqn.year-mon.域名反写:host   // 建议格式

    4.1 /> iscsi/ create iqn.2020-08.com.testdomain:target72
    Created target iqn.2020-08.com.testdomain:target72.
    Created TPG 1.
    Global pref auto_add_default_portal=true
    Created default portal listening on all IPs (0.0.0.0), port 3260.

    //查看端口
    ss -lnt
    State      Recv-Q Send-Q        Local Address:Port                       Peer Address:Port
    LISTEN     0      128                       *:22                                    *:*
    LISTEN     0      100               127.0.0.1:25                                    *:*
    LISTEN     0      256                       *:3260                                  *

5 创建lun
    /> /iscsi/iqn.2020-08.com.testdomain:target72/tpg1/luns create /backstores/block/test-b-1

6 授权 initclient1 可以访问
    /> /iscsi/iqn.2020-08.com.testdomain:target72/tpg1/acls create iqn.2020-08.com.testdomain:initclient1

7 配置认证(可选)

8 配置监听端口(可选)
/> iscsi/iqn.2020-08.com.testdomain:target72/tpg1/portals/ delete 0.0.0.0 3260
/> iscsi/iqn.2020-08.com.testdomain:target72/tpg1/portals/ creat 192.168.92.72


二:部署initiator 端:

1   安装客户端
    # yum install iscsi-initiator-utils.i686
    不要先启动,先配置配置文件,否则连接不上,重启解决

2   配置iqn
    # vim /etc/iscsi/initiatorname.iscsi
    InitiatorName=iqn.2020-08.com.testdomain:initclient1

3   配置认证认证
    # vim /etc/iscsi/iscsid.conf
    # To enable CHAP authentication set node.session.auth.authmethod
    # to CHAP. The default is None.
    #node.session.auth.authmethod = CHAP //去掉注释

    # To set a CHAP username and password for initiator
    # authentication by the target(s), uncomment the following lines:
    #node.session.auth.username = username  //配置服务端配置的用户名
    #node.session.auth.password = password  //配置服务器配置的密码

4 启动服务
    # systemctl start iscsi
    # systemctl ebable iscsi

4 发现设备
# iscsiadm -m discovery -t st -p 192.168.92.72

5 登录服务器  (登录不上。。。后面没法做了)
# iscsiadm -m node -T iqn.2020-08.com.testdomain:target72 -l
 

6 挂载 ,分区, 格式化

 #fdisk -l 

posted @ 2020-08-04 11:34  abel2020  阅读(253)  评论(0编辑  收藏  举报