galera for mysql

东方国安
2023-12-01

前期准备

三台虚拟机: 192.168.137.52

192.168.137.53

192.168.137.54

系统环境: # yum install gcc gcc-c++

# yum install boost-devel

# yum install scons check-devel openssl-devel

 

开始安装mysql

mysql的版本一定是要打过wsrep补丁的,直接用mariadb也可以



 

# yum install libaio 

# wget https://launchpad.net/codership-mysql/5.5/5.5.29-23.7.3/+download/mysql-5.5.29_wsrep_23.7.3-linux-x86_64.tar.gz 

# tar zxvf mysql-5.5.29_wsrep_23.7.3-linux-x86_64.tar.gz  

# mv mysql-5.5.29_wsrep_23.7.3-linux-x86_64 /usr/local/mysql 

# cd /usr/local/mysql/ 

# groupadd mysql 

# useradd -r -g mysql mysql

# chown -R mysql:mysql . 

# ./scripts/mysql_install_db --no-defaults --datadir=/usr/local/mysql/data --user=mysql 

# chown -R root . 

# chown -R mysql data

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 

# mkdir -p /var/lib/mysql 

# chown mysql:mysql /var/lib/mysql

再给mysql安装galera插件



 

# wget https://launchpad.net/galera/2.x/23.2.4/+download/galera-23.2.4-src.tar.gz 

# tar zxvf galera-23.2.4-src.tar.gz # cd galera-23.2.4-src

# scons 

# cp garb/garbd /usr/local/mysql/bin/ 

# cp libgalera_smm.so /usr/local/mysql/lib/plugin/

mysql的配置文件my.cnf



 

[client] 

port = 3306 

socket = /var/lib/mysql/mysql.sock  

 

[mysqld_safe] 

log-error = /var/lib/mysql/mysql.log 

pid-file = /var/lib/mysql/mysql.pid  

 

[mysqld] wsrep_node_name = node1 

wsrep_provider = /usr/local/mysql/lib/plugin/libgalera_smm.so 

#wsrep_provider_options ='gcache.size=1G;socket.ssl_key=my_key;socket.ssl_cert=my_cert' 

#wsrep_slave_threads=16 

wsrep_sst_method = rsync 

#wsrep_sst_auth=root:  

 

port = 3306 

socket = /var/lib/mysql/mysql.sock 

user = mysql 

basedir = /usr/local/mysql 

datadir = /usr/local/mysql/data  

 

default_storage_engine=InnoDB 

#innodb_buffer_pool_size=1G

#innodb_log_file_size=256M 

innodb_autoinc_lock_mode=2 

innodb_locks_unsafe_for_binlog=1 

innodb_flush_log_at_trx_commit=0 

innodb_doublewrite=0 

innodb_file_per_table=1  

 

binlog_format=ROW 

log-bin=mysql-bin 

server-id=52

relay-log=mysql-relay-bin 

#read_only=1 

log-slave-updates=1

已经完成了对galera的基本配置,接下去启动galera for mysql

初次启动:

/usr/local/mysql/bin/mysqld_safe --wsrep_cluster_address=gcomm://

或者

service mysql start --wsrep_cluster_address=gcomm://

 

查看mysqld监听端口:

# netstat -plantu | grep mysqld

 

注: 1)”gcomm://”是特殊的地址,仅仅是galera cluster初始化启动时候使用,再次启动的时候需要使用具体的IP地址. 

      2) 端口4567是wsrep使用的默认端口.该端口的防火墙设置规则应该和3306的一样.

 

关闭:

# /usr/local/mysql/bin/mysqladmin -uroot -p shutdown

 

接下去就要添加新节点了

添加新节点的时候,新接入的节点叫Joiner,给joiner提供复制的节点叫Donor.新的节点接入需要: 

1) 安装带wsrep patch的MySQL版本 

2) 安装Galera复制插件 

3) 配置好新节点的MySQL(参考Donnor的my.cnf) 

4) 配置或启动的gcomm://的地址是需要使用donnor的IP.

 

新节点启动:

# service mysql start --wsrep_cluster_address="gcomm://192.168.137.52:4567,192.168.137.54:4567"

 

这样,三个节点搭建成了mysql galera。

 

查看整个集群状态:

mysql> show status like 'wsrep%';

 类似资料:

相关阅读

相关文章

相关问答