MySQL  - 讨论区

标题:Galera Cluster 部署范例

2013年12月04日 星期三 16:06


一,服务器概况:

Galera Cluster需要至少三个节点,在此次实验过程中,三个节点IP地址:
172.16.88.57
172.16.88.181
172.16.88.231

服务器配置:
8G 内存,4核CPU,30G数据磁盘空间。
均关闭防火墙,关闭SELinux。


二,MariaDB 软件安装源(三个节点均需配置):

/etc/yum.repos.d/mariadb.repo

# MariaDB 5.5 CentOS repository list - created 2013-12-02 02:13 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
enabled=1
gpgcheck=1

三,安装MariaDB-Galera-server软件(三个节点均需安装):

yum erase -y mysql-server
yum install -y MariaDB-Galera-server
yum install -y rsync

四,初始化第一个节点(172.16.88.57)

MySQL配置文件(/etc/my.cnf):

# All files in this package is subject to the GPL v2 license
# More information is in the COPYING file in the top directory of this package.
# Copyright (C) 2011 severalnines.com
[MYSQLD]
user=mysql
basedir=/usr
datadir=/data/mysql/3306
socket=/data/mysql/3306/mysql.sock
pid-file=mysqld.pid
port=3306
log-error=mysql.err
#log-output=FILE
#relay-log=relay-bin
### INNODB OPTIONS
innodb-buffer-pool-size=4G
innodb-additional-mem-pool-size=20M
innodb-flush-log-at-trx-commit=2
innodb-file-per-table=1
innodb-data-file-path = ibdata1:100M:autoextend
## You may want to tune the below depending on number of cores and disk sub
innodb-read-io-threads=4
innodb-write-io-threads=4
innodb-doublewrite=1
innodb-log-file-size=512M
innodb-log-files-in-group=2
innodb-log-buffer-size=64M
innodb-buffer-pool-instances=4
innodb-thread-concurrency=0
innodb-file-format=barracuda
innodb-flush-method = O_DIRECT
innodb-locks-unsafe-for-binlog=1
innodb-autoinc-lock-mode=2
## avoid statistics update when doing e.g show tables
innodb-stats-on-metadata=0
engine-condition-pushdown=1
default-storage-engine=innodb

# CHARACTER SET
#collation-server = utf8_unicode_ci
#init-connect='SET NAMES utf8'
character-set-server = utf8

# REPLICATION SPECIFIC - GENERAL
#server-id must be unique across all mysql servers participating in replication.
server-id=88057
#auto_increment_increment=2
#auto_increment_offset=SERVERID
# REPLICATION SPECIFIC - MASTER
binlog_format=ROW
log-bin=binlog
expire_logs_days=7
log-slave-updates=1
# OTHER THINGS, BUFFERS ETC
key_buffer_size = 24M
tmp_table_size = 64M
max_heap_table_size = 64M
max-allowed-packet = 512M
#sort-buffer-size = 256K
#read-buffer-size = 256K
#read-rnd-buffer-size = 512K
#myisam-sort-buffer_size = 8M
skip-name-resolve
memlock=0
sysdate-is-now=1
max-connections=1000
thread-cache-size=512
query-cache-type = 0
query-cache-size = 0
table-open_cache=1024
lower-case-table-names=0
##
## WSREP options
##

# Full path to wsrep provider library or 'none'
wsrep_provider=/usr/lib64/galera/libgalera_smm.so

wsrep_node_address=
# Provider specific configuration options
wsrep_provider_options="gcache.size=2048M"

# Logical cluster name. Should be the same for all nodes.
wsrep_cluster_name="platform_images"

# Group communication system handle
wsrep_cluster_address='gcomm://'

# Human-readable node name (non-unique). Hostname by default.
#wsrep_node_name=

# Address for incoming client connections. Autodetect by default.
#wsrep_node_incoming_address=

# How many threads will process writesets from other nodes
wsrep_slave_threads=4

# DBUG options for wsrep provider
#wsrep_dbug_option

# Generate fake primary keys for non-PK tables (required for multi-master
# and parallel applying operation)
wsrep_certify_nonPK=1

# Location of the directory with data files. Needed for non-mysqldump
# state snapshot transfers. Defaults to mysql_real_data_home.
#wsrep_data_home_dir=

# Maximum number of rows in write set
wsrep_max_ws_rows=131072

# Maximum size of write set
wsrep_max_ws_size=1073741824

# to enable debug level logging, set this to 1
wsrep_debug=0

# convert locking sessions into transactions
wsrep_convert_LOCK_to_trx=0

