IT Japan

DRBD+ Heartbeat + MySQL 구축 본문

카테고리 없음

DRBD+ Heartbeat + MySQL 구축

swhwang 2014. 10. 26. 21:17
반응형

  DRBD + MySQL + Heartbeat 구축

 

1.시스템

OS

Red Hat Enterprise Linux Server release 5.8 (Tikanga)

DRBD version

8.3.1

하드웨어

동일 서버를 두대 준비

네트워크

로컬 접속이용(eth1)

 

 

 

1-1.DRBD용 영역( LVM으로 구성할 필요는 없음)

파일 시스템

마운트 포인트

용량

/dev/mapper/VG02-MYSQLDATA

/MYSQL_DATA

9.9G

 

 

 

 

1.2 구성도

 

1.3 파일시스템의 구성

[root@drbd01 ~]# df

Filesystem           1K-blocks      Used Available Use% Mounted on

/dev/vda2             10154020    478416   9151484   5% /

/dev/vda7              7111548   3888320   2856148  58% /usr

/dev/vda6             10153988    154384   9475488   2% /usr/local

/dev/vda5             10153988    250684   9379188   3% /var

/dev/vda8              6092360    143492   5634400   3% /var/crash

/dev/vda1               101086     16127     79740  17% /boot

tmpfs                   963804         0    963804   0% /dev/shm

/dev/mapper/VG01-svc   7110136    147324   6595812   3% /svc

/dev/mapper/VG01-log   7110136    147324   6595812   3% /log

/dev/mapper/VG01-app   9014656    151644   8397708   2% /app

/dev/mapper/VG02-MYSQL

                       7110136    147332   6595804   3% /MYSQL

/dev/mapper/VG02-MYSQLLOG

                      10157368    154236   9478844   2% /MYSQL/LOG

/dev/mapper/VG02-MYSQLDATA

                      10157368    154236   9478844   2% /MYSQL_DATA

 

 

 

1.4 VIP설정(vip,Heartbeat vip를 설정한다.)

[root@drbd01] #ifconfig eht0:0 192.168.0.70(VIP)

[root@drbd01] # ifconfig eht0:1 192.168.0.55(Heartbeat VIP)

 

 

 

 

 

1.4.1 가상IP가 설정되었는지 확인한다.

eth0      Link encap:Ethernet  HWaddr 00:1A:4A:A8:00:91 

          inet addr:192.168.0.33  Bcast:192.168.0.255  Mask:255.255.255.0

          inet6 addr: fe80::21a:4aff:fea8:91/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:868449 errors:0 dropped:0 overruns:0 frame:0

          TX packets:2777835 errors:0 dropped:1 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:79943986 (76.2 MiB)  TX bytes:10978071943 (10.2 GiB)

 

eth0:0    Link encap:Ethernet  HWaddr 00:1A:4A:A8:00:91 

          inet addr:192.168.0.70  Bcast:192.168.0.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

 

eth0:1    Link encap:Ethernet  HWaddr 00:1A:4A:A8:00:91 

          inet addr:192.168.0.55  Bcast:192.168.0.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

 

eth1      Link encap:Ethernet  HWaddr 00:1A:4A:A8:00:2B 

          inet addr:192.168.0.31  Bcast:192.168.0.255  Mask:255.255.255.0

          inet6 addr: fe80::21a:4aff:fea8:2b/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:24361 errors:0 dropped:0 overruns:0 frame:0

          TX packets:4030 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:3267894 (3.1 MiB)  TX bytes:1123063 (1.0 MiB)

 

lo        Link encap:Local Loopback 

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:1545 errors:0 dropped:0 overruns:0 frame:0

          TX packets:1545 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:2461424 (2.3 MiB)  TX bytes:2461424 (2.3 MiB)

 

 

1.5 호스트명의 설정(hostname을 변경한후 재부팅을 실시한다.)

DRBD구축시에 hostname을 설정하지 않으면 나중에 설정시에 에러가 날수 있다.

#vi /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=yes

HOSTNAME=drbd01

 

#vi /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=yes

HOSTNAME=drbd02

 

1.6 DRBD의 다운로드에서 인스톨까지

CentOS의 경우 yum으로 인스톨이 가능하지만 Red Hat Enterprise Linux5에는 yum으로 설치하는 것이 불가능하다.

그러므로, 소스로부터 RPM패키지를 작성해서 인스톨을 진행하도록 하자.

우선, DRBD의 인스톨 및 RPM패키지에 필요한 것을 인스톨한다.

DRBD의 소스는 하기 사이트로부터 입수가능하다.

http://oss.linbit.com/drbd/

1.6.1  이번에는 DRBD-8.3.8.1을 다운로드한다.

# wget http://oss.linbit.com/drbd/8.3/drbd-8.3.8.1 tar.gz

 

1.6.2  RPM패키지를 작성해보자.(소스는 /usr/local/src에 둔다.)

# tar zxf drbd-8.3.8.1 tar.gz

# cd drbd-8.3.8.1

# ./configure

# make rpm

# make km-rpm

 

1.6.3 RPM패키지는[/usr/src/redhat/RPMS/(아키텍쳐명.i386)/]이하에 위치한다. 패키지 작성후 인스톨을 진행한다.

[root@drbd01 x86_64]# pwd

/usr/src/redhat/RPMS/x86_64

[root@drbd01 x86_64]# ll

합계 1624

-rw-r--r-- 1 root root   23014  4 11 03:27 drbd-8.3.8.1-1.x86_64.rpm

-rw-r--r-- 1 root root    5599  4 11 03:27 drbd-bash-completion-8.3.8.1-1.x86_64.rpm

-rw-r--r-- 1 root root  310448  4 11 03:27 drbd-debuginfo-8.3.8.1-1.x86_64.rpm

-rw-r--r-- 1 root root    7161  4 11 03:27 drbd-heartbeat-8.3.8.1-1.x86_64.rpm

-rw-r--r-- 1 root root 1051453  4 11 03:27 drbd-km-2.6.18_308.el5-8.3.8.1-1.x86_64.rpm

-rw-r--r-- 1 root root    3397  4 11 03:27 drbd-km-debuginfo-8.3.8.1-1.x86_64.rpm

-rw-r--r-- 1 root root   19532  4 11 03:27 drbd-pacemaker-8.3.8.1-1.x86_64.rpm

-rw-r--r-- 1 root root    4469  4 11 03:27 drbd-udev-8.3.8.1-1.x86_64.rpm

-rw-r--r-- 1 root root  204732  4 11 03:27 drbd-utils-8.3.8.1-1.x86_64.rpm

-rw-r--r-- 1 root root    7051  4 11 03:27 drbd-xen-8.3.8.1-1.x86_64.rpm

 

1.6.4 RPM패키지의 인스톨을 해보자(의존성관계로 이하와 같은 순서로 인스톨을 실시한다.)

[root@drbd01 x86_64]# rpm -ivh drbd-utils-8.3.8.1-1.x86_64.rpm drbd-xen-8.3.8.1-1.x86_64.rpm

준비 중...               ########################################### [100%]

   1:drbd-utils             ########################################### [ 50%]

   2:drbd-xen               ########################################### [100%]

[root@drbd01 x86_64]# rpm -ivh drbd-udev-8.3.8.1-1.x86_64.rpm drbd-pacemaker-8.3.8.1-1.x86_64.rpm

