内容正式开始前,我已经在集群中添加了新的节点controller1(IP地址为10.0.0.14)。

在所有节点上安装软件:
# yum install -y mariadb-galera-server xinetd rsync

在节点1初始化数据库:
# systemctl start mariadb.service
# mysql_secure_installation
# mysql -u root -p -e "CREATE USER 'clustercheck'@'localhost' IDENTIFIED BY '123456';"
# systemctl stop mariadb.service

在所有节点上配置MariaDB和Galera:
# vi /etc/my.cnf.d/galera.cnf
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=controller1
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_name="my_wsrep_cluster"
wsrep_cluster_address="gcomm://controller1,controller2,controller3"
wsrep_slave_threads=1
wsrep_certify_nonPK=1
wsrep_max_ws_rows=131072
wsrep_max_ws_size=1073741824
wsrep_debug=0
wsrep_convert_LOCK_to_trx=0
wsrep_retry_autocommit=1
wsrep_auto_increment_control=1
wsrep_drupal_282555_workaround=0
wsrep_causal_reads=0
wsrep_notify_cmd=
wsrep_sst_method=rsync
wsrep_sst_auth=root:
“bind-address=”配置成/etc/hosts中的本机名称。
注意:如果“bind-address=0.0.0.0”,则在本机所有IP的3306端口进行监听,包括VIP。这将导致后续haproxy无法在VIP的3306端口监听。

在节点1执行如下命令:
# sudo -u mysql /usr/libexec/mysqld --wsrep-cluster-address='gcomm://' &
需要记住屏幕上的进程id,后面有用。

在节点2、节点3:
# systemctl start mariadb.service
# systemctl status -l mariadb.service

在任意节点确认集群的成员数量:
# mysql -u root -e 'SELECT VARIABLE_VALUE as "wsrep_cluster_size" FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME="wsrep_cluster_size"'
+--------------------+
| wsrep_cluster_size |
+--------------------+
| 3 |
+--------------------+

以上状态均正常,重启节点1的服务:
# kill <mysql PIDs>
# systemctl start mariadb.service

在所有节点上创建健康检查登录信息文件:
# vi /etc/sysconfig/clustercheck
MYSQL_USERNAME=clustercheck
MYSQL_PASSWORD=123456
MYSQL_HOST=localhost
MYSQL_PORT=3306

在所有节点上创建供HAProxy调用的健康检查服务:
#vi /etc/xinetd.d/galera-monitor
service galera-monitor
{
port = 9200
disable = no
socket_type = stream
protocol = tcp
wait = no
user = root
group = root
groups = yes
server = /usr/bin/clustercheck
type = UNLISTED
per_source = UNLIMITED
log_on_success =
log_on_failure = HOST
flags = REUSE
}
此处检查状态的端口为9200。

在所有节点上启动xinetd服务,clustercheck需要这个服务:
# systemctl daemon-reload
# systemctl enable xinetd
# systemctl start xinetd

测试检查效果:
# clustercheck
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: close
Content-Length: 32

Galera cluster node is synced.

或:
# telnet 10.0.0.14 9200
Trying 10.0.0.14...
Connected to 10.0.0.14.
Escape character is '^]'.
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: close
Content-Length: 32

Galera cluster node is synced.
Connection closed by foreign host.

在所有节点上配置haproxy.cfg:
# vi /etc/haproxy/haproxy.cfg
global
chroot /var/lib/haproxy
daemon
group haproxy
maxconn 4000
pidfile /var/run/haproxy.pid
user haproxy

defaults
log global
maxconn 4000
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout check 10s

listen galera_cluster
bind 10.0.0.10:3306
balance source
option httpchk
server controller1 10.0.0.14:3306 check port 9200 inter 2000 rise 2 fall 5
server controller2 10.0.0.12:3306 check port 9200 inter 2000 rise 2 fall 5
server controller3 10.0.0.13:3306 check port 9200 inter 2000 rise 2 fall 5

查看资源当前在哪个节点:
# crm_mon

重启资源所在节点的haproxy服务:
# systemctl restart haproxy.service
# systemctl status -l haproxy.service