# how many times to retry deadlocked autocommits
wsrep_retry_autocommit=1

# change auto_increment_increment and auto_increment_offset automatically
wsrep_auto_increment_control=1

# replicate myisam
wsrep_replicate_myisam=1
# retry autoinc insert, which failed for duplicate key error
wsrep_drupal_282555_workaround=0

# enable "strictly synchronous" semantics for read operations
wsrep_causal_reads=0

# Command to call when node status or cluster membership changes.
# Will be passed all or some of the following options:
# --status  - new status of this node
# --uuid    - UUID of the cluster
# --primary - whether the component is primary or not ("yes"/"no")
# --members - comma-separated list of members
# --index   - index of this node in the list
#wsrep_notify_cmd=

##
## WSREP State Transfer options
##

# State Snapshot Transfer method
# ClusterControl currently DOES NOT support wsrep_sst_method=mysqldump
wsrep_sst_method=rsync

# Address on THIS node to receive SST at. DON'T SET IT TO DONOR ADDRESS!!!
# (SST method dependent. Defaults to the first IP of the first interface)
#wsrep_sst_receive_address=

# SST authentication string. This will be used to send SST to joining nodes.
# Depends on SST method. For mysqldump method it is root:<root password>
wsrep_sst_auth=dump:password

# Desired SST donor name.
#wsrep_sst_donor=

# Protocol version to use
# wsrep_protocol_version=
[MYSQL]
socket=/data/mysql/3306/mysql.sock
[client]
socket=/data/mysql/3306/mysql.sock
[mysqldump]
max-allowed-packet = 512M
[MYSQLD_SAFE]
pid-file=mysqld.pid
log-error=mysql.err
basedir=/usr/
datadir=/data/mysql/3306


初始化并启动MySQL:

mkdir -p /data/mysql/3306
chown -R mysql:mysql /data/mysql
mysql_install_db
service mysql start


然后修改配置文件,将
wsrep_cluster_address='gcomm://'
修改为:
wsrep_cluster_address='gcomm://172.16.88.57:4567,172.16.88.181:4567,172.16.88.231:4567'

五,初始化第二个节点(172.16.88.181)

MySQL配置文件(/etc/my.cnf):
# All files in this package is subject to the GPL v2 license
# More information is in the COPYING file in the top directory of this package.
# Copyright (C) 2011 severalnines.com
[MYSQLD]
user=mysql
basedir=/usr
datadir=/data/mysql/3306
socket=/data/mysql/3306/mysql.sock
pid-file=mysqld.pid
port=3306
log-error=mysql.err
#log-output=FILE
#relay-log=relay-bin
### INNODB OPTIONS
innodb-buffer-pool-size=4G
innodb-additional-mem-pool-size=20M
innodb-flush-log-at-trx-commit=2
innodb-file-per-table=1
innodb-data-file-path = ibdata1:100M:autoextend
## You may want to tune the below depending on number of cores and disk sub
innodb-read-io-threads=4
innodb-write-io-threads=4
innodb-doublewrite=1
innodb-log-file-size=512M
innodb-log-files-in-group=2
innodb-log-buffer-size=64M
innodb-buffer-pool-instances=4
innodb-thread-concurrency=0
innodb-file-format=barracuda
innodb-flush-method = O_DIRECT
innodb-locks-unsafe-for-binlog=1
innodb-autoinc-lock-mode=2
## avoid statistics update when doing e.g show tables
innodb-stats-on-metadata=0
engine-condition-pushdown=1
default-storage-engine=innodb

# CHARACTER SET
#collation-server = utf8_unicode_ci
#init-connect='SET NAMES utf8'
character-set-server = utf8

# REPLICATION SPECIFIC - GENERAL
#server-id must be unique across all mysql servers participating in replication.
server-id=88181
#auto_increment_increment=2
#auto_increment_offset=SERVERID
# REPLICATION SPECIFIC - MASTER
binlog_format=ROW
log-bin=binlog
expire_logs_days=7
log-slave-updates=1
# OTHER THINGS, BUFFERS ETC
key_buffer_size = 24M
tmp_table_size = 64M
max_heap_table_size = 64M
max-allowed-packet = 512M
#sort-buffer-size = 256K
#read-buffer-size = 256K
#read-rnd-buffer-size = 512K
#myisam-sort-buffer_size = 8M
skip-name-resolve
memlock=0
sysdate-is-now=1
max-connections=1000
thread-cache-size=512
query-cache-type = 0
query-cache-size = 0
table-open_cache=1024
lower-case-table-names=0
##
## WSREP options
##