준비 중...               ########################################### [100%]

   1:drbd-pacemaker         ########################################### [ 50%]

   2:drbd-udev              ########################################### [100%]

[root@drbd01 x86_64]# rpm -ivh drbd-km-debuginfo-8.3.8.1-1.x86_64.rpm drbd-km-2.6.18_308.el5-8.3.8.1-1.x86_64.rpm

준비 중...               ########################################### [100%]

   1:drbd-km-2.6.18_308.el5 ########################################### [ 50%]

   2:drbd-km-debuginfo      ########################################### [100%]

[root@drbd01 x86_64]# rpm -ivh drbd-heartbeat-8.3.8.1-1.x86_64.rpm drbd-debuginfo-8.3.8.1-1.x86_64.rpm

준비 중...               ########################################### [100%]

   1:drbd-debuginfo         ########################################### [ 50%]

   2:drbd-heartbeat         ########################################### [100%]

[root@drbd01 x86_64]# rpm -ivh drbd-bash-completion-8.3.8.1-1.x86_64.rpm drbd-8.3.8.1-1.x86_64.rpm

준비 중...               ########################################### [100%]

   1:drbd-bash-completion   ########################################### [ 50%]

   2:drbd                   ########################################### [100%]

 

 

이상으로 DRBD의 인스톨은 끝났다.인스톨은 active서버, standby서버에서 같이 실행한다.

1.6.5 drbd 패키지가 인스톨 되었는지 확인한다.

[root@drbd01 x86_64]# rpm -qa | grep drbd

drbd-debuginfo-8.3.8.1-1

drbd-udev-8.3.8.1-1

drbd-utils-8.3.8.1-1

drbd-km-2.6.18_308.el5-8.3.8.1-1

drbd-bash-completion-8.3.8.1-1

drbd-xen-8.3.8.1-1

drbd-km-debuginfo-8.3.8.1-1

drbd-8.3.8.1-1

drbd-pacemaker-8.3.8.1-1

drbd-heartbeat-8.3.8.1-1

 

1.7 DRBD의 설정

# You can find an example in  /usr/share/doc/drbd.../drbd.conf.example

 

# At most ONE global section is allowed.

# It must precede any resource section.

#

global {

    usage-count no;

}

 

common {

          syncer { rate 33M; }

}

 

#

# this need not be r#, you may use phony resource names,

# like "resource web" or "resource mail", too

#

 

