转自:https://extremeshok.com/5100/ubuntu-12-04-lts-3-node-percona-xtradb-cluster-xtrabackup-glb-load-balancer-aka-mysql-galera/
Assumptions:
Completed Server Preparation: KVM / VMware / Standalone Ubuntu 12.04 / 12.10 Server Preparation or Proxmox / OpenVZ Container / Ubuntu 12.04 /12.10 Server Preparation
Percona XtraDB CLluster provides the following features
Synchronous replication
Active/active multi-master topology
Read and write to any cluster node
Automatic membership control, failed nodes drop from the cluster
Automatic node joining
True parallel row level replication
Direct client connections
Drop-in replacement for native MySQL
All the Percona XtraDB benefits
Benefits using Galera Replication
High Availability
No slave lag
No lost transactions
No more data inconsistency
Smaller client latencies
Read scalability and write throughput improvement (3 times and more, depending on your workload
#Hostnames
dbnode1 11.11.11.11
dbnode2 22.22.22.22
dbnode3 33.33.33.33#Ports
TCP 22 : SSH#MariaDB Cluster Ports
TCP 3306 : Regular MySQL
TCP 4567 : Group Communication (wsrep_provider gmcast.listen_addr)
TCP 4568 : Incremental State Transfer (wsrep_provider ist.recv_addr)
TCP 4444 : State Transfer (wsrep_sst_receive_address)
Set the timezone
Set the system timezone to UTC
1
|
ln
-
sf
/
usr
/
share
/
zoneinfo
/
UTC
/
etc
/
localtime
|
Remove conflicting solutions and configs
**all nodes**
1
2
3
4
5
6
7
8
9
|
apt
-
get
update
apt
-
get
purge
-
y
mysql
*
apt
-
get
purge
-
y
mariadb
*
apt
-
get
purge
-
y
percona
*
apt
-
get
autoremove
-
y
rm
-
rf
/
etc
/
mysql
rm
-
rf
/
var
/
lib
/
mysql
rm
-
rf
/
etc
/
rc
*
.d
/
*
mysql
rm
-
rf
/
var
/
lib
/
update
-
rc
.d
/
mysql
|
Setup Hostnames and SSH Passwordless logins between the nodes
Generate the rsa key **all nodes**
1
|
ssh
-
keygen
-
t
rsa
|
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Optional: Add hosts to /etc/hosts.allow **all nodes**
1
|
echo
-
e
"\nALL: dbnode1\nALL: dbnode2\nALL: dbnode3"
>>
/
etc
/
hosts
.allow
|
Node1
1
2
3
|
echo
-
e
"\n#MariaDB Cluster Node Names\n127.0.0.1 dbnode1\n22.22.22.22 dbnode2\n33.33.33.33 dbnode3"
>>
/
etc
/
hosts
ssh
-
copy
-
id
root
@
dbnode2
ssh
-
copy
-
id
root
@
dbnode3
|
Node2
1
2
3
|
echo
-
e
"\n#MariaDB Cluster Node Names\n11.11.11.11 dbnode1\n127.0.0.1 dbnode2\n33.33.33.33 dbnode3"
>>
/
etc
/
hosts
ssh
-
copy
-
id
root
@
dbnode1
ssh
-
copy
-
id
root
@
dbnode3
|
Node3
1
2
3
|
echo
-
e
"\n#MariaDB Cluster Node Names\n11.11.11.11 dbnode1\n22.22.22.22 dbnode2\n127.0.0.1 dbnode3"
>>
/
etc
/
hosts
ssh
-
copy
-
id
root
@
dbnode1
ssh
-
copy
-
id
root
@
dbnode2
|
Install the latest Percona XtraDB Cluster
Install the latest Percona XtraDB Cluster ( mysql )
**all nodes**
add the repository **all nodes**
1
|
echo
-
e
"# Percona repository list - created 2012-06-17 16:25 UTC\n# http://www.percona.com/doc/percona-server/5.5/installation/apt_repo.html\ndeb http://repo.percona.com/apt precise main\ndeb-src http://repo.percona.com/apt precise main"
>
/
etc
/
apt
/
sources
.list
.d
/
Percona
.list
|
Import the GP key **all nodes**
1
|
gpg
--
keyserver
hkp
:
/
/
keys
.gnupg
.net
--
recv
-
keys
1C4CBDCDCD2EFD2A
&&
gpg
-
a
--
export
CD2EFD2A
|
apt
-
key
add
-
|
Apt-Pinning the packages **all nodes**
1
|
echo
-
e
"# Percona XtraDB repository\nPackage: *\nPin: origin percona.com\nPin-Priority: 1000\n\nPackage: *\nPin: origin repo.percona.comg\nPin-Priority: 1000\n\nPackage: libmysqlclient18\nPin: origin repo.percona.com\nPin-Priority: 1000"
>
/
etc
/
apt
/
preferences
.d
/
00XtraDB.pref
|
Install XtraDB Cluster **all nodes**
1
|
apt
-
get
update
&&
apt
-
get
install
-
y
percona
-
xtradb
-
cluster
-
client
-
5.5
percona
-
xtradb
-
cluster
-
server
-
5.5
percona
-
xtradb
-
cluster
-
common
-
5.5
percona
-
xtradb
-
cluster
-
galera
-
2.x
libmysqlclient18
rsync
netcat
-
openbsd
tinyca
|
**SET A PERCONA XTRADB CLUSTER ROOT PASSWORD, SAME ON ALL NODES**
Initial XtraDB Cluster COnfiguration
Our default my.cnf config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
cat
>
/
etc
/
mysql
/
my
.cnf
<<
EOF
## eXtremeSHOK.com
# XtraDB Cluster database server configuration file.
#
# You can copy this file to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[
client
]
port
=
3306
socket
=
/
var
/
run
/
mysqld
/
mysqld
.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[
mysqld_safe
]
socket
=
/
var
/
run
/
mysqld
/
mysqld
.sock
nice
=
0
[
mysqld
]
# * START * Mandatory settings REQUIRED for proper cluster operations#
query_cache_size
=
0
binlog_format
=
ROW
default_storage_engine
=
innodb
innodb_autoinc_lock_mode
=
2
innodb_locks_unsafe_for_binlog
=
1
innodb_doublewrite
=
1
# wsrep provider configuration: basic wsrep options
wsrep_provider
=
/
usr
/
lib
/
galera
/
libgalera_smm
.so
wsrep_provider_options
=
"gcache.size=2G; gcache.page_size=1G"
wsrep_cluster_address
=
gcomm
:
/
/
{
hosts_list
}
wsrep_cluster_name
=
{
cluster_name
}
wsrep_node_address
=
"{node_name}"
wsrep_node_name
=
"{node_name}"
#wsrep_sst_method=xtrabackup-wan
wsrep_sst_method
=
xtrabackup
wsrep_sst_auth
=
{
root_username
}
:
{
root_password
}
# additional "frequentrly used" wsrep settings
wsrep_node_incoming_address
=
{
node_address
}
wsrep_sst_receive_address
=
{
node_address
}
#wsrep_sst_donor=dbnode1
wsrep_slave_threads
=
16
# * END * Mandatory settings REQUIRED for proper cluster operations#
#
# * Basic Settings
#
user
=
mysql
pid
-
file
=
/
var
/
run
/
mysqld
/
mysqld
.pid
socket
=
/
var
/
run
/
mysqld
/
mysqld
.sock
port
=
3306
basedir
=
/
usr
datadir
=
/
var
/
lib
/
mysql
tmpdir
=
/
tmp
lc_messages_dir
=
/
usr
/
share
/
mysql
lc_messages
=
en_US
skip
-
external
-
locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind
-
address
=
0.0.0.0
#
# * Fine Tuning
#
max_connections
=
100
connect_timeout
=
5
wait_timeout
=
600
max_allowed_packet
=
16M
thread_cache_size
=
128
sort_buffer_size
=
4M
bulk_insert_buffer_size
=
16M
tmp_table_size
=
32M
max_heap_table_size
=
32M
#
# * MyISAM
#
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched. On error, make copy and try a repair.
myisam_recover
=
BACKUP
key_buffer_size
=
128M
#open-files-limit = 2000
table_open_cache
=
400
myisam_sort_buffer_size
=
512M
concurrent_insert
=
2
read_buffer_size
=
2M
read_rnd_buffer_size
=
1M
#
# * Query Cache Configuration
#
# Cache only tiny result sets, so we can fit more in the query cache.
# query_cache_limit = 128K
# query_cache_size = 64M
# for more write intensive setups, set to DEMAND or OFF
#query_cache_type = DEMAND
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
general_log_file
=
/
var
/
log
/
mysql
/
mysql
.log
#general_log = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# we do want to know about network errors and such
log_warnings
=
2
#
# Enable the slow query log to see queries with especially long duration
slow_query_log
=
0
slow_query_log_file
=
/
var
/
log
/
mysql
/
slow
.log
long_query_time
=
10
#log_slow_rate_limit = 1000
log_slow_verbosity
=
query_plan
#log-queries-not-using-indexes
#log_slow_admin_statements
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#report_host = master1
#auto_increment_increment = 2
#auto_increment_offset = 1
log_bin
=
/
var
/
log
/
mysql
/
mysql
-
bin
log_bin_index
=
/
var
/
log
/
mysql
/
mysql
-
bin
.index
# not fab for performance, but safer
#sync_binlog = 1
expire_logs_days
=
10
max_binlog_size
=
100M
# slaves
#relay_log = /var/log/mysql/relay-bin
#relay_log_index = /var/log/mysql/relay-bin.index
#relay_log_info_file = /var/log/mysql/relay-bin.info
#log_slave_updates
#read_only
#
# If applications support it, this stricter sql_mode prevents some
# mistakes like inserting invalid dates etc.
#sql_mode = NO_ENGINE_SUBSTITUTION,TRADITIONAL
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
# you can't just change log file size, requires special procedure
#innodb_log_file_size = 50M
innodb_buffer_pool_size
=
256M
innodb_flush_log_at_trx_commit
=
2
innodb_log_buffer_size
=
8M
innodb_file_per_table
=
1
innodb_open_files
=
400
innodb_io_capacity
=
400
innodb_flush_method
=
O_DIRECT
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
[
mysqldump
]
quick
quote
-
names
max_allowed_packet
=
16M
[
mysql
]
#no-auto-rehash # faster start of mysql but no tab completition
[
isamchk
]
key_buffer
=
16M
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!
includedir
/
etc
/
mysql
/
conf
.d
/
## eXtremeSHOK.com
EOF
|
Shutdown all instances of XtraDB Cluster **all nodes**
1
|
service
mysql
stop
|
Node1
Replace dbclusterroot with a random username
Replace securepassword with a random password
1
2
3
4
5
6
|
service
mysql
start
mysql
-
u
root
-
e
"CREATE USER 'root'@'localhost' IDENTIFIED BY 'securepassword'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;"
mysql
-
u
root
-
e
"CREATE USER 'root'@'dbnode1' IDENTIFIED BY 'securepassword'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'dbnode1' WITH GRANT OPTION;"
mysql
-
u
root
-
e
"CREATE USER 'root'@'dbnode2' IDENTIFIED BY 'securepassword'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'dbnode2' WITH GRANT OPTION;"
mysql
-
u
root
-
e
"CREATE USER 'root'@'dbnode3' IDENTIFIED BY 'securepassword'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'dbnode3' WITH GRANT OPTION;"
mysql
-
u
root
-
e
"GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'localhost' WITH GRANT OPTION;"
|
Configure XtraDB Cluster
Add missing my.cnf options **all nodes**
1
2
|
sed
-
i
's|{cluster_name}|"MariaDB_Cluster"|'
/
etc
/
mysql
/
my
.cnf
sed
-
i
's|{hosts_list}|"dbnode1,dbnode2,dbnode3"|'
/
etc
/
mysql
/
my
.cnf
|
Create the cluster root sql user **all nodes**
Replace securepassword with a random password
*avoid all special characters*
1
|
sed
-
i
's|{root_username}:{root_password}|"root:securepassword"|'
/
etc
/
mysql
/
my
.cnf
|
Default is 4GB ram
**optional: gcache for 512MB ram **all nodes**
1
|
sed
-
i
's|gcache.size=2G; gcache.page_size=1G|gcache.size=256M; gcache.page_size=128M|g'
/
etc
/
mysql
/
my
.cnf
|
**optional: gcache for 1024MB ram **all nodes**
1
|
sed
-
i
's|gcache.size=2G; gcache.page_size=1G|gcache.size=512M; gcache.page_size=256M|g'
/
etc
/
mysql
/
my
.cnf
|
**optional: gcache for 2GB ram **all nodes**
1
|
sed
-
i
's|gcache.size=2G; gcache.page_size=1G|gcache.size=1G; gcache.page_size=512M|g'
/
etc
/
mysql
/
my
.cnf
|
**optional: Enable slow query logging **all nodes**
1
|
sed
-
i
-
e
's|slow_query_log = 1|slow_query_log = 0|g'
/
etc
/
mysql
/
my
.cnf
|
Node1
1
2
|
sed
-
i
's|{node_name}|dbnode1|'
/
etc
/
mysql
/
my
.cnf
sed
-
i
's|{node_address}|11.11.11.11|'
/
etc
/
mysql
/
my
.cnf
|
Node2
1
2
|
sed
-
i
's|{node_name}|dbnode2|'
/
etc
/
mysql
/
my
.cnf
sed
-
i
's|{node_address}|22.22.22.22|'
/
etc
/
mysql
/
my
.cnf
|
Node3
1
2
|
sed
-
i
's|{node_name}|dbnode3|'
/
etc
/
mysql
/
my
.cnf
sed
-
i
's|{node_address}|33.33.33.33|'
/
etc
/
mysql
/
my
.cnf
|
Bugfix: Access denied for user ‘debian-sys-maint’@’localhost’
[Warning] Access denied for user ‘debian-sys-maint’@’localhost’ (using password: YES)
Node1
1
2
|
scp
/
etc
/
mysql
/
debian
.cnf
dbnode2
:
/
etc
/
mysql
/
debian
.cnf
scp
/
etc
/
mysql
/
debian
.cnf
dbnode3
:
/
etc
/
mysql
/
debian
.cnf
|
Optional: Install the latest xtrabackup ( wsrep_sst_method=xtrabackup ) to avoid read-only Donor during SST
The main advantage of using xtrabackup to synchronize the nodes, is that the Donor is writeable during the synchronization process.
Install Xtrabackup and Percona-toolkit **all nodes**
Note: install netcat-openbsd fixes the error: nc: invalid option — ‘d’
1
|
apt
-
get
update
&&
apt
-
get
-
y
install
percona
-
toolkit
percona
-
xtrabackup
netcat
-
openbsd
|
Set the wsrep_sst_method to xtrabackup **all nodes**
1
|
sed
-
i
's|wsrep_sst_method=rsync|wsrep_sst_method=xtrabackup|'
/
etc
/
mysql
/
my
.cnf
|
Bootstrap the cluster
Stop mysql** all nodes **
1
2
3
4
5
6
7
8
|
service
mysql
stop
service
rsync
stop
#added to prevent issues from non terminated processes
pkill
-
9
-
f
maria
pkill
-
9
-
f
percona
pkill
-
9
-
f
mysql
pkill
-
9
-
f
rsync
pkill
-
9
-
f
innobackupex
|
Bootstrap node1** node 1 **
Set the wsrep_cluster_address to gcom:// to enable the cluster to be bootstrapped
1
|
sed
-
i
-
e
's|wsrep_cluster_address=gcom://|wsrep_cluster_address=gcom://\n#|'
/
etc
/
mysql
/
my
.cnf
|
Start MySQL Server
1
|
service
mysql
start
|
Check that mysql is online, functioning and to monitor real-time node status
1
|
watch
-
d
-
n1
-
x
mysql
-
B
--
password
=
securepassword
-
e
"SHOW STATUS WHERE variable_name ='wsrep_local_state_comment' OR variable_name ='wsrep_cluster_size' OR variable_name ='wsrep_incoming_addresses' OR variable_name ='wsrep_cluster_status' OR variable_name ='wsrep_connected' OR variable_name ='wsrep_ready' OR variable_name ='wsrep_local_state_uuid' OR variable_name ='wsrep_cluster_state_uuid';"
|
Variable_name Value
wsrep_local_state_uuid 2e1a97ef-d284-11e2-0800-122d8af6b436
wsrep_local_state_comment Synced
wsrep_incoming_addresses 33.33.33.33:3306
wsrep_cluster_size 1
wsrep_cluster_state_uuid 2e1a97ef-d284-11e2-0800-122d8af6b436
wsrep_cluster_status Primary
wsrep_connected ON
wsrep_ready ON
Restore the wsrep_cluster_address to the cluster, to enable node1 to connect to the cluster
1
|
sed
-
i
-
e
':a;N;$!ba;s|wsrep_cluster_address=gcom://\n#|wsrep_cluster_address=gcom://|'
/
etc
/
mysql
/
my
.cnf
|
Bootstrap node2**node 2 **
1
|
service
mysql
start
|
Check that mysql is online, functioning and to monitor real-time node status
1
|
watch
-
d
-
n1
-
x
mysql
-
B
--
password
=
securepassword
-
e
"SHOW STATUS WHERE variable_name ='wsrep_local_state_comment' OR variable_name ='wsrep_cluster_size' OR variable_name ='wsrep_incoming_addresses' OR variable_name ='wsrep_cluster_status' OR variable_name ='wsrep_connected' OR variable_name ='wsrep_ready' OR variable_name ='wsrep_local_state_uuid' OR variable_name ='wsrep_cluster_state_uuid';"
|
Variable_name Value
wsrep_local_state_uuid 2e1a97ef-d284-11e2-0800-122d8af6b436
wsrep_local_state_comment Synced
wsrep_incoming_addresses 33.33.33.33:3306,11.11.11.11:3306
wsrep_cluster_size 2
wsrep_cluster_state_uuid 2e1a97ef-d284-11e2-0800-122d8af6b436
wsrep_cluster_status Primary
wsrep_connected ON
wsrep_ready ON
Bootstrap node2**node 3 **
1
|
service
mysql
start
|
Check that mysql is online, functioning and to monitor real-time node status
1
|
watch
-
d
-
n1
-
x
mysql
-
B
--
password
=
securepassword
-
e
"SHOW STATUS WHERE variable_name ='wsrep_local_state_comment' OR variable_name ='wsrep_cluster_size' OR variable_name ='wsrep_incoming_addresses' OR variable_name ='wsrep_cluster_status' OR variable_name ='wsrep_connected' OR variable_name ='wsrep_ready' OR variable_name ='wsrep_local_state_uuid' OR variable_name ='wsrep_cluster_state_uuid';"
|
Variable_name Value
wsrep_local_state_uuid 2e1a97ef-d284-11e2-0800-122d8af6b436
wsrep_local_state_comment Synced
wsrep_incoming_addresses 33.33.33.33:3306,22.22.22.22:3306,11.11.11.11:3306
wsrep_cluster_size 3
wsrep_cluster_state_uuid 2e1a97ef-d284-11e2-0800-122d8af6b436
wsrep_cluster_status Primary
wsrep_connected ON
wsrep_ready ON
Notes / Bug Fixes: * Starting XtraDB Cluster database server mysqld [fail]
I have had issues with large databases and mysql failing to start. This is caused by the start script timing out before rsync is able to complete.
A simple solution to this is to start the failed node manually with the following:
Make sure mysql is not running and force kill any processes
1
2
3
4
5
6
|
service
mysql
stop
service
rsync
stop
#added to prevent issues from non terminated processes
pkill
-
9
-
f
maria
pkill
-
9
-
f
mysql
pkill
-
9
-
f
rsync
|
Start mysql manually
1
|
mysqld
--
service
-
startup
-
timeout
=
-
1
>
/
dev
/
null
2
>
&
1
&
|
Optional: allow a node to handle the traffic in a splitbrain situation
** primary node only**
1
|
sed
-
i
's|wsrep_provider_options="|wsrep_provider_options="pc.ignore_sb = yes; |'
/
etc
/
mysql
/
my
.cnf
|
Test
Monitor the XtraDB Cluster Status
1
|
watch
-
d
-
n1
-
x
mysql
-
B
--
password
=
"securepassword"
-
e
"SHOW STATUS LIKE 'wsrep_%';"
|
Variable_name Value
wsrep_local_state_uuid 2e1a97ef-d284-11e2-0800-122d8af6b436
wsrep_protocol_version 4
wsrep_last_committed 44150
wsrep_replicated 20000
wsrep_replicated_bytes 22623578
wsrep_received 4163
wsrep_received_bytes 4863775
wsrep_local_commits 20000
wsrep_local_cert_failures 0
wsrep_local_bf_aborts 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_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_incoming_addresses 33.33.33.33:3306,22.22.22.22:3306,11.11.11.11:3306
wsrep_cluster_conf_id 22
wsrep_cluster_size 3
wsrep_cluster_state_uuid 2e1a97ef-d284-11e2-0800-122d8af6b436
wsrep_cluster_status Primary
wsrep_connected ON
wsrep_local_index 0
wsrep_provider_name Galera
wsrep_provider_vendor Codership Oy
wsrep_provider_version 2.6(r152)
wsrep_ready ON
1
|
watch
-
d
-
n1
-
x
mysql
-
B
--
password
=
securepassword
-
e
"SHOW STATUS WHERE variable_name ='wsrep_local_state_comment' OR variable_name ='wsrep_cluster_size' OR variable_name ='wsrep_incoming_addresses' OR variable_name ='wsrep_cluster_status' OR variable_name ='wsrep_connected' OR variable_name ='wsrep_ready' OR variable_name ='wsrep_local_state_uuid' OR variable_name ='wsrep_cluster_state_uuid';"
|
Variable_name Value
wsrep_local_state_uuid 2e1a97ef-d284-11e2-0800-122d8af6b436
wsrep_local_state_comment Synced
wsrep_incoming_addresses 33.33.33.33:3306,22.22.22.22:3306,11.11.11.11:3306
wsrep_cluster_size 3
wsrep_cluster_state_uuid 2e1a97ef-d284-11e2-0800-122d8af6b436
wsrep_cluster_status Primary
wsrep_connected ON
wsrep_ready ON
Performance Testing
Create the sbtest database with 1 000 000 tables** Node1 **
Replace securepassword with a random password
1
2
|
mysql
-
u
root
--
password
=
"securepassword"
-
e
"CREATE SCHEMA 'sbtest';"
sysbench
--
test
=
oltp
--
mysql
-
table
-
engine
=
innodb
--
oltp
-
table
-
size
=
1000000
--
mysql
-
user
=
root
--
mysql
-
password
=
securepassword
--
mysql
-
host
=
localhost
--
mysql
-
port
=
3306
prepare
|
Run the test on all nodes** All Nodes **
Replace securepassword with a random password
1
|
sysbench
--
num
-
threads
=
16
--
max
-
time
=
300
--
max
-
requests
=
500000
--
test
=
oltp
--
mysql
-
user
=
root
--
mysql
-
password
=
securepassword
--
mysql
-
host
=
localhost
--
mysql
-
port
=
3306
--
oltp
-
test
-
mode
=
complex
--
oltp
-
table
-
size
=
1000000
run
|
Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using “BEGIN” for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 500000
Threads started!
Time limit exceeded, exiting…
(last message repeated 15 times)
Done.OLTP test statistics:
queries performed:
read: 856198
write: 305785
other: 122314
total: 1284297
transactions: 61157 (203.81 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 1161983 (3872.47 per sec.)
other operations: 122314 (407.63 per sec.)Test execution summary:
total time: 300.0627s
total number of events: 61157
total time taken by event execution: 4799.9976
per-request statistics:
min: 55.43ms
avg: 78.49ms
max: 689.76ms
approx. 95 percentile: 98.52msThreads fairness:
events (avg/stddev): 3822.3125/6.61
execution time (avg/stddev): 299.9999/0.02
Test Cluster load with Pen Load Balancer
This is just to test load balance performance, I suggest you use either GLB or HAProxy in a production environment
Install Pen** Node 1 **
1
|
apt
-
get
install
-
y
pen
|
Run Pen and listen to port 4406** Node 1 **
1
|
pen
-
d
4406
dbnode1
:
3306
dbnode2
:
3306
dbnode3
:
3306
|
Execute the Sysbench, using the Pen Load Balancer
1
|
sysbench
--
num
-
threads
=
8
--
max
-
time
=
300
--
max
-
requests
=
500000
--
test
=
oltp
--
mysql
-
user
=
root
--
mysql
-
password
=
securepassword
--
mysql
-
host
=
localhost
--
mysql
-
port
=
4406
--
oltp
-
test
-
mode
=
complex
--
oltp
-
table
-
size
=
1000000
run
|
Number of threads: 16
Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using “BEGIN” for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 500000
Threads started!
Time limit exceeded, exiting…
(last message repeated 15 times)
Done.OLTP test statistics:
queries performed:
read: 855974
write: 305705
other: 122282
total: 1283961
transactions: 61141 (203.76 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 1161679 (3871.43 per sec.)
other operations: 122282 (407.52 per sec.)Test execution summary:
total time: 300.0643s
total number of events: 61141
total time taken by event execution: 4799.9052
per-request statistics:
min: 55.38ms
avg: 78.51ms
max: 605.87ms
approx. 95 percentile: 94.22msThreads fairness:
events (avg/stddev): 3821.3125/11.27
execution time (avg/stddev): 299.9941/0.02
Terminate Pen
1
|
pkill
-
9
-
f
pen
|
Optional: Galera Load Balancer ( GLB )
Note: I will only write a guide once the 1.0 version is released.
http://www.codership.com/downloads/glb
http://www.codership.com/files/glb/README-1.0.0rc1
Optional: CSF Firewall
Allow/add the dbnode IPs to csf** all nodes **
1
2
3
4
|
csf
-
a
11.11.11.11
csf
-
a
22.22.22.22
csf
-
a
33.33.33.33
csf
-
r
|
==== THE ITEMS BELOW ARE IN PROGRESS :: DO NOT USE =====
Optional: UFW Firewall
Install UFW
1
|
|
Secure SSH for galera/wsrep
Secure MariaDB
1
|
mysql_secure_installation
|
Enter current password for root (enter for none): yoursecurepassword
Change the root password? N
Remove anonymous users? Y
Disallow root login remotely? Y
Remove test database and access to it? Y
Reload privilege tables now? Y
Restart MariaDB (mysql server)
1
|
service
mysql
restart
|
Confirm MariaDB is running
1
|
netstat
-
tap
|
grep
mysql
|
tcp 0 0 localhost:mysql *:* LISTEN 11878/mysqld