day5 RHCE

19 、配置 iSCSI 服务端  (***先做这个题目**,挂载重启,机器会挂掉)

配置server0提供一个iSCSI服务磁盘名为iqn.2014-11.com.example:server0,并符合下列要求:
  服务端口为3260
  使用iscsi_store作为其后端卷,其大小为3G(题意含糊,其实iscsi_store是一个逻辑卷,需要自己建立)
  此服务只能被desktop0.example.com访问。

[root@server0 ~]# yum install targetcli.noarch -y

[root@server0 ~]# systemctl enable target
[root@server0 ~]# systemctl restart target
[root@server0 ~]# systemctl status target.service 

[root@server0 ~]# firewall-cmd --permanent --add-port=3260/tcp
[root@server0 ~]# firewall-cmd --reload 


[root@server0 ~]# ll /dev/sd*
[root@server0 ~]# fdisk /dev/sdb 
p  n  p  +4G 
   p  t  8e  p  w
[root@server0 ~]# partprobe 

[root@server0 ~]# ll /dev/sd*
[root@server0 ~]# pvcreate /dev/sdb1
[root@server0 ~]# vgcreate vg1 /dev/sdb1
[root@server0 ~]# lvcreate -L 3G vg1 -n iscsi_store      #iscsi_store作为其后端卷
[root@server0 ~]# lvs

  

[root@server0 ~]# targetcli 
/> 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]

  

/> cd backstores/block 
/backstores/block> ls
/backstores/block> create name=LUN0 dev=/dev/iscsi_vg/iscsi_store     #定义了一个本地的块设备
/backstores/block> ls 


/backstores/block> cd /iscsi 
/iscsi> create iqn.2014-11.com.example:server0               #定义target 的入口
/iscsi> ls

/iscsi> cd iqn.2014-11.com.example:server0/tpg1
/iscsi/iqn.20...:server0/tpg1> ls

/iscsi/iqn.20...:server0/tpg1> cd acls 
/iscsi/iqn.20...er0/tpg1/acls> create iqn.2014-11.com.example:desktop0   #允许该名字的客户端访问本iscsi 的tagert

/iscsi/iqn.20...:server0/tpg1> cd luns 
/iscsi/iqn.20...er0/tpg1/luns> create /backstores/block/LUN0     # 把定义好了的块设备通过该target 共享出去

/iscsi/iqn.20...:server0/tpg1> cd portals     
/iscsi/iqn.20.../tpg1/portals> create ip_address=172.25.0.11 ip_port=3260


/iscsi/iqn.20...:server0/tpg1> ls

/iscsi/iqn.20...:server0/tpg1> set attribute authentication=0     #该tgp 关闭帐号验证
/iscsi/iqn.20...:server0/tpg1> set attribute generate_node_acls=0    #该tgp 使用自定义的acl 实现节点访问限制
/> saveconfig 
/> exit

 

重启服务,添加防火墙
[root@server0 ~]# firewall-cmd --permanent --add-port=3260/tcp
[root@server0 ~]# firewall-cmd --reload 

[root@server0 ~]# systemctl enable target.service 
[root@server0 ~]# systemctl restart target.service 
[root@server0 ~]# systemctl status target.service

  

[root@server0 ~]# targetcli 
/> ls
o- / ......................................................................................................................... [...]
o- backstores .............................................................................................................. [...]
| o- block .................................................................................................. [Storage Objects: 1]
| | o- LUN0 ......................................................... [/dev/iscsi_vg/iscsi_store (3.0GiB) write-thru activated]
| o- fileio ................................................................................................. [Storage Objects: 0]
| o- pscsi .................................................................................................. [Storage Objects: 0]
| o- ramdisk ................................................................................................ [Storage Objects: 0]
o- iscsi ............................................................................................................ [Targets: 1]
| o- iqn.2014-11.com.example:server0 ................................................................................... [TPGs: 1]
| o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
| o- acls .......................................................................................................... [ACLs: 1]
| | o- iqn.2014-11.com.example:desktop0 ..................................................................... [Mapped LUNs: 1]
| | o- mapped_lun0 .................................................................................. [lun0 block/LUN0 (rw)]
| o- luns .......................................................................................................... [LUNs: 1]
| | o- lun0 ...................................................................... [block/LUN0 (/dev/iscsi_vg/iscsi_store)]
| o- portals .................................................................................................... [Portals: 1]
| o- 0.0.0.0:3260 ..................................................................................................... [OK]
o- loopback ......................................................................................................... [Targets: 0]

  

 

20 、配置 iSCSI 的客户端

配置desktop0使其能连接在server0上提供的iqn.2014-11.com.example:server0并符合以下要求:
  iSCSI设备在系统启动的时候自动加载
  块设备iSCSI上包含一个大小为2100 MiB的分区,并格式化为ext4。
  此分区挂载在/mnt/data上同时在系统启动的期间自动挂载。

[root@desktop0 ~]# yum install iscsi-initiator-utils.i686 -y     #安装客户端软件包

[root@desktop0 ~]# vim /etc/iscsi/initiatorname.iscsi       #配置iscsi 客户端的名字
InitiatorName=iqn.2014-11.com.example:desktop0


[root@desktop0 ~]# systemctl enable iscsi
[root@desktop0 ~]# systemctl restart iscsi
[root@desktop0 ~]# systemctl status iscsi

[root@desktop0 ~]# systemctl enable iscsid
[root@desktop0 ~]# systemctl restart iscsid
[root@desktop0 ~]# systemctl status iscsid


[root@desktop0 ~]# iscsiadm --help
iscsiadm -m discovery [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -Dl ] ]

[root@desktop0 ~]# iscsiadm -m discovery -t st -p 172.25.0.11      #发现target
[root@desktop0 ~]# iscsiadm -m discovery -t st -p 172.25.0.11 -l   #登录target


[root@desktop0 ~]# yum install lsscsi.x86_64  -y
[root@desktop0 ~]# lsscsi    #查看
[33:0:0:0]   disk    LIO-ORG  LUN0             4.0   /dev/sdc 



#分区格式化,开机挂载
[root@desktop0 ~]# fdisk /dev/sdc
p n  p  +2100M  w
[root@desktop0 ~]# partprobe 
[root@desktop0 ~]# ll /dev/sd*
[root@desktop0 ~]# mkfs.ext4 /dev/sdc1

[root@desktop0 ~]# mkdir -pv /mnt/data
[root@desktop0 ~]# mount /dev/sdc1 /mnt/data
[root@desktop0 ~]# mount -a
[root@desktop0 ~]# df -h

[root@desktop0 ~]# blkid
[root@desktop0 ~]# vim /etc/fstab   #挂载的时候需要添加_netdev参数
UUID=f5c9e6ae-c0b0-401d-beb0-96da19cd23dc /mnt/data     ext4    defaults,_netdev        0 0     注意:添加_netdev,不然机子启动不起来
[root@desktop0 ~]# mount -a [root@desktop0 ~]# df -h

[root@desktop0 ~]# shutdown    关机(等待一会)!! 不要重启(重启机子就崩溃了,手动开机) (关机:1011错误)

  

posted @ 2017-10-08 11:04  venicid  阅读(329)  评论(0编辑  收藏  举报