# Full path to wsrep provider library or 'none'
wsrep_provider=/usr/lib64/galera/libgalera_smm.so

wsrep_node_address=
# Provider specific configuration options
wsrep_provider_options="gcache.size=2048M"

# Logical cluster name. Should be the same for all nodes.
wsrep_cluster_name="platform_images"

# Group communication system handle
wsrep_cluster_address='gcomm://172.16.88.57:4567,172.16.88.181:4567,172.16.88.231:4567'

# Human-readable node name (non-unique). Hostname by default.
#wsrep_node_name=

# Address for incoming client connections. Autodetect by default.
#wsrep_node_incoming_address=

# How many threads will process writesets from other nodes
wsrep_slave_threads=4

# DBUG options for wsrep provider
#wsrep_dbug_option

# Generate fake primary keys for non-PK tables (required for multi-master
# and parallel applying operation)
wsrep_certify_nonPK=1

# Location of the directory with data files. Needed for non-mysqldump
# state snapshot transfers. Defaults to mysql_real_data_home.
#wsrep_data_home_dir=

# Maximum number of rows in write set
wsrep_max_ws_rows=131072

# Maximum size of write set
wsrep_max_ws_size=1073741824

# to enable debug level logging, set this to 1
wsrep_debug=0

# convert locking sessions into transactions
wsrep_convert_LOCK_to_trx=0

# how many times to retry deadlocked autocommits
wsrep_retry_autocommit=1

# change auto_increment_increment and auto_increment_offset automatically
wsrep_auto_increment_control=1

# replicate myisam
wsrep_replicate_myisam=1
# retry autoinc insert, which failed for duplicate key error
wsrep_drupal_282555_workaround=0

# enable "strictly synchronous" semantics for read operations
wsrep_causal_reads=0

# Command to call when node status or cluster membership changes.
# Will be passed all or some of the following options:
# --status  - new status of this node
# --uuid    - UUID of the cluster
# --primary - whether the component is primary or not ("yes"/"no")
# --members - comma-separated list of members
# --index   - index of this node in the list
#wsrep_notify_cmd=

##
## WSREP State Transfer options
##

# State Snapshot Transfer method
# ClusterControl currently DOES NOT support wsrep_sst_method=mysqldump
wsrep_sst_method=rsync

# Address on THIS node to receive SST at. DON'T SET IT TO DONOR ADDRESS!!!
# (SST method dependent. Defaults to the first IP of the first interface)
#wsrep_sst_receive_address=

# SST authentication string. This will be used to send SST to joining nodes.
# Depends on SST method. For mysqldump method it is root:<root password>
wsrep_sst_auth=dump:password

# Desired SST donor name.
#wsrep_sst_donor=

# Protocol version to use
# wsrep_protocol_version=
[MYSQL]
socket=/data/mysql/3306/mysql.sock
[client]
socket=/data/mysql/3306/mysql.sock
[mysqldump]
max-allowed-packet = 512M
[MYSQLD_SAFE]
pid-file=mysqld.pid
log-error=mysql.err
basedir=/usr/
datadir=/data/mysql/3306


初始化并启动MySQL:
mkdir -p /data/mysql/3306
chown -R mysql:mysql /data/mysql
mysql_install_db
service mysql start

六,初始化第三个节点(172.16.88.231)

MySQL配置文件(/etc/my.cnf):

# All files in this package is subject to the GPL v2 license
# More information is in the COPYING file in the top directory of this package.
# Copyright (C) 2011 severalnines.com
[MYSQLD]
user=mysql
basedir=/usr
datadir=/data/mysql/3306
socket=/data/mysql/3306/mysql.sock
pid-file=mysqld.pid
port=3306
log-error=mysql.err
#log-output=FILE
#relay-log=relay-bin
### INNODB OPTIONS
innodb-buffer-pool-size=4G
innodb-additional-mem-pool-size=20M
innodb-flush-log-at-trx-commit=2
innodb-file-per-table=1
innodb-data-file-path = ibdata1:100M:autoextend
## You may want to tune the below depending on number of cores and disk sub
innodb-read-io-threads=4
innodb-write-io-threads=4
innodb-doublewrite=1
innodb-log-file-size=512M
innodb-log-files-in-group=2
innodb-log-buffer-size=64M
innodb-buffer-pool-instances=4
innodb-thread-concurrency=0
innodb-file-format=barracuda
innodb-flush-method = O_DIRECT
innodb-locks-unsafe-for-binlog=1
innodb-autoinc-lock-mode=2
## avoid statistics update when doing e.g show tables
innodb-stats-on-metadata=0
engine-condition-pushdown=1
default-storage-engine=innodb

