成都网站建设设计

将想法与焦点和您一起共享

MySQL如何实现高可用+共享存储NFS

小编给大家分享一下MySQL如何实现高可用+共享存储NFS,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

创新互联专注于高明企业网站建设,响应式网站设计,成都商城网站开发。高明网站建设公司,为高明等地区提供建站服务。全流程按需搭建网站,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

规划图

1、首先进行资源的分析

1)Vip

2)Mysqld

3)Nfs

理清他们之间的启动先后顺序:nfs必须在mysqld启动前启动

2、nfs的配置

NFS共享目录上挂载的分区,最好做成lvm,实现自动扩展

2.1 安装

# yum -y install nfs-utils

2.2 配置

# mkdir /share

# vim /etc/exports

172.16.98.3:/share    172.16.98.1(rw,no_root_squash) 172.16.98.2(rw,no_root_squash)

# service nfs start

# groupadd -g 186 mysql

# useradd -u 186 -g mysql -s /sbin/nologin -M mysql

# chown mysql:mysql /share

3、在mysql1上挂载nfs分区进行mysql安装测试

3.1 挂载nfs

# mkdir /data

# chown mysql:mysql /data

# mount 172.16.98.3:/share /data

3.2 使用mysql的解压缩包安装

# groupadd -g 186 mysql

# useradd -u 186 -g mysql -s /sbin/nologin -M mysql
在三台机器上,创建的mysql组和用户的uid、gid要保持一致

# tar -zxvf mysql-5.5.24-linux2.6-i686.tar.gz -C /usr/local

# cd /usr/local

# ln -s mysql-5.5.24-linux2.6-i686 mysql

# cd mysql

# chown -R mysql:mysql .

# scripts/mysql_install_db --user=mysql --datadir=/data

# chowm -R root .

# cp support-files/my-large.cnf /etc/my.cnf

# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

# chmod +x /etc/rc.d/init.d/mysqld

# vim /etc/profile

PATH=$PATH:/usr/local/mysql/bin

# export PATH=$PATH:/usr/local/mysql/bin

3.3 编辑配置文件,启动服务

# vim /etc/my.cnf

[mysqld]

thread_concurrency = 2

datadir=/data

# service mysqld start

3.4 在mysql2上的安装

参考前面的步骤,需要说明一点的是MySQL的安装,这里不需要再进行初始化mysql

# tar -zxvf mysql-5.5.24-linux2.6-i686.tar.gz -C /usr/local

# cd /usr/local

# ln -s mysql-5.5.24-linux2.6-i686 mysql

# cd mysql

# chowm -R root .

# cp support-files/my-large.cnf /etc/my.cnf

# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

# chmod +x /etc/rc.d/init.d/mysqld

# vim /etc/profile

PATH=$PATH:/usr/local/mysql/bin

# export PATH=$PATH:/usr/local/mysql/bin

# service mysqld start

# cd /data

3.5 停止所有资源

1)关闭mysql服务
# service mysqld stop

2)将nfs共享目录卸载

# umount /data

4、Corosync的安装

前期准备

1)ssh双机互信,方便配置

2)时间保持一致

3)/etc/hosts ,主机名设置,互相解析

4.1 在mysql1、mysql2上安装corosync

# yum install -y cluster-glue-1.0.6-1.6.el5.i386.rpm cluster-glue-libs-1.0.6-1.6.el5.i386.rpm corosynclib-1.2.7-1.1.el5.i386.rpm corosync-1.2.7-1.1.el5.i386.rpm heartbeat-3.0.3-2.3.el5.i386.rpm heartbeat-libs-3.0.3-2.3.el5.i386.rpm libesmtp-1.0.4-5.el5.i386.rpm pacemaker-cts-1.1.5-1.1.el5.i386.rpm pacemaker-libs-1.1.5-1.1.el5.i386.rpm pacemaker-1.1.5-1.1.el5.i386.rpm perl-TimeDate-1.16-5.el5.noarch.rpm resource-agents-1.0.4-1.1.el5.i386.rpm

4.2 corosync的配置

1)mysql1

# cd /etc/corosync

# cp corosync.conf.example corosync.conf

# vim corosync.conf

compatibility: whitetank
totem {

        version: 2

        secauth:on           开启身份验证

        threads: 0

        interface {

                ringnumber: 0

                bindnetaddr: 172.16.0.0

                mcastaddr: 226.94.1.1

                mcastport: 5405

        }

}


logging {

        fileline: off

        to_stderr: on

        to_logfile: yes

#       to_syslog: yes

        logfile: /var/log/cluster/corosync.log

        debug: off

        timestamp: on

        logger_subsys {

                subsys: AMF

                debug: off

        }

}


amf {

        mode: disabled

}

service {

   ver:0

   name:pacemaker

}

# corosync-keygen        创建authkeys

# scp authkeys corosync.conf node2:/etc/corosync

两台mysql上分别创建用于日志的目录

# mkdir /var/log/cluster

4.3 通过mysql1开启corosync,配置资源

1)开启

# service corosync start

# ssh node2 'service corosync start'

# crm_mon

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

Last updated: Thu Aug  9 22:12:22 2012

Stack: openais

Current DC: node1.linuxidc.com - partition with quorum

Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f

2 Nodes configured, 2 expected votes

0 Resources configured.

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


Online: [ node2.linuxidc.com node1.linuxidc.com ]

2)资源的配置

# crm

crm(live)# configure

crm(live)configure# primitive vip ocf:heartbeat:IPaddr params ip=172.16.99.1

crm(live)configure# primitive mysqld lsb:mysqld

crm(live)configure# primitive nfs ocf:heartbeat:Filesystem params device=172.16.98.3:/share directory=/data fstype=nfs op start timeout=60 op stop timeout=60

//定义nfs资源,默认的超时时间是20s,是小于建议的时间60s的,所以手动配置

crm(live)configure# colocation vip_mysqld_nfs inf: mysqld nfs vip

crm(live)configure# order mysqld_after_nfs inf: nfs mysqld

crm(live)configure# property stonith-enabled=false

crm(live)configure# property no-quorum-policy=ignore

crm(live)configure# verify

crm(live)configure# commit

3)检测

# crm_mon

Last updated: Thu Aug  9 22:34:52 2012

Stack: openais

Current DC: node1.linuxidc.com - partition with quorum

Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f

2 Nodes configured, 2 expected votes

3 Resources configured.

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


Online: [ node2.linuxidc.com node1.linuxidc.com ]


nfs     (ocf::heartbeat:Filesystem):    Started node1.linuxidc.com

vip     (ocf::heartbeat:IPaddr):        Started node1.linuxidc.com

mysqld  (lsb:mysqld):   Started node1.linuxidc.com

# crm node standy

# crm_mon

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

Last updated: Thu Aug  9 22:36:18 2012

Stack: openais

Current DC: node1.linuxidc.com - partition with quorum

Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f

2 Nodes configured, 2 expected votes

3 Resources configured.

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


Node node1.linuxidc.com: standby

Online: [ node2.linuxidc.com ]


nfs     (ocf::heartbeat:Filesystem):    Started node2.linuxidc.com

vip     (ocf::heartbeat:IPaddr):        Started node2.linuxidc.com

mysqld  (lsb:mysqld):   Started node2.linuxidc.com

以上是“MySQL如何实现高可用+共享存储NFS”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


新闻名称:MySQL如何实现高可用+共享存储NFS
文章链接:http://chengdu.cdxwcx.cn/article/iepijg.html