환경개요
서버 대수 : 2대
구성 방식 : Master & Standby 구성
OS : centos7
Master서버
IP : 192.168.0.177
hostname : node1
drbd 사용장치 : /dev/sdb1
Standby서버
IP : 192.168.0.178
hostname : node2
drbd 사용장치 : /dev/sdb1
- elrepo 저장소 등록
Import the public key:
rpm –import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
To install ELRepo for RHEL-7, SL-7 or CentOS-7:
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
2. drbd 패키지 설치
yum install drbd84-utils kmod-drbd84
사실 yum install drbd 라고 명령어를 내리면 drbd84-utils 를 자동으로 인지하고 설치한다.
3. selinux 끄기
파일 : /etc/sysconfig/selinux
SELINUX=diabled
리부팅을 해도 되고 ”setenforce 0” 명령을 실행해도 됨
4. 호스트이름 설정
Master :
hostname node1
Standby :
hostname node2
5. /etc/hosts 파일 설정 (Master, Standby 모두 동일)
192.168.0.177 node1 192.168.0.178 node2
6. 파티션 생성
[root@node1]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-4194303, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): Using default value 4194303 Partition 1 of type Linux and of size 2 GiB is set Command (m for help): wq The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@node1]# fdisk -l /dev/sdb Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 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 label type: dos Disk identifier: 0xc4ea1609 Device Boot Start End Blocks Id System /dev/sdb1 2048 4194303 2096128 83 Linux
7. 설정파일 생성 (Master, Standby 모두 동일)
파일위치 : /etc/drbd.d/drbddata
resource drbddata { startup { wfc-timeout 30; degr-wfc-timeout 30; } net { cram-hmac-alg sha1; shared-secret sync_disk; } syncer { rate 100M; al-extents 257; on-no-data-accessible io-error; } on node1 { device /dev/drbd0; disk /dev/sdb1; address 192.168.0.177:7788; meta-disk internal; } on node2 { device /dev/drbd0; disk /dev/sdb1; address 192.168.0.178:7788; meta-disk internal; } }
8. 메타데이터 생성 (Master, Standby 모두 동일)
drbdadm create-md drbddata
대략 이런 결과…
[root@node1]# drbdadm create-md drbddata md_offset 2146430976 al_offset 2146398208 bm_offset 2146332672 Found ext3 filesystem 2096028 kB data area apparently used 2096028 kB left usable by current configuration Even though it looks like this would place the new meta data into unused space, you still need to confirm, as this is only a guess. Do you want to proceed? [need to type 'yes' to confirm] yes initializing activity log NOT initializing bitmap Writing meta data... New drbd meta data block successfully created. success
9. drbd 구동
Master 서버에서 먼저 drbd를 구동후 완료될때 까지 기다리자.
구동이 완료되고 난후 /proc/drbd 를 확인하여 상태를 본다.
[root@node1]# systemctl start drbd [root@node1]# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101) GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R7, 2015-04-10 05:13:52 0: cs:WFConnection ro:Secondary/Unknown ds:Inconsistent/DUnknown C r----s ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:2096028
여기 까지 확인했다면 Standby 서버에서도 drbd를 구동한다.
구동이 완료되고 난후 다시한번 /proc/drbd 를 확인하여 상태를 본다.
[root@node1]# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101) GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R7, 2015-04-10 05:13:52 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r----- ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:2096028
[root@node2]# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101) GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R7, 2015-04-10 05:13:52 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r----- ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:2096028
10. Master 설정 (Master 서버에서만 실행)
[root@node1]# drbdadm primary --force drbddata [root@node1]# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101) GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R7, 2015-04-10 05:13:52 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----- ns:74224 nr:0 dw:0 dr:74952 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:2021804 [>....................] sync'ed: 3.8% (2021804/2096028)K finish: 0:01:21 speed: 24,740 (24,740) K/sec
drbdadm -- --overwrite-data-of-peer primary drbddata
11. 파티션 마운트
[root@node1 ~]# mkfs.ext4 /dev/drbd0 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 131072 inodes, 524007 blocks 26200 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=536870912 16 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done [root@node1 ~]# mount /dev/drbd0 /data [root@node1 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/centos-root 6981632 2489436 4492196 36% / devtmpfs 499476 0 499476 0% /dev tmpfs 508740 0 508740 0% /dev/shm tmpfs 508740 6708 502032 2% /run tmpfs 508740 0 508740 0% /sys/fs/cgroup /dev/sda1 508588 153416 355172 31% /boot /dev/drbd0 2030316 6144 1902988 1% /data
12. Master 가 죽었다고 가정한뒤 Standby를 활성화
Master가 죽었음을 흉내
systemctl stop drbd
Standby에서 상태확인
[root@node2]# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101) GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R7, 2015-04-10 05:13:52 0: cs:WFConnection ro:Secondary/Unknown ds:UpToDate/DUnknown C r----- ns:0 nr:2211728 dw:2211728 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
Standby 서버를 primary 모드로 전환
[root@node2 drbd.d]# drbdadm primary drbddata [root@node2 drbd.d]# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101) GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R7, 2015-04-10 05:13:52 0: cs:WFConnection ro:Primary/Unknown ds:UpToDate/DUnknown C r----- ns:0 nr:2211728 dw:2211728 dr:728 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
13. Master 서버를 복구한뒤 다시 서비스 전환
Master 서버가 복구되었음을 가정하고
drbd 서비스를 올림
[root@node1 ~]# systemctl start drbd [root@node1 ~]# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101) GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R7, 2015-04-10 05:13:52 0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r----- ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
/proc/drbd를 확인해보면 본래의 Master서버가 secondary 상태임을 알 수 있다.
Standby 서버를 secondary 모드로 전환
(현재 Standby서버가 primary 모드인데, 구성상 primary 상태의 서버가 두대일 수 없으므로 secondary 모드로 전환하는 것이다)
[root@node2]# drbdadm secondary drbddata [root@node2]# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101) GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R7, 2015-04-10 05:13:52 0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r----- ns:73108 nr:2211728 dw:2284836 dr:1898 al:6 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
Master 서버를 primary 모드로 전환
[root@node1 ~]# drbdadm primary drbddata [root@node1 ~]# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101) GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R7, 2015-04-10 05:13:52 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----- ns:0 nr:73108 dw:73108 dr:728 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
이것으로 복구 작업이 완료되었다.
It’s a pity you don’t have a donate button! I’d certainly
donate to this fantastic blog! I guess for now i’ll settle for bookmarking and
adding your RSS feed to my Google account. I look
forward to fresh updates and will share this blog with my Facebook group.
Talk soon!
We’re a bunch of volunteers and opening a brand new scheme
in our community. Your website provided us with helpful information to work on. You’ve done a formidable
activity and our whole community shall be grateful to
you.
Very descriptive blog, I liked that a lot. Will there be a part 2?
thank you
maybe… another parts.
ex) management in linux
emergency in drbd… etc
Hey there! Would you mind if I share your blog with my twitter
group? There’s a lot of people that I think would really enjoy your content.
Please let me know. Cheers
ok~
thank you.. :)
Hi there to all, the contents present at this website are really
remarkable for people knowledge, well, keep up the nice work fellows.
Thank you for your rating.
see you again :)
Thanks for one’s marvelous posting! I truly enjoyed reading it, you may be a great author.I will always bookmark your blog
and may come back at some point. I want to encourage you to definitely
continue your great job, have a nice morning!
thank you!
have a nice week!!!!!
^^
I need to to thank you for this very good read!!
I definitely enjoyed every little bit of it.
I have got you saved as a favorite to look at new things you post…
This website was… how do I say it? Relevant!!
Finally I’ve found something which helped me. Cheers!
와우 이런대서 보다니… 오랜만이다 – woon
누구세요???? 메일주소가 없으셔서..