欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

马哥 41_02 _Linux集群系列之二十——iSCSI及gfs2 有大用

发现target之后,

在第一个节点 192.168.0.45 上

[root@node1 ~]# cd /var/lib/iscsi/

[root@node1 iscsi]# ls

ifaces  isns  nodes  send_targets  slp  static

[root@node1 iscsi]# ls send_targets/        #看到主机及对应的端口

192.168.0.100,3260

[root@node1 iscsi]# ls send_targets/192.168.0.100,3260/

iqn.2013-05.com.magedu:teststore.disk1,192.168.0.100,3260,1,default  st_config

[root@node1 iscsi]#

[root@node1 iscsi]# ls ifaces/    #因为没有绑定(网卡)接口,所以看不到信息

[root@node1 iscsi]#

[root@node1 ~]# cd /etc/iscsi/

[root@node1 iscsi]# ls

initiatorname.iscsi  iscsid.conf

[root@node1 iscsi]#

[root@node1 iscsi]# vim iscsid.conf

...................


#*****************

# Startup settings

#*****************


# To request that the iscsi initd scripts startup a session set to "automatic".

# node.startup = automatic   

#

# To manually startup the session set to "manual". The default is automatic.

node.startup = automatic         #服务刚启动的时候,登录每一个target的时候,是不是自动启动节点登录进去


# For "automatic" startup nodes, setting this to "Yes" will try logins on each

# available iface until one succeeds, and then stop.  The default "No" will try

# logins on all availble ifaces simultaneously.

node.leading_login = No

# *************

# CHAP Settings

# *************


# To enable CHAP authentication set node.session.auth.authmethod

# to CHAP. The default is None.

#node.session.auth.authmethod = CHAP    #基于哪种方式认证,默认使用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     #对应用户的密码


# To set a CHAP username and password for target(s)

# authentication by the initiator, uncomment the following lines:

#node.session.auth.username_in = username_in   #客户端的帐号密码,用来认证服务器端的

#node.session.auth.password_in = password_in


# To enable CHAP authentication for a discovery session to the target

# set discovery.sendtargets.auth.authmethod to CHAP. The default is None.

#discovery.sendtargets.auth.authmethod = CHAP        #discovery时要发送的帐号密码, open iscsi不支持它,,,所以discovery的相关内容,基本不用管了


# To set a discovery session CHAP username and password for the initiator

# authentication by the target(s), uncomment the following lines:

#discovery.sendtargets.auth.username = username

#discovery.sendtargets.auth.password = password


# To set a discovery session CHAP username and password for target(s)

# authentication by the initiator, uncomment the following lines:

#discovery.sendtargets.auth.username_in = username_in

#discovery.sendtargets.auth.password_in = password_in


# ********

# Timeouts

# ********

#

.....................

#

# See the iSCSI REAME's Advanced Configuration section for tips

# on setting timeouts when using multipath or doing root over iSCSI.

#

# To specify the length of time to wait for session re-establishment

# before failing SCSI commands back to the application when running

# the Linux SCSI Layer error handler, edit the line.

# The value is in seconds and the default is 120 seconds.

node.session.timeo.replacement_timeout = 120


# To specify the time to wait for login to complete, edit the line.

# The value is in seconds and the default is 15 seconds.

node.conn[0].timeo.login_timeout = 15        #登录的超时时间


# To specify the time to wait for logout to complete, edit the line.

# The value is in seconds and the default is 15 seconds.

node.conn[0].timeo.logout_timeout = 15


# Time interval to wait for on connection before sending a ping.

node.conn[0].timeo.noop_out_interval = 5        #间隔时间


# To specify the time to wait for a Nop-out response before failing

# the connection, edit this line. Failing the connection will

# cause IO to be failed back to the SCSI layer. If using dm-multipath

# this will cause the IO to be failed to the multipath layer.

node.conn[0].timeo.noop_out_timeout = 5


# To specify the time to wait for abort response before

# failing the operation and trying a logical unit reset edit the line.

# The value is in seconds and the default is 15 seconds.

node.session.err_timeo.abort_timeout = 15


# To specify the time to wait for a logical unit response

# before failing the operation and trying session re-establishment

# edit the line.

# The value is in seconds and the default is 30 seconds.

node.session.err_timeo.lu_reset_timeout = 30


#******

# Retry   #下面关于retry的时间

#******


# To specify the number of times iscsid should retry a login

# if the login attempt fails due to the node.conn[0].timeo.login_timeout

# expiring modify the following line. Note that if the login fails

# quickly (before node.conn[0].timeo.login_timeout fires) because the network

# layer or the target returns an error, iscsid may retry the login more than

# node.session.initial_login_retry_max times.

#

# This retry count along with node.conn[0].timeo.login_timeout

# determines the maximum amount of time iscsid will try to

# establish the initial login. node.session.initial_login_retry_max is

# multiplied by the node.conn[0].timeo.login_timeout to determine the

# maximum amount.

#

# The default node.session.initial_login_retry_max is 8 and

# node.conn[0].timeo.login_timeout is 15 so we have:

#

# node.conn[0].timeo.login_timeout * node.session.initial_login_retry_max =

#                                                               120 seconds

#

# Valid values are any integer value. This only

# affects the initial login. Setting it to a high value can slow

# down the iscsi service startup. Setting it to a low value can

# cause a session to not get logged into, if there are distuptions

# during startup or if the network is not ready at that time.

node.session.initial_login_retry_max = 8


################################

# session and device queue depth

################################


# To control how many commands the session will queue set

# node.session.cmds_max to an integer between 2 and 2048 that is also

# a power of 2. The default is 128.

node.session.cmds_max = 128


# To control the device's queue depth set node.session.queue_depth

# to a value between 1 and 1024. The default is 32.

node.session.queue_depth = 32


##################################

# MISC SYSTEM PERFORMANCE SETTINGS

##################################


# For software iscsi (iscsi_tcp) and iser (ib_iser) each session

# has a thread used to transmit or queue data to the hardware. For

# cxgb3i you will get a thread per host.

#

# Setting the thread's priority to a lower value can lead to higher throughput

# and lower latencies. The lowest value is -20. Setting the priority to

# a higher value, can lead to reduced IO performance, but if you are seeing

# the iscsi or scsi threads dominate the use of the CPU then you may want

# to set this value higher.

#

# Note: For cxgb3i you must set all sessions to the same value, or the

# behavior is not defined.

#

# The default value is -20. The setting must be between -20 and 20.

node.session.xmit_thread_priority = -20


#***************

# iSCSI settings

#***************


# To enable R2T flow control (i.e., the initiator must wait for an R2T

# command before sending any data), uncomment the following line:

#

#node.session.iscsi.InitialR2T = Yes

#

# To disable R2T flow control (i.e., the initiator has an implied

# initial R2T of "FirstBurstLength" at offset 0), uncomment the following line:

#

# The defaults is No.

node.session.iscsi.InitialR2T = No


#

# To disable immediate data (i.e., the initiator does not send

# unsolicited data with the iSCSI command PDU), uncomment the following line:

#

#node.session.iscsi.ImmediateData = No

#

# To enable immediate data (i.e., the initiator sends unsolicited data

# with the iSCSI command packet), uncomment the following line:

#

# The default is Yes

node.session.iscsi.ImmediateData = Yes


# To specify the maximum number of unsolicited data bytes the initiator

# can send in an iSCSI PDU to a target, edit the following line.

#

# The value is the number of bytes in the range of 512 to (2^24-1) and

# the default is 262144

node.session.iscsi.FirstBurstLength = 262144


# To specify the maximum SCSI payload that the initiator will negotiate

# with the target for, edit the following line.

#

# The value is the number of bytes in the range of 512 to (2^24-1) and

# the defauls it 16776192

node.session.iscsi.MaxBurstLength = 16776192


# To specify the maximum number of data bytes the initiator can receive

# in an iSCSI PDU from a target, edit the following line.

#

# The value is the number of bytes in the range of 512 to (2^24-1) and

# the default is 262144

node.conn[0].iscsi.MaxRecvDataSegmentLength = 262144


# To specify the maximum number of data bytes the initiator will send

# in an iSCSI PDU to the target, edit the following line.

#

# The value is the number of bytes in the range of 512 to (2^24-1).

# Zero is a special case. If set to zero, the initiator will use

# the target's MaxRecvDataSegmentLength for the MaxXmitDataSegmentLength.

# The default is 0.

node.conn[0].iscsi.MaxXmitDataSegmentLength = 0


# To specify the maximum number of data bytes the initiator can receive

# in an iSCSI PDU from a target during a discovery session, edit the

# following line.

#

# The value is the number of bytes in the range of 512 to (2^24-1) and

# the default is 32768

#

discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768


# To allow the targets to control the setting of the digest checking,

# with the initiator requesting a preference of enabling the checking, uncomment

# the following lines (Data digests are not supported and on ppc/ppc64

# both header and data digests are not supported.):

#node.conn[0].iscsi.HeaderDigest = CRC32C,None


#

# To allow the targets to control the setting of the digest checking,

# with the initiator requesting a preference of disabling the checking,

# uncomment the following line:

#node.conn[0].iscsi.HeaderDigest = None,CRC32C

#

# To enable CRC32C digest checking for the header and/or data part of

# iSCSI PDUs, uncomment the following line:

#node.conn[0].iscsi.HeaderDigest = CRC32C

#

# To disable digest checking for the header and/or data part of

# iSCSI PDUs, uncomment the following line:

#node.conn[0].iscsi.HeaderDigest = None

#

# The default is to never use DataDigests or HeaderDigests.

#

node.conn[0].iscsi.HeaderDigest = None


# For multipath configurations, you may want more than one session to be

# created on each iface record.  If node.session.nr_sessions is greater