# CHARACTER SET
#collation-server = utf8_unicode_ci
#init-connect='SET NAMES utf8'
character-set-server = utf8

# REPLICATION SPECIFIC - GENERAL
#server-id must be unique across all mysql servers participating in replication.
server-id=88231
#auto_increment_increment=2
#auto_increment_offset=SERVERID
# REPLICATION SPECIFIC - MASTER
binlog_format=ROW
log-bin=binlog
expire_logs_days=7
log-slave-updates=1
# OTHER THINGS, BUFFERS ETC
key_buffer_size = 24M
tmp_table_size = 64M
max_heap_table_size = 64M
max-allowed-packet = 512M
#sort-buffer-size = 256K
#read-buffer-size = 256K
#read-rnd-buffer-size = 512K
#myisam-sort-buffer_size = 8M
skip-name-resolve
memlock=0
sysdate-is-now=1
max-connections=1000
thread-cache-size=512
query-cache-type = 0
query-cache-size = 0
table-open_cache=1024
lower-case-table-names=0
##
## WSREP options
##

# Full path to wsrep provider library or 'none'
wsrep_provider=/usr/lib64/galera/libgalera_smm.so

wsrep_node_address=
# Provider specific configuration options
wsrep_provider_options="gcache.size=2048M"

# Logical cluster name. Should be the same for all nodes.
wsrep_cluster_name="platform_images"

# Group communication system handle
wsrep_cluster_address='gcomm://172.16.88.57:4567,172.16.88.181:4567,172.16.88.231:4567'

# Human-readable node name (non-unique). Hostname by default.
#wsrep_node_name=

# Address for incoming client connections. Autodetect by default.
#wsrep_node_incoming_address=

# How many threads will process writesets from other nodes
wsrep_slave_threads=4

# DBUG options for wsrep provider
#wsrep_dbug_option

# Generate fake primary keys for non-PK tables (required for multi-master
# and parallel applying operation)
wsrep_certify_nonPK=1

# Location of the directory with data files. Needed for non-mysqldump
# state snapshot transfers. Defaults to mysql_real_data_home.
#wsrep_data_home_dir=

# Maximum number of rows in write set
wsrep_max_ws_rows=131072

# Maximum size of write set
wsrep_max_ws_size=1073741824

# to enable debug level logging, set this to 1
wsrep_debug=0

# convert locking sessions into transactions
wsrep_convert_LOCK_to_trx=0

# how many times to retry deadlocked autocommits
wsrep_retry_autocommit=1

# change auto_increment_increment and auto_increment_offset automatically
wsrep_auto_increment_control=1

# replicate myisam
wsrep_replicate_myisam=1
# retry autoinc insert, which failed for duplicate key error
wsrep_drupal_282555_workaround=0

# enable "strictly synchronous" semantics for read operations
wsrep_causal_reads=0

# Command to call when node status or cluster membership changes.
# Will be passed all or some of the following options:
# --status  - new status of this node
# --uuid    - UUID of the cluster
# --primary - whether the component is primary or not ("yes"/"no")
# --members - comma-separated list of members
# --index   - index of this node in the list
#wsrep_notify_cmd=

##
## WSREP State Transfer options
##

# State Snapshot Transfer method
# ClusterControl currently DOES NOT support wsrep_sst_method=mysqldump
wsrep_sst_method=rsync

# Address on THIS node to receive SST at. DON'T SET IT TO DONOR ADDRESS!!!
# (SST method dependent. Defaults to the first IP of the first interface)
#wsrep_sst_receive_address=

# SST authentication string. This will be used to send SST to joining nodes.
# Depends on SST method. For mysqldump method it is root:<root password>
wsrep_sst_auth=dump:password

# Desired SST donor name.
#wsrep_sst_donor=

# Protocol version to use
# wsrep_protocol_version=
[MYSQL]
socket=/data/mysql/3306/mysql.sock
[client]
socket=/data/mysql/3306/mysql.sock
[mysqldump]
max-allowed-packet = 512M
[MYSQLD_SAFE]
pid-file=mysqld.pid
log-error=mysql.err
basedir=/usr/
datadir=/data/mysql/3306

初始化并启动MySQL:

mkdir -p /data/mysql/3306
chown -R mysql:mysql /data/mysql
mysql_install_db
service mysql start

然后就可以测试多个节点的读写同步了。
下一篇文章会介绍多个节点的负载均衡以及故障处理。

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2024

    京ICP备05028076号