系统: Centos Stream 9
节点: 2节点
机器IP: 两台节点加入以下解析到 /etc/hosts
172.16.0.96 mysql96
172.16.0.97 mysql97
1、更新系统
# dnf -y update
2、配置 mariadb 官方源(https://mariadb.com/kb/en/yum/ )
(想要查看安装其他可用版本,访问 https://dlm.mariadb.com/repo/mariadb-server)
https://dlm.mariadb.com/repo/mariadb-server
# cat /etc/yum.repos.d/mariadb.repo (可将11.3改为其他版本号)
[mariadb-main]
name = MariaDB Server
baseurl = https://dlm.mariadb.com/repo/mariadb-server/11.3/yum/rhel/9/x86_64
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY
gpgcheck = 1
enabled = 1
module_hotfixes = 1
[mariadb-maxscale]
# To use the latest stable release of MaxScale, use "latest" as the version
# To use the latest beta (or stable if no current beta) release of MaxScale, use "beta" as the version
name = MariaDB MaxScale
baseurl = https://dlm.mariadb.com/repo/maxscale/latest/yum/rhel/9/x86_64
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-MaxScale-GPG-KEY
gpgcheck = 1
enabled = 1
[mariadb-tools]
name = MariaDB Tools
baseurl = https://downloads.mariadb.com/Tools/rhel/9/x86_64
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Enterprise-GPG-KEY
gpgcheck = 1
enabled = 1
3、导入GPG KEY
# rpm --import https://supplychain.mariadb.com/MariaDB-Server-GPG-KEY
4、安装 mariadb ,galera插件
# dnf clean all
# dnf install MariaDB-server galera-4 MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common
5、配置galera cluster (复制两台机相同配置)
wsrep_cluster_name 可*设置
wsrep_cluster_address 根据自身环境修改ip
# vi /etc/my.cnf.d/server.conf
.......
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
wsrep_cluster_name="ers_galera_cluster"
wsrep_cluster_address="gcomm://172.16.0.96,172.16.0.97"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_doublewrite=1
query_cache_size=0
innodb_buffer_pool_size=2G
bind-address=0.0.0.0
.....
6、初始化集群,会自动启动mariadb服务 (两台机上同样执行)
# galera_new_cluster
7、配置mysql root密码登陆 (这里设置密码为 test, 根据自身需要修改)
登陆其中一台
# mysql
> show grant for 'root';
> GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` IDENTIFIED BY 'test' with grant option;
> exit;
再次登陆需要密码
# mysql -uroot -p
在另外一台节点会自动同步,登陆另外一台mysql 同样会要求密码登陆
8、测试同步
在其中一台机创建数据库,再另外一台节点查看已有新建的数据库表示galera集群部署成功