分类目录归档:Linux高可用

heartbeat+drbd+mysql高可用配置

一、heartbeat
1、安装heartbeat
Heartbeat安装及简单配置

2、配置参数
2.1)/etc/ha.d/ha.cf
logfile /var/log/ha-log
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
ucast eth1 10.10.10.2
auto_failback off
watchdog /dev/watchdog
node node1
node node2
ping 192.168.1.1
respawn hacluster /usr/lib/heartbeat/ipfail

2.2)/etc/ha.d/haresources
node1 IPaddr::192.168.1.100/24/eth0/ drbddisk Filesystem::/dev/drbd0::/opt/mysql::ext3 mysql

2.3)/etc/ha.d/authkeys
auth 1
1 crc

二、DRBD
1、DRBD安装
DRBD安装配置说明

2、/etc/drbd.conf

global {
usage-count yes;
}
common {
  syncer { rate 10M; }
}
resource r0 {
protocol C;
disk {
    on-io-error   detach;
  }
net {
after-sb-0pri disconnect;
after-sb-1pri disconnect;
after-sb-2pri disconnect;
rr-conflict   disconnect;
}
on node1 {
    device     /dev/drbd0;
    disk       /dev/sdb1;
    address    10.10.10.1:7788;
    meta-disk  internal;
  }
on node2 {
    device    /dev/drbd0;
    disk      /dev/sdb1;
    address   10.10.10.2:7788;
    meta-disk internal;
  }
}

三、mysql
1、mysql安装
mysql 5.5二进制文件安装

四、服务配置
1、配置mysql服务器(不要设置开机启动,由heartbeat控制)
修改mysql.server文件
basedir=/opt/mysql/product/5.5
datadir=/opt/mysql/mysqldata
mv /opt/mysql/product/5.5/support-files/mysql.server /etc/init.d/mysql

2、配置heartbeat
chkconfig –add heartbeat
chkconfig heartbeat on

发表在 Linux高可用 | 一条评论

DRBD安装配置说明

一、安装前说明
DRBD(Distributed Replicated Block Device),分布式复制块设备,是一种通过TCP/IP网络实现块设备数据实时镜像的方案。利用这种方案,单一主节点模式(single primary mode)双机系统能够实时地将业务数据保存在主备节点的磁盘中,正常情况下两个节点的数据是一模一样的。
根据官方的说明文档,如果系统内核(linux)版本低于2.6.33,在安装软件之前需要加载DRBD模块,如果高于(或等于)2.6.33,则只安装客户端软件。
如果没有安装DRBD模块,会在启动drbd时出现如下错误:
[root@node1 tmp]# /etc/init.d/drbd start
Starting DRBD resources: Can not load the drbd module.
其实就是安装一个kmod-drbd包即可

二、安装前环境设定
主机名        IP地址       DRBD使用磁盘
node1     10.10.10.1    /dev/sdb1
node2     10.10.10.2    /dev/sdb1
版本信息
[root@node1 /]# uname -a
Linux node1 2.6.9-89.0.0.0.1.ELsmp #1 SMP Tue May 19 04:23:49 EDT 2009 i686 i686 i386 GNU/Linux
[root@node2 test]# uname -a
Linux node2 2.6.9-89.0.0.0.1.ELsmp #1 SMP Tue May 19 04:23:49 EDT 2009 i686 i686 i386 GNU/Linux
挂载点:/drbd

三、安装步骤(两个节点相同)
1、安装kmod-drbd包
[root@node1 ~]# rpm -ivh /tmp/kmod-drbd83-smp-8.3.8-1.el4_8.i686.rpm
警告:/tmp/kmod-drbd83-smp-8.3.8-1.el4_8.i686.rpm: V3 DSA 簽章:NOKEY, key ID 443e1821
準備中… ########################################### [100%]
1:kmod-drbd83-smp ########################################### [100%]

2、安装drbd包
[root@node1 ~]# rpm -ivh /tmp/drbd83-8.3.8-1.el4_8.i386.rpm
警告:/tmp/drbd83-8.3.8-1.el4_8.i386.rpm: V3 DSA 簽章:NOKEY, key ID 443e1821
準備中… ########################################### [100%]
1:drbd83 ########################################### [100%]

四、fdisk磁盘(两个节点均要)
[root@node1 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won’t be recoverable.

The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0×0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): 200

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

五、/etc/drbd.conf配置(两个节点一样)

global {
usage-count yes;
}
common {
  syncer { rate 10M; }
}
resource r0 {
protocol C;
disk {
    on-io-error   detach;
  }
net {
after-sb-0pri disconnect;
after-sb-1pri disconnect;
after-sb-2pri disconnect;
rr-conflict   disconnect;
}
on node1 {
    device     /dev/drbd0;
    disk       /dev/sdb1;
    address    10.10.10.1:7788;
    meta-disk  internal;
  }
on node2 {
    device    /dev/drbd0;
    disk      /dev/sdb1;
    address   10.10.10.2:7788;
    meta-disk internal;
  }
}

六、创建DRBD资源
[root@node1 tmp]# drbdadm create-md r0 //r0为配置文件中定义的资源名
[root@node2 tmp]# drbdadm create-md r0

七、DRBD的启动、关闭以及测试
1、启动DRBD
[root@node1 ~]# /etc/init.d/drbd start
[root@node2 ~]# /etc/init.d/drbd start

