【MySQL】第九章:MariaDB Galera Cluster

[root@wallet01 ~]# 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] Succeessfully added trusted package signing keys.

[root@wallet01 ~]# yum install -y MariaDB-server MariaDB-client MariaDB-backup galera
[root@wallet01 ~]# rpm -qa MariaDB-* galera
MariaDB-common-10.3.12-1.el6.x86_64
MariaDB-server-10.3.12-1.el6.x86_64
MariaDB-compat-10.3.12-1.el6.x86_64
MariaDB-backup-10.3.12-1.el6.x86_64
MariaDB-client-10.3.12-1.el6.x86_64
galera-25.3.25-1.rhel6.el6.x86_64

[root@wallet01 ~]# cd /etc/my.cnf.d/
[root@wallet01 my.cnf.d]# vi server.cnf
[mysqld]
bind-address=0.0.0.0
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
wsrep_on = 1
wsrep_provider = /usr/lib64/galera/libgalera_smm.so
wsrep_provider_options="gcache.size=1024M; gcache.page_size=512M"
wsrep_cluster_name = "MariaDB Galera Cluster"
wsrep_cluster_address = "gcomm://192.168.1.201,192.168.1.202,192.168.1.203"
wsrep_sst_method=mariabackup
wsrep_sst_auth=sst:sst
wsrep_node_name = wallet01
wsrep_node_address="192.168.1.201"

[root@wallet01 ~]# /etc/init.d/mysql bootstrap
Bootstrapping the cluster.. Starting MariaDB.190222 13:30:26 mysqld_safe Logging to '/var/lib/mysql/wallet01.err'.
190222 13:30:26 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
. SUCCESS! 

[root@wallet01 ~]# service mysql status
 SUCCESS! MariaDB running (18754)

[root@wallet01 ~]# netstat -tunlp | grep mysqld
tcp        0      0 0.0.0.0:4567        0.0.0.0:*        LISTEN      18754/mysqld        
tcp        0      0 0.0.0.0:3306        0.0.0.0:*        LISTEN      18754/mysqld 

[root@wallet01 ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

[root@wallet01 ~]# mysql -uroot -pabcd.1234
MariaDB [(none)]> create user sst@'%' identified by 'sst';
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> grant reload,lock tables,replication client,process on *.* to sst@'%';
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)


[root@wallet02 ~]# 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] Succeessfully added trusted package signing keys.

[root@wallet02 ~]# yum install -y MariaDB-server MariaDB-client MariaDB-backup galera
[root@wallet02 ~]# rpm -qa MariaDB-* galera
MariaDB-common-10.3.12-1.el6.x86_64
MariaDB-server-10.3.12-1.el6.x86_64
MariaDB-compat-10.3.12-1.el6.x86_64
MariaDB-backup-10.3.12-1.el6.x86_64
MariaDB-client-10.3.12-1.el6.x86_64
galera-25.3.25-1.rhel6.el6.x86_64

[root@wallet02 ~]# cd /etc/my.cnf.d/
[root@wallet02 my.cnf.d]# vi server.cnf
[mysqld]
bind-address=0.0.0.0
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
wsrep_on = 1
wsrep_provider = /usr/lib64/galera/libgalera_smm.so
wsrep_provider_options="gcache.size=1024M; gcache.page_size=512M"
wsrep_cluster_name = "MariaDB Galera Cluster"
wsrep_cluster_address = "gcomm://192.168.1.201,192.168.1.202,192.168.1.203"
wsrep_sst_method=mariabackup
wsrep_sst_auth=sst:sst
wsrep_node_name = wallet02
wsrep_node_address="192.168.1.202"

[root@wallet02 ~]# /etc/init.d/mysql start        
Starting MariaDB.190222 14:10:56 mysqld_safe Logging to '/var/lib/mysql/wallet02.err'.
190222 14:10:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
............... SUCCESS! 

[root@wallet02 ~]# service mysql status
 SUCCESS! MariaDB running (24789)
 
[root@wallet02 ~]# netstat -tunlp | grep mysqld
tcp        0      0 0.0.0.0:4567        0.0.0.0:*        LISTEN      24789/mysqld        
tcp        0      0 0.0.0.0:3306        0.0.0.0:*        LISTEN      24789/mysqld


[root@wallet03 ~]# 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] Succeessfully added trusted package signing keys.

[root@wallet03 ~]# yum install -y MariaDB-server MariaDB-client MariaDB-backup galera
[root@wallet03 ~]# rpm -qa MariaDB-* galera
MariaDB-common-10.3.12-1.el6.x86_64
MariaDB-server-10.3.12-1.el6.x86_64
MariaDB-compat-10.3.12-1.el6.x86_64
MariaDB-backup-10.3.12-1.el6.x86_64
MariaDB-client-10.3.12-1.el6.x86_64
galera-25.3.25-1.rhel6.el6.x86_64

[root@wallet03 ~]# cd /etc/my.cnf.d/
[root@wallet03 my.cnf.d]# vi server.cnf
[mysqld]
bind-address=0.0.0.0
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
wsrep_on = 1
wsrep_provider = /usr/lib64/galera/libgalera_smm.so
wsrep_provider_options="gcache.size=1024M; gcache.page_size=512M"
wsrep_cluster_name = "MariaDB Galera Cluster"
wsrep_cluster_address = "gcomm://192.168.1.201,192.168.1.202,192.168.1.203"
wsrep_sst_method=mariabackup
wsrep_sst_auth=sst:sst
wsrep_node_name = wallet03
wsrep_node_address="192.168.1.203"

[root@wallet01 ~]# su - mysql
[mysql@wallet01 ~]$mariabackup --backup --user=root --password=abcd.1234 --galera-info \
--target-dir=/home/mysql/backup/`date '+%Y-%m-%d_%H-%M-%S'`

[mysql@wallet01 ~]$ cd backup
[mysql@wallet01 backup]$ scp -r 2019-02-22_15-16-30 192.168.1.203:/home/mysql/backup/

[root@wallet03 ~]# su - mysql
[mysql@wallet03 ~]$ cd backup/
[mysql@wallet03 ~]$ mariabackup --prepare --target-dir=/home/mysql/backup/2019-02-22_15-16-30
[mysql@wallet03 ~]$ mariabackup --copy-back --target-dir=/home/mysql/backup/2019-02-22_15-16-30

[mysql@wallet03 ~]$ cd /var/lib/mysql
[mysql@wallet03 mysql]$ cat xtrabackup_galera_info
7ae6f9c9-365d-11e9-959a-66896ee8c65d:58

[mysql@wallet03 mysql]$ vi grastate.dat
# GALERA saved state
version: 2.1
uuid:    7ae6f9c9-365d-11e9-959a-66896ee8c65d
seqno:   58
safe_to_bootstrap: 0

[root@wallet03 ~]# service mysql start 
Starting MariaDB.190222 14:48:32 mysqld_safe Logging to '/var/lib/mysql/wallet03.err'.
190222 14:48:32 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
. SUCCESS! 

[root@wallet03 ~]# service mysql status
 SUCCESS! MariaDB running (32584)
 
[root@wallet02 ~]# netstat -tunlp | grep mysqld
tcp        0      0 0.0.0.0:4567        0.0.0.0:*        LISTEN      32584/mysqld        
tcp        0      0 0.0.0.0:3306        0.0.0.0:*        LISTEN      32584/mysqld


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章