注意这里接上一篇内容:
建立高可用OpenStack云系列共6篇-- 第一篇:《建立高可用OpenStack云(一):安装集群》
第二篇:《建立高可用OpenStack云(二):安装Mysql》
本文是《构建高可用OpenStack云》的第二篇。Openstack的核心就是MySQL数据库,几乎每个组件都是用MySQL获取/设置信息,让我们来看看如何建立一个完全高度可用的MySQL终端。
在hosts文件/etc/hosts中,加入这行:
复制代码
首先我们需要为mysql下载资源代理:
- cd /usr/lib/ocf/resource.d/
- mkdir percona
- cd percona
- wget -q https://github.com/y-trudeau/resource-agents-prm/raw/master/heartbeat/mysql
- chmod u+x mysql
复制代码
这样一来,当我们从从属机到主机升级MySQL服务器是,我们还要将“mysqlmaster”的IP绑定到那个节点上,当失效服务器出现时,它将以slave模式启动MySQL。因为,让我们来建立我们的虚拟IP:
- crm configure primitive mysqlmasterIP ocf:heartbeat:IPaddr2 params ip=10.0.1.1 cidr_netmask=16 nic=eth1 op monitor interval=10s
复制代码
我们可以通过再次运行集群监视器来检查我们的新IP:
- Last updated: Mon Jul 16 16:10:34 2012
- Last change: Mon Jul 16 16:10:33 2012 via cibadmin on server1
- Stack: openais
- Current DC: server1 - partition with quorum
- Version: 1.1.6-9971ebba4494012a93c03b40a2c58ec0eb60f50c
- 2 Nodes configured, 3 expected votes
- 2 Resources configured.
- Online: [ server1 server2 ]
- mysqlmasterIP (ocf::heartbeat:IPaddr2): Started server1
复制代码
现在我们已经配置好了虚拟IP,接下来设置MySQL复制,在两个节点上安装MySQL服务器:
- apt-get install mysql-server
复制代码
我们来安装基本的复制,在server1上,编辑/etc/mysql/my.cnf,在[mysqld]这部分(85行附近),取消这部分的注释:
- server-id = 1
- log_bin = /var/log/mysql/mysql-bin.log
复制代码
在第二个服务器上,同样文件内,取消注释并编辑:
- server-id = 2
- log_bin = /var/log/mysql/mysql-bin.log
复制代码
并让MySQL监听所有地址:
复制代码
之后建立一个复制和一个测试用户,这样在所有服务器的mysql客户端上都会出现:
- grant replication client, replication slave on *.* to repl_user@'10.0.%.%' 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;
复制代码
现在禁用启动时开启MySQL,因为初始化脚本已经被转换成upstart,在所有的节点上打开/etc/init/mysql.conf并注释掉以下这行:
复制代码
现在来创建MySQL资源:
- crm configure 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"
复制代码
你会发现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 server1
- Stack: openais
- Current DC: server2 - partition with quorum
- Version: 1.1.6-9971ebba4494012a93c03b40a2c58ec0eb60f50c
- 2 Nodes configured, 3 expected votes
- 3 Resources configured.
- ============
- Online: [ server1 server2]
- mysqlmasterIP (ocf::heartbeat:IPaddr2): Started server2
- clustermysql (ocf::heartbeat:mysql): Started server2
复制代码
现在要安装master/slave控制器,首先我们需要设置hosts的IP,这样它才能迁移MySQL主机,用crm configure edit改动这几行:
- node server1 \
- attributes clustermysql_mysql_master_IP="10.0.0.1"
- node server2 \
- attributes clustermysql_mysql_master_IP="10.0.0.2"
复制代码
然后创建真正的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"
复制代码
现在MySQL应以master/slave模式启动,crm_mon -1会产生以下结果:
- ============
- Last updated: Tue Jul 17 11:26:04 2012
- Last change: Tue Jul 17 11:00:34 2012 via cibadmin on server1
- Stack: openais
- Current DC: server1- partition with quorum
- Version: 1.1.6-9971ebba4494012a93c03b40a2c58ec0eb60f50c
- 2 Nodes configured, 3 expected votes
- 4 Resources configured.
- ============
- Online: [ server1 server2 ]
- Master/Slave Set: ms_MySQL [clustermysql]
- Masters: [ server1 ]
- Slaves: [ server2 ]
- mysqlmasterIP (ocf::heartbeat:IPaddr2): Started server1
复制代码
最后要做的就是当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也会相应变动。
下一篇:建立高可用OpenStack云--建立HA Openstack云(三):安装RabbitMQ
|