# than 1, performing a 'login' for that node will ensure that the

# appropriate number of sessions is created.

node.session.nr_sessions = 1


#************

# Workarounds

#************


# Some targets like IET prefer after an initiator has sent a task

# management function like an ABORT TASK or LOGICAL UNIT RESET, that

# it does not respond to PDUs like R2Ts. To enable this behavior uncomment

# the following line (The default behavior is Yes):

node.session.iscsi.FastAbort = Yes


# Some targets like Equalogic prefer that after an initiator has sent

# a task management function like an ABORT TASK or LOGICAL UNIT RESET, that

# it continue to respond to R2Ts. To enable this uncomment this line

# node.session.iscsi.FastAbort = No


image.png



在第一个节点 192.168.0.45 上

[root@node1 iscsi]# ls  /var/lib/iscsi/send_targets/192.168.0.100,3260/        #登录的信息

iqn.2013-05.com.magedu:teststore.disk1,192.168.0.100,3260,1,default  st_config

[root@node1 iscsi]#       

[root@node1 iscsi]# iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -u             #去掉登录的信息(登出)

Logging out of session [sid: 2, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260]

Logout of [sid: 2, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] successful.

[root@node1 iscsi]#

[root@node1 iscsi]# ls  /var/lib/iscsi/send_targets/192.168.0.100,3260/        #登出之后这个数据库还在

iqn.2013-05.com.magedu:teststore.disk1,192.168.0.100,3260,1,default  st_config

[root@node1 iscsi]#

[root@node1 iscsi]# chkconfig --list iscsi            #如果重启node1,它会自动启动iscsi服务的,所以重启node1后仍然是自动登录target的,,,,为了避免自动登录,要删除相应的数据库

iscsi           0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:启用  6:关闭

[root@node1 iscsi]#


[root@node1 iscsi]# iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -o delete        #就把这个主机上的相关的target上的相关的数据库信息给它delete掉

[root@node1 iscsi]#

[root@node1 iscsi]# ls  /var/lib/iscsi/send_targets/

192.168.0.100,3260

[root@node1 iscsi]#

[root@node1 iscsi]# ls  /var/lib/iscsi/send_targets/192.168.0.100,3260/      #iqn信息没有了  

 st_config

[root@node1 iscsi]# 

[root@node1 iscsi]# rm -rf /var/lib/iscsi/send_targets/192.168.0.100,3260/           #手动 删掉 192.168.0.100,3260 目录吧  (好像也可以不用删吧)

[root@node1 iscsi]#


在第二个节点 192.168.0.55 上

[root@node2 ~]# iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -u        #登出

Logging out of session [sid: 1, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260]

Logout of [sid: 1, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] successful.

[root@node2 ~]#

[root@node2 ~]# iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -o delete             #就把这个主机上的相关的target上的相关的数据库信息给它delete掉

[root@node2 ~]#

[root@node2 ~]# rm -rf  /var/lib/iscsi/send_targets/192.168.0.100,3260/        #好像可以不用删,为了保险起见,删掉

[root@node2 ~]#



在 target 192.168.0.100 上

[root@steppingstone ~]# tgtadm --lld iscsi --mode target --op show

Target 1: iqn.2013-05.com.magedu:teststore.disk1

    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: 50010 MB, Block size: 512

            Online: Yes

            Removable media: No

            Readonly: No

            Backing store type: rdwr

            Backing store path: /dev/sdb5

            Backing store flags:

    Account information:

    ACL information:

        192.168.0.0/24

[root@steppingstone ~]#

[root@steppingstone ~]# tgtadm --lld iscsi -m target --op unbind --tid 1 --initiator-address 192.168.0.0/24            #解除绑定

[root@steppingstone ~]#

[root@steppingstone ~]# tgtadm --lld iscsi --mode target --op show

Target 1: iqn.2013-05.com.magedu:teststore.disk1

    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: 50010 MB, Block size: 512

            Online: Yes

            Removable media: No

            Readonly: No

            Backing store type: rdwr

            Backing store path: /dev/sdb5

            Backing store flags:

    Account information:

    ACL information:        #看不到绑定信息了

[root@steppingstone ~]#




image.png

tgtadm             account模式主要实现帐号的创建绑定等相关功能的


[root@steppingstone ~]# tgtadm -h

Usage: tgtadm [OPTION]

Linux SCSI Target Framework Administration Utility, version


  --lld <driver> --mode target --op new --tid <id> --targetname <name>

                        add a new target with <id> and <name>. <id> must not be zero.

  --lld <driver> --mode target --op delete --tid <id>

                        delete the specific target with <id>. The target must

                        have no activity.

  --lld <driver> --mode target --op show

                        show all the targets.

  --lld <driver> --mode target --op show --tid <id>

                        show the specific target's parameters.

  --lld <driver> --mode target --op update --tid <id> --name <param> --value <value>

                        change the target parameters of the specific

                        target with <id>.

  --lld <driver> --mode target --op bind --tid <id> --initiator-address <src>

                        enable the target to accept the specific initiators.

  --lld <driver> --mode target --op unbind --tid <id> --initiator-address <src>

                        disable the specific permitted initiators.

  --lld <driver> --mode logicalunit --op new --tid <id> --lun <lun> \

                        --backing-store <path> --bstype <type> --bsoflags <options>

                        add a new logical unit with <lun> to the specific

                        target with <id>. The logical unit is offered

                        to the initiators. <path> must be block device files

                        (including LVM and RAID devices) or regular files.

                        bstype option is optional.

                        bsoflags supported options are sync and direct

                        (sync:direct for both).

  --lld <driver> --mode logicalunit --op delete --tid <id> --lun <lun>

                        delete the specific logical unit with <lun> that

                        the target with <id> has.

  --lld <driver> --mode account --op new --user <name> --password <pass>

                        add a new account with <name> and <pass>.        # new一个帐号指定一个帐号名密码

  --lld <driver> --mode account --op delete --user <name>          # 删除一个帐号

                        delete the specific account having <name>.

  --lld <driver> --mode account --op bind --tid <id> --user <name> [--outgoing]        #在某一个tid上将某个用户名给它绑定    --outgoing出去的,表示绑定用来让客户端认证我们服务器端的那个帐号密码????

                        add the specific account having <name> to    

                        the specific target with <id>.

                        <user> could be <IncomingUser> or <OutgoingUser>.

                        If you use --outgoing option, the account will

                        be added as an outgoing account.

  --lld <driver> --mode account --op unbind --tid <id> --user <name>

                        delete the specific account having <name> from specific

                        target.

  --control-port <port> use control port <port>

  --help                display this help and exit


Report bugs to <stgt@vger.kernel.org>.

[root@steppingstone ~]#


image.png




在 target 192.168.0.100 上

[root@steppingstone ~]# tgtadm --lld iscsi --mode account --op new --user iscsiuser --password iscsiuser            #先只验证客户端的,不让客户端来验证服务器端的 创建一个用户(因为没有使用 outgoing )

[root@steppingstone ~]# tgtadm --lld iscsi --mode account --op bind --tid 1 --user iscsiuser        #绑定用户

[root@steppingstone ~]#

[root@steppingstone ~]# tgtadm --lld iscsi --mode target --op show

Target 1: iqn.2013-05.com.magedu:teststore.disk1

    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: 50010 MB, Block size: 512

            Online: Yes

            Removable media: No

            Readonly: No

            Backing store type: rdwr

            Backing store path: /dev/sdb5

            Backing store flags:

    Account information:

        iscsiuser        #绑定了iscsiuser

    ACL information:

[root@steppingstone ~]#



在第一个initiator 192.168.0.45 上 

[root@node1 ~]# iscsiadm -m discovery -t sendTarget -p 192.168.0.100

iscsiadm: Discovery record [192.168.0.100,3260] not found!

[root@node1 ~]#


root@node1 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.0.100    #没有找到target

iscsiadm: No portals found

[root@node1 ~]#

[root@node1 ~]# iscsiadm -m discovery -t st -p 192.168.0.100        #st 就是 sendtargets  

iscsiadm: No portals found

[root@node1 ~]#

[root@node1 ~]# iscsiadm -m discovery -d 2 -t st -p 192.168.0.100        # -d 2 为调试debug等级

iscsiadm: Max file limits 1024 1024


iscsiadm: starting sendtargets discovery, address 192.168.0.100:3260,

iscsiadm: connecting to 192.168.0.100:3260

iscsiadm: connected local port 45577 to 192.168.0.100:3260

iscsiadm: connected to discovery address 192.168.0.100

iscsiadm: login response status 0000        #对方不让登录的意思吧

iscsiadm: discovery process to 192.168.0.100:3260 exiting

iscsiadm: disconnecting conn 0x8be3c30, fd 3

iscsiadm: No portals found

[root@node1 ~]#


在第一个initiator 192.168.0.45 上         

[root@node1 ~]# cd /etc/iscsi/        # 配置一下 sendtargets 的用户名密码认证

[root@node1 iscsi]# ls

initiatorname.iscsi  iscsid.conf

[root@node1 iscsi]#

[root@node1 iscsi]# vim iscsid.conf

..........................................

discovery.sendtargets.auth.authmethod = CHAP

# To set a discovery session CHAP username and password for the initiator

# authentication by the target(s), uncomment the following lines:

discovery.sendtargets.auth.username = iscsiuser

discovery.sendtargets.auth.password = iscsiuser

..........................................


[root@node1 iscsi]# service iscsi restart        #重启下 iscsi 服务

iscsiadm: No matching sessions found

Stopping iSCSI daemon:

iscsid 已停                                                [确定]

Starting iSCSI daemon:                                     [确定]

                                                           [确定]

设置 iSCSI 目标:iscsiadm: No records found

                                                           [确定]