openstack controller ha测试环境搭建记录(四)——配置mysql数据库集群的更多相关文章

  1. openstack controller ha测试环境搭建记录(一)——操作系统准备

    为了初步了解openstack controller ha的工作原理,搭建测试环境进行学习. 在学习该方面知识时,当前采用的操作系统版本是centos 7.1 x64.首先在ESXi中建立2台用于测试 ...

  2. openstack controller ha测试环境搭建记录(十五)——创建实例

    # source demo-openrc.sh # ssh-keygenGenerating public/private rsa key pair.Enter file in which to sa ...

  3. openstack controller ha测试环境搭建记录(七)——配置glance

    在所有集群安装glance软件:yum install -y openstack-glance python-glanceclient 在任一节点创建glance用户:mysql -u root -p ...

  4. openstack controller ha测试环境搭建记录(六)——配置keystone

    在所有节点的hosts文件添加:10.0.0.10 myvip 在所有节点安装# yum install -y openstack-keystone python-keystoneclient# yu ...

  5. openstack controller ha测试环境搭建记录(五)——配置rabbitmq集群

    配置rabbitmq集群的步骤非常简单,因为其本身含集群功能,参考openstack官网文档:http://docs.openstack.org/ha-guide/controller-ha-rabb ...

  6. openstack controller ha测试环境搭建记录(三)——配置haproxy

    haproxy.cfg请备份再编辑:# vi /etc/haproxy/haproxy.cfg global    chroot /var/lib/haproxy    daemon    group ...

  7. openstack controller ha测试环境搭建记录(二)——配置corosync和pacemaker

    corosync.conf请备份再编辑:# vi /etc/corosync/corosync.conf totem {        version: 2 token: 10000        t ...

  8. openstack controller ha测试环境搭建记录(十四)——配置cinder(存储节点)

    先简述cinder存储节点的配置:  1.IP地址是10.0.0.41:  2.主机名被设置为block1:  3.所有节点的hosts文件已添加相应条目:  4.已经配置了ntp时间同步:  5.已 ...

  9. openstack controller ha测试环境搭建记录(十三)——配置cinder(控制节点)

    在任一控制节点创建用户:mysql -u root -pCREATE DATABASE cinder;GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'loc ...

随机推荐

  1. iOS开发:后台运行以及保持程序在后台长时间运行

    第一部分 1.先说说iOS 应用程序5个状态: 停止运行-应用程序已经终止,或者还未启动. 不活动-应用程序处于前台但不再接收事件(例如,用户在app处于活动时锁住了设备). 活动-app处于“使用中 ...

  2. drupal错误: Maximum execution time of 240 seconds exceeded

    drupal7.5安装完成,导入汉化包时,出现错误: Fatal error: Maximum execution time of 240 seconds exceeded in D:\phpweb\ ...

  3. 【转】linux ls -l的详解

    原文:http://blog.csdn.net/sjzs5590/article/details/8254527 以root的家目录为例: 可以看到,用ls -l命令查看某一个目录会得到一个7个字段的 ...

  4. servlet多次跳转报IllegalStateException异常

    当发生在如下错误的时候,有一个方案可行, "java.lang.IllegalStateException: Cannot forward after response has been c ...

  5. Android OpenGL ES(九)绘制线段Line Segment .

    创建一个DrawLine Activity,定义四个顶点: float vertexArray[] = { -0.8f, -0.4f * 1.732f, 0.0f, -0.4f, 0.4f * 1.7 ...

  6. Android OpenGL ES .介绍

    引自:http://blog.csdn.net/hgl868/article/details/6971624 1.    OpenGL ES 简介 Android 3D引擎采用的是OpenGL ES. ...

  7. HDU 2018 undefined

    题目思路:完全背包,dp[i][j]代表,砍j只怪,用i点疲劳最多能获得的经验值. 和平常的完全背包不一样的是多了一个限制条件:最多只砍S只怪,所以我们应该多一重循环来q:for 1->S,代表 ...

  8. 正确使用#include和前置声明(forward declaration)

    http://blog.csdn.net/SpriteLW/article/details/965702

  9. FZU 2140 Forever 0.5(将圆离散化)

    主要就是将圆离散化,剩下的都好办 #include<iostream> #include<cstdio> #include<cstring> #include< ...

  10. Python基础学习8---list列表的操作

    a_list = ['hello','world',1,'shanghai',3.99] #列表添加操作的4种方法 #1. 通过+ 字符来拼接 a_list = a_list + [1,'wuhan' ...