设为首页 收藏本站
查看: 499|回复: 0

[经验分享] mysql+drbd+corosync实现高可用mysql

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-5-4 08:38:12 | 显示全部楼层 |阅读模式
RHEL6
node1 192.168.1.7
node2 192.168.1.8


双机互信

1
2
3
4
5
6
进192.168.1.7
# ssh-keygen -t rsa ~/.ssh/id_rsa
# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.8
进192.168.1.8
# ssh-keygen -t rsa ~/.ssh/id_rsa
# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.7




编辑/etc/hosts文件
1
2
3
4
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.7 node1.mingxiao.info node1
192.168.1.8 node2.mingxiao.info node2



1
# ssh /etc/hosts node2:/etc/



1
2
3
4
5
时间同步
# ntpdate time.windows.com
# ssh node2 'ntpdate time.windows.com'
# crontab -e
*/5 * * * *  /usr/sbin/ntpdate time.windows.com && /dev/null





配置corosync

# yum install corosync pacemaker
# rpm -ivh crmsh-2.1-1.6.x86_64.rpm

编辑/etc/corosync/corosync.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Please read the corosync.conf.5 manual page
compatibility: whitetank
totem {
        version: 2
        secauth: off
        threads: 0
        interface {
                ringnumber: 0
                bindnetaddr: 192.168.1.0
                mcastaddr: 239.255.1.1
                mcastport: 5405
                ttl: 1
        }
}
logging {
        fileline: off
        to_stderr: no
        to_logfile: yes
        logfile: /var/log/cluster/corosync.log
        to_syslog: no
        debug: off
        timestamp: on
        logger_subsys {
                subsys: AMF
                debug: off
        }
}
service {
        ver: 0
        name: pacemaker
}
sisexec {
        user: root
        group: root
}




# scp /etc/corosync/corosync.conf  node2:/etc/corosync/
# /etc/init.d/corosync start

# ssh node2 '/etc/init.d/corosync start'

请确保corosync启动正常
# crm status
1
2
3
4
5
6
7
8
Last updated: Sun May  3 18:53:33 2015
Last change: Sun May  3 12:53:05 2015
Stack: classic openais (with plugin)
Current DC: node2.mingxiao.info - partition with quorum
Version: 1.1.11-97629de
2 Nodes configured, 2 expected votes
0 Resources configured
Online: [ node1.mingxiao.info node2.mingxiao.info ]



1
2
crm(live)configure# property no-quorum-policy=ignore
crm(live)configure# property stonith-enabled=false






配置drbd
1
2
# yum install drbd84-utils kmod-drbd84
# ssh node2 'yum -y install drbd84-utils kmod-drbd84'




node1和node2创建两个一样的分区,这里为sdb1,分区过程不再说明。

编辑/etc/drbd.d/global_common.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
global {
        usage-count no;
}
common {
        handlers {
                 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";
        }
        startup {
                # wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb
        }
        options {
                # cpu-mask on-no-data-accessible
        }
        disk {
                on-io-error detach;
        }
        net {
                cram-hmac-alg "sha1";
                shared-secret "mydrbdlab";
        }
        syncer {
                rate 200M;
        }
}




编辑/etc/drbd.d/drbd.res
1
2
3
4
5
6
7
8
9
10
11
resource mydrbd {
        device /dev/drbd0;
        disk /dev/sdb1;
        meta-disk internal;
        on node1.mingxiao.info {
                address 192.168.1.7:7789;
        }
        on node2.mingxiao.info {
                address 192.168.1.8:7789;
        }
}



1
2
# drbdadm create-md mydrbd
# ssh node2 'drbdadm create-md mydrbd'




node1和node2节点执行

1
# /etc/init.d/drbd start






node1
1
2
# drbd-overview
0:mydrbd/0  Connected Secondary/Secondary UpToDate/UpToDate



将node1提升为主节点
1
# drbdadm -- --overwrite-data-of-peer primary mydrbd