[root@node1 iscsi]#


[root@node1 iscsi]# iscsiadm -m discovery -d 2 -t st -p 192.168.0.100    #还是不能发现 target

iscsiadm: Max file limits 1024 1024


iscsiadm: starting sendtargets discovery, address 192.168.0.100:3260,

iscsiadm: connecting to 192.168.0.100:3260

iscsiadm: connected local port 45578 to 192.168.0.100:3260

iscsiadm: connected to discovery address 192.168.0.100

iscsiadm: login response status 0000    # 0000 表示登录失败

iscsiadm: login response status 0000

iscsiadm: discovery process to 192.168.0.100:3260 exiting

iscsiadm: disconnecting conn 0x9aa1c30, fd 3

iscsiadm: No portals found

[root@node1 iscsi]#

[root@node1 iscsi]# vim iscsid.conf        #修改这里看看

....................................

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 = iscsiuser

node.session.auth.password = iscsiuser

....................................


[root@node1 iscsi]# service iscsi restart

iscsiadm: No matching sessions found

Stopping iSCSI daemon:

iscsid 已停                                                [确定]

Starting iSCSI daemon:                                     [确定]

                                                           [确定]

设置 iSCSI 目标:iscsiadm: No records found

                                                           [确定]

[root@node1 iscsi]#

[root@node1 iscsi]# iscsiadm -m discovery -d 2 -t st -p 192.168.0.100        #还是不能发现target

iscsiadm: Max file limits 1024 1024


iscsiadm: starting sendtargets discovery, address 192.168.0.100:3260,

iscsiadm: connecting to 192.168.0.100:3260

iscsiadm: connected local port 45579 to 192.168.0.100:3260

iscsiadm: connected to discovery address 192.168.0.100

iscsiadm: login response status 0000

iscsiadm: login response status 0000

iscsiadm: discovery process to 192.168.0.100:3260 exiting

iscsiadm: disconnecting conn 0x88acc30, fd 3

iscsiadm: No portals found

[root@node1 iscsi]#


[root@node1 iscsi]# iscsiadm -m discovery -d 5 -t st -p 192.168.0.100        #调试级别改为5看看

iscsiadm: ip 192.168.0.100, port -1, tgpt -1

iscsiadm: Max file limits 1024 1024


iscsiadm: starting sendtargets discovery, address 192.168.0.100:3260,

iscsiadm: Matched transport be2iscsi


iscsiadm: sysfs_attr_get_value: open '/class/iscsi_transport/be2iscsi'/'handle'


iscsiadm: sysfs_attr_get_value: new uncached attribute '/sys/class/iscsi_transpo                                      rt/be2iscsi/handle'


iscsiadm: sysfs_attr_get_value: add to cache '/sys/class/iscsi_transport/be2iscs                                      i/handle'


iscsiadm: sysfs_attr_get_value: cache '/sys/class/iscsi_transport/be2iscsi/handl                                      e' with attribute value '4176119872'


iscsiadm: sysfs_attr_get_value: open '/class/iscsi_transport/be2iscsi'/'caps'


iscsiadm: sysfs_attr_get_value: new uncached attribute '/sys/class/iscsi_transpo                                      rt/be2iscsi/caps'


iscsiadm: sysfs_attr_get_value: add to cache '/sys/class/iscsi_transport/be2iscs                                      i/caps'


iscsiadm: sysfs_attr_get_value: cache '/sys/class/iscsi_transport/be2iscsi/caps'                                       with attribute value '0x8b9'


iscsiadm: Matched transport bnx2i


iscsiadm: sysfs_attr_get_value: open '/class/iscsi_transport/bnx2i'/'handle'


iscsiadm: sysfs_attr_get_value: new uncached attribute '/sys/class/iscsi_transpo                                      rt/bnx2i/handle'


iscsiadm: sysfs_attr_get_value: add to cache '/sys/class/iscsi_transport/bnx2i/h                                      andle'


iscsiadm: sysfs_attr_get_value: cache '/sys/class/iscsi_transport/bnx2i/handle'                                       with attribute value '4174517408'


iscsiadm: sysfs_attr_get_value: open '/class/iscsi_transport/bnx2i'/'caps'


iscsiadm: sysfs_attr_get_value: new uncached attribute '/sys/class/iscsi_transpo                                      rt/bnx2i/caps'


iscsiadm: sysfs_attr_get_value: add to cache '/sys/class/iscsi_transport/bnx2i/c                                      aps'


iscsiadm: sysfs_attr_get_value: cache '/sys/class/iscsi_transport/bnx2i/caps' wi                                      th attribute value '0x8b9'


iscsiadm: Matched transport cxgb3i


iscsiadm: sysfs_attr_get_value: open '/class/iscsi_transport/cxgb3i'/'handle'


iscsiadm: sysfs_attr_get_value: new uncached attribute '/sys/class/iscsi_transpo                                      rt/cxgb3i/handle'


iscsiadm: sysfs_attr_get_value: add to cache '/sys/class/iscsi_transport/cxgb3i/                                      handle'


iscsiadm: sysfs_attr_get_value: cache '/sys/class/iscsi_transport/cxgb3i/handle'                                       with attribute value '4172801280'


iscsiadm: sysfs_attr_get_value: open '/class/iscsi_transport/cxgb3i'/'caps'


iscsiadm: sysfs_attr_get_value: new uncached attribute '/sys/class/iscsi_transpo                                      rt/cxgb3i/caps'


iscsiadm: sysfs_attr_get_value: add to cache '/sys/class/iscsi_transport/cxgb3i/                                      caps'


iscsiadm: sysfs_attr_get_value: cache '/sys/class/iscsi_transport/cxgb3i/caps' w                                      ith attribute value '0x3039'


iscsiadm: Matched transport iser


iscsiadm: sysfs_attr_get_value: open '/class/iscsi_transport/iser'/'handle'


iscsiadm: sysfs_attr_get_value: new uncached attribute '/sys/class/iscsi_transpo                                      rt/iser/handle'


iscsiadm: sysfs_attr_get_value: add to cache '/sys/class/iscsi_transport/iser/ha                                      ndle'


iscsiadm: sysfs_attr_get_value: cache '/sys/class/iscsi_transport/iser/handle' w                                      ith attribute value '4175144672'


iscsiadm: sysfs_attr_get_value: open '/class/iscsi_transport/iser'/'caps'


iscsiadm: sysfs_attr_get_value: new uncached attribute '/sys/class/iscsi_transpo                                      rt/iser/caps'


iscsiadm: sysfs_attr_get_value: add to cache '/sys/class/iscsi_transport/iser/ca                                      ps'


iscsiadm: sysfs_attr_get_value: cache '/sys/class/iscsi_transport/iser/caps' wit                                      h attribute value '0x9'


iscsiadm: Matched transport tcp


iscsiadm: sysfs_attr_get_value: open '/class/iscsi_transport/tcp'/'handle'


iscsiadm: sysfs_attr_get_value: new uncached attribute '/sys/class/iscsi_transpo                                      rt/tcp/handle'


iscsiadm: sysfs_attr_get_value: add to cache '/sys/class/iscsi_transport/tcp/han                                      dle'


iscsiadm: sysfs_attr_get_value: cache '/sys/class/iscsi_transport/tcp/handle' wi                                      th attribute value '4172655232'


iscsiadm: sysfs_attr_get_value: open '/class/iscsi_transport/tcp'/'caps'


iscsiadm: sysfs_attr_get_value: new uncached attribute '/sys/class/iscsi_transpo                                      rt/tcp/caps'


iscsiadm: sysfs_attr_get_value: add to cache '/sys/class/iscsi_transport/tcp/cap                                      s'


iscsiadm: sysfs_attr_get_value: cache '/sys/class/iscsi_transport/tcp/caps' with                                       attribute value '0x39'


iscsiadm: sendtargets discovery to 192.168.0.100:3260 using isid 0x00023d000000

iscsiadm: resolved 192.168.0.100 to 192.168.0.100

iscsiadm: discovery timeouts: login 15, reopen_cnt 6, auth 45.

iscsiadm: connecting to 192.168.0.100:3260

iscsiadm: connected local port 45580 to 192.168.0.100:3260

iscsiadm: connected to discovery address 192.168.0.100

iscsiadm: discovery session to 192.168.0.100:3260 starting iSCSI login

iscsiadm: sending login PDU with current stage 0, next stage 1, transit 0x80, is                                      id 0x00023d000000 exp_statsn 0

iscsiadm: >    InitiatorName=iqn.2013-05.com.magedu:ebf32f4b5bb

iscsiadm: >    InitiatorAlias=node1.magedu.com

iscsiadm: >    SessionType=Discovery

iscsiadm: >    AuthMethod=CHAP,None

iscsiadm: wrote 48 bytes of PDU header

iscsiadm: wrote 124 bytes of PDU data

iscsiadm: read 48 bytes of PDU header

iscsiadm: read 48 PDU header bytes, opcode 0x23, dlength 39, data 0x9160de8, max                                       32768

iscsiadm: read 39 bytes of PDU data

iscsiadm: read 1 pad bytes

iscsiadm: finished reading login PDU, 48 hdr, 0 ah, 39 data, 1 pad

iscsiadm: login current stage 0, next stage 1, transit 0x80

iscsiadm: >    TargetPortalGroupTag=1

iscsiadm: >    AuthMethod=None

iscsiadm: login response status 0000

iscsiadm: sending login PDU with current stage 1, next stage 3, transit 0x80, is                                      id 0x00023d000000 exp_statsn 1

iscsiadm: >    HeaderDigest=None

iscsiadm: >    DataDigest=None

iscsiadm: >    DefaultTime2Wait=2

iscsiadm: >    DefaultTime2Retain=0

