centos6设置单节点iscsi

192.168.10.15  共享磁盘机器(只分区,不要格式化)
192.168.10.25  iscsi1
192.168.10.30  iscsi2

10.15
 ll /dev/sd*
 fdisk -l
 fdisk /dev/sdb(新添加的硬盘)

yum install -y scsi*

vim /etc/tgt/targets.conf

    backing-store /dev/sdb1  (共享磁盘路径)


service tgtd start

chkconfig tgtd on

10.25和10.30
yum install -y iscsi*

iscsiadm -m discovery -t st -p 192.168.10.15

iscsiadm -m node -T iqn.2018-06.com.example.DNS:sdb1.2G -p 192.168.10.15 -l

 fdisk /dev/sdb

 mkfs.ext4 /dev/sdb1

 mount /dev/sdb1 /mnt/
 *(以上单节点的iscsi共享完成了,但有时我们的需求是,两个机器挂同一块共享盘,两台机器的修改也能同步,解决方法-----集群)

 集群解决多节点
 10.25和10.30
 vim /etc/hosts
 192.168.10.25 iscsi1
192.168.10.30 iscsi2

10.30
yum install -y ricci

service ricci start

passwd ricci

10.25
yum install -y ricci luci

service ricci start

passwd ricci

service luci start

centos6+centos7 iscsi存储单节点+多节点_第1张图片

10.25
clustat(查看集群状态)

cman_tool status

Version: 6.2.0
Config Version: 1
Cluster Name: cluster-0
Cluster Id: 27705
Cluster Member: Yes
Cluster Generation: 16
Membership state: Cluster-Member
Nodes: 2
Expected votes: 1
Total votes: 2
Node votes: 1
Quorum: 1
Active subsystems: 9
Flags: 2node
Ports Bound: 0 11 177
Node name: iscsi1
Node ID: 1
Multicast addresses: 239.192.108.165(组播地址)
Node addresses: 192.168.10.25

service rgmanager stop

service clvmd stop

service cman restart(查看cman的启动情况,以上两个依赖服务下关闭,只是看效果)

service rgmanager start

service clvmd start

mkfs.gfs2 -p lock_dlm -t cluster-0:testlock -j 2 /dev/sdb1(cluster-0不能乱写是集群名,-j 2 给两台机器分配日志)

10.25和10.30
mount /dev/sdb1 /mnt/ (任意一台机器修改,都会同步)
*(以上centos6的单节点多节点iscsi配置完成)

cenos7 iscsi单节点

服务器

yum -y install targetcli
//创建目录
mkdir /iscsi_disks

//进入进入管理控制台
targetcli
cd backstores/fileio 
create disk01 /iscsi_disks/disk01.img 2G

//创建目标
cd /iscsi
create iqn.2018-01.iewb.net:storage01
cd iqn.2018-01.iewb.net:storage01/tpg1/luns 
create /backstores/fileio/disk01

//创建acls
cd ../acls 
create iqn.2018-01.iewb.net:storage01

//设置ACL(客户端连接的IQN)
cd iqn.2018-01.iewb.net:storage01
set auth userid=username
set auth password=password
exit

//查看
ss -napt | grep 3260
systemctl start target
systemctl enable target
firewall-cmd --add-port 4260/tcp --permanent

客户端

yum -y install iscsi-initiator-utils 
vi /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2018-01.iewb.net:storage01    
vi /etc/iscsi/iscsid.conf
//取消以下注释:
node.session.auth.authmethod = CHAP
node.session.auth.username = username
node.session.auth.password = password
systemctl restart iscsid
systemctl restart iscsi
//发现target
iscsiadm -m discovery -t sendtargets -p 172.16.88.21
iscsiadm -m node -o show
//登录target
iscsiadm -m node --login
//确认连接状态
iscsiadm -m session -o show
//确认分区状况
cat /proc/partitions
//新建分区
fdisk /dev/sdb -n-p
//格式化分区
mkfs.ext4 /dev/sdb1
//挂载分区
mkdir /data
mount /dev/sdb1 /data
在/etc/fstab中添加
/dev/sdb1       /data       ext4     _netdev   0   0
命令tune2fs -l /dev/sdb可以查到文件系统的UUID
在/etc/fstab中添加  
UUID=xxxxxxx  /data ext4   _netdev 0  0  替换掉原来的那行

大容量磁盘格式化

parted /dev/sdb
mklabel gpt       //将MBR磁盘格式化为GPT
mkpart primary 0% 100%    //将整块磁盘分成一个分区,0是分区开始位置,100%是分区结束位置。相同的命令为:mkpart primary 0-1
mkfs.ext4  /dev/sdb1

创建raid备忘:

mdadm -E /dev/sd[b-c]
# mdadm --create /dev/md0 --level=mirror --raid-devices=2 /dev/sd[b-c]1
# cat /proc/mdstat
# mdadm -E /dev/sd[b-c]1
# mdadm --detail /dev/md0
mdadm --detail --scan --verbose >> /etc/mdadm.conf

centos7 iscsi多节点
1
2