3月 272015
使用脚本快速安装MariaDB YUM源仓库配置文件
https://mariadb.com/kb/en/mariadb-package-repository-setup-and-usage/ [root@ip-172-31-33-11 ~]# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash [info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo [info] Adding trusted package signing keys... [info] Successfully added trusted package signing keys [root@ip-172-31-33-11 ~]# ls /etc/yum.repos.d/ CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo mariadb.repo [root@ip-172-31-33-11 ~]# cat /etc/yum.repos.d/mariadb.repo [mariadb-main] name = MariaDB Server baseurl = https://downloads.mariadb.com/MariaDB/mariadb-10.4/yum/rhel/$releasever/$basearch gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY gpgcheck = 1 enabled = 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://downloads.mariadb.com/MaxScale/2.4/centos/$releasever/$basearch 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/$releasever/$basearch gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Enterprise-GPG-KEY gpgcheck = 1 enabled = 1 [root@ip-172-31-33-11 ~]#
查看版本信息
[root@ip-172-31-33-11 ~]# yum info MariaDB-server Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: d36uatko69830t.cloudfront.net * extras: d36uatko69830t.cloudfront.net * updates: d36uatko69830t.cloudfront.net Available Packages Name : MariaDB-server Arch : x86_64 Version : 10.4.12 Release : 1.el7.centos Size : 26 M Repo : mariadb-main/7/x86_64 Summary : MariaDB: a very fast and robust SQL database server URL : http://mariadb.org License : GPLv2 Description : MariaDB: a very fast and robust SQL database server : : It is GPL v2 licensed, which means you can use the it free of charge under the : conditions of the GNU General Public License Version 2 (http://www.gnu.org/licenses/). : : MariaDB documentation can be found at https://mariadb.com/kb : MariaDB bug reports should be submitted through https://jira.mariadb.org Name : mariadb-server Arch : x86_64 Epoch : 1 Version : 5.5.64 Release : 1.el7 Size : 11 M Repo : base/7/x86_64 Summary : The MariaDB server and related files URL : http://mariadb.org License : GPLv2 with exceptions and LGPLv2 and BSD Description : MariaDB is a multi-user, multi-threaded SQL database server. It is a : client/server implementation consisting of a server daemon (mysqld) : and many different client programs and libraries. This package contains : the MariaDB server and some accompanying files and directories. : MariaDB is a community developed branch of MySQL. [root@ip-172-31-33-11 ~]#
查看galera复制引擎的版本信息
[root@ip-172-31-33-11 ~]# yum info galera-4 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: d36uatko69830t.cloudfront.net * extras: d36uatko69830t.cloudfront.net * updates: d36uatko69830t.cloudfront.net Available Packages Name : galera-4 Arch : x86_64 Version : 26.4.3 Release : 1.rhel7.el7.centos Size : 9.3 M Repo : mariadb-main/7/x86_64 Summary : Galera: a synchronous multi-master wsrep provider (replication engine) URL : http://www.codership.com/ License : GPL-2.0 Description : Galera is a fast synchronous multimaster wsrep provider (replication engine) : for transactional databases and similar applications. For more information : about wsrep API see http://launchpad.net/wsrep. For a description of Galera : replication engine see http://www.codership.com. : : Copyright 2007-2014 Codership Oy. All rights reserved. Use is subject to license terms under GPLv2 : license. : : This software comes with ABSOLUTELY NO WARRANTY. This is free software, : and you are welcome to modify and redistribute it under the GPLv2 license. [root@ip-172-31-33-11 ~]#
安装MariaDB数据库服务及依赖软件包
[root@server1 ~]# yum -y install MariaDB-server MariaDB-client [root@server2 ~]# yum -y install MariaDB-server MariaDB-client [root@server3 ~]# yum -y install MariaDB-server MariaDB-client
查看依赖
启动服务
[root@server1 ~]# systemctl enable mariadb Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mariadb.service. Created symlink from /etc/systemd/system/mysqld.service to /usr/lib/systemd/system/mariadb.service. Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. [root@server1 ~]# systemctl start mariadb [root@server1 ~]# [root@server2 ~]# systemctl enable mariadb Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mariadb.service. Created symlink from /etc/systemd/system/mysqld.service to /usr/lib/systemd/system/mariadb.service. Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. [root@server2 ~]# systemctl start mariadb [root@server2 ~]# [root@server3 ~]# systemctl enable mariadb Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mariadb.service. Created symlink from /etc/systemd/system/mysqld.service to /usr/lib/systemd/system/mariadb.service. Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. [root@server3 ~]# systemctl start mariadb [root@server3 ~]#
安装同步软件rsync
[root@server1 ~]# yum -y install rsync
查看rsync版本信息
[root@server1 ~]# yum info rsync Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: d36uatko69830t.cloudfront.net * extras: d36uatko69830t.cloudfront.net * updates: d36uatko69830t.cloudfront.net Installed Packages Name : rsync Arch : x86_64 Version : 3.1.2 Release : 6.el7_6.1 Size : 815 k Repo : installed From repo : base Summary : A program for synchronizing files over a network URL : http://rsync.samba.org/ License : GPLv3+ Description : Rsync uses a reliable algorithm to bring remote and host files into : sync very quickly. Rsync is fast because it just sends the differences : in the files over the network instead of sending the complete : files. Rsync is often used as a very powerful mirroring process or : just as a more capable replacement for the rcp command. A technical : report which describes the rsync algorithm is included in this : package. [root@server1 ~]#
编辑集群配置文件
server1
[root@server1 ~]# vi /etc/my.cnf.d/galera.cnf [mysqld] binlog_format=ROW default-storage-engine=innodb innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 # Galera Provider Configuration wsrep_on=ON wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so # Galera Cluster Configuration wsrep_cluster_name="test_cluster" wsrep_cluster_address="gcomm://172.31.46.167,172.31.33.251,172.31.46.43" # Galera Synchronization Configuration wsrep_sst_method=rsync # Galera Node Configuration wsrep_node_address="172.31.46.167" wsrep_node_name="server01"
server2
[root@server2 ~]# vi /etc/my.cnf.d/galera.cnf [mysqld] binlog_format=ROW default-storage-engine=innodb innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 # Galera Provider Configuration wsrep_on=ON wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so # Galera Cluster Configuration wsrep_cluster_name="test_cluster" wsrep_cluster_address="gcomm://172.31.46.167,172.31.33.251,172.31.46.43" # Galera Synchronization Configuration wsrep_sst_method=rsync # Galera Node Configuration wsrep_node_address="172.31.33.251" wsrep_node_name="server02"
server3
[root@server3 ~]# vi /etc/my.cnf.d/galera.cnf [mysqld] binlog_format=ROW default-storage-engine=innodb innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 # Galera Provider Configuration wsrep_on=ON wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so # Galera Cluster Configuration wsrep_cluster_name="test_cluster" wsrep_cluster_address="gcomm://172.31.46.167,172.31.33.251,172.31.46.43" # Galera Synchronization Configuration wsrep_sst_method=rsync # Galera Node Configuration wsrep_node_address="172.31.46.43" wsrep_node_name="server03"
停止所有节点的MariaDB服务
[root@server3 ~]# systemctl stop mariadb [root@server2 ~]# systemctl stop mariadb [root@server1 ~]# systemctl stop mariadb
启动的一个节点
[root@server1 ~]# galera_new_cluster [root@server1 ~]# mysql -u root -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'" Enter password: +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 1 | +--------------------+-------+ [root@server1 ~]#
启动第二个节点
[root@server2 ~]# systemctl start mariadb [root@server2 ~]# mysql -u root -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'" Enter password: +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 2 | +--------------------+-------+ [root@server2 ~]#
启动第三个节点
[root@server3 ~]# systemctl start mariadb [root@server3 ~]# mysql -u root -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'" Enter password: +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 3 | +--------------------+-------+ [root@server3 ~]#