1
2
3
4
5
6
7
8
9
# mkfs.ext4 /dev/drbd0
# mkdir /mydata
# ssh node2 'mkdir /mydata
# mount /dev/drbd0 /mydata

# drbd-overview
0:mydrbd/0  Connected Primary/Secondary UpToDate/UpToDate
# umount /mydata
# drbdadm secondary mydrbd




配置drbd资源和主从属性
1
2
3
4
5
6
7
8
crm(live)configure# primitive mysqldrbd ocf:linbit:drbd \
   >         params drbd_resource=mydrbd \
   >         op start interval=0 timeout=240 \
   >         op stop interval=0 timeout=100 \
   >         op monitor interval=20 role=Master timeout=30 \
   >         op monitor interval=30 role=Slave timeout=30
crm(live)configure# ms ms_mysqldrbd mysqldrbd \
   >         meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true



查看状态
1
2
3
4
5
6
7
8
9
10
11
12
crm(live)# status
Last updated: Sun May  3 19:55:32 2015
Last change: Sun May  3 19:55:19 2015
Stack: classic openais (with plugin)
Current DC: node2.mingxiao.info - partition with quorum
Version: 1.1.11-97629de
2 Nodes configured, 2 expected votes
2 Resources configured
Online: [ node1.mingxiao.info node2.mingxiao.info ]
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
     Masters: [ node1.mingxiao.info ]
     Slaves: [ node2.mingxiao.info ]




配置文件系统资源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
crm(live)configure# primitive mystore ocf:heartbeat:Filesystem params device=/dev/drbd0 directory=/mydata fstype=ext4 op start timeout=60 op stop timeout=60
crm(live)configure# colocation mystore_with_ms_mysqldrbd inf: mystore ms_mysqldrbd:Master
crm(live)configure# order mystore_after_ms_mysqldrbd mandatory: ms_mysqldrbd:promote mystore:start
crm(live)configure# verify
crm(live)configure# commit
crm(live)# status
Last updated: Sun May  3 19:59:13 2015
Last change: Sun May  3 19:58:54 2015
Stack: classic openais (with plugin)
Current DC: node2.mingxiao.info - partition with quorum
Version: 1.1.11-97629de
2 Nodes configured, 2 expected votes
3 Resources configured
Online: [ node1.mingxiao.info node2.mingxiao.info ]
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
     Masters: [ node1.mingxiao.info ]
     Slaves: [ node2.mingxiao.info ]
mystore(ocf::heartbeat:Filesystem):Started node1.mingxiao.info





node1初始化mysql

# tar xf mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql
1
2
3
4
# groupadd -r -g 306 mysql
# useradd -g 306 -r -u 306 mysql
# mkdir /mydata/data
   # chown -R mysql.mysql /mydata/data




MySQL初始化:  
1
2
3
# cd /usr/local/mysql
   # scripts/mysql_install_db --user=mysql --datadir=/mydata/data
   # chown -R root /usr/local/mysql/*



提供SysV风格服务脚本
1
# cp support-files/mysql.server /etc/init.d/mysqld




提供MySQL配置文件
1
2
3
4
5
6
# cp my.cnf /etc/my.cnf
   # vim /etc/my.cnf
    basedir = /usr/local/mysql
    datadir = /mydata/data
    port = 3306
    sock=/var/lib/mysql/mysql.sock




编辑/etc/profile.d/mysql.sh
1
export PATH=$PATH:/usr/local/mysql/bin




编辑/etc/ld.so.conf.d/mysql.conf
1
  /usr/local/mysql/lib



  # su
man帮助文档,编辑/etc/man.config      
1
  MANPATH /usr/local/mysql/man




头文件
1
ln -sv /usr/local/mysql/include/ /usr/include/mysql




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mysql> use mysql;
mysql> GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'xiaoming';
mysql> CREATE DATABASE xiaoming;
mysql> show database;
mysql> show DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| xiaoming           |
+--------------------+
5 rows in set (0.00 sec)




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# crm node standby
# crm node online
# crm status
Last updated: Sun May  3 20:09:58 2015
Last change: Sun May  3 20:09:56 2015
Stack: classic openais (with plugin)
Current DC: node2.mingxiao.info - partition with quorum
Version: 1.1.11-97629de
2 Nodes configured, 2 expected votes
3 Resources configured
Online: [ node1.mingxiao.info node2.mingxiao.info ]
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
     Masters: [ node2.mingxiao.info ]
     Slaves: [ node1.mingxiao.info ]
mystore(ocf::heartbeat:Filesystem):Started node2.mingxiao.info




node2配置mysql
1
2
3
4
5
# groupadd -r -g 306 mysql
# useradd -g 306 -r -u 306 mysql
# tar xf  mysql-5.6.14-linux-glibc2.5-x86_64  /usr/local/mysql
# cd /usr/local/mysql
# chown -R root:mysql ./



提供SysV风格服务脚本
1
# cp support-files/mysql.server /etc/init.d/mysqld




提供MySQL配置文件
1
2
3
4
5
6
# cp my.cnf /etc/my.cnf
   # vim /etc/my.cnf
    basedir = /usr/local/mysql
    datadir = /mydata/data
    port = 3306
    sock=/var/lib/mysql/mysql.sock




编辑/etc/profile.d/mysql.sh
1
export PATH=$PATH:/usr/local/mysql/bin




编辑/etc/ld.so.conf.d/mysql.conf
1
  /usr/local/mysql/lib



  # su
man帮助文档,编辑/etc/man.config      
1
  MANPATH /usr/local/mysql/man




头文件
1
ln -sv /usr/local/mysql/include/ /usr/include/mysql




由于node1已经初始化过mysql,这里不用重新初始化,可以直接启动。
1
2
3
4
5
6
7
8
9
10
11
12
13
# service mysqld start
Starting MySQL.. SUCCESS!
mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| xiaoming           |
+--------------------+
5 rows in set (0.02 sec)




配置mysqld资源:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
crm(live)configure# primitive mysqld lsb:mysqld
crm(live)configure# colocation mysqld_with_mystore inf: mysqld mystore
crm(live)configure# order mysqld_after_mystore mandatory: mystore: mysqld

crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# cd
crm(live)# status
Last updated: Sun May  3 20:19:41 2015
Last change: Sun May  3 20:19:34 2015
Stack: classic openais (with plugin)
Current DC: node2.mingxiao.info - partition with quorum
Version: 1.1.11-97629de
2 Nodes configured, 2 expected votes
4 Resources configured
Online: [ node1.mingxiao.info node2.mingxiao.info ]
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
     Masters: [ node2.mingxiao.info ]
     Slaves: [ node1.mingxiao.info ]
mystore(ocf::heartbeat:Filesystem):Started node2.mingxiao.info
mysqld(lsb:mysqld):Started node2.mingxiao.info




配置IP,从此IP访问可连接至mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
crm(live)configure# primitive myip IPaddr2  params ip=192.168.1.20 nic=eth1 cidr_netmask=24
crm(live)configure# colocation myip_with_mysqld inf: mysqld myip

crm(live)# status
Last updated: Sun May  3 20:36:26 2015
Last change: Sun May  3 20:36:23 2015
Stack: classic openais (with plugin)
Current DC: node2.mingxiao.info - partition with quorum
Version: 1.1.11-97629de
2 Nodes configured, 2 expected votes
5 Resources configured
Online: [ node1.mingxiao.info node2.mingxiao.info ]
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
     Masters: [ node2.mingxiao.info ]
     Slaves: [ node1.mingxiao.info ]
mystore(ocf::heartbeat:Filesystem):Started node2.mingxiao.info
mysqld(lsb:mysqld):Started node2.mingxiao.info
myip(ocf::heartbeat:IPaddr2):Started node2.mingxiao.info





一切都已配置完毕


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-63328-1-1.html 上篇帖子: mysql-poxy 实现mysql主从架构读写分离 下篇帖子: 解决误删Mysql中root所有权限的方法! mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表