2、查看状态(两种方法均可)
[root@node1 tmp]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:13:40
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:b oos:1606380

[root@node2 ~]# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:13:40
m:res cs ro ds p mounted fstype
0:r0 Connected Secondary/Secondary Inconsistent/Inconsistent C

3、设置主机
[root@node1 tmp]# drbdsetup /dev/drbd0 primary -o

4、再查看状态
[root@node1 tmp]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:13:40
0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r—-
ns:15520 nr:0 dw:0 dr:15520 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:1590860
[>....................] sync’ed: 1.3% (1590860/1606380)K delay_probe: 0
finish: 0:03:23 speed: 7,760 (7,760) K/sec

[root@node2 ~]# /etc/init.d/drbd status //表示数据初始化已经完成
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:13:40
m:res cs ro ds p mounted fstype
0:r0 Connected Secondary/Primary UpToDate/UpToDate C

5、主节点磁盘操作
[root@node1 tmp]# mkfs.ext3 /dev/drbd0
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
200928 inodes, 401595 blocks
20079 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=415236096
13 block groups
32768 blocks per group, 32768 fragments per group
15456 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@node1 tmp]# mkdir /drbd
[root@node1 tmp]# mount /dev/drbd0 /drbd
[root@node1 tmp]# df -h
Filesystem 容量 已用 可用 已用% 挂载点
/dev/sda2 18G 9.1G 7.7G 55% /
/dev/sda1 99M 13M 82M 14% /boot
none 395M 0 395M 0% /dev/shm
/dev/drbd0 1.6G 35M 1.4G 3% /drbd
[root@node1 tmp]# cd /drbd/
[root@node1 drbd]# ll
总用量 16
drwx—— 2 root root 16384 7月 14 15:01 lost+found
[root@node1 drbd]# mkdir test
[root@node1 drbd]# mkdir test
[root@node1 drbd]# cd test
[root@node1 test]# vi xifenfei.cf
drbd 测试 //vi 写入xifenfei.cf中数据

6、启用备机磁盘
[root@node1 /]# umount /drbd/
[root@node1 /]# drbdsetup 0 secondary
[root@node2 ~]# drbdadm primary r0
[root@node2 ~]# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:13:40
m:res cs ro ds p mounted fstype
0:r0 Connected Primary/Secondary UpToDate/UpToDate C
[root@node2 ~]# mkdir /drbd
[root@node2 ~]# mount /dev/drbd0 /drbd
[root@node2 ~]# df -h
Filesystem 容量 已用 可用 已用% 挂载点
/dev/sda2 18G 9.1G 7.7G 55% /
/dev/sda1 99M 13M 82M 14% /boot
none 395M 0 395M 0% /dev/shm
/dev/drbd0 1.6G 35M 1.4G 3% /drbd
[root@node2 ~]# cd /drbd
[root@node2 drbd]# ll
总用量 20
drwx—— 2 root root 16384 7月 14 15:01 lost+found
drwxr-xr-x 2 root root 4096 7月 14 15:05 test
[root@node2 drbd]# cd test/
[root@node2 test]# ll
总用量 4
-rw-r–r– 1 root root 10 7月 14 15:05 chengfei.cf
[root@node2 test]# more xifenfei.cf
drbd 测试 //主节点中 vi 写入xifenfei.cf中数据

发表在 Linux高可用 | 2 条评论

heartbeat中ha.cf参数说明

#debugfile /var/log/ha-debug
说明:调试日志文件文件,取默认值

logfile /var/log/ha-log
说明:系统运行日志文件,取默认值

#logfacility local0
说明:用于syslog()/logger的设备

keepalive 2
说明:心跳频率,自己设定。1:表示1秒;200ms:表示200毫秒

deadtime 30
说明:节点死亡时间阀值,就是从节点在过了10后还没有收到心跳就认为主节点死亡,自己设定

warntime 10
说明:发出警告时间,自己设定

udpport 694
说明:心跳信息传递的udp端口,自己设定

#bcast eth0 # Linux
说明:采用udp广播播来通知心跳,建议在副节点不只一台时使用

ucast eth0 172.30.31.68
说明:采用网卡eth0的udp单播来通知心跳,eth0的IP

#mcast eth0 225.0.0.1 694 1 0
说明:采用udp多播播来通知心跳,建议在副节点不只一台时使用

auto_failback off
说明:主节点重启成功后,资源是自动拿回到主节点还是等到副节点down调后拿回资源

node heartbeat1
说明:主节点名称,与uname –n保持一致。排在第一的默认为主节点,所以不要搞措顺序
node heartbeat2
说明:副节点名称,与uname –n保持一致

watchdog /dev/watchdog
说明:看门狗。如果本节点在超过一分钟后还没有发出心跳,那么本节点自动重启

以上这些是我个人认为必配项,下面这些是可选项
stonith baytech /etc/ha.d/conf/stonith.baytech
说明:主/副等所有节点的一种校验。

respawn userid /path/name/to/run
说明:和heartbeat必须一起启动的本地服务

ping 10.10.10.254
说明:伪节点IP,伪节点就是其失效时主/副节点不会正常工作但本身不是主/副节点之一。

respawn hacluster /usr/lib/heartbeat/ipfail
说明:与ping选项一起使用,取默认值。

baud 19200
说明:串口波特率,与serial一起使用。

serial /dev/ttyS0 # Linux
说明:采用串口来传递心跳信息。

发表在 Linux高可用 | 评论关闭