(13)现在我们已经配置好了虚拟IP,接下来设置MySQL复制,在两个节点上安装MySQL服务器:
#apt-get install mysql-server
(14)我们来安装基本的replication,在ha1上,编辑/etc/mysql/my.cnf,在[mysqld]这部分(85行附近),取消这部分的注释:
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
在第二个服务器ha2上,同样文件内,取消注释并编辑:
server-id = 2
log_bin = /var/log/mysql/mysql-bin.log
并让mysql监听所有地址
bind-address=0.0.0.0 #只需要在ha2上修改
(15)建立一个复制和测试用户,在两台ha1,ha2,上分别用
#mysql -uroot -p 进入数据库
执行如下命令:
grant replication client, replication slave on *.* to repl_user@'192.168.1.%' identified by 'password';
grant replication client, replication slave, SUPER, PROCESS, RELOAD on *.* to repl_user@'localhost' identified by 'password';
grant select ON mysql.user to test_user@'localhost' identified by 'password';
FLUSH PRIVILEGES;
(16)
现在禁用启动时开启MySQL,因为初始化脚本已经被转换成upstart,在所有的节点上打开/etc/init/mysql.conf并注释掉以下这行:
start on runlevel [2345]
(17)创建pacemaker的MySQL资源:
#crm configure #先执行该命令,进入crm配置模式,然后分别复制粘贴以下内容
primitive clustermysql ocf:percona:mysql \
params binary="/usr/bin/mysqld_safe" log="/var/log/mysql.log" socket="/var/run/mysqld/mysqld.sock" \
evict_outdated_slaves="false" config="/etc/mysql/my.cnf" pid="/var/run/mysqld/mysqld.pid" socket="/var/run/mysqld/mysqld.sock" \
replication_user="repl_user" replication_passwd="password" \
test_user="test_user" test_passwd="password" \
op monitor interval="5s" role="Master" OCF_CHECK_LEVEL="1" \
op monitor interval="2s" role="Slave" timeout="30" OCF_CHECK_LEVEL="1" \
op start interval="0" timeout="120" \
op stop interval="0" timeout="120"
复制粘贴完毕后,正常不会有错误提示,从->回到配置模式下
最后注意要用commit命令提交
(18)执行crm status
你会发现MySQL正在一个节点上运行:
crm_mon -1
============
Last updated: Mon Jul 16 17:36:22 2012
Last change: Mon Jul 16 17:14:55 2012 via cibadmin on ha1
Stack: openais
Current DC: ha2 - partition with quorum
Version: 1.1.6-9971ebba4494012a93c03b40a2c58ec0eb60f50c
2 Nodes configured, 3 expected votes
2 Resources configured.
============
Online: [ ha1 ha2]
mysqlmasterIP (ocf::heartbeat:IPaddr2): Started ha2
clustermysql (ocf::heartbeat:mysql): Started ha2
(19)
现在要安装master/slave控制器,首先我们需要设置hosts的IP,这样它才能迁移MySQL主机,用crm configure edit改动这几行:
node ha1 \
attributes clustermysql_mysql_master_IP="192.168.1.143"
node ha2 \
attributes clustermysql_mysql_master_IP="192.168.1.144"
(20)
然后创建真正的master/slave资源,要实现该步,只需通过crm建立:
#crm configure
ms ms_MySQL clustermysql \
meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true" globally-unique="false" target-role="Master" is-managed="true"
最后记得还要用commit提交
(21)
现在MySQL应以master/slave模式启动,crm status会产生以下结果:
(22)
最后要做的就是当mysql以master或slave模式启动时,变动master/slave IP,复制粘贴运行以下操作可轻易实现:
#crm configure colocation masterIP_on_mysqlMaster inf: mysqlmasterIP ms_MySQL:Master
#crm configure order mysqlPromote_before_IP inf: ms_MySQL:promote mysqlmasterIP:start
好了,现在当你停止pacemaker服务时,MySQL在另一节点上会以master模式启动,而且ip也会相应变动。
在MySQL之后,我们需要让RabbitMQ高度可用。