MariaDB+gelera HA
環境信息
centos 7.2.1511
版本信息
MariaDB 10.1.19-client
MariaDB 10.1.19-common
MariaDB 10.1.19-server
安裝mariadb
yum install MariaDB-serverMariaDB-client
測試mysql是否正常
Service mysql start
Service mysql stop
創建mysql數據存放目錄並授權
mkdir -p /data
chown -R mysql.mysql /data
刪除存在的數據庫文件
rm -rf /var/lib/mysql/*
修改/etc/my.cnf
[mysqld]
binlog_format=ROW
bind-address = 172.16.16.1
collation-server = utf8_general_ci
character-set-server = utf8
default_storage_engine=innodb
datadir = /data
max_connections = 4096
pid-file = /data/mysql/mysql.pid
query_cache_size=0
socket = /tmp/mysql.sock
#*Innodb setting
#
innodb_file_per_table
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=256M
初始化數據庫
mysql_install_db
重新啓動數據庫
service mysql start
創建鏈接文件
ln -s /tmp/mysql.sock /var/lib/mysql/
安全安裝
mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THISSCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB tosecure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root passwordyet, the password will be blank,
so you should just press enterhere.
Enter current password for root(enter for none):
OK, successfully used password,moving on...
Setting the root password ensuresthat nobody can log into the MariaDB
root user without the properauthorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installationhas an anonymous user, allowing anyone
to log into MariaDB without havingto have a user account created for
them. This is intended only for testing, and tomake 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 beallowed to connect from 'localhost'. This
ensures that someone cannot guess atthe root password from the network.
Disallow root login remotely?[Y/n] n
... skipping.
By default, MariaDB comes with adatabase named 'test' that anyone can
access. This is also intended only for testing, andshould be removed
before moving into a productionenvironment.
Remove test database and access toit? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tableswill 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!
創建同步用戶
grant all privileges on *.* to 'wsrep_user'@'controller2' identified by'wsreppasswd';
flush privileges;
更新gelera下wsrep信息
編輯/etc/my.cnf.d/server.cnf
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://
wsrep_cluster_name='dbcluster'
wsrep_node_address='172.16.16.1'
wsrep_sst_method=rsync
#wsrep_sst_method=xtrabackup
wsrep_sst_auth=wsrep_user:wsreppasswd
wsrep_node_name='HA-1'
wsrep_node_address=172.16.16.1
wsrep_provider_options="pc.recovery=TRUE;gcache.size=300M"
此時沒有同步對象,所以wsrep_cluster_address=gcomm://留空
啓動節點
sudo -u mysql mysqld --wsrep-cluster-address='gcomm://'
首先配置節點2
使用1的配置文件直接複製後,修改信息
[mysqld]
bind-address = 172.16.16.2
[gelera]
wsrep_cluster_address=gcomm://172.16.16.1
wsrep_node_address='172.16.16.2'
wsrep_node_name='HA-2'
wsrep_node_address=172.16.16.2
此時數據同步方向爲2同步1
啓動節點2上的服務
同步完成後
關閉節點1服務
service mysql stop
修改同步對象wsrep_cluster_address=gcomm://172.16.16.2
重啓服務後,雙向同步完成,驗證服務
MariaDB
[(none)]>show global status like 'wsrep_cluster%';
從此處可以看出當有其他節點加入到集羣中時,wsrep_cluster_size可以反映出當前集羣節點數量,wsrep_cluster_status可以判定當前節點屬於primary還是slave
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'' WITH GRANT OPTION;
mysqladmin flush-hosts -h172.16.16.1 -P3306 -uroot -pdftcpass
mysql -uroot -h172.16.16.10 -P3307 -pdftcpass