Chinaunix首页 | 论坛 | 博客
  • 博客访问: 339818
  • 博文数量: 58
  • 博客积分: 30
  • 博客等级: 民兵
  • 技术积分: 543
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-25 01:47
个人简介

我们都是没伞的孩子,所以我只能靠自己。

文章分类

全部博文(58)

文章存档

2019年(2)

2018年(1)

2017年(1)

2016年(2)

2015年(22)

2014年(20)

2013年(10)

我的朋友

分类: 服务器与存储

2015-05-12 16:13:59

一、资源
    两台主机IP地址和计算机名分别为:
            192.168.20.178    iscsi-1
            192.168.20.179    iscsi-2
二、存储设备分区
      用GTP分区,需安装parted,怎么分区请自己百度
     yum -y install parted
     /dev/sdb1 分2T
     /dev/sdb2 分1T
三、安装DRBD
     #添加yum源  
       rpm -Uvh
       yum -y install drbd84-utils kmod-drbd84
      双方的ip地址和计算机名添加到 /etc/hosts
cat > /etc/drbd.d/global_common.conf << EOF
 DRBD is the result of over a decade of development by LINBIT.
# In case you need professional services for DRBD or have
# feature requests visit


global {
     usage-count yes;
     # minor-count dialog-refresh disable-ip-verification
}


common {
     handlers {
          # These are EXAMPLE handlers only.
          # They may have severe implications,
          # like hard resetting the node under certain circumstances.
          # Be careful when chosing your poison.


          # pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
          # pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
          # local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
          # fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
          # split-brain "/usr/lib/drbd/notify-split-brain.sh root";
          # out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
          # before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k";
          # after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
     }


     startup {
          degr-wfc-timeout 120; #连接超时时间
          # wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb
     }


     options {
          on-no-data-accessible suspend-io;
          # cpu-mask on-no-data-accessible
     }


     disk {
          on-io-error detach; #磁盘错误停止同步
          # size on-io-error fencing disk-barrier disk-flushes
          # disk-drain md-flushes resync-rate resync-after al-extents
                # c-plan-ahead c-delay-target c-fill-target c-max-rate
                # c-min-rate disk-timeout
     }


     net {
          protocol C; #确认方式  A:数据一旦写入磁盘并发送到网络中就认为完成了写入操;作B:收到接收确认就认为完成了写入操作;C:收到写入确认就认为完成了写入操作。
          # protocol timeout max-epoch-size max-buffers unplug-watermark
          # connect-int ping-int sndbuf-size rcvbuf-size ko-count
          # allow-two-primaries cram-hmac-alg shared-secret after-sb-0pri
          # after-sb-1pri after-sb-2pri always-asbp rr-conflict
          # ping-timeout data-integrity-alg tcp-cork on-congestion
          # congestion-fill congestion-extents csums-alg verify-alg
          # use-rle
     }
     syncer {
          rate 1000M; #传输速度
     }
}
EOF
cat > /etc/drbd.d/share.res << EOF
resource cs1  {
      volume 1 {
          device /dev/drbd1;
          disk /dev/sdb1;
          meta-disk internal;
     }
     on iscsi-1 {
          address    $iscsi_1_ip:7781;
     }
     on iscsi-2 {
          address    $iscsi_2_ip:7781;
     }
}


resource cs2 {
     volume 2 {
          device /dev/drbd2;
          disk /dev/sdb2;
          meta-disk internal;
     }
     on iscsi-1 {
          address    $iscsi_1_ip:7782;
     }
     on iscsi-2 {
          address    $iscsi_2_ip:7782;
     }
}
EOF

由于安装drbd过程中会更新kernel,所有最好重启系统再初始资源
#Initialize resource
dd if=/dev/zero of=/dev/sdb1 bs=1M count=100
drbdadm create-md cs1
drbdadm create-md cs2

drbdadm up cs1
drbdadm up cs2


保持两台机器设置一样,到此DRBD安装完成,随便设置一台为primary
这里设置192.168.20.178为primary
drbdadm primary all --force
分别启动两台机器的drbd服务
/etc/init.d/drbd start     需要关闭IPtables
查看状态,/etc/init.d/drbd status  会开始同步数据,完成后如下

[root@iscsi-1 ~]# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.4.6 (api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00
m:res  cs         ro                 ds                 p  mounted  fstype
1:cs1  Connected  Primary/Secondary  UpToDate/UpToDate  C
2:cs2  Connected  Primary/Secondary  UpToDate/UpToDate  C
红色表示数据是同步的

四、安装ISCSI
yum install scsi-target-utils
在主上启动ISCSI,客户端即可连接,我们用的是windows 2008R自带的有ISCSI连接工具
/etc/init.d/tgtd start

以下是安装脚本

