全部博文(389)
分类: Mysql/postgreSQL
2014-11-23 22:43:08
MySQL Galera 集群的安装过程
MySQL Galera集群版的mysql是经过codeship打了wsrep补丁的,不是普通的mysql版本.可以从github下载。
环境:redhat 7
mysql:5.5.37
galera: 25.3.5
解压,新增mysql用户,然后初始化mysql
[root@os1 ~]# ls -l mysql-5.5.37_wsrep_25.10-linux-x86_64.tar.gz
-rw-r--r--. 1 root root 62014481 Nov 23 17:17 mysql-5.5.37_wsrep_25.10-linux-x86_64.tar.gz
[root@os1 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data
安装 galera的plugin
[root@os1 ~]# rpm -ivh --force galera-25.3.5-1.rhel6.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:galera-25.3.5-1.rhel6 ################################# [100%]
拷贝libgalera的plugin到mysql/lib目录下
[root@os1 local]# cp /usr/lib64/galera/libgalera_smm.so /usr/local/mysql/lib/plugin
[root@os1 ~]# chown -R mysql:mysql /usr/local/mysql
编写/etc/my.cnf文件
[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in
default_storage_engine=innodb
log_bin=1
binlog_format=ROW
innodb_file_per_table=1
log-slave-updates=1
server_id=1225
innodb_autoinc_lock_mode=2
wsrep_node_name = 192.168.12.25
wsrep_provider = /usr/local/mysql/lib/plugin/libgalera_smm.so
wsrep_sst_method = mysqldump
wsrep_sst_auth=root:rootroot --mysql密码
然后启动第一个mysql节点
[root@os1 plugin]# /usr/local/mysql/bin/mysqld_safe --wsrep-cluster-address=gcomm://
141123 19:48:06 mysqld_safe Logging to '/var/log/mysqld.log'.
141123 19:48:06 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql
141123 19:48:06 mysqld_safe WSREP: Running position recovery with --log_error='/usr/local/mysql/wsrep_recovery.u1fVym' --pid-file='/usr/local/mysql/os1.abc.com-recover.pid'
141123 19:48:06 mysqld_safe WSREP: Failed to recover position:
''
..............
[root@os1 support-files]# netstat -nltp | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 10023/mysqld
[root@os1 support-files]# /usr/local/mysql/bin/mysql -u root -p --socket=/usr/local/mysql/mysql/mysql.sock
mysql> show global status like '%state%';
+---------------------------+--------------------------------------+
| Variable_name | Value |
+---------------------------+--------------------------------------+
| wsrep_local_state_uuid | b34c90ed-7306-11e4-ba41-a65afe12d31b |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_cluster_state_uuid | b34c90ed-7306-11e4-ba41-a65afe12d31b |
+---------------------------+--------------------------------------+
在第二个节点如法炮制,但是/etc/my.cnf稍有不同
[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in
default_storage_engine=innodb
log_bin=1
binlog_format=ROW
innodb_file_per_table=1
log-slave-updates=1
server_id=12213
innodb_autoinc_lock_mode=2
wsrep_node_name = 192.168.12.213
wsrep_provider = /usr/local/mysql/lib/plugin/libgalera_smm.so
wsrep_sst_method = mysqldump
wsrep_sst_auth=root:rootroot
在第二个节点上启动mysql
[root@os2 mysql]# /usr/local/mysql/bin/mysqld_safe --wsrep-cluster-address="gcomm://192.168.12.25:4567"
.........
141123 20:08:42 [Note] WSREP: Setting initial position to 00000000-0000-0000-0000-000000000000:-1
141123 20:08:42 [Note] WSREP: protonet asio version 0
141123 20:08:42 [Note] WSREP: Using CRC-32C (optimized) for message checksums.
141123 20:08:42 [Note] WSREP: backend: asio
141123 20:08:42 [Note] WSREP: GMCast version 0
141123 20:08:42 [Note] WSREP: (77c88cef-7309-11e4-8435-43850781c6da, 'tcp://0.0.0.0:4567') listening at tcp://0.0.0.0:4567
141123 20:08:42 [Note] WSREP: (77c88cef-7309-11e4-8435-43850781c6da, 'tcp://0.0.0.0:4567') multicast: , ttl: 1
141123 20:08:42 [Note] WSREP: EVS version 0
141123 20:08:42 [Note] WSREP: PC version 0
141123 20:08:42 [Note] WSREP: gcomm: connecting to group 'my_wsrep_cluster', peer '192.168.12.25:4567'
141123 20:08:45 [Warning] WSREP: no nodes coming from prim view, prim not possible
从第一个节点上查看,wsrep_cluser相关变量,表明集群现在已经就绪.
mysql> show global status like '%wsrep_cluster%';
+--------------------------+--------------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------------+
| wsrep_cluster_conf_id | 2 |
| wsrep_cluster_size | 2 |
| wsrep_cluster_state_uuid | ff4f28f7-7318-11e4-8e26-8bcedbe58a6d |
| wsrep_cluster_status | Primary |
+--------------------------+--------------------------------------+
在两个节点上相互增加数据测试,可以见到对方数据,表明集群正常. 如果是第一次搭建,也许会碰到很多坑,
作者打算写专门一个文章来总结.