标签:
Galera Cluster for MySQL是一套基于同步复制的多主MySQL集群解决方案,使用简单,没有单点故障,可用性高,能很好保证业务不断增长时我们数据的安全和随时的扩展,主要特点:
注意: Galera Cluster需要至少三台mysql服务器,如果只有两台做cluster的话,一旦出现数据不一致的情况,就可能发生脑裂,需要一台仲裁服务器,如果直接三台做cluster的话,就不再需要仲裁
--wsrep-new-cluster
参数启动:service mysql start ----wsrep-new-cluster
, wsrep_cluster_address
必须设置成"gcomm://
192.168.1.85
#galera.node1
192.168.1.86
#galera.node2
192.168.1.87
#galera.node3
galera_password
vi /etc/yum.repos.d/galera.repo
内容如下:
[galera]
name = Galera
gpgcheck=0
enabled=1
baseurl = http://releases.galeracluster.com/centos/6/x86_64/
yum install galera-3 mysql-wsrep-5.6
先删除系统自带的mysql:rpm -qa | grep -i mysql
输出:
root@pts/0 # rpm -qa | grep -i mysql
mysql-libs-5.1.73-3.el6_5.x86_64
mysql-5.1.73-3.el6_5.x86_64
然后执行:
rpm --nodeps -ev mysql-libs-5.1.73-3.el6_5.x86_64
rpm --nodeps -ev mysql-5.1.73-3.el6_5.x86_64
创建目录: mkdir -p /opt/tmp_galera/
复制文件:
boost-program-options-1.41.0-25.el6.x86_64.rpm
galera-3-25.3.10-2.el6.x86_64.rpm
mysql-wsrep-5.6-5.6.23-25.10.el6.x86_64.rpm
mysql-wsrep-client-5.6-5.6.23-25.10.el6.x86_64.rpm
mysql-wsrep-server-5.6-5.6.23-25.10.el6.x86_64.rpm
nc-1.84-22.el6.x86_64.rpm
nmap-5.51-4.el6.x86_64.rpm
到/opt/tmp_galera/
安装依赖库:
cd /opt/tmp_galera/
rpm -Uvh boost-program-options-*.rpm
rpm -Uvh ./nmap-*.rpm
rpm -Uvh ./nc-*.rpm
安装galerarpm -Uvh ./galera-*.rpm
安装mysqlrpm -Uvh ./mysql-wsrep-*.rpm
输出:
warning: ./mysql-wsrep-5.6-5.6.23-25.10.el6.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID bc19ddba: NOKEY
Preparing... ########################################### [100%]
1:mysql-wsrep-server-5.6 ########################################### [ 33%]
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
2015-05-04 10:52:23 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-05-04 10:52:23 29838 [Note] WSREP: Read nil XID from storage engines, skipping position init
2015-05-04 10:52:23 29838 [Note] WSREP: wsrep_load(): loading provider library ‘none‘
2015-05-04 10:52:23 29838 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-05-04 10:52:23 29838 [Note] InnoDB: The InnoDB memory heap is disabled
2015-05-04 10:52:23 29838 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-05-04 10:52:23 29838 [Note] InnoDB: Memory barrier is not used
2015-05-04 10:52:23 29838 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-05-04 10:52:23 29838 [Note] InnoDB: Using Linux native AIO
2015-05-04 10:52:23 29838 [Note] InnoDB: Using CPU crc32 instructions
2015-05-04 10:52:23 29838 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-05-04 10:52:23 29838 [Note] InnoDB: Completed initialization of buffer pool
2015-05-04 10:52:24 29838 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2015-05-04 10:52:24 29838 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2015-05-04 10:52:24 29838 [Note] InnoDB: Database physically writes the file full: wait...
2015-05-04 10:52:24 29838 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2015-05-04 10:52:24 29838 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2015-05-04 10:52:24 29838 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2015-05-04 10:52:24 29838 [Warning] InnoDB: New log files created, LSN=45781
2015-05-04 10:52:24 29838 [Note] InnoDB: Doublewrite buffer not found: creating new
2015-05-04 10:52:24 29838 [Note] InnoDB: Doublewrite buffer created
2015-05-04 10:52:24 29838 [Note] InnoDB: 128 rollback segment(s) are active.
2015-05-04 10:52:24 29838 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-05-04 10:52:24 29838 [Note] InnoDB: Foreign key constraint system tables created
2015-05-04 10:52:24 29838 [Note] InnoDB: Creating tablespace and datafile system tables.
2015-05-04 10:52:24 29838 [Note] InnoDB: Tablespace and datafile system tables created.
2015-05-04 10:52:24 29838 [Note] InnoDB: Waiting for purge to start
2015-05-04 10:52:24 29838 [Note] InnoDB: 5.6.23 started; log sequence number 0
A random root password has been set. You will find it in ‘/root/.mysql_secret‘.
2015-05-04 10:52:24 29838 [Note] WSREP: Service disconnected.
2015-05-04 10:52:25 29838 [Note] WSREP: Some threads may fail to exit.
2015-05-04 10:52:25 29838 [Note] Binlog end
2015-05-04 10:52:25 29838 [Note] InnoDB: FTS optimize thread exiting.
2015-05-04 10:52:25 29838 [Note] InnoDB: Starting shutdown...
2015-05-04 10:52:27 29838 [Note] InnoDB: Shutdown completed; log sequence number 1625977
2015-05-04 10:52:27 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-05-04 10:52:27 29867 [Note] WSREP: Read nil XID from storage engines, skipping position init
2015-05-04 10:52:27 29867 [Note] WSREP: wsrep_load(): loading provider library ‘none‘
2015-05-04 10:52:27 29867 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-05-04 10:52:27 29867 [Note] InnoDB: The InnoDB memory heap is disabled
2015-05-04 10:52:27 29867 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-05-04 10:52:27 29867 [Note] InnoDB: Memory barrier is not used
2015-05-04 10:52:27 29867 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-05-04 10:52:27 29867 [Note] InnoDB: Using Linux native AIO
2015-05-04 10:52:27 29867 [Note] InnoDB: Using CPU crc32 instructions
2015-05-04 10:52:27 29867 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-05-04 10:52:27 29867 [Note] InnoDB: Completed initialization of buffer pool
2015-05-04 10:52:27 29867 [Note] InnoDB: Highest supported file format is Barracuda.
2015-05-04 10:52:27 29867 [Note] InnoDB: 128 rollback segment(s) are active.
2015-05-04 10:52:27 29867 [Note] InnoDB: Waiting for purge to start
2015-05-04 10:52:27 29867 [Note] InnoDB: 5.6.23 started; log sequence number 1625977
2015-05-04 10:52:27 29867 [Note] WSREP: Service disconnected.
2015-05-04 10:52:28 29867 [Note] WSREP: Some threads may fail to exit.
2015-05-04 10:52:28 29867 [Note] Binlog end
2015-05-04 10:52:28 29867 [Note] InnoDB: FTS optimize thread exiting.
2015-05-04 10:52:28 29867 [Note] InnoDB: Starting shutdown...
2015-05-04 10:52:30 29867 [Note] InnoDB: Shutdown completed; log sequence number 1625987
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in ‘/root/.mysql_secret‘.
You must change that password on your first connect,
no other statement but ‘SET PASSWORD‘ will be accepted.
See the manual for the semantics of the ‘password expired‘ flag.
Also, the account for the anonymous user has been removed.
In addition, you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test database.
This is strongly recommended for production servers.
See the manual for more instructions.
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
2:mysql-wsrep-client-5.6 ########################################### [ 67%]
3:mysql-wsrep-5.6 ########################################### [100%]
service mysql start
/usr/bin/mysql_secure_installation
/root/.mysql_secret
文件里!输出:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we‘ll need the current
password for the root user. If you‘ve just installed MySQL, and
you haven‘t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
You already have a root password set, so you can safely answer ‘n‘.
Change the root password? [Y/n] y
New password: galera_password
Re-enter new password: galera_password
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from ‘localhost‘. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
... skipping.
By default, MySQL comes with a database named ‘test‘ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] n
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
All done! If you‘ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
mysql -h 127.0.0.1 -u root --password=galera_password
mysql>SET wsrep_on=OFF;
mysql>use mysql
mysql>update user set password=password("galera_password") where user="root";
mysql>GRANT ALL ON *.* TO root@localhost IDENTIFIED BY ‘galera_password‘ WITH GRANT OPTION;
mysql>GRANT ALL ON *.* TO root@"%" IDENTIFIED BY ‘galera_password‘ WITH GRANT OPTION;
mysql>DELETE FROM mysql.user WHERE user=‘‘;
mysql>GRANT ALL ON *.* TO ‘wsrep_sst-user‘@‘%‘ IDENTIFIED BY ‘galera_password‘;
mysql>flush privileges;
mysql>exit
service mysql stop
mkdir -p /etc/mysql/conf.d
vi /etc/my.cnf
内容如下:
[mysqld]
!includedir /etc/mysql/conf.d/
service mysql stop
vi /etc/mysql/conf.d/my_galera.cnf
内容如下:
[mysql]
#设置mysql client default character
default-character-set=utf8
[mysqld]
bind-address=0.0.0.0
character-set-server=utf8
default-storage-engine=INNODB
#配置时区
default-time-zone = ‘+8:00‘
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
#Skip reverse DNS lookup of clients
skip-name-resolve
max_connections=5000
key_buffer_size = 384M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU‘s*2 for thread_concurrency
thread_concurrency = 8
innodb_buffer_pool_size = 384M
innodb_additional_mem_pool_size = 20M
#galera innodb参数
binlog_format=ROW
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
#galera cluster参数
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
wsrep_provider_options="gcache.size=300M; gcache.page_size=1G"
wsrep_sst_method=rsync
wsrep_sst_auth=wsrep_sst-user:galera_password
wsrep_cluster_name=MyCluster
wsrep_cluster_address="gcomm://"
wsrep_node_name=galera.node1
wsrep_node_address="192.168.1.85"
[mysql_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
注意: 启动galera集群的第1个节点不要设置
wsrep_cluster_address
地址!"gcomm://"
是特殊的地址,仅仅是Galera Cluster集群的第1个节点初始化启动时候使用.
如果集群启动以后,我们关闭了第1个节点,那么再次启动的时候必须先修改"gcomm://"
为其他节点的集群地址!
启动第1个节点的mysql:service mysql start --wsrep-new-cluster
galera集群的第一个节点必须加上
--wsrep-new-cluster
参数
用本机连接: mysql -h 127.0.0.1 -u root --password=galera_password
在mysql里执行如下命令:
mysql>SHOW STATUS LIKE ‘wsrep%‘;
如果:
wsrep_ready=ON,wsrep_cluster_size=1
,就说明一切正常
service mysql stop
vi /etc/mysql/conf.d/my_galera.cnf
内容如下:
[mysql]
#设置mysql client default character
default-character-set=utf8
[mysqld]
bind-address=0.0.0.0
character-set-server=utf8
default-storage-engine=INNODB
#配置时区
default-time-zone = ‘+8:00‘
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
#Skip reverse DNS lookup of clients
skip-name-resolve
max_connections=5000
key_buffer_size = 384M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU‘s*2 for thread_concurrency
thread_concurrency = 8
innodb_buffer_pool_size = 384M
innodb_additional_mem_pool_size = 20M
#galera innodb参数
binlog_format=ROW
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
#galera cluster参数
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
wsrep_provider_options="gcache.size=300M; gcache.page_size=1G"
wsrep_sst_method=rsync
wsrep_sst_auth=wsrep_sst-user:galera_password
wsrep_cluster_name=MyCluster
wsrep_cluster_address="gcomm://192.168.1.85"
wsrep_node_name=galera.node2
wsrep_node_address="192.168.1.86"
[mysql_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
wsrep_cluster_address
地址是第1个节点的地址!
service mysql start
mysql -h 127.0.0.1 -u root --password=galera_password
mysql>SHOW STATUS LIKE ‘wsrep%‘;
如果输出里:
wsrep_ready=ON,wsrep_cluster_size=2
,就说明第2个节点正常!
service mysql stop
vi /etc/mysql/conf.d/my_galera.cnf
内容如下:
[mysql]
#设置mysql client default character
default-character-set=utf8
[mysqld]
bind-address=0.0.0.0
character-set-server=utf8
default-storage-engine=INNODB
#配置时区
default-time-zone = ‘+8:00‘
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
#Skip reverse DNS lookup of clients
skip-name-resolve
max_connections=5000
key_buffer_size = 384M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU‘s*2 for thread_concurrency
thread_concurrency = 8
innodb_buffer_pool_size = 384M
innodb_additional_mem_pool_size = 20M
#galera innodb参数
binlog_format=ROW
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
#galera cluster参数
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
wsrep_provider_options="gcache.size=300M; gcache.page_size=1G"
wsrep_sst_method=rsync
wsrep_sst_auth=wsrep_sst-user:galera_password
wsrep_cluster_name=MyCluster
wsrep_cluster_address="gcomm://192.168.1.86"
wsrep_node_name=galera.node3
wsrep_node_address="192.168.1.87"
[mysql_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
wsrep_cluster_address
地址是第2个节点的地址!
service mysql start
mysql -h 127.0.0.1 -u root --password=galera_password
mysql>SHOW STATUS LIKE ‘wsrep%‘;
如果输出里:
wsrep_ready=ON,wsrep_cluster_size=3
,就说明第3个节点正常!
至此,Galera_Cluster_For_MySQL安装配置完毕!!!
在Galera Cluster中,新接入的节点叫Joiner(结合者),给Joiner提供复制的节点叫Donor(供体).
在生产环境中,建议设置一个专用的Donor,集群中其它所有节点的集群ip都指向这个Donor,这个专用的Donor不执行任何来自客户端的SQL请求,也不放在负载均衡里;这样做有以下几点好处:
指定集群ip的方式有三种:
wsrep_cluster_state_uuid
:在集群所有节点的值应该是相同的,有不同值的节点,说明其没有连接入集群. wsrep_cluster_conf_id
:正常情况下所有节点上该值是一样的.如果值不同,说明该节点被临时"分区"了.当节点之间网络连接恢复的时候应该会恢复一样的值. wsrep_cluster_size
:如果这个值跟预期的节点数一致,则所有的集群节点已经连接. wsrep_cluster_status
:集群组成的状态.如果不为"Primary”,说明出现"分区"或是"split-brain"状况.
wsrep_ready
: 该值为ON,则说明可以接受SQL负载.如果为Off,则需要检查wsrep_connected. wsrep_connected
: 如果该值为Off,且wsrep_ready的值也为Off,则说明该节点没有连接到集群. wsrep_local_state_comment
:如果wsrep_connected为On,但wsrep_ready为OFF,则可以从该项查看原因.
wsrep_flow_control_paused
:表示复制停止了多长时间.即表明集群因为Slave延迟而慢的程度.值为0~1,越靠近0越好,值为1表示复制完全停止.可优化wsrep_slave_threads的值来改善. wsrep_cert_deps_distance
:有多少事务可以并行应用处理.wsrep_slave_threads设置的值不应该高出该值太多. wsrep_flow_control_sent
:表示该节点已经停止复制了多少次. wsrep_local_recv_queue_avg
:表示slave事务队列的平均长度.slave瓶颈的预兆.
最慢的节点的wsrep_flow_control_sent
和wsrep_local_recv_queue_avg
这两个值最高.这两个值较低的话,相对更好.
wsrep_local_send_queue_avg
:网络瓶颈的预兆.如果这个值比较高的话,可能存在网络瓶.
wsrep_last_committed
:最后提交的事务数目. wsrep_local_cert_failures
和wsrep_local_bf_aborts
:回滚,检测到的冲突数目.
“gcomm://“是特殊地址,仅仅是galera cluster初始化启动时候使用,再次启动时需要使用具体的ip地址
wsrep默认使用4567端口,mysql启动后,除了检查mysql的3306端口外,还要检查此端口!
service mysql stop
rpm -ev mysql-wsrep-5.6-5.6.23-25.10.el6.x86_64
rpm -ev mysql-wsrep-client-5.6-5.6.23-25.10.el6.x86_64
rpm -ev mysql-wsrep-server-5.6-5.6.23-25.10.el6.x86_64
rpm -ev galera-3-25.3.10-2.el6.x86_64
rm -rf /var/lib/mysql/*
rm -rf /etc/mysql/*
rm /etc/my.cnf
标签:
原文地址:http://my.oschina.net/wstone/blog/410908