iscsiadm: >    IFMarker=No

iscsiadm: >    OFMarker=No

iscsiadm: >    ErrorRecoveryLevel=0

iscsiadm: >    MaxRecvDataSegmentLength=32768

iscsiadm: wrote 48 bytes of PDU header

iscsiadm: wrote 152 bytes of PDU data

iscsiadm: read 48 bytes of PDU header

iscsiadm: read 48 PDU header bytes, opcode 0x23, dlength 119, data 0x9160de8, ma                                      x 32768

iscsiadm: read 119 bytes of PDU data

iscsiadm: read 1 pad bytes

iscsiadm: finished reading login PDU, 48 hdr, 0 ah, 119 data, 1 pad

iscsiadm: login current stage 1, next stage 3, transit 0x80

iscsiadm: >    HeaderDigest=None

iscsiadm: >    DataDigest=None

iscsiadm: >    DefaultTime2Wait=2

iscsiadm: >    DefaultTime2Retain=0

iscsiadm: >    IFMarker=No

iscsiadm: >    OFMarker=No

iscsiadm: >    ErrorRecoveryLevel=0

iscsiadm: login response status 0000

iscsiadm: discovery login success to 192.168.0.100

iscsiadm: sending text pdu with CmdSN 1, exp_statsn 1

iscsiadm: >    SendTargets=All

iscsiadm: wrote 48 bytes of PDU header

iscsiadm: wrote 16 bytes of PDU data

iscsiadm: discovery process  192.168.0.100:3260 polling fd 3, timeout in 30.0000                                      00 seconds

iscsiadm: read 48 bytes of PDU header

iscsiadm: read 48 PDU header bytes, opcode 0x24, dlength 0, data 0x9160de8, max                                       32768

iscsiadm: discovery session to 192.168.0.100:3260 received text response, 0 data                                       bytes, ttt 0xffffffff, final 0x80

iscsiadm: discovery process to 192.168.0.100:3260 exiting

iscsiadm: disconnecting conn 0x9158c30, fd 3

iscsiadm: No portals found

[root@node1 iscsi]#



在 target 192.168.0.100 上

[root@steppingstone ~]# tgtadm --lld iscsi -m target --op bind --tid 1 --initiator-address 192.168.0.0/24        #这里设下发起者网络地址

[root@steppingstone ~]# 


[root@steppingstone ~]# tgtadm --lld iscsi --mode target --op show

Target 1: iqn.2013-05.com.magedu:teststore.disk1

    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: 50010 MB, Block size: 512

            Online: Yes

            Removable media: No

            Readonly: No

            Backing store type: rdwr

            Backing store path: /dev/sdb5

            Backing store flags:

    Account information:

        iscsiuser        #帐户有了

    ACL information:

        192.168.0.0/24        #地址有了

[root@steppingstone ~]#



在第二个 initiator 192.168.0.55 上

[root@node2 ~]# cd /etc/iscsi/

[root@node2 iscsi]# ls

initiatorname.iscsi  iscsid.conf

[root@node2 iscsi]# 

[root@node2 iscsi]# vim iscsid.conf        #里面未进行任何配置

.....................

[root@node2 iscsi]# iscsiadm -m discovery -t st -p 192.168.0.100        #能发现target

192.168.0.100:3260,1 iqn.2013-05.com.magedu:teststore.disk1

[root@node2 iscsi]#


[root@node2 iscsi]# iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -l            # 不能登录

Logging in to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] (multiple)

iscsiadm: Could not login to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260].

iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)

iscsiadm: Could not log into all portals

[root@node2 iscsi]#

[root@node2 iscsi]# pwd

/etc/iscsi

[root@node2 iscsi]# ls

initiatorname.iscsi  iscsid.conf

[root@node2 iscsi]# vim iscsid.conf

.................................................................

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 = iscsiuser

node.session.auth.password = iscsiuser

.................................................................

[root@node2 iscsi]# service iscsi restart            #重启下登录依然失败

iscsiadm: No matching sessions found

Stopping iSCSI daemon:

iscsid 已停                                                [确定]

Starting iSCSI daemon:                                     [确定]

                                                           [确定]

设置 iSCSI 目标:Logging in to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] (multiple)

iscsiadm: Could not login to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260].

iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)    #认证失败

iscsiadm: Could not log into all portals

                                                           [确定]

[root@node2 iscsi]#

[root@node2 iscsi]# iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -l            # 不能够登录到 target 

Logging in to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] (multiple)

iscsiadm: Could not login to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260].

iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)

iscsiadm: Could not log into all portals

[root@node2 iscsi]#


刚才处理应该没有错,,,,可能是此前的删除库删除的不彻底????

image.png


iscsi-initiator-utils:

    是不支持 discovery 认证的(马哥也不知道是 客户端还是服务端不支持,只知道有一端不支持)

所以 discovery 的时候,不成功,提供帐号密码的话,是没用的

    如果使用基于用户的认证,必须首先开放基于IP的认证

   # vim iscsid.conf  中关于 discovery auth 什么的,不用启用了,因为没有什么意义

image.png



在第一个 initiator 192.168.0.45 上

[root@node1 iscsi]# ls /var/lib/iscsi/send_targets/

192.168.0.100,3260

[root@node1 iscsi]# ls /var/lib/iscsi/send_targets/192.168.0.100,3260/

st_config

[root@node1 iscsi]# rm -Rf /var/lib/iscsi/send_targets/192.168.0.100,3260/        #删除这个目录吧

[root@node1 iscsi]#


[root@node1 iscsi]# ls

initiatorname.iscsi  iscsid.conf

[root@node1 iscsi]# vim iscsid.conf

....................................................................................................

#discovery.sendtargets.auth.authmethod = CHAP       #与discovery这些相关的不要启用


# To set a discovery session CHAP username and password for the initiator

# authentication by the target(s), uncomment the following lines:

#discovery.sendtargets.auth.username = iscsiuser       #与discovery这些相关的不要启用

#discovery.sendtargets.auth.password = iscsiuser       #与discovery这些相关的不要启用

....................................................................................................



[root@node1 iscsi]# service iscsi restart

iscsiadm: No matching sessions found

Stopping iSCSI daemon:

iscsid 已停                                                [确定]

Starting iSCSI daemon:                                     [确定]

                                                           [确定]

设置 iSCSI 目标:iscsiadm: No records found  #表示target(至少我们现在要使用target)没有被发现,说明是正常的

                                                           [确定]

[root@node1 iscsi]# 


在 target 192.168.0.100 上            确保基于IP和帐号

[root@steppingstone ~]# tgtadm --lld iscsi --mode target --op show

Target 1: iqn.2013-05.com.magedu:teststore.disk1

    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: 50010 MB, Block size: 512

            Online: Yes

            Removable media: No

            Readonly: No

            Backing store type: rdwr

            Backing store path: /dev/sdb5

            Backing store flags:

    Account information:

        iscsiuser

    ACL information:

        192.168.0.0/24

[root@steppingstone ~]#

[root@node1 iscsi]# iscsiadm -m discovery -t st -p 192.168.0.100        #发现了

192.168.0.100:3260,1 iqn.2013-05.com.magedu:teststore.disk1

[root@node1 iscsi]#

[root@node1 iscsi]# iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -l    #登录成功了

Logging in to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] (multiple)

Login to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] successful.

[root@node1 iscsi]#

[root@node1 iscsi]# 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        2610    20860402+  8e  Linux LVM


Disk /dev/sdb: 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/sdb1               1        2610    20964793+   5  Extended

/dev/sdb5               1         200     1606437   8e  Linux LVM

/dev/sdb6             201         323      987966   83  Linux


Disk /dev/sdc: 50.0 GB, 50009637888 bytes

64 heads, 32 sectors/track, 47692 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


   Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        1908     1953776   83  Linux

[root@node1 iscsi]#



# 在第二个initiator 192.168.0.55 上

[root@node2 iscsi]# ls -la /var/lib/iscsi/send_targets/

总计 24

drwxr-xr-x 3 root root 4096 02-21 14:05 .

drwxr-xr-x 8 root root 4096 2019-07-12 ..

drw------- 2 root root 4096 02-21 14:05 192.168.0.100,3260

[root@node2 iscsi]# rm -Rf /var/lib/iscsi/send_targets/192.168.0.100,3260/

[root@node2 iscsi]#

[root@node2 iscsi]# iscsiadm -m discovery -t st -p 192.168.0.100        #发现了

192.168.0.100:3260,1 iqn.2013-05.com.magedu:teststore.disk1

[root@node2 iscsi]# iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -l    #登录成功了

Logging in to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] (multiple)

Login to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] successful.

[root@node2 iscsi]#

[root@node2 iscsi]# service iscsi restart        #重启是登出,,,再登录

Logging out of session [sid: 8, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260]

Logout of [sid: 8, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] successful.

Stopping iSCSI daemon:

iscsid 已停                                                [确定]

Starting iSCSI daemon:                                     [确定]

                                                           [确定]

设置 iSCSI 目标:Logging in to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] (multiple)

Login to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] successful.

                                                           [确定]

[root@node2 iscsi]#


[root@node2 iscsi]# 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        2610    20860402+  8e  Linux LVM


Disk /dev/sdb: 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/sdb1               1        2610    20964793+   5  Extended

/dev/sdb5               1         200     1606437   8e  Linux LVM

/dev/sdb6             201         323      987966   83  Linux


Disk /dev/sdd: 50.0 GB, 50009637888 bytes        # 这里看到的是 /dev/sdd ,,,应该是登出,再登录就是 /dev/sdc 了?????好像不行呢?????,如果想给它个固定名称,得需要依赖于额外的其它机制

64 heads, 32 sectors/track, 47692 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


   Device Boot      Start         End      Blocks   Id  System