resource sktdrbd {

  protocol C;                           #데이터동기의 프로토콜

 

  handlers {

    pri-on-incon-degr "echo o > /proc/sysrq-trigger ; halt -f";

    pri-lost-after-sb "echo o > /proc/sysrq-trigger ; halt -f";

    local-io-error "/usr/lib/drbd/notify-local-io-error.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo o > /proc/sysrq-trigger ; reboot -f";

   # outdate-peer "/usr/lib64/heartbeat/drbd-peer-outdater -t 5";

    split-brain "/usr/lib/drbd/notify-split-brain.sh root";

   # fence-peer "/usr/lib/drbd/crm-fence-peer.sh";

   # after-resync-target "/usr/lib/drbd/crm-unfence-peer.sh";

  }

 

  startup {

    # wfc-timeout  0;

    degr-wfc-timeout 120;    # 2 minutes.

    # wait-after-sb;

  }

 

  disk {

    on-io-error   call-local-io-error;

  }

 

  net {

     timeout       60;    #  6 seconds  (unit = 0.1 seconds)

     connect-int   10;    # 10 seconds  (unit = 1 second)

     ping-int      10;    # 10 seconds  (unit = 1 second)

     ping-timeout   5;    # 500 ms (unit = 0.1 seconds)

 

     max-buffers     2048;

     unplug-watermark   128;

     max-epoch-size  2048;

    # ko-count 4;

 

    after-sb-0pri discard-zero-changes;

    after-sb-1pri discard-secondary;

    after-sb-2pri disconnect;

 

    # allow-two-primaries;

    # shared-secret "FooFunFactory";

    #after-sb-0pri disconnect;

    #after-sb-1pri disconnect;

    #after-sb-2pri disconnect;

    rr-conflict disconnect;

  }

 

  syncer {

    rate 300M;ㅇㅇ

    al-extents 257;

    # cpu-mask 15;

  }

 

  on drbd01 {                                      # uname -n

    device    /dev/drbd0;

    disk      /dev/VG02/MYSQLDATA;

    address   192.168.0.55:7788;

    flexible-meta-disk internal;

  }

 

  on drbd02 {                                      # uname -n

    device    /dev/drbd0;

    disk      /dev/VG02/MYSQLDATA;

    address   192.168.0.53:7788;

    meta-disk internal;

  }

 

1.7.1 drbd모듈을 읽어옵니다. 모든 서버에서 실행합니다.

# modprobe drbd

 

 

1.8 메타파일의 작성

Meta-disk[internal]을 지정한 경우, ext3등의 파일시스템이 작성되어 있으면 메타 파일의 작성에 실패하는경우가 있기 때문에, dd명령어를 이용해서 meta-disk의 디바이스를 제로화합니다.

[root@drbd01 VG02]# dd if=/dev/zero of=/dev/VG02/MYSQLDATA bs=1M count=128

128+0 records in

128+0 records out

134217728 bytes (134 MB) copied, 25.8882 seconds, 5.2 MB/s

 

 

1.8.1      메타영역의 작성. 메타영역을 작성후, DRBD를 기동합니다.

[root@drbd01 VG02]#  drbdadm create-md sktdrbd

Writing meta data...

initializing activity log

NOT initialized bitmap

New drbd meta data block successfully created.

 

1.9 자동기동의 설정

1.9.1      자동기동을 on으로 설정합니다.

# chkconfig drbd on

 

1.9.2      chconfig명령어로 자동기동이 on으로 되어있는지 확인합니다.

# chkconfig --list drbd

drbd            0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

 

1.10         DRBD의 기동

1.10.1    다른 한대의 DRBD가 기동하고 있지 않기 때문에, 최초에 기동한 서버에는 이하와 같은 경고가 나오지만, yes라고 치고 먼저 진행합니다. 기동에 성공하면 , 다른 한대도 기동합니다.

# /etc/init.d/drbd start

Starting DRBD resources: [ d(r0) ]..........

***************************************************************

 DRBD's startup script waits for the peer node(s) to appear.

 - In case this node was already a degraded cluster before the

 reboot the timeout is 0 seconds. [degr-wfc-timeout]

- If the peer was available before the reboot the timeout will

 expire after 120 seconds. [wfc-timeout]

 (These values are for resource 'r0'; 0 sec -> wait forever)

 To abort waiting enter 'yes' [  13]:yes

 

1.10.2    각 서버의 DRBD를 기동하면, 이하와 같이 상태를 확인합니다.

[root@drbd01 VG02]# cat /proc/drbd

version: 8.3.8.1 (api:88/proto:86-94)

GIT-hash: 0d8589fcc32c874df57c930ca1691399b55ec893 build by root@drbd01, 2013-04-11 03:27:31

 0: cs:SyncSource ro:Secondary/Secondary ds:UpToDate/Inconsistent C r----

    ns:63840 nr:0 dw:0 dr:70112 al:0 bm:3 lo:12 pe:348 ua:207 ap:0 ep:1 wo:b oos:9449628

           [>....................] sync'ed:  0.6% (9228/9276)M

           finish: 0:26:50 speed: 5,856 (5,856) K/sec

ro:Secondary/Secondary」와 같이 , 기동시에는 양서버가 secondary로 접속되어있습니다.

 

1.11         Primary설정과 데이터 동기(Primary측만)

1.11.1     Primary로 지정하고 싶은 서버에서, 이하의 명령어를 실행하면, Primary에의 승격과 데이터 동기가 실시됩니다.

[root@drbd01 VG02]# drbdadm -- --overwrite-data-of-peer primary all

 

1.11.2     다음으로 데이터의 동기상태를 이하의 명령어로 확인합니다.

[root@drbd01 VG02]# /etc/init.d/drbd status

drbd driver loaded OK; device status:

version: 8.3.8.1 (api:88/proto:86-94)

GIT-hash: 0d8589fcc32c874df57c930ca1691399b55ec893 build by root@drbd01, 2013-04-11 03:27:31

m:res      cs         ro                 ds                   p  mounted  fstype

0:sktdrbd  Connected  Primary/Secondary  UpToDate/UpToDate  C

 

1.12         DRBD볼륨의 마운트(Primary측만)

1.12.1    DRBD볼륨에 파일시스템을 작성후, 마운트합니다.

이번에는 ext3파일시스템을 작성합니다.

[root@drbd01 VG02]# mke2fs -j /dev/drbd0

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

1310720 inodes, 2621351 blocks

131067 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2684354560

80 block groups

32768 blocks per group, 32768 fragments per group

16384 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

 

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 39 mounts or

180ys, whichever comes first.  Use tune2fs -c or -i to override.

 

1.12.2 active서버에서 마운트가 되는 것을 확인합니다.

[root@drbd01 VG02]# mount /dev/drbd0 /MYSQL_DATA

 

 

 

 

1.12.2    DRBD의 상태를 확인합니다.

[root@drbd01 VG02]# /etc/init.d/drbd status

drbd driver loaded OK; device status:

version: 8.3.8.1 (api:88/proto:86-94)

GIT-hash: 0d8589fcc32c874df57c930ca1691399b55ec893 build by root@drbd01, 2013-04-11 03:27:31

m:res      cs         ro                 ds                   p  mounted      fstype

0:sktdrbd  Connected  Primary/Secondary  UpToDate/UpToDate  C  /MYSQL_DATA  ext3

 

이것으로 DRBD볼륨이 이용가능합니다.

 

1.13         DRBD의 동작확인

DRBD의 기동은 끝났지만, 테스트로써 [/MYSQL_DATA]영역을 standby서버로 절체해봅시다.

active서버로 [/MYSQL_DATA]unmount해서,DRBDsecondary상태로 이행합니다.

[root@drbd01 VG02]# umount /dev/drbd0 /MYSQL_DATA

umount: /dev/drbd0: not mounted

umount: /dev/drbd0: not mounted

[root@drbd01 VG02]# drbdadm secondary sktdrbd

 

 

 

standby서버에서DRBDPrimary상태로 이행해서, [/MYSQL_DATA]영역이 마운트되는 것을 확인해주세요.

[root@drbd02 x86_64]# drbdadm primary sktdrbd

[root@drbd02 x86_64]# mount /dev/drbd0 /MYSQL_DATA

 

2  MySQL 의 도입

MySQL Binary source 파일로 설치한다.

2.1 user group 생성

[root@drbd01 MYSQL]# groupadd -g 501 dba

 [root@drbd01 MYSQL]# useradd -g dba -u 501 mysql

 [root@drbd01 MYSQL]# cat /etc/group | grep dba

dba:x:501:

[root@drbd01 MYSQL]# cat /etc/passwd | grep mysql

mysql:x:501:501::/home/mysql:/bin/bash

 

2.2 MySQL 엔진 심볼릭 링크 생성 및 압축 풀기

[root@drbd01 MYSQL]# ls

LOG  lost+found    mysql-5.5.25a-linux2.6-x86_64.tar.gz

 [root@drbd01 MYSQL]# tar xvf mysql-5.5.25a-linux2.6-x86_64.tar.gz

[root@drbd01 MYSQL]# ln -s mysql-5.5.25a-linux2.6-x86_64 mysql

[root@drbd01 MYSQL]# ls -al

합계 182212

drwxr-xr-x  5 root root      4096  4 15 20:09 .

drwxr-xr-x 30 root root      4096  4 15 18:44 ..

drwxr-xr-x  3 root root      4096  2 24 16:52 LOG

drwx------  2 root root     16384  2 25 03:50 lost+found

lrwxrwxrwx  1 root root        29  4 15 20:09 mysql -> mysql-5.5.25a-linux2.6-x86_64

drwxr-xr-x 13 root root      4096  4 15 20:07 mysql-5.5.25a-linux2.6-x86_64

-rw-r--r--  1 root root 186355822 12 27 17:27 mysql-5.5.25a-linux2.6-x86_64.tar.gz

 

 

2.3 디렉토리 권한 설정

[root@drbd01 MYSQL]# chown -R mysql.dba /MYSQL/mysql

[root@drbd01 /]# chown -R mysql.dba /MYSQL_DATA/DATA/

[root@drbd01 /]# chown -R mysql.dba /MYSQL/LOG

 

2.4  mysql_install_db 실행

mysql_install_db 실행하여 database를 생성한다.

[root@drbd01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/MYSQL_DATA/DATA/

Installing MySQL system tables...

OK

Filling help tables...

OK

 

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

 

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

 

./bin/mysqladmin -u root password 'new-password'

./bin/mysqladmin -u root -h drbd01 password 'new-password'

 

Alternatively you can run:

./bin/mysql_secure_installation

 

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

 

See the manual for more instructions.

 

You can start the MySQL daemon with:

cd . ; ./bin/mysqld_safe &

 

You can test the MySQL daemon with mysql-test-run.pl

cd ./mysql-test ; perl mysql-test-run.pl

 

Please report any problems with the ./bin/mysqlbug script!

 

MYSQL_DATA 디렉토리 DB 생성을 확인한다. (mysql, test, performance_schema)

[root@drbd01 DATA]# ls -al /MYSQL_DATA/DATA/

합계 24

drwxr-xr-x 5 mysql dba  4096  4 15 20:18 .

drwxr-xr-x 3 root  root 4096  4 15 20:14 ..

drwx------ 2 mysql root 4096  4 15 20:18 mysql

drwx------ 2 mysql dba  4096  4 15 20:18 performance_schema

drwx------ 2 mysql root 4096  4 15 20:18 test

 

2.5  파라미터 설정

표준파라메터 적용은 /etc/my.cnf에서 한다.

2.5.1

[client]

port = 3306

socket = /tmp/mysql.sock

 

[mysqld]

port = 3306

socket = /tmp/mysql.sock

basedir = /MYSQL/mysql

datadir = /MYSQL_DATA/DATA

 

#ADD for SKT base

 

# query_cache 설정 (사용하지 않음)

query_cache_type = 0

query_cache_size = 16M

query_cache_limit = 2M

 

# Log 파일 설정

log-error = /MYSQL/LOG/mysql.err

slow_query_log = 1

slow_query_log_file = /MYSQL/LOG/mysql-slow-query.log

long_query_time = 3

 

# Time out 설정

wait_timeout = 28800

interactive_timeout = 600

 

# transaction 격리수준 설정

transaction_isolation = READ-COMMITTED

 

# 기타 환경 설정

back_log = 1024

max_connections = 1024

max_connect_errors = 1024

table_open_cache = 2048

max_allowed_packet = 16M

max_heap_table_size = 1024M

sort_buffer_size = 2M

join_buffer_size = 2M

thread_cache_size = 8

thread_concurrency = 36

tmp_table_size = 1024M

 

# 문자셋 설정 (기본값은 utf8로 설정하나 서비스에 따라 euckr로 변경)

init_connect = "SET collation_connection = utf8_general_ci"

init_connect = "SET NAMES utf8"

character-set-server = utf8

 

# innodb 설정

innodb_lock_wait_timeout = 50

innodb_file_per_table

innodb_thread_sleep_delay = 0

innodb_commit_concurrency = 36

innodb_doublewrite = 0

innodb_flush_log_at_trx_commit = 2

innodb_additional_mem_pool_size = 50M

innodb_thread_concurrency = 36

innodb_log_files_in_group = 3

 

# /MYSQL_DATA/DATA 파티션 크기에 따른 분류

innodb_data_file_path = ibdata1:1024M;ibdata2:1024M;ibdata3:10M:autoextend

innodb_log_file_size = 256M

 

# H/W RAM 용량에 따른 분류

# RAM < 8GB

innodb_buffer_pool_size = 2G

innodb_log_buffer_size = 32M

# RAM > 8GB

innodb_buffer_pool_size = 4G

innodb_log_buffer_size = 32M

 

# MyISAM 사용시

key_buffer_size = 512

read_buffer_size = 2M

read_rnd_buffer_size = 16M

bulk_insert_buffer_size = 64M

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 2G

myisam_repair_threads = 1

myisam_recover

 

# innodb 사용시

key_buffer_size = 32M

read_buffer_size = 2M

read_rnd_buffer_size = 16M

bulk_insert_buffer_size = 64M

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

myisam_recover

 

[mysqldump]

quick

 

[mysqlhotcopy]

interactive-timeout

 

[mysqld_safe]

open-files-limit = 8192

 

 

2.5.2 MySQL 기동스크립트의 작성

[root@drbd01 support-files]# vi mysql.server

basedir=/MYSQL/mysql

datadir=/MYSQL_DATA/DATA

wq!

 

[root@drbd01 support-files]# cp mysql.server /etc/init.d/mysql

[root@drbd01 init.d]# ls -al mysql

-rwxr-xr-x 1 root root 10678  4 15 20:29 mysql

 

2.5.3  MySQL 실행

MySQL 엔진 디렉토리에서 mysqld_safe 실행하여 mysql 실행한다.

[root@drbd01 mysql]# ./bin/mysqld_safe --user=mysql &

[1] 6316

[root@drbd01 mysql]# 130415 20:31:46 mysqld_safe Logging to '/MYSQL/LOG/mysql.err'.

130415 20:31:46 mysqld_safe Starting mysqld daemon with databases from /MYSQL_DATA/DATA

 

2.6 보안적용

2.6.1  /etc/my.cnf 권한은 640, 사용자 및 그룹은 mysql.dba로 설정

chmod chown 을 사용하여 권한 및 사용자 그룹을 변경한다.

[root@drbd01 mysql]# chmod 640 /etc/my.cnf

[root@drbd01 mysql]# chown mysql.dba /etc/my.cnf

[root@drbd01 mysql]# ls -al /etc/my.cnf

-rw-r----- 1 mysql dba 2225  4 15 20:25 /etc/my.cnf

 

2.6.2  mysqld_safe mysql.server의 권한은 750으로 설정

chmod를 사용하여 권한을 750으로 변경한다.

[root@drbd01 support-files]# chmod 750 mysql.server

[root@drbd01 support-files]# ls -al mysql.server

-rwxr-x--- 1 mysql dba 10678  4 15 20:28 mysql.server

[root@drbd01 bin]# ls -al mysqld_safe

-rwxr-x--- 1 mysql dba 23184  6 29  2012 mysqld_safe

 

2.6.3  $datadir 디렉토리 및 데이터 파일 접근제한 설정

데이터 파일의 권한이 600 또는 640

$datadir의 접근 권한은 750 이하로 설정

[root@drbd01 bin]# cd /MYSQL_DATA/DATA/

[root@drbd01 DATA]#

[root@drbd01 DATA]# chmod 750 /MYSQL_DATA/DATA/

[root@drbd01 DATA]# ls -al

합계 2896704

drwxr-x--- 5 mysql dba        4096  4 15 20:34 .

drwxr-xr-x 3 root  root       4096  4 15 20:14 ..

-rw-rw---- 1 mysql dba           5  4 15 20:34 drbd01.pid

-rw-rw---- 1 mysql dba   268435456  4 15 20:34 ib_logfile0

-rw-rw---- 1 mysql dba   268435456  4 15 20:33 ib_logfile1

-rw-rw---- 1 mysql dba   268435456  4 15 20:34 ib_logfile2

-rw-rw---- 1 mysql dba  1073741824  4 15 20:34 ibdata1

-rw-rw---- 1 mysql dba  1073741824  4 15 20:32 ibdata2

-rw-rw---- 1 mysql dba    10485760  4 15 20:33 ibdata3

drwx------ 2 mysql root       4096  4 15 20:18 mysql

drwx------ 2 mysql dba        4096  4 15 20:18 performance_schema

drwx------ 2 mysql root       4096  4 15 20:18 test

[root@drbd01 DATA]# chmod 640 ib_logfile0 ib_logfile1 ib_logfile2 ibdata1 ibdata2 ibdata3

 [root@drbd01 DATA]# ls -al

합계 2896704

drwxr-x--- 5 mysql dba        4096  4 15 20:34 .

drwxr-xr-x 3 root  root       4096  4 15 20:14 ..

-rw-rw---- 1 mysql dba           5  4 15 20:34 drbd01.pid

-rw-r----- 1 mysql dba   268435456  4 15 20:34 ib_logfile0

-rw-r----- 1 mysql dba   268435456  4 15 20:33 ib_logfile1

-rw-r----- 1 mysql dba   268435456  4 15 20:34 ib_logfile2

-rw-r----- 1 mysql dba  1073741824  4 15 20:34 ibdata1

-rw-r----- 1 mysql dba  1073741824  4 15 20:32 ibdata2

-rw-r----- 1 mysql dba    10485760  4 15 20:33 ibdata3

drwx------ 2 mysql root       4096  4 15 20:18 mysql

drwx------ 2 mysql dba        4096  4 15 20:18 performance_schema

drwx------ 2 mysql root       4096  4 15 20:18 test

 

1.4.4 보안적용

1.4.4.1 기본 보안적용

MySQL Binary source에서 제공하는 mysql_secure_installation 스크립트를 이용해 기본 보안 적용

root 패스워드 설정, 익명 사용자 삭제, test db 삭제

 

[root@drbd01 mysql]# ./bin/mysql_secure_installation

 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

 

 

In order to log into MySQL to secure it, we'll need the current

password for the root user.  If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

 

Enter current password for root (enter for none):

OK, successfully used password, moving on...

 

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

 

Set root password? [Y/n] Y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

 ... Success!

 

 

By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

 

Remove anonymous users? [Y/n] Y

 ... Success!

 

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

 

Disallow root login remotely? [Y/n] n

 ... skipping.

 

By default, MySQL comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

 

Remove test database and access to it? [Y/n] Y

 - Dropping test database...

 ... Success!

 - Removing privileges on test database...

 ... Success!

 

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

 

Reload privilege tables now? [Y/n] Y

 ... Success!

 

Cleaning up...

 

All done!  If you've completed all of the above steps, your MySQL

installation should now be secure.

 

Thanks for using MySQL!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3. Heartbeat의 도입

3.1 Heartbeat의 인스톨(다음 순서대로 인스톨한다.)

rpm -ivh heartbeat-pils-2.1.3-3.el5.centos.x86_64.rpm

rpm -ivh heartbeat-gui-2.1.3-3.el5.centos.x86_64.rpm

rpm -ivh heartbeat-stonith-2.1.3-3.el5.centos.x86_64.rpm

rpm -ivh heartbeat-2.1.3-3.el5.centos.x86_64.rpm

rpm -ivh heartbeat-devel-2.1.3-3.el5.centos.x86_64.rpm

 

3.2 Heartbeat의 설정

Heartbeat의 설정으로 이용하는 설정파일

구분

내용

/etc/ha.d/ha.cf

클러스터구성을 정의하는 메인설정파일

/etc/ha.d/haresources

Version1용 리소스 설정파일. Version2용의 리소스 설정화일을 작성하기 위해 이용

/var/lib/heartbeat/crm/cib.xml

Version2용 리소스 설정화일

/etc/ha.d/authkeys

인증설정화일

 

3.3 Haresource의 설정

/etc/ha.d/haresource

drbd01 IPaddr::192.168.0.70 IPaddr::192.168.0.55 drbddisk::sktdrbd Filesystem::/dev/drbd0::/MYSQL_DATA::ext3 mysql

( heartbeat vip , service vip, drbddisk, Filesystem, mysql )

 

 

 

 

Heartbeat의 설정은 이하의 3군데에서 설정한다.

디렉토리 /etc/ha.d/의 안에

1.     authkeys->노드의 인증

2.     ha.cf->Heartbeat의 전반구성

3.     Heartbeat drbd01drbd02의 설정이 다르다.

Drbd01의 경우

Haresource->리소스의 구성을 작성할 필요가 있음`.

샘플파일을 복사해서 가져온다.

# cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/.

# cp /usr/share/doc/heartbeat-2.1.3/ha.cf/etc/ha.d/.

# cp /usr/share/doc/heartbeat-2.1.3/haresources/etc/ha.d/.

 

이하의 설정에 대해서, 설명합니다.

1.     파일 authkeys의 편집

# vi /etc/ha.d/authkeys

------------------

#auth 1

auth 2

#2 sha1 HI!

2 sha1 geodb

------------------

     

 

 

퍼미션의 변경

 

자동생성된 cib.xml이 이미 존재하므로 삭제한다.

# rm /var/lib/heartbeat/crm/cib.xml*

 

Heartbeat를 정지해서, cib.xml을 수정해서 재기동할 때 이 삭제수순도 필요

변환 툴을 실행

[root@drbd01 heartbeat]# python /usr/lib64/heartbeat/haresources2cib.py ~/haresources.tmp

 

Drbd02에도 같은 cib.xml이 필요하므로, scp로 전송한다.

[root@drbd01 crm]# scp /var/lib/heartbeat/crm/cib.xml root@192.168.0.38:/var/lib/heartbeat/crm/

 

Cib.xml의 권한을 주의

[root@drbd01 crm]# chown -R hacluster:haclient /var/lib/heartbeat/crm/cib.xml

[root@drbd01 crm]# chmod -R 600 /var/lib/heartbeat/crm/cib.xml

 

Cib.xml의 기술이 정확한지를 확인

[root@drbd01 crm]# crm_verify -x /var/lib/heartbeat/crm/cib.xml

 

 

 

Cib.xml파일의 편집

<?xml version="1.0" ?>

<cib admin_epoch="0" epoch="0" num_updates="0">

              <configuration>

                            <crm_config>

                                          <cluster_property_set id="cib-bootstrap-options">

                                                        <attributes>

                                                                      <nvpair id="cib-bootstrap-options-symmetric-cluster" name="symmetric-cluster" value="true"/>

                                                                      <nvpair id="cib-bootstrap-options-no-quorum-policy" name="no-quorum-policy" value="stop"/>

                                                                      <nvpair id="cib-bootstrap-options-default-resource-stickiness" name="default-resource-stickiness" value="INFIVITY"/>

                                                                      <nvpair id="cib-bootstrap-options-default-resource-failure-stickiness" name="default-resource-failure-stickiness" value="0"/>

                                                                      <nvpair id="cib-bootstrap-options-stonith-enabled" name="stonith-enabled" value="false"/>

                                                                      <nvpair id="cib-bootstrap-options-stonith-action" name="stonith-action" value="reboot"/>

                                                                      <nvpair id="cib-bootstrap-options-startup-fencing" name="startup-fencing" value="true"/>

                                                                      <nvpair id="cib-bootstrap-options-stop-orphan-resources" name="stop-orphan-resources" value="true"/>

                                                                      <nvpair id="cib-bootstrap-options-stop-orphan-actions" name="stop-orphan-actions" value="true"/>

                                                                      <nvpair id="cib-bootstrap-options-remove-after-stop" name="remove-after-stop" value="false"/>

                                                                      <nvpair id="cib-bootstrap-options-short-resource-names" name="short-resource-names" value="true"/>

                                                                      <nvpair id="cib-bootstrap-options-transition-idle-timeout" name="transition-idle-timeout" value="5min"/>

                                                                      <nvpair id="cib-bootstrap-options-default-action-timeout" name="default-action-timeout" value="60s"/>

                                                                      <nvpair id="cib-bootstrap-options-is-managed-default" name="is-managed-default" value="true"/>

                                                                      <nvpair id="cib-bootstrap-options-cluster-delay" name="cluster-delay" value="60s"/>

                                                                      <nvpair id="cib-bootstrap-options-pe-error-series-max" name="pe-error-series-max" value="-1"/>

                                                                      <nvpair id="cib-bootstrap-options-pe-warn-series-max" name="pe-warn-series-max" value="-1"/>

                                                                      <nvpair id="cib-bootstrap-options-pe-input-series-max" name="pe-input-series-max" value="-1"/>

                                                        </attributes>

                                          </cluster_property_set>

                            </crm_config>

                            <nodes/>

                            <resources>

                                          <group id="group_1">

                                                        <primitive class="ocf" id="IPaddr_192_168_0_70" provider="heartbeat" type="IPaddr">

                                                                      <operations>

                                                                                    <op id="IPaddr_192_168_0_70_mon" interval="5s" name="monitor" timeout="60s"/>

                                                                      </operations>

                                                                      <instance_attributes id="IPaddr_192_168_0_70_inst_attr">

                                                                                    <attributes>

                                                                                                  <nvpair id="IPaddr_192_168_0_70_attr_0" name="ip" value="192.168.0.70"/>

                                                                                    </attributes>

                                                                      </instance_attributes>

                                                        </primitive>

                                                        <primitive class="ocf" id="IPaddr_192_168_0_55" provider="heartbeat" type="IPaddr">

                                                                      <operations>

                                                                                    <op id="IPaddr_192_168_0_55_mon" interval="5s" name="monitor" timeout="60s"/>

                                                                      </operations>

                                                                      <instance_attributes id="IPaddr_192_168_0_55_inst_attr">

                                                                                    <attributes>

                                                                                                  <nvpair id="IPaddr_192_168_0_55_attr_0" name="ip" value="192.168.0.55"/>

                                                                                    </attributes>

                                                                      </instance_attributes>

                                                        </primitive>

                                                        <primitive class="heartbeat" id="drbddisk_3" provider="heartbeat" type="drbddisk">

                                                                      <operations>

                                                                                    <op id="drbddisk_3_mon" interval="120s" name="monitor" timeout="60s"/>

                                                                      </operations>

                                                                      <instance_attributes id="drbddisk_3_inst_attr">

                                                                                    <attributes>

                                                                                                  <nvpair id="drbddisk_3_attr_1" name="1" value="sktdrbd"/>

                                                                                    </attributes>

                                                                      </instance_attributes>

                                                        </primitive>

                                                        <primitive class="ocf" id="Filesystem_4" provider="heartbeat" type="Filesystem">

                                                                      <operations>

                                                                                    <op id="Filesystem_4_mon" interval="120s" name="monitor" timeout="60s"/>

                                                                      </operations>

                                                                      <instance_attributes id="Filesystem_4_inst_attr">

                                                                                    <attributes>

                                                                                                  <nvpair id="Filesystem_4_attr_0" name="device" value="/dev/drbd0"/>

                                                                                                  <nvpair id="Filesystem_4_attr_1" name="directory" value="/MYSQL_DATA"/>

                                                                                                  <nvpair id="Filesystem_4_attr_2" name="fstype" value="ext3"/>

                                                                                    </attributes>

                                                                      </instance_attributes>

                                                        </primitive>

                                                        <primitive class="ocf" id="mysql_5" provider="heartbeat" type="mysql">

                                                                      <operations>

                                                                                    <op id="mysql_5_mon" interval="5s" name="monitor" timeout="60s"/>

                                                                      </operations>

                                                        </primitive>

                                          </group>

                            </resources>

                            <constraints>

                                          <rsc_location id="rsc_location_group_1" rsc="group_1">

                                                        <rule id="prefered_location_group_1" score="100">

                                                                      <expression attribute="#uname" id="prefered_location_group_1_expr" operation="eq" value="drbd01"/>

                                                        </rule>

                                          </rsc_location>

                            </constraints>

              </configuration>

              <status/>

</cib>

 

 

Drbd02에도 cib.xml파일을 drbd01과 같이 설정한다.(scpcib.xml파일 전송)

[root@drbd01 crm] #scp –p cib.xml root@192.168.0.38:/var/lib/heartbeat/crm

 

다음으로 mysql을 기동시키기 위해 heartbeat의 기동스크립트를 지정합니다.

[root@drbd01 heartbeat] cd /usr/lib/ocf/resource.d/heartbeat

#!/bin/sh

#

#

# MySQL

#

# Description:     Manages a MySQL database as Linux-HA resource

 

#

# Author:          Alan Robertson              : DB2 Script

# Author:          Jakub Janczak                : Rewrite as MySQL

# Author:          Andrew Beekhof             : Cleanup and import

# Author:          Sebastian Reitenbach       : add OpenBSD defaults, more cleanup

#

# Support:         linux-ha@lists.linux-ha.org

# License:          GNU General Public License (GPL)

# Copyright:       (C) 2002 - 2005 International Business Machines, Inc.

#

# An example usage in /etc/ha.d/haresources:

#       node1  10.0.0.170 mysql

#

# See usage() function below for more details...

#

# OCF instance parameters:

#   OCF_RESKEY_binary

#   OCF_RESKEY_config

#   OCF_RESKEY_datadir

#   OCF_RESKEY_user

#   OCF_RESKEY_group

#   OCF_RESKEY_test_table

#   OCF_RESKEY_test_user

#   OCF_RESKEY_test_password

#   OCF_RESKEY_enable_creation

#   OCF_RESKEY_additional_parameters

#   OCF_RESKEY_log

#   OCF_RESKEY_pid

#   OCF_RESKEY_socket

 

#######################################################################

# Initialization:

 

. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs

 

#######################################################################

 

# Fill in some defaults if no values are specified

 

#추가

# user define mysql information

BASEDIR="/MYSQL/mysql"

DATADIR="/MYSQL_DATA/DATA"

LOGDIR="/MYSQL/LOG"

HOSTNAME=`hostname`

 

OCF_RESKEY_binary_default="${BASEDIR}/bin/mysqld_safe"

OCF_RESKEY_config_default="/etc/my.cnf"

OCF_RESKEY_datadir_default="${DATADIR}"

OCF_RESKEY_user_default="mysql"

OCF_RESKEY_group_default="dba"

OCF_RESKEY_log_default="${LOGDIR}/${HOSTNAME}.err"

OCF_RESKEY_pid_default="${LOGDIR}/${HOSTNAME}.pid"

OCF_RESKEY_socket_default="/tmp/mysql.sock"

OCF_RESKEY_test_user_default="root"

OCF_RESKEY_test_table_default="mysql.user"

OCF_RESKEY_test_passwd_default=""

OCF_RESKEY_enable_creation_default=0

OCF_RESKEY_additional_parameters_default=""

 

 

#주석처리

#HOSTOS='uname'

#if [ "X${HOSTOS}" == "XOpenBSD" ];then

#OCF_RESKEY_binary_default="/usr/local/bin/mysqld_safe"

#OCF_RESKEY_config_default="/etc/my.cnf"

#OCF_RESKEY_datadir_default="/var/mysql"

#OCF_RESKEY_user_default="_mysql"

#OCF_RESKEY_group_default="_mysql"

#OCF_RESKEY_log_default="/var/log/mysqld.log"

#OCF_RESKEY_pid_default="/var/mysql/mysqld.pid"

#OCF_RESKEY_socket_default="/var/run/mysql/mysql.sock"

#OCF_RESKEY_test_user_default="root"

#OCF_RESKEY_test_table_default="mysql.user"

#OCF_RESKEY_test_passwd_default=""

#OCF_RESKEY_enable_creation_default=0

#OCF_RESKEY_additional_parameters_default=""

#else

#OCF_RESKEY_binary_default="/usr/bin/safe_mysqld"

#OCF_RESKEY_config_default="/etc/my.cnf"

#OCF_RESKEY_datadir_default="/var/lib/mysql"

#OCF_RESKEY_user_default="mysql"

#OCF_RESKEY_group_default="mysql"

#OCF_RESKEY_log_default="/var/log/mysqld.log"

#OCF_RESKEY_pid_default="/var/run/mysql/mysqld.pid"

#OCF_RESKEY_socket_default="/var/lib/mysql/mysql.sock"

#OCF_RESKEY_test_user_default="root"

#OCF_RESKEY_test_table_default="mysql.user"

#OCF_RESKEY_test_passwd_default=""

#OCF_RESKEY_enable_creation_default=0

#OCF_RESKEY_additional_parameters_default=""

#fi

 

: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}

MYSQL_BINDIR=`dirname ${OCF_RESKEY_binary}`

 

: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}}

: ${OCF_RESKEY_datadir=${OCF_RESKEY_datadir_default}}

 

: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}}

: ${OCF_RESKEY_group=${OCF_RESKEY_group_default}}

 

: ${OCF_RESKEY_log=${OCF_RESKEY_log_default}}

: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}}

: ${OCF_RESKEY_socket=${OCF_RESKEY_socket_default}}

 

: ${OCF_RESKEY_test_user=${OCF_RESKEY_test_user_default}}

: ${OCF_RESKEY_test_table=${OCF_RESKEY_test_table_default}}

: ${OCF_RESKEY_test_passwd=${OCF_RESKEY_test_passwd_default}}

 

: ${OCF_RESKEY_enable_creation=${OCF_RESKEY_enable_creation_default}}

: ${OCF_RESKEY_additional_parameters=${OCF_RESKEY_additional_parameters_default}}

 

usage() {

  cat <<UEND

           usage: $0 (start|stop|validate-all|meta-data|monitor)

 

           $0 manages a MySQL Database as an HA resource.

 

           The 'start' operation starts the database.

           The 'stop' operation stops the database.

           The 'status' operation reports whether the database is running

           The 'monitor' operation reports whether the database seems to be working

           The 'validate-all' operation reports whether the parameters are valid

 

UEND

}

 

meta_data() {

           cat <<END

<?xml version="1.0"?>

<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">

<resource-agent name="mysql">

<version>1.0</version>

 

<longdesc lang="en">

Resource script for MySQL.

It manages a MySQL Database instance as an HA resource.

</longdesc>

<shortdesc lang="en">MySQL resource agent</shortdesc>

 

<parameters>

 

<parameter name="binary" unique="0" required="0">

<longdesc lang="en">

Location of the MySQL binary

</longdesc>

<shortdesc lang="en">MySQL binary</shortdesc>

<content type="string" default="${OCF_RESKEY_binary_default}" />

</parameter>

 

<parameter name="config" unique="0" required="0">

<longdesc lang="en">

Configuration file

</longdesc>

<shortdesc lang="en">MySQL config</shortdesc>

<content type="string" default="${OCF_RESKEY_config_default}" />

</parameter>

 

<parameter name="datadir" unique="0" required="0">

<longdesc lang="en">

Directory containing databases

</longdesc>

<shortdesc lang="en">MySQL datadir</shortdesc>

<content type="string" default="${OCF_RESKEY_datadir_default}" />

</parameter>

 

<parameter name="user" unique="0" required="0">

<longdesc lang="en">

User running MySQL daemon

</longdesc>

<shortdesc lang="en">MySQL user</shortdesc>

<content type="string" default="${OCF_RESKEY_user_default}" />

</parameter>

 

<parameter name="group" unique="0" required="0">

<longdesc lang="en">

Group running MySQL daemon (for logfile and directory permissions)

</longdesc>

<shortdesc lang="en">MySQL group</shortdesc>

<content type="string" default="${OCF_RESKEY_group_default}"/>

</parameter>

 

<parameter name="log" unique="0" required="0">

<longdesc lang="en">

The logfile to be used for mysqld.

</longdesc>

<shortdesc lang="en">MySQL log file</shortdesc>

<content type="string" default="${OCF_RESKEY_log_default}"/>

</parameter>

 

<parameter name="pid" unique="0" required="0">

<longdesc lang="en">

The pidfile to be used for mysqld.

</longdesc>

<shortdesc lang="en">MySQL pid file</shortdesc>

<content type="string" default="${OCF_RESKEY_pid_default}"/>

</parameter>

 

<parameter name="socket" unique="0" required="0">

<longdesc lang="en">

The socket to be used for mysqld.

</longdesc>

<shortdesc lang="en">MySQL socket</shortdesc>

<content type="string" default="${OCF_RESKEY_pid_default}"/>

</parameter>

 

<parameter name="test_table" unique="0" required="0">

<longdesc lang="en">

Table to be tested in monitor statement (in database.table notation)

</longdesc>

<shortdesc lang="en">MySQL test table</shortdesc>

<content type="string" default="OCF_RESKEY_test_table_default" />

</parameter>

 

<parameter name="test_user" unique="0" required="0">

<longdesc lang="en">

MySQL test user

</longdesc>

<shortdesc lang="en">MySQL test user</shortdesc>

<content type="string" default="OCF_RESKEY_test_user_default" />

</parameter>

 

<parameter name="test_passwd" unique="0" required="0">

<longdesc lang="en">

MySQL test user password

</longdesc>

<shortdesc lang="en">MySQL test user password</shortdesc>

<content type="string" default="${OCF_RESKEY_test_passwd_default}" />

</parameter>

 

<parameter name="enable_creation" unique="0" required="0">

<longdesc lang="en">

If the MySQL database does not exist, it will be created

</longdesc>

<shortdesc lang="en">Create the database if it does not exist</shortdesc>

<content type="integer" default="${OCF_RESKEY_enable_creation_default}"/>

</parameter>

 

<parameter name="additional_parameters" unique="0" required="0">

<longdesc lang="en">

Additional parameters which are passed to the mysqld on startup.

(e.g. --skip-external-locking or --skip-grant-tables)

</longdesc>

<shortdesc lang="en">Additional paramters to pass to mysqld</shortdesc>

<content type="integer" default="${OCF_RESKEY_additional_parameters_default}"/>

</parameter>

 

</parameters>

 

<actions>

<action name="start" timeout="120" />

<action name="stop" timeout="120" />

<action name="status" timeout="60" />

<action name="monitor" depth="0" timeout="30" interval="10" start-delay="10" />

<action name="validate-all" timeout="5" />

<action name="meta-data" timeout="5" />

</actions>

</resource-agent>

END

}

 

mysql_validate() {

# checking the parameters

    if [ ! -f $OCF_RESKEY_config ]; then

           ocf_log err "Config $OCF_RESKEY_mysql_config doesn't exist";

           exit $OCF_ERR_ARGS;

    fi

   

    if [ ! -d $OCF_RESKEY_datadir ]; then

           ocf_log err "Datadir $OCF_RESKEY_datadir dosen't exist";

           exit $OCF_ERR_ARGS;

    fi

   

    getent passwd $OCF_RESKEY_user >/dev/null 2>&1

    if [ ! $? -eq 0 ]; then

           ocf_log err "User $OCF_RESKEY_user doesn't exit";

           exit $OCF_ERR_ARGS;

    fi

   

    getent group $OCF_RESKEY_group >/dev/null 2>&1

    if [ ! $? -eq 0 ]; then

           ocf_log err "Group $OCF_RESKEY_group doesn't exist";

           exit $OCF_ERR_ARGS;

    fi

}

 

mysql_status() {

           if [ ! -e $OCF_RESKEY_pid ]; then

                      ocf_log debug "MySQL is not running"

                      return $OCF_NOT_RUNNING;

           fi

          

           pid=`cat $OCF_RESKEY_pid`;

           if [ -d /proc -a -d /proc/1 ]; then

                      [ "u$pid" != "u" -a -d /proc/$pid ]

           else

                      kill -0 $pid >/dev/null 2>&1

           fi

 

           if [ $? -eq 0 ]; then

                      return $OCF_SUCCESS;

           else     

                      ocf_log debug "MySQL not running: removing old PID file"

                      rm -f $OCF_RESKEY_pid

                      return $OCF_NOT_RUNNING;

           fi

}

 

mysql_monitor() {

    mysql_status

    rc=$?

 

    if [ $OCF_CHECK_LEVEL = 0 -o $rc != 0 ]; then

           return $rc

    fi

 

    # Do a detailed status check

    buf=`echo "SELECT * FROM $OCF_RESKEY_test_table" | mysql --user=$OCF_RESKEY_test_user --password=$OCF_RESKEY_test_passwd --socket=$OCF_RESKEY_socket -O connect_timeout=1 2>&1`

    rc=$?

    if [ ! $rc -eq 0 ]; then

           ocf_log err "MySQL $test_table monitor failed:";

           if [ ! -z "$buf" ]; then ocf_log err $buf; fi

           return $OCF_ERR_GENERIC;

    else

           ocf_log info "MySQL monitor succeded";

           return $OCF_SUCCESS;

    fi

}

 

mysql_start() {

    mysql_status

    if [ $? == $OCF_SUCCESS ]; then

           ocf_log info "MySQL already running"

           return $OCF_SUCCESS

    fi

          

    touch $OCF_RESKEY_log

    chown $OCF_RESKEY_user:$OCF_RESKEY_group $OCF_RESKEY_log

    chmod 0640 $OCF_RESKEY_log

    [ -x /sbin/restorecon ] && /sbin/restorecon $OCF_RESKEY_log

   

    if [ $OCF_RESKEY_enable_creation -a ! -d $OCF_RESKEY_datadir/mysql ] ; then        

        ocf_log info "Initializing MySQL database: "

           $MYSQL_BINDIR/mysql_install_db --datadir=$OCF_RESKEY_datadir

        rc=$?

        if [ $rc -ne 0 ] ; then

               ocf_log err "Initialization failed: $rc";

            exit $OCF_ERR_GENERIC

        fi

        chown -R $OCF_RESKEY_user:$OCF_RESKEY_group $OCF_RESKEY_datadir

    fi

 

    # Uncomment to perform permission clensing

    # - not convinced this should be enabled by default

    #

    #chmod 0755 $OCF_RESKEY_datadir

    #chown -R $OCF_RESKEY_user $OCF_RESKEY_datadir

    #chgrp -R $OCF_RESKEY_group $OCF_RESKEY_datadir

 

    ${OCF_RESKEY_binary}  --defaults-file=$OCF_RESKEY_config --pid-file=$OCF_RESKEY_pid --socket=$OCF_RESKEY_socket --datadir=$OCF_RESKEY_datadir --user=$OCF_RESKEY_user $OCF_RESKEY_additional_parameters >/dev/null 2>&1 &

    rc=$?

   

    if [ $rc != 0 ]; then

           ocf_log err "MySQL start command failed: $rc"

           return $rc

    fi

   

    # Spin waiting for the server to come up.

    # Let the CRM/LRM time us out if required

    start_wait=1

    while [ $start_wait = 1 ]; do

           mysql_status

           rc=$?

           if [ $rc = $OCF_SUCCESS ]; then

               start_wait=0

 

           elif [ $rc != $OCF_NOT_RUNNING ]; then

               ocf_log info "MySQL start failed: $rc"

               return $rc

           fi

        sleep 2

    done

   

    ocf_log info "MySQL started"

    return $OCF_SUCCESS

}

 

mysql_stop() {

    if [ ! -f $OCF_RESKEY_pid ]; then

        return $OCF_SUCCESS

    fi

 

    pid=`cat $OCF_RESKEY_pid 2> /dev/null `

    /bin/kill $pid > /dev/null 2>&1

    rc=$?

    if [ $rc != 0 ]; then

        ocf_log err "MySQL couldn't be stopped"

           return $OCF_ERR_GENERIC

    fi

 

    stop_wait=1

    while [ $stop_wait = 1 ]; do

           mysql_status

           rc=$?

           if [ $rc == $OCF_NOT_RUNNING ]; then

               stop_wait=0

           fi

        sleep 1

    done

 

    ocf_log info "MySQL stopped";

    rm -f /var/lock/subsys/mysqld

    rm -f $OCF_RESKEY_datadir/mysql.sock

    return $OCF_SUCCESS

}

 

 

# What kind of method was invoked?

case "$1" in

  start)  mysql_validate;

                      mysql_start;;

  stop)              mysql_stop;;

  status) mysql_status;;

  monitor)         mysql_monitor;;

 

  meta-data)      meta_data; exit $OCF_SUCCESS;;

  validate-all)     mysql_validate; exit $OCF_SUCCESS;;

 

 *)                   usage

                      exit $OCF_ERR_UNIMPLEMENTED;;

esac

exit $?

 

Drbd02에도 똑같이 설정을 해준다.(scp명령어를 사용하여 스크립트를 전송한다.)

[root@drbd01 heartbeat] #Scp –p mysql root@192.168.0.38:/usr/lib/ocf/resource.d/heartbeat

 

 

설정후 양서버에서 Heartbeat를 기동한다.

[root@drbd01 ~]# service heartbeat start

[root@drbd02 MYSQL]#  service heartbeat start

 

Crm_mon으로 상태확인한다.(모든 리소스가 다 올라오면 정상)

[root@drbd01 ~]# crm_mon

Defaulting to one-shot mode

You need to have curses available at compile time to enable console mode

 

 

============

Last updated: Fri Apr 19 16:56:17 2013

Current DC: drbd02 (c7c96c5d-8df8-4dbc-a568-7e6be5631e2d)

2 Nodes configured.

1 Resources configured.

============

 

Node: drbd02 (c7c96c5d-8df8-4dbc-a568-7e6be5631e2d): online

Node: drbd01 (73dfc495-abe0-433c-831a-904125dec395): online

 

Resource Group: group_1

    IPaddr_192_168_0_70  (heartbeat::ocf:IPaddr):     Started drbd01

    IPaddr_192_168_0_55  (heartbeat::ocf:IPaddr):     Started drbd01

    drbddisk_3    (heartbeat:drbddisk):        Started drbd01

    Filesystem_4  (heartbeat::ocf:Filesystem): Started drbd01

    mysql_5       (heartbeat::ocf:mysql):      Started drbd01

 

[root@drbd02 ~]# crm_mon

Defaulting to one-shot mode

You need to have curses available at compile time to enable console mode

 

 

============

Last updated: Fri Apr 19 16:57:14 2013

Current DC: drbd02 (c7c96c5d-8df8-4dbc-a568-7e6be5631e2d)

2 Nodes configured.

1 Resources configured.

============

 

Node: drbd02 (c7c96c5d-8df8-4dbc-a568-7e6be5631e2d): online

Node: drbd01 (73dfc495-abe0-433c-831a-904125dec395): online

 

Resource Group: group_1

    IPaddr_192_168_0_70  (heartbeat::ocf:IPaddr):     Started drbd01

    IPaddr_192_168_0_55  (heartbeat::ocf:IPaddr):     Started drbd01

    drbddisk_3    (heartbeat:drbddisk):        Started drbd01

    Filesystem_4  (heartbeat::ocf:Filesystem): Started drbd01

    mysql_5       (heartbeat::ocf:mysql):      Started drbd01

 

 

 

반응형
Comments