【注意】最后更新于 July 11, 2021,文中内容可能已过时,请谨慎使用。
全centos7环境
10.69.0.10 | cmp-vi650rc4 |
---|
10.69.0.11 | cmp-d8uc6edi |
10.69.0.5 | cmp-g7msocxo |
添加host到 /etc/hosts
创建 /etc/yum.repos.d/galera.repo
1
2
3
4
5
6
7
8
9
10
11
12
13
| cat > /etc/yum.repos.d/galera.repo <<EOF
[galera]
name = Galera
baseurl = http://releases.galeracluster.com/galera-3/centos/7/$basearch/
gpgkey = http://releases.galeracluster.com/GPG-KEY-galeracluster.com
gpgcheck = 1
[mysql-wsrep]
name = MySQL-wsrep
baseurl = http://releases.galeracluster.com/mysql-wsrep-5.7/centos/7/$basearch/
gpgkey = http://releases.galeracluster.com/GPG-KEY-galeracluster.com
gpgcheck = 1
EOF
|
安装 galera
和 mysql-wsrep
1
| yum update -y && yum install -y galera-3 mysql-wsrep-server-5.7 rsync
|
selinux 开启mysql的其他端口
1
| semanage permissive -a mysqld_t
|
如果semanage找不到,请安装
1
| yum install policycoreutils-python
|
启动mysql
修改mysql root 密码:
1
2
3
| password_match=`awk '/A temporary password is generated for/ {a=$0} END{ print a }' /var/log/mysqld.log | awk '{print $(NF)}'`
echo "$password_match"
mysql -uroot -p$password_match --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root-mysql-pw@2017'; FLUSH PRIVILEGES; "
|
1
2
| grant all privileges on *.* to sst@'%' identified by '123456';
flush privileges;
|
1
2
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' identified by 'Root-mysql-pw@2017';
flush privileges;
|
修改 /etc/my.cnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| [mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
binlog_format=ROW
bind-address=0.0.0.0
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=122M
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
wsrep_provider_options="gcache.size=300M; gcache.page_size=300M"
wsrep_sst_method=rsync
wsrep_cluster_address="gcomm://10.69.0.10,10.69.0.11"
wsrep_cluster_name="mysql_cluster"
wsrep_node_address='10.69.0.10'
wsrep_node_name='node1'
!includedir /etc/my.cnf.d/
[mysql_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
|
在其他node上修改
1
2
| wsrep_node_address='10.69.0.11'
wsrep_node_name='node2'
|
在第一台机器上执行:
1
| /usr/bin/mysqld_bootstrap
|
后面的机器普通启动就好了