/dev/sdd1               1        1908     1953776   83  Linux

[root@node2 iscsi]#



target端 建立的内容都是在内存中工作的,与iptables,ipvsadm建立的规则是一样的,,,,

早期要把命令写到 /etc/rc.local 当中,

在 target 端 192.168.0.100 上

[root@steppingstone ~]# rpm -ql scsi-target-utils

/etc/rc.d/init.d/tgtd

/etc/sysconfig/tgtd

/etc/tgt/targets.conf       #  内容定义到这儿,下次开机也会生效的(重启 service tgtd restart 也会生效的)

/usr/sbin/tgt-admin        # tgt-admin这个命令 读取 /etc/tgt/targets.conf 去创建target的  

/usr/sbin/tgt-setup-lun

/usr/sbin/tgtadm

/usr/sbin/tgtd

/usr/sbin/tgtimg

/usr/share/doc/scsi-target-utils-1.0.14

/usr/share/doc/scsi-target-utils-1.0.14/README

/usr/share/doc/scsi-target-utils-1.0.14/README.iscsi

/usr/share/doc/scsi-target-utils-1.0.14/README.iser

/usr/share/doc/scsi-target-utils-1.0.14/README.lu_configuration

/usr/share/doc/scsi-target-utils-1.0.14/README.mmc

/usr/share/man/man8/tgt-admin.8.gz

/usr/share/man/man8/tgt-setup-lun.8.gz

/usr/share/man/man8/tgtadm.8.gz

[root@steppingstone ~]#


[root@steppingstone sysconfig]# cd /etc/tgt/

[root@steppingstone tgt]# ls

targets.conf

[root@steppingstone tgt]# pwd

/etc/tgt

[root@steppingstone tgt]#

[root@steppingstone tgt]# cp targets.conf targets.conf.backup

[root@steppingstone tgt]#

[root@steppingstone tgt]# vim targets.conf

# This is a sample config file for tgt-admin.

# By default, tgt-admin looks for its config file in /etc/tgt/targets.conf

#

# The "#" symbol disables the processing of a line.



# This one includes other config files:


#include /etc/tgt/temp/*.conf



# Set the driver. If not specified, defaults to "iscsi".


default-driver iscsi        #驱动


# Set iSNS parameters, if needed


#iSNSServerIP 192.168.111.222

#iSNSServerPort 3205

#iSNSAccessControl On

#iSNS On



# Continue if tgtadm exits with non-zero code (equivalent of

# --ignore-errors command line option)

#ignore-errors yes            #忽略错误



# Sample target with one LUN only. Defaults to allow access for all initiators:


#<target iqn.2008-09.com.example:server.target1>    #封装一个target

#    backing-store /dev/LVM/somedevice

#</target>

<target iqn.2013-05.com.magedu:teststore.disk1>        #仅在这里做了添加

        backing-store /dev/sdb5

        incominguser iscsiuser iscsiuser

        initiator-address 192.168.0.0/24

</target>


# Similar, but we use "direct-store" instead of "backing-store".

# "direct-store" reads drive parameters with sg_inq command and sets them to

# the target.

# Parameters fatched with sg_inq are:

# - Vendor identification

# - Product identification

# - Product revision level

# - Unit serial number (if present)

# We also specify "incominguser".


#<target iqn.2008-09.com.example:server.target2>

#    direct-store /dev/sdd

#    incominguser someuser secretpass12    # 进来的用户和密码 服务器端验证客户端

                                                                      # 多个用户名密码可以写多份

#</target>



# An example with multiple LUNs, disabled write-cache (tgtd enables write-cache

# by default) and vendor identification set to "MyVendor"


#<target iqn.2008-09.com.example:server.target3>

#    backing-store /dev/LVM/somedevice1 # Becomes LUN 1

#    backing-store /dev/LVM/somedevice2 # Becomes LUN 2

#    backing-store /dev/LVM/somedevice3 # Becomes LUN 3

#    write-cache off

#    vendor_id MyCompany Inc.

#</target>



# Similar to the one above, but we fetch vendor_id, product_id, product_rev and

# scsi_sn from the disks.

# Vendor identification (vendor_id) is replaced in all disks by "MyVendor"


#<target iqn.2008-09.com.example:server.target4>

#    direct-store /dev/sdb      # Becomes LUN 1

#    direct-store /dev/sdc      # Becomes LUN 2

#    direct-store /dev/sdd      # Becomes LUN 3

#    write-cache off

#    vendor_id MyCompany Inc.

#</target>



# Note that "first-device-first-lun numbering" will work only for simple

# scenarios above, where _only_ direct-store _or_ backing-store is used.

# If you mix backing-store and direct-store, then all backing-store entries

# are processed before direct-store-entries.

#<target iqn.2008-09.com.example:server.target4>

#    direct-store /dev/sdb      # Becomes LUN 3

#    backing-store /dev/sdc     # Becomes LUN 1

#    direct-store /dev/sdd      # Becomes LUN 4

#    backing-store /dev/sde     # Becomes LUN 2

#</target>



# Even more complicated example - each device has different parameters.

# You can use indentation to make the config file more readable.

# Note that LUNs will be assigned more or less randomly here (and still

# backing-store get LUNs assigned before drect-store).

# You can specify multiple mode_page parameters (they are commented out

# in this example).

# Note that some parameters (write-cache, scsi_sn) were specified "globally".

# "Global" parameters will be applied to all LUNs; they can be overwritten

# "locally", per LUN.

# If lun is not specified, it will be allocated automatically (first available).


#<target iqn.2008-09.com.example:server.target5>


#    <direct-store /dev/sdd>

#       vendor_id VENDOR1

#       removable 1

#       device-type cd

#       lun 1

#    </direct-store>


#    <direct-store /dev/sda>

#       vendor_id VENDOR2

#       lun 2

#    </direct-store>


#    <backing-store /dev/sdb1>

#       vendor_id back1

#       scsi_sn SERIAL

#       write-cache on

        # lun 3         # lun is commented out - will be allocated automatically

#   </backing-store>


#    <backing-store /dev/sdd1>

#       vendor_id back2

        #mode_page 8:0:18:0x10:0:0xff....

        #mode_page 8:0:18:0x10:0:0xff....

        #bs-type aio

#       lun 15

#    </backing-store>


    # Some more parameters which can be specified locally or globally:

    #scsi_id ...

    #scsi_sn ...

    #vendor_id ...

    #product_id ...

    #product_rev ...

    #sense_format ...

    #removable ...

    #online ...

    #path ...

    #mode_page 8:0:18:0x10:0:0xff....

    #mode_page 8:0:18:0x10:0:0xff....

    #device-type ...

    #bs-type ...        # backing store type - default rdwr, can be aio, mmap, etc...

    #allow-in-use yes   # if specified globally, can't be overwritten locally


#    write-cache off

#    scsi_sn multipath-10


    # Parameters below are only global. They can't be configured per LUN.

    # Only allow connections from 192.168.100.1 and 192.168.200.5

#    initiator-address 192.168.100.1

#    initiator-address 192.168.200.5


    # Tuning parameters (global, per target)

    #MaxRecvDataSegmentLength 8192

    #MaxXmitDataSegmentLength 8192

    #HeaderDigest None

    #DataDigest None

    #InitialR2T Yes

    #MaxOutstandingR2T 1

    #ImmediateData Yes

    #FirstBurstLength 65536

    #MaxBurstLength 262144

    #DataPDUInOrder Yes

    #DataSequenceInOrder Yes

    #ErrorRecoveryLevel 0

    #IFMarker No

    #OFMarker No

    #DefaultTime2Wait 2

    #DefaultTime2Retain 20

    #OFMarkInt Reject

    #IFMarkInt Reject

    #MaxConnections 1


    # Allowed incoming users

#    incominguser user1 secretpass12

#    incominguser user2 secretpass23


    # Outgoing user

#    outgoinguser userA secretpassA        #出去的帐号密码


#</target>



# The device will have lun 1 unless you specify something else

#<target iqn.2008-09.com.example:server.target6>

#    backing-store /dev/LVM/somedevice

#    lun 10

#</target>



# Devices which are in use (by system: mounted, for swap, part of RAID, or by

# userspace: dd, by tgtd for another target etc.) can't be used, unless you use

# --force flag or add 'allow-in-use yes' option

#<target iqn.2008-09.com.example:server.target7>

#    backing-store /dev/LVM/somedevice

#    allow-in-use yes

#</target>


#<target iqn.2008-09.com.example:server.target8>

#    <backing-store /dev/LVM/somedevice>

#        scsi_sn serial1

#    </backing-store>


#    <backing-store /dev/LVM/somedevice2>

#        scsi_sn serial2

#    </backing-store>


#    allow-in-use yes

#</target>





# Not supported configurations, and therefore, commented out:


#<target iqn.2008-09.com.example:server.target9>

#    backing-store /dev/LVM/somedevice1

#    backing-store /dev/LVM/somedevice2

#    lun 10

#    lun 11

#</target>


#<target iqn.2008-09.com.example:server.target10>

#    <direct-store /dev/sdd>

#        vendor_id VENDOR1

#    </direct-store>

#

#    direct-store /dev/sdc

#</target>


# This one will break the parser:

#<target iqn.2008-09.com.example:server.target11>

#    <direct-store /dev/sdd>

#        vendor_id VENDOR1

#    </direct-store>

#

#    direct-store /dev/sdc

#

#    <direct-store /dev/sdd>

#        vendor_id VENDOR1

#    </direct-store>

#</target>


在 target 端 192.168.0.100 上

[root@steppingstone tgt]# service tgtd restart

Stopping SCSI target daemon: Stopping target framework daemon

Some initiators are still connected - could not stop tgtd        #客户端仍然在登录,所以不让重启??

