heartbeat+drbd+mysql

配置heartbeat接管drbd服务

配置heartbeat接管drbd服务(延续之前heartbeat及drbd博文内容)
  1、两端确认都建立好 /data目录
  2、关闭drbd服务,关闭heartbeat服务,自启动全部关闭
  3、两端配置haresources
  data-1-1 IPaddr::192.168.0.191/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3

启动顺序
  1、依次启动主备端drbd
  2、drbd置主
  3、依次启动主备端heartbeat,启动后主端自动挂载drbd0到/data

启动完成后状态如下
[root@data-1-1 /]# cat /proc/drbd
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
    ns:340 nr:16 dw:356 dr:3646 al:2 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[root@data-1-1 /]# ip addr | grep 191
    inet 192.168.0.191/24 brd 192.168.0.255 scope global secondary eth0
[root@data-1-1 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2        5916420 4207616   1401604  76% /
tmpfs             502384       0    502384   0% /dev/shm
/dev/sda1         194241   36262    147739  20% /boot
/dev/drbd0       1011928   47696    912828   5% /data

[root@data-1-2 ~]# cat /proc/drbd

version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
 0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
    ns:16 nr:340 dw:356 dr:1364 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

 

安装mysql

#install cmake
tar -zxvf cmake-2.8.0.tar.gz
cd cmake-2.8.0
./configure
gmake && gmake install
cd ..

#install ncurses
yum install ncurses-devel -y

#install mysql5.5.49
useradd mysql -s /bin/nologin -M
mkdir /data
chown -R mysql.mysql /data
tar xf mysql-5.5.49.tar.gz
cd mysql-5.5.49
cmake \
 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.5.49 \
 -DMYSQL_DATADIR=/data \
 -DMYSQL_UNIX_ADDR=/usr/local/mysql5.5.49/tmp/mysqld.sock \
 -DDEFAULT_CHARSET=utf8 \
 -DDEFAULT_COLLATION=utf8_general_ci \
 -DEXTRA_CHARSETS=all \
 -DENABLED_LOCAL_INFILE=1 \
 -DWITH_INNOBASE_STORAGE_ENGINE=1 \
 -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 \
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
 -DWITH_FAST_MUTEXES=1 \
 -DWITH_ZLIB=bundled \
 -DENABLED_LOCAL_INFILE=1 \
 -DWITH_READLINE=1 \
 -DWITH_EMBEDDED_SERVER=1 \
 -DWITH_DEBUG=0;
make && make install 

#init mysql
ln -s /usr/local/mysql5.5.49  /usr/local/mysql
/bin/cp /usr/local/mysql/support-files/my-small.cnf  /etc/my.cnf
echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
source /etc/profile
chown -R mysql.mysql /usr/local/mysql
chmod -R 1777 /tmp
cd  /usr/local/mysql/scripts   =======>备端忽略此步
./mysql_install_db --basedir=/usr/local/mysql --datadir=/data/ --user=mysql    =======>备端忽略此步
cp /usr/local/mysql5.5.49/support-files/mysql.server  /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start    =======>备端忽略此步
netstat -lntup | grep 3306    =======>备端忽略此步


[root@data-1-1 scripts]# mysql    确认mysql安装ok
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.49 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database drbd;  #用来确认备端
Query OK, 1 row affected (0.06 sec)

 

配置heartbeat接管mysql

两端配置haresources
[root@data-1-1 ~]# cat /etc/ha.d/haresources 
data-1-1 IPaddr::192.168.0.191/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 mysqld
[root@data-1-2 ~]# cat /etc/ha.d/haresources 
data-1-1 IPaddr::192.168.0.191/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/data::ext3 mysqld
说明
  data-1-1                  主机名
  IPaddr::192.168.0.191/24/eth0      heartbeat配置ip的脚本,等于/etc/ha.d/resource.d/IPaddr 192.168.0.191/24/eth0 start/stop
  drbddisk::data                启动drbd定义的data资源,等于/etc/ha.d/resource.d/drbddisk data stop/start
  Filesystem::/dev/drbd0::/data::ext3  将drbd0设备挂载到/data/目录,原理同上
  mysqld                       mysql服务起停脚本,等于/etc/init.d/mysqld start/stop
进行测试
[root@data-1-1 ~]# /etc/init.d/heartbeat stop  #主端停止heartbeat,看备端情况
Stopping High-Availability services: Done.
[root@data-1-2 ~]# df  #确认/data已挂载
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2        5916420 4243564   1365656  76% /
tmpfs             502384       0    502384   0% /dev/shm
/dev/sda1         194241   36263    147738  20% /boot
/dev/drbd0       1011928   47692    912832   5% /data
[root@data-1-2 ~]# ip addr | grep 191  #确认vip漂移
    inet 192.168.0.191/24 brd 192.168.0.255 scope global secondary eth0

[root@data-1-2 ~]# mysql -u root -e "show databases;" | grep drbd #确认数据库及数据
drbd

[root@data-1-2 ~]# cat /proc/drbd  #接管drbd,成为primary
version: 8.4.9-1 (api:1/proto:86-101)
GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
    ns:612 nr:42460 dw:43072 dr:17959 al:8 bm:0 lo:2 pe:0 ua:0 ap:2 ep:1 wo:f oos:0

[root@data-1-1 ~]# /etc/init.d/heartbeat start 检测同上,回切正常

管理要点

1、heartbeat drbd mysql都设置为非开机自启动
2、主备依次启动drbd,并置主
3、主备依次启动heartbeat,heartbeat会启动vip,挂载drbd设备,启动mysql

 

posted @ 2017-05-01 02:23  黑色月牙  阅读(387)  评论(0编辑  收藏  举报