点击(此处)折叠或打开

  1. #! /bin/bash
  2. # 系统环境 CentOS6.5
  3. ######=======安装前先修改计算机名=========########
  4. # iscsi-1 192.168.20.178
  5. # iscsi-2 192.168.20.179
  6. read -p "Please master iscsi HOSTNAME": iscsi_1_hostname
  7. read -p "Please master iscsi IP": iscsi_1_ip
  8. read -p "Please slave iscsi HOSTNAME": iscsi_2_hostname
  9. read -p "Please slave iscsi IP": iscsi_2_ip
  10. #添加yum源
  11. rpm -Uvh
  12. yum -y install drbd84-utils kmod-drbd84
  13. if ! grep iscsi /etc/hosts; then
  14. echo "$iscsi_1_ip $iscsi_1_hostname" >> /etc/hosts
  15. echo "$iscsi_2_ip $iscsi_2_hostname" >> /etc/hosts
  16. fi
  17. #configur /etc/drbd.d/global_common.conf
  18. cp /etc/drbd.d/global_common.conf /etc/drbd.d/global_common.conf.default
  19. cat > /etc/drbd.d/global_common.conf << EOF
  20. # DRBD is the result of over a decade of development by LINBIT.
  21. # In case you need professional services for DRBD or have
  22. # feature requests visit
  23. global {
  24. usage-count yes;
  25. # minor-count dialog-refresh disable-ip-verification
  26. }
  27. common {
  28. handlers {
  29. # These are EXAMPLE handlers only.
  30. # They may have severe implications,
  31. # like hard resetting the node under certain circumstances.
  32. # Be careful when chosing your poison.
  33. # pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
  34. # pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
  35. # local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
  36. # fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
  37. # split-brain "/usr/lib/drbd/notify-split-brain.sh root";
  38. # out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
  39. # before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k";
  40. # after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
  41. }
  42. startup {
  43. degr-wfc-timeout 120; #连接超时时间
  44. # wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb
  45. }
  46. options {
  47. on-no-data-accessible suspend-io;
  48. # cpu-mask on-no-data-accessible
  49. }
  50. disk {
  51. on-io-error detach; #磁盘错误停止同步
  52. # size on-io-error fencing disk-barrier disk-flushes
  53. # disk-drain md-flushes resync-rate resync-after al-extents
  54. # c-plan-ahead c-delay-target c-fill-target c-max-rate
  55. # c-min-rate disk-timeout
  56. }
  57. net {
  58. protocol C; #确认方式 A:数据一旦写入磁盘并发送到网络中就认为完成了写入操;作B:收到接收确认就认为完成了写入操作;C:收到写入确认就认为完成了写入操作。
  59. # protocol timeout max-epoch-size max-buffers unplug-watermark
  60. # connect-int ping-int sndbuf-size rcvbuf-size ko-count
  61. # allow-two-primaries cram-hmac-alg shared-secret after-sb-0pri
  62. # after-sb-1pri after-sb-2pri always-asbp rr-conflict
  63. # ping-timeout data-integrity-alg tcp-cork on-congestion
  64. # congestion-fill congestion-extents csums-alg verify-alg
  65. # use-rle
  66. }
  67. syncer {
  68. rate 1000M; #传输速度
  69. }
  70. }
  71. EOF
  72. cat > /etc/drbd.d/share.res << EOF
  73. resource cs1 {
  74. volume 1 {
  75. device /dev/drbd1;
  76. disk /dev/sdb1;
  77. meta-disk internal;
  78. }
  79. on $iscsi_1_hostname {
  80. address $iscsi_1_ip:7781;
  81. }
  82. on $iscsi_2_hostname {
  83. address $iscsi_2_ip:7781;
  84. }
  85. }
  86. resource cs2 {
  87. volume 2 {
  88. device /dev/drbd2;
  89. disk /dev/sdb2;
  90. meta-disk internal;
  91. }
  92. on $iscsi_1_hostname {
  93. address $iscsi_1_ip:7782;
  94. }
  95. on $iscsi_2_hostname {
  96. address $iscsi_2_ip:7782;
  97. }
  98. }
  99. EOF
  100. #Initialize resource
  101. dd if=/dev/zero of=/dev/sdb1 bs=1M count=100
  102. drbdadm create-md cs1
  103. drbdadm create-md cs2
  104. drbdadm up cs1
  105. drbdadm up cs2
  106. if hostname | grep iscsi-1 > /dev/null;then
  107. drbdadm primary all
  108. fi
  109. #Install ISCSI
  110. if ! rpm -qa | grep scsi-target-utils; then
  111. yum install scsi-target-utils
  112. cat >> /etc/tgt/targets.conf << EOF
  113. #iqn.年-月.反写的域名:iscsi目标名,可以自定义名字
  114. backing-store /dev/drbd1 #iscsi使用的设备名,支持很多种,可以在配置多个
  115. backing-store /dev/drbd2
  116. write-cache off #关闭写缓存,安全第一
  117. #initiator-address 192.168.20.176 #允许访问的IP,可以配置多个 或者整个网段
  118. EOF
  119. fi







阅读(1359) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~