[root@steppingstone tgt]#


在第一个 initiator 192.168.0.45 上

[root@node1 iscsi]# iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -u         #登出

Logging out of session [sid: 10, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260]

Logout of [sid: 10, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] successful.



在第二个 initiator 192.168.0.55 上

[root@node2 iscsi]#  iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -u        #登出

Logging out of session [sid: 10, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260]

Logout of [sid: 10, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] successful.

[root@node2 iscsi]#


在 target 端 192.168.0.100 上

[root@steppingstone tgt]#

[root@steppingstone tgt]# service tgtd restart    #现在可以重启了

Stopping SCSI target daemon: Stopping target framework daemon

                                                           [确定]

Starting SCSI target daemon: Starting target framework daemon


[root@steppingstone tgt]#

[root@steppingstone tgt]# tgtadm --lld iscsi --mode target --op show

Target 1: iqn.2013-05.com.magedu:teststore.disk1

    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: 50010 MB, Block size: 512

            Online: Yes

            Removable media: No

            Readonly: No

            Backing store type: rdwr

            Backing store path: /dev/sdb5

            Backing store flags:

    Account information:

        iscsiuser        #有帐号信息

    ACL information:

        192.168.0.0/24       #有关于哪个IP段可以访问的信息

[root@steppingstone tgt]#

[root@steppingstone tgt]# pwd

/etc/tgt

[root@steppingstone tgt]# ls

targets.conf  targets.conf.backup

[root@steppingstone tgt]# vim targets.conf

............................................................................................................................

<target iqn.2013-05.com.magedu:teststore.disk1>

        backing-store /dev/sdb5        #这是一个lun,,,这个LUN号为1,,,  调换次序可以改变LUN号

        backing-store /dev/sdb6        #这是另一个lun,,,这个LUN号为2

        incominguser iscsiuser iscsiuser

        initiator-address 192.168.0.0/24

</target>

............................................................................................................................


[root@steppingstone tgt]# service tgtd restart

Stopping SCSI target daemon: Stopping target framework daemon

                                                           [确定]

Starting SCSI target daemon: Starting target framework daemon


[root@steppingstone tgt]#

[root@steppingstone tgt]# tgtadm --lld iscsi --mode target --op show


Target 1: iqn.2013-05.com.magedu:teststore.disk1

    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        #第一个LUN

            Type: disk

            SCSI ID: IET     00010001

            SCSI SN: beaf11

            Size: 50010 MB, Block size: 512

            Online: Yes

            Removable media: No

            Readonly: No

            Backing store type: rdwr

            Backing store path: /dev/sdb5

            Backing store flags:

        LUN: 2      #第二个LUN

            Type: disk

            SCSI ID: IET     00010002

            SCSI SN: beaf12

            Size: 20012 MB, Block size: 512

            Online: Yes

            Removable media: No

            Readonly: No

            Backing store type: rdwr

            Backing store path: /dev/sdb6

            Backing store flags:

    Account information:

        iscsiuser

    ACL information:

        192.168.0.0/24

[root@steppingstone tgt]#

[root@steppingstone tgt]# pwd

/etc/tgt

[root@steppingstone tgt]# vim targets.conf

................................................................

<target iqn.2013-05.com.magedu:teststore.disk1>

        backing-store /dev/sdb5     #  backing-store 仅会输出这样一个设备的,不会输出生产厂商,序列号等信息

        direct-store /dev/sdb6        #   direct-store 能够让我们的tgtd直接去读取硬件设备 ( 通常为硬盘,有生产厂商,有序列号,使用direct-store会自动读取这些信息,并输出出去)

        incominguser iscsiuser iscsiuser

        initiator-address 192.168.0.0/24

</target>

................................................................

#<target iqn.2008-09.com.example:server.target5>


#    <direct-store /dev/sdd>    #它应该是个硬盘,而不是一个分区,分区本身不具备我们所需要的信息,所以下面 # service tgtd restart  它会报错的,,,,所以我们可以给direct-store指定一些信息的

#       vendor_id VENDOR1

#       removable 1

#       device-type cd

#       lun 1        #direct-store里面指定lun号

#    </direct-store>


#    <direct-store /dev/sda>

#       vendor_id VENDOR2

#       lun 2

#    </direct-store>


#    <backing-store /dev/sdb1>

#       vendor_id back1

#       scsi_sn SERIAL

#       write-cache on

        # lun 3         # lun is commented out - will be allocated automatically  #或者backing-store里面指定lun号

#   </backing-store>


................................................................



[root@steppingstone tgt]# service tgtd restart

Stopping SCSI target daemon: Stopping target framework daemon

                                                           [确定]

Starting SCSI target daemon: Starting target framework daemon

Command 'sg_inq' (needed by 'option direct-store') is not in your path - can't continue!        # direct-store 需要给个号码???


[root@steppingstone tgt]#

[root@steppingstone ~]# rpm -ql scsi-target-utils

/etc/rc.d/init.d/tgtd

/etc/sysconfig/tgtd

/etc/tgt/targets.conf

/usr/sbin/tgt-admin

/usr/sbin/tgt-setup-lun

/usr/sbin/tgtadm

/usr/sbin/tgtd

/usr/sbin/tgtimg

/usr/share/doc/scsi-target-utils-1.0.14

/usr/share/doc/scsi-target-utils-1.0.14/README

/usr/share/doc/scsi-target-utils-1.0.14/README.iscsi

/usr/share/doc/scsi-target-utils-1.0.14/README.iser

/usr/share/doc/scsi-target-utils-1.0.14/README.lu_configuration

/usr/share/doc/scsi-target-utils-1.0.14/README.mmc

/usr/share/man/man8/tgt-admin.8.gz

/usr/share/man/man8/tgt-setup-lun.8.gz

/usr/share/man/man8/tgtadm.8.gz

[root@steppingstone ~]#


[root@steppingstone ~]# cd /etc/tgt/

[root@steppingstone tgt]# pwd

/etc/tgt

[root@steppingstone tgt]# ls

targets.conf  targets.conf.backup

[root@steppingstone tgt]#

[root@steppingstone tgt]# vim targets.conf

....................................................................

<target iqn.2013-05.com.magedu:teststore.disk1>

        <backing-store /dev/sdb5>

                lun 6            # lun 号

        </backing-store>

        backing-store /dev/sdb6        #把上面的 direct-store 改成 backing-store 吧

        incominguser iscsiuser iscsiuser

        initiator-address 192.168.0.0/24

</target>

....................................................................


[root@steppingstone tgt]# service tgtd restart

Stopping SCSI target daemon: Stopping target framework daemon

                                                           [确定]

Starting SCSI target daemon: Starting target framework daemon


Your config file is not supported. See targets.conf.example for details.


[root@steppingstone tgt]# vim targets.conf

..............................................................................

<target iqn.2013-05.com.magedu:teststore.disk1>

        <backing-store /dev/sdb5>

                vendor_id magedu

                lun 6

        </backing-store>

        backing-store /dev/sdb6

        incominguser iscsiuser iscsiuser

        initiator-address 192.168.0.0/24

</target>

..............................................................................

[root@steppingstone tgt]# service tgtd restart        #还是不行

Stopping SCSI target daemon: Stopping target framework daemon

                                                           [确定]

Starting SCSI target daemon: Starting target framework daemon


Your config file is not supported. See targets.conf.example for details.


[root@steppingstone tgt]# vim targets.conf

..............................................................................

<target iqn.2013-05.com.magedu:teststore.disk1>

        <backing-store /dev/sdb5>

                vendor_id magedu

                lun 6

        </backing-store>

        <backing-store /dev/sdb6>        #这一个也封装一下

                vendor_id magedu

                lun 7

        </backing-store>

        incominguser iscsiuser iscsiuser

        initiator-address 192.168.0.0/24

</target>

..............................................................................


[root@steppingstone tgt]# service tgtd restart        #现在可以了

Stopping SCSI target daemon: Stopping target framework daemon

                                                           [确定]

Starting SCSI target daemon: Starting target framework daemon


[root@steppingstone tgt]#

[root@steppingstone tgt]# tgtadm --lld iscsi --mode target --op show

Target 1: iqn.2013-05.com.magedu:teststore.disk1

    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: 6        #一个6

            Type: disk

            SCSI ID: IET     00010006

            SCSI SN: beaf16

            Size: 50010 MB, Block size: 512

            Online: Yes

            Removable media: No

            Readonly: No

            Backing store type: rdwr

            Backing store path: /dev/sdb5

            Backing store flags:

        LUN: 7       #一个7

            Type: disk

            SCSI ID: IET     00010007

            SCSI SN: beaf17

            Size: 20012 MB, Block size: 512

            Online: Yes

            Removable media: No

            Readonly: No

            Backing store type: rdwr

            Backing store path: /dev/sdb6

            Backing store flags:

    Account information:

        iscsiuser

    ACL information:

        192.168.0.0/24

[root@steppingstone tgt]#



在第一个 initiator 192.168.0.45 上

[root@node1 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.0.100        #发现

192.168.0.100:3260,1 iqn.2013-05.com.magedu:teststore.disk1

[root@node1 ~]# iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -l    #登录

Logging in to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] (multiple)

Login to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] successful.

[root@node1 ~]#

[root@node1 ~]# 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        2610    20860402+  8e  Linux LVM


Disk /dev/sdb: 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/sdb1               1        2610    20964793+   5  Extended

/dev/sdb5               1         200     1606437   8e  Linux LVM

/dev/sdb6             201         323      987966   83  Linux


Disk /dev/sdc: 50.0 GB, 50009637888 bytes    # 第一个设备

64 heads, 32 sectors/track, 47692 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


   Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        1908     1953776   83  Linux


