码迷,mamicode.com
首页 > 数据库 > 详细

openstack controller ha测试环境搭建记录(四)——配置mysql数据库集群

时间:2015-12-10 18:54:54      阅读:358      评论:0      收藏:0      [点我收藏+]

标签:

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




安装软件:
# yum install -y mariadb-galera-server xinetd rsync


创建用于健康检查的用户:
# systemctl start mysqld.service
# mysql -e "CREATE USER ‘clustercheck‘@‘localhost‘ IDENTIFIED BY ‘123456‘;"
# systemctl stop mysqld.service


创建健康检查登录信息文件:
# vi /etc/sysconfig/clustercheck
MYSQL_USERNAME=clustercheck
MYSQL_PASSWORD=123456
MYSQL_HOST=controller1
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


配置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=0.0.0.0”,则在本机所有IP的3306端口进行监听,包括VIP。这将导致后续haproxy无法在VIP的3306端口监听。


配置防火墙:
# firewall-cmd --add-service=mysql
# firewall-cmd --add-port=4444/tcp
# firewall-cmd --add-port=4567/tcp
# firewall-cmd --add-port=4568/tcp
# firewall-cmd --add-port=9200/tcp
# firewall-cmd --add-port=9300/tcp
# firewall-cmd --add-service=mysql --permanent
# firewall-cmd --add-port=4444/tcp --permanent
# firewall-cmd --add-port=4567/tcp --permanent
# firewall-cmd --add-port=4568/tcp --permanent
# firewall-cmd --add-port=9200/tcp --permanent
# firewall-cmd --add-port=9300/tcp --permanent


上述配置3个节点均要做,做完后准备启动MariaDB集群。



在节点1:
# /usr/libexec/mysqld --wsrep-new-cluster --user=root &
--wsrep-new-cluster这个参数只能在初始化集群使用,且只能在一个节点使用。


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


测试检查效果:
# 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.


在clustercheck的返回值为200后,重启节点1的mariadb:
# kill <mysql PIDs>
# systemctl start mariadb.service


如果出现整个集群的mariadb都关闭,需要在第一个节点用下列命令启动mysql:
# sudo -u mysql /usr/libexec/mysqld --wsrep-cluster-address=‘gcomm://‘ &

其他节点:
# systemctl start mariadb.service

在clustercheck的返回值为200后,重启节点1的mariadb:
# kill <mysql PIDs>
# systemctl start 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                  |
+--------------------+

查看节点在集群中的索引值(从0开始):
# mysql -u root -e ‘SELECT VARIABLE_VALUE as "wsrep_local_index" FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME="wsrep_local_index"‘
+-------------------+
| wsrep_local_index |
+-------------------+
| 0                 |
+-------------------+

或查看所有“wsrep_”开头的状态值:
# mysql -u root -e "show status like ‘wsrep_%‘"
+------------------------------+----------------------------------------------+
| Variable_name                | Value                                        |
+------------------------------+----------------------------------------------+
| wsrep_local_state_uuid       | 7312b4a3-9ee3-11e5-92a7-f70cf44d9e42         |
| wsrep_protocol_version       | 5                                            |
| wsrep_last_committed         | 0                                            |
| wsrep_replicated             | 0                                            |
| wsrep_replicated_bytes       | 0                                            |
| wsrep_repl_keys              | 0                                            |
| wsrep_repl_keys_bytes        | 0                                            |
| wsrep_repl_data_bytes        | 0                                            |
| wsrep_repl_other_bytes       | 0                                            |
| wsrep_received               | 4                                            |
| wsrep_received_bytes         | 504                                          |
| wsrep_local_commits          | 0                                            |
| wsrep_local_cert_failures    | 0                                            |
| wsrep_local_replays          | 0                                            |
| wsrep_local_send_queue       | 0                                            |
| wsrep_local_send_queue_avg   | 0.000000                                     |
| wsrep_local_recv_queue       | 0                                            |
| wsrep_local_recv_queue_avg   | 0.000000                                     |
| wsrep_local_cached_downto    | 18446744073709551615                         |
| wsrep_flow_control_paused_ns | 0                                            |
| wsrep_flow_control_paused    | 0.000000                                     |
| wsrep_flow_control_sent      | 0                                            |
| wsrep_flow_control_recv      | 0                                            |
| wsrep_cert_deps_distance     | 0.000000                                     |
| wsrep_apply_oooe             | 0.000000                                     |
| wsrep_apply_oool             | 0.000000                                     |
| wsrep_apply_window           | 0.000000                                     |
| wsrep_commit_oooe            | 0.000000                                     |
| wsrep_commit_oool            | 0.000000                                     |
| wsrep_commit_window          | 0.000000                                     |
| wsrep_local_state            | 4                                            |
| wsrep_local_state_comment    | Synced                                       |
| wsrep_cert_index_size        | 0                                            |
| wsrep_causal_reads           | 0                                            |
| wsrep_cert_interval          | 0.000000                                     |
| wsrep_incoming_addresses     | 10.0.0.14:3306,10.0.0.12:3306,10.0.0.13:3306 |
| wsrep_cluster_conf_id        | 3                                            |
| wsrep_cluster_size           | 3                                            |
| wsrep_cluster_state_uuid     | 7312b4a3-9ee3-11e5-92a7-f70cf44d9e42         |
| wsrep_cluster_status         | Primary                                      |
| wsrep_connected              | ON                                           |
| wsrep_local_bf_aborts        | 0                                            |
| wsrep_local_index            | 1                                            |
| wsrep_provider_name          | Galera                                       |
| wsrep_provider_vendor        | Codership Oy <info@codership.com>            |
| wsrep_provider_version       | 3.5(rXXXX)                                   |
| wsrep_ready                  | ON                                           |
| wsrep_thread_count           | 2                                            |
+------------------------------+----------------------------------------------+


配置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数据库集群

标签:

原文地址:http://www.cnblogs.com/endoresu/p/5036534.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!