mariadb-galera-cluster
mariadb-galera-cluster
1,初始化:不写了。时间同步啥啥啥的
10.11.201.221 | mariadb1 | centos7 |
---|---|---|
10.11.201.222 | mariadb2 | centos7 |
10.11201.223 | mariadb3 | centos7 |
2,配置yum源
cat >/etc/yum.repos.d/MariaDB.repo <<EOF
[mariadb]
name=MariaDB
baseurl=https://mirrors.aliyun.com/mariadb/yum/10.6.16/centos7-amd64/
gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
enabled=1
gpgcheck=1
EOF
3,三台主机安装软件包
yum -y install MariaDB-server galera-4 MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common MariaDB-cracklib-password-check
4,三台启动mariadb,初始化mariadb,需要设置一个root密码,并赋予权限,所有地址,所有库都可访问,赋权以后交叉登录测试
systemctl start mariadb
mysql -uroot
CREATE USER 'root'@'%' IDENTIFIED BY 'emporer123';
grant all privileges on *.* to root@"%" identified by "emporer123";
grant all privileges on *.* to root@"localhost" identified by "emporer123";
FLUSH PRIVILEGES;
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 44
Server version: 10.6.16-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE USER 'root'@'%' IDENTIFIED BY 'emporer123';
MariaDB [(none)]> grant all privileges on *.* to root@"%" identified by "emporer123";
5,附加工作目录权限
chown -R /var/lib/mysql/
chown -R /var/log/mariadb/
6,关闭所有节点的mariadb服务,
systemctl stop mariadb
7,更改所有节点的mariadb配置文件
mariadb1
mariadb1
cat > /etc/my.cnf.d/server.cnf <<EOF
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
[mysqld]
basedir = /usr
bind-address = 10.11.201.221
port = 3306
log_error = /var/log/mariadb/mariadb.log
log_bin = mysql-bin
binlog_format = ROW
expire_logs_days = 14
default-storage-engine = innodb
innodb_autoinc_lock_mode = 2
collation-server = utf8_general_ci
init-connect = SET NAMES utf8
character-set-server = utf8
datadir = /var/lib/mysql/
wsrep_cluster_address = gcomm://10.11.201.221:4567,10.11.201.222:4567,10.11.201.223:4567
wsrep_provider_options = gmcast.listen_addr=tcp://10.11.201.221:4567;ist.recv_addr=10.11.201.221:4568;
wsrep_node_address = 10.11.201.221:4567
wsrep_sst_receive_address = 10.11.201.221:4444
wsrep_provider = /usr/lib64/galera-4/libgalera_smm.so
wsrep_cluster_name = emporer
wsrep_node_name = mariadb1
wsrep_sst_method = mariabackup
wsrep_sst_auth = root:emporer123
wsrep_slave_threads = 4
wsrep_on = ON
max_connections = 10000
key_buffer_size = 64M
max_heap_table_size = 64M
tmp_table_size = 64M
innodb_buffer_pool_size = 8192M
[server]
pid-file = /var/lib/mysql/mariadb.pid
[sst]
EOF
[root@mariadb1 ~]#
mariadb2
[root@mariadb2 ~]#
cat > /etc/my.cnf.d/server.cnf << EOF
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
[mysqld]
basedir = /usr
bind-address = 10.11.201.222
port = 3306
log_error = /var/log/mariadb/mariadb.log
log_bin = mysql-bin
binlog_format = ROW
expire_logs_days = 14
default-storage-engine = innodb
innodb_autoinc_lock_mode = 2
collation-server = utf8_general_ci
init-connect = SET NAMES utf8
character-set-server = utf8
datadir = /var/lib/mysql/
wsrep_cluster_address = gcomm://10.11.201.221:4567,10.11.201.222:4567,10.11.201.223:4567
wsrep_provider_options = gmcast.listen_addr=tcp://10.11.201.222:4567;ist.recv_addr=10.11.201.222:4568;
wsrep_node_address = 10.11.201.222:4567
wsrep_sst_receive_address = 10.11.201.222:4444
wsrep_provider = /usr/lib64/galera-4/libgalera_smm.so
wsrep_cluster_name = emporer
wsrep_node_name = mariadb2
wsrep_sst_method = mariabackup
wsrep_sst_auth = root:emporer123
wsrep_slave_threads = 4
wsrep_on = ON
max_connections = 10000
key_buffer_size = 64M
max_heap_table_size = 64M
tmp_table_size = 64M
innodb_buffer_pool_size = 8192M
[server]
pid-file = /var/lib/mysql/mariadb.pid
[sst]
EOF
[root@mariadb2 ~]#
mariadb3
[root@mariadb3 ~]#
cat > /etc/my.cnf.d/server.cnf << EOF
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
[mysqld]
basedir = /usr
bind-address = 10.11.201.223
port = 3306
log_error = /var/log/mariadb/mariadb.log
log_bin = mysql-bin
binlog_format = ROW
expire_logs_days = 14
default-storage-engine = innodb
innodb_autoinc_lock_mode = 2
collation-server = utf8_general_ci
init-connect = SET NAMES utf8
character-set-server = utf8
datadir = /var/lib/mysql/
wsrep_cluster_address = gcomm://10.11.201.221:4567,10.11.201.222:4567,10.11.201.223:4567
wsrep_provider_options = gmcast.listen_addr=tcp://10.11.201.223:4567;ist.recv_addr=10.11.201.223:4568;
wsrep_node_address = 10.11.201.223:4567
wsrep_sst_receive_address = 10.11.201.223:4444
wsrep_provider = /usr/lib64/galera-4/libgalera_smm.so
wsrep_cluster_name = emporer
wsrep_node_name = mariadb3
wsrep_sst_method = mariabackup
wsrep_sst_auth = root:emporer123
wsrep_slave_threads = 4
wsrep_on = ON
max_connections = 10000
key_buffer_size = 64M
max_heap_table_size = 64M
tmp_table_size = 64M
innodb_buffer_pool_size = 8192M
[server]
pid-file = /var/lib/mysql/mariadb.pid
[sst]
EOF
8,第一台mariadb1初始化点火节点
galera_new_cluster
9,剩余两个节点启动服务即可
[root@mariadb2 ~]# systemctl start mariadb
[root@mariadb3 ~]# systemctl start mariadb
10,查看
[root@mariadb2 ~]# mysql -uroot -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
Enter password:
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 3 |
+--------------------+-------+
本文链接:
/archives/1704439379878
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
Emporer-Linux!
喜欢就支持一下吧