Disk /dev/sdd: 20.0 GB, 20012073984 bytes    #第二个设备

64 heads, 32 sectors/track, 19085 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


Disk /dev/sdd doesn't contain a valid partition table    

[root@node1 ~]#


在第二个 initiator 192.168.0.55 上  

[root@node2 ~]#  iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -l    #也登录成功了

Logging in to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] (multiple)

Login to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] successful.

[root@node2 ~]#

[root@node2 ~]# 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        2610    20860402+  8e  Linux LVM


Disk /dev/sdb: 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/sdb1               1        2610    20964793+   5  Extended

/dev/sdb5               1         200     1606437   8e  Linux LVM

/dev/sdb6             201         323      987966   83  Linux


Disk /dev/sdd: 50.0 GB, 50009637888 bytes

64 heads, 32 sectors/track, 47692 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


   Device Boot      Start         End      Blocks   Id  System

/dev/sdd1               1        1908     1953776   83  Linux


Disk /dev/sde: 20.0 GB, 20012073984 bytes

64 heads, 32 sectors/track, 19085 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


Disk /dev/sde doesn't contain a valid partition table

[root@node2 ~]#


如何使用集群文件系统?

rhcs的集群,至少要提供3个节点


在第三个initiator 192.168.0.65 上

iscsi-initiator-utils 已经装过了

[root@node3 ~]# cd /etc/iscsi/

[root@node3 iscsi]# ls

initiatorname.iscsi  iscsid.conf

[root@node3 iscsi]# vim initiatorname.iscsi        #起initiator name名字

InitiatorName=iqn.2013-05.com.magedu:node3


[root@node3 iscsi]# pwd

/etc/iscsi

[root@node3 iscsi]# ls

initiatorname.iscsi  iscsid.conf

[root@node3 iscsi]# vim iscsid.conf        #编辑配置文件,提供CHAP认证的帐号和密码

......................................................................................

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 = iscsiuser

node.session.auth.password = iscsiuser

......................................................................................

    

[root@node3 iscsi]# service iscsi start        #启动 iscsi

iscsid (pid  5709) 正在运行...

设置 iSCSI 目标:iscsiadm: No records found

                                                           [确定]

[root@node3 iscsi]#

[root@node3 iscsi]# chkconfig iscsi on            #开机自动启动

[root@node3 iscsi]#

[root@node3 iscsi]# iscsiadm -m discovery -t st -p 192.168.0.100        #发现target

192.168.0.100:3260,1 iqn.2013-05.com.magedu:teststore.disk1

[root@node3 iscsi]#               

[root@node3 iscsi]# iscsiadm -m node -T iqn.2013-05.com.magedu:teststore.disk1 -p 192.168.0.100 -l         #登录

Logging in to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] (multiple)

Login to [iface: default, target: iqn.2013-05.com.magedu:teststore.disk1, portal: 192.168.0.100,3260] successful.

[root@node3 iscsi]#


在三个initiator上安装 cman,rgmanager,gfs2-utils(用来配置集群文件系统)



三个initiator上 通过 # fdisk -l

得到的共享盘名称不统一 (可以定义udb规则,可以让它统一起来,得起个名吧)

分别为

 Disk /dev/sdc: 50.0 GB, 50009637888 bytes     Disk /dev/sdd: 20.0 GB, 20012073984 bytes

 Disk /dev/sdd: 50.0 GB, 50009637888 bytes     Disk /dev/sde: 20.0 GB, 20012073984 bytes

 Disk /dev/sdc: 50.0 GB, 50009637888 bytes      Disk /dev/sdd: 20.0 GB, 20012073984 bytes


在第一个initiator 192.168.0.45 上  对50G的共享盘进行分区

[root@node1 ~]# fdisk /dev/sdc


The number of cylinders for this disk is set to 47692.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)


Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 2

First cylinder (1909-47692, default 1909):

Using default value 1909

Last cylinder or +size or +sizeM or +sizeK (1909-47692, default 47692): +10G


Command (m for help): m

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition

   l   list known partition types

   m   print this menu

   n   add a new partition

   o   create a new empty DOS partition table

   p   print the partition table

   q   quit without saving changes

   s   create a new empty Sun disklabel

   t   change a partition's system id

   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit

   x   extra functionality (experts only)


Command (m for help): p


Disk /dev/sdc: 50.0 GB, 50009637888 bytes

64 heads, 32 sectors/track, 47692 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


   Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        1908     1953776   83  Linux

/dev/sdc2            1909       11446     9766912   83  Linux


Command (m for help): w

The partition table has been altered!


Calling ioctl() to re-read partition table.

Syncing disks.

[root@node1 ~]# partprobe /dev/sdc

[root@node1 ~]#


在第二个initiator 192.168.0.55 上

[root@node2 ~]# 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        2610    20860402+  8e  Linux LVM


Disk /dev/sdb: 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/sdb1               1        2610    20964793+   5  Extended

/dev/sdb5               1         200     1606437   8e  Linux LVM

/dev/sdb6             201         323      987966   83  Linux


Disk /dev/sdd: 50.0 GB, 50009637888 bytes

64 heads, 32 sectors/track, 47692 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


   Device Boot      Start         End      Blocks   Id  System        #立即看到效果,但是格式化什么的,执行不了

/dev/sdd1               1        1908     1953776   83  Linux

/dev/sdd2            1909       11446     9766912   83  Linux    


Disk /dev/sde: 20.0 GB, 20012073984 bytes

64 heads, 32 sectors/track, 19085 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


Disk /dev/sde doesn't contain a valid partition table

[root@node2 ~]#

[root@node2 ~]# partprobe /dev/sdd        #此时才能格式化什么的,此时内核才能识别????

[root@node2 ~]#



在第三个initiator 192.168.0.65 上

[root@node3 iscsi]# 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        2610    20860402+  8e  Linux LVM


Disk /dev/sdb: 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/sdb1               1        2610    20964793+   5  Extended

/dev/sdb5               1         200     1606437   8e  Linux LVM

/dev/sdb6             201         323      987966   83  Linux


Disk /dev/sdc: 50.0 GB, 50009637888 bytes

64 heads, 32 sectors/track, 47692 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


   Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        1908     1953776   83  Linux

/dev/sdc2            1909       11446     9766912   83  Linux


Disk /dev/sdd: 20.0 GB, 20012073984 bytes

64 heads, 32 sectors/track, 19085 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


Disk /dev/sdd doesn't contain a valid partition table

[root@node3 iscsi]#

[root@node3 iscsi]# partprobe /dev/sdc

[root@node3 iscsi]#


在跳板机 192.168.0.100

