共计 4652 个字符,预计需要花费 12 分钟才能阅读完成。
丸趣 TV 小编给大家分享一下 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”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!