手机版
你好,游客 登录 注册
背景:
阅读新闻

构建LVS+Keepalived+iSCSI集群(DR)

[日期:2012-08-29] 来源:51cto  作者:huyuedong [字体:大 中 小]

四、配置iSCSI存储服务器
(1)安装服务端所需软件包

# yum -y install scsi-target-utils

 

(2)准备存储设备

创建一个LVM逻辑卷

# pvcreate /dev/sdb5

# vgcreate vol0 /dev/sdb5

# lvcreate -L 500M -n lv-host4 vol0

# lvscan

ACTIVE '/dev/vol0/lv-host4' [500.00 MiB] inherit

创建一个软RAID

# mdadm -Cv /dev/md0 -a yes -n3 -l5 /dev/sdb[678]

# mdadm -Q /dev/md0

# mdadm -D -s >> /etc/mdadm.conf

# cat /etc/mdadm.conf

ARRAY /dev/md0 metadata=1.2 spares=1 name=host1.zc.com:0

UUID=a0093bb0:d52fd73f:fb9469f3:0fbee1f2

(3)启动iscsi服务,设置开启启动

# /etc/init.d/tgtd start

# netstat -anpt | grep tgt

tcp 0 0 0.0.0.0:3260 0.0.0.0:*

LISTEN 1850/tgtd

tcp 0 0 :::3260 :::*

LISTEN 1850/tgtd

[root@host1 ~]# chkconfig tgtd on

(4)创建ISCSI对象(Target)

# tgtadm -L iscsi -o new -m target -t 1 -T iqn.2012-06.com.dong.www:lvm

# tgtadm -L iscsi -o new -m target -t 2 -T iqn.2012-06.com.dong.www:raid

# tgtadm -L iscsi -o show -m target

(5)为客户机分配存储空间(LUN)

# tgtadm --lld iscsi -o new -m logicalunit -t 1 -l 1 -b

/dev/vol0/lv-host4

# tgtadm --lld iscsi -o new -m logicalunit -t 2 -l 1 -b /dev/md0

# tgtadm --lld iscsi -o bind -m target -t 1 -I 192.168.10.3

# tgtadm --lld iscsi -o bind -m target -t 2 -I 192.168.10.4

# tgtadm --lld iscsi -o bind -m target -t 1 -I 192.168.10.3

# tgtadm --lld iscsi -o bind -m target -t 2 -I 192.168.10.4

# tgtadm --lld iscsi -o show -m target

 

(6)保存target和LUN配置

# vim /etc/tgt/targets.conf                  #配置永久生效

<target iqn.2012-06.com.dong.www:lvm>    #最后添加以下内容

backing-store /dev/vol0/lv-host21

initiator-address 192.168.10.5

</target>

<target iqn.2012-06.com.dong.www:raid>

backing-store /dev/md0

initiator-address 192.168.10.5

</target>

五、节点配置
(1)分别在2台RealServer(节点)上面编写脚本

[root@host3 ~]# vim /etc/init.d/realserver.sh

#!/bin/bash

VIP=192.168.10.100

startrs()

{

echo "start LVS of REALServer"

/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up

/sbin/route add -host $VIP dev lo:0

echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce

echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

}

stoprs()

{

/sbin/ifconfig lo:0 down

echo "close LVS Directorserver"

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce

echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce

}

# ============ Main ===========

case $1 in

"start")

startrs;;

"stop")

stoprs;;

"*")

echo "Usage $0 {start|stop}"

exit 1

esac

 
 

 

 

[root@host3 ~]# chmod +x /etc/init.d/realserver.sh

[root@host3 ~]#/etc/init.d/realserver.sh start

 

(2)挂载存储客户端

安装iSCSI客户端相关软件

# yum -y install iscsi-initiator-utils lsscsi

# /etc/init.d/iscsi restart

# chkconfig iscsi on

发现ISCSI设备

# iscsiadm -m discovery -t sendtargets -p 192.168.10.5

192.168.10.5:3260,1 iqn.2012-06.com.dong.www:lvm

192.168.10.5:3260,1 iqn.2012-06.com.dong.www:raid

查看现有分区

# fdisk -cul

连接ISCSI设备

# iscsiadm -m node -T iqn.2012-06.com.dong.www:lvm --login

# iscsiadm -m node -T iqn.2012-06.com.dong.www:raid --login

查看分区

# lsscsi

[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0

[2:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda

[3:0:0:0] storage IET Controller 0001 -

[3:0:0:1] disk IET VIRTUAL-DISK 0001 /dev/sdb

[4:0:0:0] storage IET Controller 0001 -

[4:0:0:1] disk IET VIRTUAL-DISK 0001 /dev/sdc

# fdisk -cul

……

Disk /dev/sdb: 524 MB, 524288000 bytes

17 heads, 59 sectors/track, 1020 cylinders, total 1024000 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

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

Disk /dev/sdc: 2146 MB, 2146435072 bytes

67 heads, 62 sectors/track, 1009 cylinders, total 4192256 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

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

将/dev/sdc划分并使用

# partprobe /dev/sdc

# fdisk -cu /dev/sdc

# fdisk -cul /dev/sdc

Disk /dev/sdc: 2146 MB, 2146435072 bytes

15 heads, 2 sectors/track, 139741 cylinders, total 4192256 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x8338546c

Device Boot Start End Blocks Id System

/dev/sdc1 2048 4192255 2095104 83 Linux

# mkfs.ext4 /dev/sdc1

# mkdir /opt/data

# mount /dev/sdc1 /opt/data/     #临时挂载,重启失效

# cat /etc/mtab

/dev/sda2 / ext4 rw 0 0

proc /proc proc rw 0 0

sysfs /sys sysfs rw 0 0

devpts /dev/pts devpts rw,gid=5,mode=620 0 0

tmpfs /dev/shm tmpfs rw 0 0

/dev/sda1 /boot ext4 rw 0 0

/dev/sda3 /data ext4 rw 0 0

none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0

/dev/sdc1 /opt/data ext4 rw 0 0

# blkid /dev/sdb1 >> /etc/fstab    #挂载永久生效

# vim /etc/fstab

...... //省略部分信息

UUID="78e6d91e-10bf-4180-b308-4259145853d6" /var/www/html/ ext4

defaults,_netdev 0 0

 

(3)在2台RealServer(节点)中分别配置HTTP并启动realserver.sh

[root@host3 ~]# yum -y install httpd

 

[root@host3 ~]# cd /var/www/html/

 

[root@host3 html]# echo "192.168.10.3" > index.html

 

[root@host3 html]# cat index.html

192.168.10.3

 

[root@host4 html]# cat index.html         #两台节点的配置除了网页不一样(为了更明显的看到测试效果),其他都一样

192.168.10.4

 

[root@host3 ~]# /etc/init.d/realserver.sh start

 

[root@host3 ~]# echo "/etc/init.d/realserver.sh start" >> /etc/rc.local

 

[root@host3 html]# /etc/init.d/httpd start

 

[root@host3 html]# chkconfig httpd on

 

(4)给2台节点添加一条路由记录,将访问VIP的数据限制在本地以避免通信紊乱

[root@host4 ~]# route add -host 192.168.10.100 dev lo:0

 

[root@host4 ~]# echo "/sbin/route add -host 192.168.10.100 dev lo:0" >> /etc/rc.local

 

另一台的配置过程一样,过程略

 

六、测试
在两台调度器上分别启动Keepalived

[root@host1 ~]# /etc/init.d/keepalived restart

 

[root@host1 ~]# ipvsadm -Ln

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

TCP  192.168.10.100:80 rr persistent 50

  -> 192.168.10.3:80              Route   1      0          0        

  -> 192.168.10.4:80              Route   1      0          0

 

使用客户机访问<http://192.168.10.100>,使主调度器挂掉看是否能够访问

使用客户机访问<http://192.168.10.100>,使一个节点挂掉看是否能够访问

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款