循环安装集群文件系统            (三个initiator 上 都要 # mount /dev/cdrom /media/cdrom/)

[root@steppingstone tgt]# alias ha='for I in {1..3};do'

[root@steppingstone tgt]#

[root@steppingstone tgt]# ha ssh node$I 'yum -y install gfs2-utils';done        #最后都安装完成了

image.png


三个initiator上都启动 # service cman start                 #service rgmanager start

在第一个initiator 192.168.0.45 上

[root@node1 ~]# cman_tool status

Version: 6.2.0

Config Version: 7

Cluster Name: tcluster

Cluster Id: 28212

Cluster Member: Yes

Cluster Generation: 132

Membership state: Cluster-Member

Nodes: 3

Expected votes: 3

Total votes: 3

Node votes: 1

Quorum: 2

Active subsystems: 8

Flags: Dirty

Ports Bound: 0 177

Node name: node1.magedu.com

Node ID: 1

Multicast addresses: 239.192.110.162

Node addresses: 192.168.0.45

[root@node1 ~]#

[root@node1 ~]# clustat        #都是 online 的

Cluster Status for tcluster @ Mon Feb 22 11:12:03 2021

Member Status: Quorate


 Member Name                             ID   Status

 ------ ----                             ---- ------

 node1.magedu.com                            1 Online, Local

 node2.magedu.com                            2 Online

 node3.magedu.com                            3 Online


[root@node1 ~]#

[root@node1 ~]# rpm -ql gfs2-utils

/etc/rc.d/init.d/gfs2

/sbin/fsck.gfs2

/sbin/gfs2_convert

/sbin/gfs2_edit

/sbin/gfs2_fsck

/sbin/gfs2_grow

/sbin/gfs2_jadd        #新增日志区域

/sbin/gfs2_quota

/sbin/gfs2_tool        #模式化工具,能够实现gfs2文件系统的众多功能的管理,比如调整性能参数,属性

/sbin/mkfs.gfs2        #格式化创建gfs2文件系统

/sbin/mount.gfs2        #挂载文件系统

/sbin/umount.gfs2        #卸载文件系统

/usr/share/man/man8/fsck.gfs2.8.gz

/usr/share/man/man8/gfs2.8.gz

/usr/share/man/man8/gfs2_convert.8.gz

/usr/share/man/man8/gfs2_edit.8.gz

/usr/share/man/man8/gfs2_fsck.8.gz

/usr/share/man/man8/gfs2_grow.8.gz

/usr/share/man/man8/gfs2_jadd.8.gz

/usr/share/man/man8/gfs2_mount.8.gz

/usr/share/man/man8/gfs2_quota.8.gz

/usr/share/man/man8/gfs2_tool.8.gz

/usr/share/man/man8/mkfs.gfs2.8.gz

/usr/share/man/man8/mount.gfs2.8.gz

[root@node1 ~]#



[root@node1 ~]# mkfs.gfs2 -h        (与  mkfs.ext3  mke2fs 的选项有所不同)

Usage:


mkfs.gfs2 [options] <device> [ block-count ]


Options:


  -b <bytes>       Filesystem block size    #块大小

  -c <MB>          Size of quota change file

  -D               Enable debugging code        # Debug 模式 显示详细调试信息

  -h               Print this help, then exit

  -J <MB>          Size of journals            # 指定日志区域的大小 ,单位是 MB ,(默认128M)

  -j <num>         Number of journals     # (必填项) 指定日志的数目 (一个集群文件系统可能被多个节点同时挂载,每一个节点都需要日志区域来实现它的文件管理修改操作,指定两个只能被两个节点挂载?不要指定太多,因为默认每个日志文件的大小是128M,)            #mke2fs -j 指定为日志文件系统的

  -O               Don't ask for confirmation

  -p <name>        Name of the locking protocol      #  (必填项) 锁协议的名称  (lock_dlm 分布式文件锁, 或者   lock_nolock,不使用锁) (若只被一个节点挂载了,就使用 lock_nolock 吧,,,,,,一般情况下 gfs2 比 ext3等文件系统慢,所以只有一个节点挂载的话,现实情况是没有人使用gfs2文件系统的吧 )

  -q               Don't print anything

  -r <MB>          Resource Group Size

  -t <name>        Name of the lock table        #  (必填项)  锁表的名称,用来表示某一个文件系统上的锁的持有情况的,格式为 clustername:locktablename    ,,clustername就是当前节点所在的集群名称,,locktablename可以自己任意取,不能与其它锁表名称相同,,,所以集群内部唯一的

  -u <MB>          Size of unlinked file

  -V               Print program version information, then exit

[root@node1 ~]#

image.png

image.png


在第一个节点 192.168.0.45 上

[root@node1 ~]#  mkfs.gfs2 -j 2 -p lock_dlm -t tcluster:mysqlstore /dev/sdc2 

 # -j 我们先指定两个日志文件吧      -p 锁协议   -t 锁表的名称 

 # 马哥说格式化成集群文件系统的速度是比较慢的,可能要等一分两分钟,,,但是我为什么觉得快

This will destroy any data on /dev/sdc2.


Are you sure you want to proceed? [y/n] y


Device:                    /dev/sdc2

Blocksize:                 4096

Device Size                9.31 GB (2441728 blocks)              # 当前大小

Filesystem Size:           9.31 GB (2441725 blocks)            # 当前大小

Journals:                  2            # 日志个数为2个

Resource Groups:           38

Locking Protocol:          "lock_dlm"        # 锁协议

Lock Table:                "tcluster:mysqlstore"        # 锁表的名称

UUID:                      08BE6C01-1550-D3CF-24AA-2D6EF70FD64B        #UUID


[root@node1 ~]#


[root@node1 ~]# gfs2_tool -h        # 看到很多子命令

Clear a flag on a inode

  gfs2_tool clearflag flag <filenames>


Do a GFS2 specific "df":

  gfs2_tool df <mountpoint>    # df 显示内容的


Freeze a GFS2 cluster:

  gfs2_tool freeze <mountpoint>


Print the current mount arguments of a mounted filesystem:

  gfs2_tool getargs <mountpoint>


Get tuneable parameters for a filesystem

  gfs2_tool gettune <mountpoint>


List the file system's journals:

  gfs2_tool journals <mountpoint>    # 显示日志个数的???


List filesystems:

  gfs2_tool list        #列出文件系统


Have GFS2 dump its lock state:

  gfs2_tool lockdump <mountpoint> [buffersize]


Provide arguments for next mount:

  gfs2_tool margs <mountarguments>


Tune a GFS2 superblock

  gfs2_tool sb <device> proto [newval]

  gfs2_tool sb <device> table [newval]

  gfs2_tool sb <device> ondisk [newval]

  gfs2_tool sb <device> multihost [newval]

  gfs2_tool sb <device> all


Set a flag on a inode

  gfs2_tool setflag flag <filenames>


Tune a running filesystem

  gfs2_tool settune <mountpoint> <parameter> <value>


Shrink a filesystem's inode cache:

  gfs2_tool shrink <mountpoint>


Unfreeze a GFS2 cluster:

  gfs2_tool unfreeze <mountpoint>


Print tool version information

  gfs2_tool version


Withdraw this machine from participating in a filesystem:

  gfs2_tool withdraw <mountpoint>

[root@node1 ~]#


[root@node1 ~]# gfs2_tool journals        # 指定要挂载的文件系统??????,现在还没有挂载,还不能查看

gfs2_tool: can't open root directory (null): Bad address

[root@node1 ~]#


[root@node1 ~]# gfs2_tool list        # 列出文件系统,现在还没有挂载,所以显示不出来

[root@node1 ~]#


[root@node1 ~]# mount /dev/sdc2 /mnt        #挂载下共享的文件系统,没指定文件系统的话,它会自己去找的 (-t gfs2 )

[root@node1 ~]#

[root@node1 ~]# ls /mnt        # 它是没有  lost+found 的

[root@node1 ~]# cd /mnt

[root@node1 mnt]# touch a.txt

[root@node1 mnt]# 



在第二个节点 192.168.0.55 上

[root@node2 ~]# 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        2610    20860402+  8e  Linux LVM


Disk /dev/sdb: 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/sdb1               1        2610    20964793+   5  Extended

/dev/sdb5               1         200     1606437   8e  Linux LVM

/dev/sdb6             201         323      987966   83  Linux


Disk /dev/sdd: 50.0 GB, 50009637888 bytes

64 heads, 32 sectors/track, 47692 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


   Device Boot      Start         End      Blocks   Id  System

/dev/sdd1               1        1908     1953776   83  Linux

/dev/sdd2            1909       11446     9766912   83  Linux


Disk /dev/sde: 20.0 GB, 20012073984 bytes

64 heads, 32 sectors/track, 19085 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


Disk /dev/sde doesn't contain a valid partition table

[root@node2 ~]#

[root@node2 ~]# mount -t gfs2 /dev/sdd2 /mnt

[root@node2 ~]#

[root@node2 ~]# ls /mnt        #看到 a.txt

a.txt

[root@node2 ~]# cd /mnt

[root@node2 mnt]# ls

a.txt

[root@node2 mnt]# touch b.txt

[root@node2 mnt]#


在第一个节点 192.168.0.45 上

[root@node1 mnt]# ls        #可看到 b.txt

a.txt  b.txt

[root@node1 mnt]#


集群文件系统,创建一个文件,会立即同步到磁盘上,而且会通知其它节点


在第三个节点 192.168.0.65 上

[root@node3 iscsi]# 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        2610    20860402+  8e  Linux LVM


Disk /dev/sdb: 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/sdb1               1        2610    20964793+   5  Extended

/dev/sdb5               1         200     1606437   8e  Linux LVM

/dev/sdb6             201         323      987966   83  Linux


Disk /dev/sdc: 50.0 GB, 50009637888 bytes

64 heads, 32 sectors/track, 47692 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


   Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1        1908     1953776   83  Linux

/dev/sdc2            1909       11446     9766912   83  Linux


Disk /dev/sdd: 20.0 GB, 20012073984 bytes

64 heads, 32 sectors/track, 19085 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes


Disk /dev/sdd doesn't contain a valid partition table

[root@node3 iscsi]#

[root@node3 iscsi]# mount -t gfs2 /dev/sdc2 /mnt        #报错了,没有空闲的日志了

/sbin/mount.gfs2: Too many nodes mounting filesystem, no free journals

[root@node3 iscsi]#


在第一个节点 192.168.0.45 上

[root@node1 mnt]# gfs2_jadd -h

Usage:


gfs2_jadd [options] /path/to/filesystem    #挂载的文件系统,必须要挂载以后才能操作的


Options:


  -c <MB>           Size of quota change file

  -D                Enable debugging code

  -h                Print this help, then exit

  -J <MB>           Size of journals

  -j <num>          Number of journals    #日志的数目

  -q                Don't print anything

  -V                Print program version information, then exit

[root@node1 mnt]#

[root@node1 mnt]# gfs2_tool journals

gfs2_tool: can't open root directory (null): Bad address

[root@node1 mnt]# gfs2_tool journals /mnt

journal1 - 128MB

journal0 - 128MB

2 journal(s) found.

[root@node1 mnt]#

[root@node1 mnt]# gfs2_tool journals /dev/sdc2    #或者这样

journal1 - 128MB

journal0 - 128MB

2 journal(s) found.

[root@node1 mnt]#


马哥那边集群文件系统中的命令返回的比较慢,,我这边好像返回的比较快

[root@node1 mnt]# gfs2_jadd -j 3 /dev/sdc2

Filesystem:            /mnt

Old Journals           2

New Journals           5        # -j 为 3 时,它就是5个了 ,,,所以这里应该为 -j 1 ,,,,,,jadd表示加几个

[root@node1 mnt]#


我们需要3个,现在5个,,多一个,就是128M的空间,,,一般我们要求,集群文件系统性能方面的考虑,它所支持的节点数不能超过16个,,超过差,性能特差


在第三个节点 192.168.0.65 上

[root@node3 iscsi]# mount -t gfs2 /dev/sdc2 /mnt        #可以挂载了

[root@node3 iscsi]#

[root@node3 iscsi]# cd /mnt

[root@node3 mnt]# ls        # a.txt  b.txt 两个文件都有了

a.txt  b.txt

[root@node3 mnt]#

[root@node3 mnt]# touch c.txt

[root@node3 mnt]#


在第二个节点 192.168.0.55 上

[root@node2 mnt]# pwd

/mnt

[root@node2 mnt]# ls        #看到了c.txt

a.txt  b.txt  c.txt

[root@node2 mnt]#


在第一个节点 192.168.0.45 上

[root@node1 mnt]# pwd

/mnt

[root@node1 mnt]# ls       #也看到了c.txt

a.txt  b.txt  c.txt

[root@node1 mnt]#


下一节课讲集群逻辑卷

普通分类: