Step 1: Add MariaDB Repositories
Create a mariadb repository /etc/yum.repos.d/mariadb.repo using following content in your system.
For CentOS 6 – 64bit:
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.0/centos6-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
For CentOS 6 – 32bit:
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.0/centos6-x86 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
Step 2 – Set SELinux in permissive mode
Before starting the setup put SELinux into permissive mode on all nodes:
sudo setenforce0
Step 3 – Install MariaDB Galera Cluster 10.0 software
If you did a CentOS 6 minimal installation then make sure you install the socat package from the EPEL repository before proceeding with installing the MariaDB Galera Cluster 10.0 software.
You can install socat package directly from EPEL with the following command (for x86_64):
sudo yum install http://dl.fedoraproject.org/pub/epel/6/x86_64/socat-1.7.2.3-1.el6.x86_64.rpm
On CentOS 7 you can install socat package with following command.
sudo yum install socat
Install the MariaDB Galera Cluster 10.0 software by executing the following command on all nodes:
sudo yum install MariaDB-Galera-server MariaDB-client rsync galera
Step 4: Setup MariaDB security
Start the mysql ( init script in MariaDB 10.0 is still called mysql)
sudo service mysql start
Run the mysql_secure_installation script so we can improve the security. Run the following command on all nodes:
sudo /usr/bin/mysql_secure_installation
I choose password as ‘dbpass’ and accepted all defaults (so answered yes to all questions).
Step 5 – Create MariaDB Galera Cluster users
Now, we have to create some users that must be able to access the database. The ‘sst_user’
is the user which a database node will use for authenticating to
another database node in the State Transfer Snapshot (SST) phase.
Run the following command on all nodes:
mysql -u root -p
mysql> DELETE FROM mysql.user WHERE user=''; mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'dbpass'; mysql> GRANT USAGE ON *.* to sst_user@'%' IDENTIFIED BY 'dbpass'; mysql> GRANT ALL PRIVILEGES on *.* to sst_user@'%'; mysql> FLUSH PRIVILEGES; mysql> quit
You are suggested to change ‘%’ to hostname(s) or IP addresses from which those users can access the database. Because ‘%’ means that the root or sst_user is allowed to access the database from any host, So less security.
Step 6 – Create the MariaDB Galera Cluster config
First stop the mysql services on all nodes:
sudo service mysql stop
Next, We are going to create the MariaDB
Galera Cluster configuration by the following command on all nodes (go
through the IMPORTANT NOTE after the config and make required changes
for db2):
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
binlog_format=ROW
bind-address=0.0.0.0
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=122M
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
innodb_log_file_size=100M
innodb_file_per_table
innodb_flush_log_at_trx_commit=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://IP_kilo_01,IP_kilo_02"
wsrep_cluster_name='galera_cluster'
wsrep_node_address='IP_kilo_01'
wsrep_node_name='db1'
wsrep_sst_method=rsync
wsrep_sst_auth=sst_user:dbpass
[mysql_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
binlog_format=ROW
bind-address=0.0.0.0
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=122M
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
innodb_log_file_size=100M
innodb_file_per_table
innodb_flush_log_at_trx_commit=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://IP_kilo_01,IP_kilo_02"
wsrep_cluster_name='galera_cluster'
wsrep_node_address='IP_kilo_01'
wsrep_node_name='db1'
wsrep_sst_method=rsync
wsrep_sst_auth=sst_user:dbpass
[mysql_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
Step 7– Initialize the first cluster node
Start MariaDB with the special ‘‐‐wsrep-new-cluster’ option , Do it on node db1 only so the primary node of the cluster is initialized:
sudo /etc/init.d/mysql start --wsrep-new-cluster
Check status by run the following command on node db1 only:
mysql-uroot-p-e"show status like 'wsrep%'"
Some important information in the output are the following lines:
wsrep_local_state_comment | Synced <-- cluster is synced wsrep_incoming_addresses | IP_kilo_01:3306 <-- node db1 is a provider wsrep_cluster_size | 1 <-- cluster consists of 1 node wsrep_ready | ON <-- good :)
mysql -u root -p -e "show status like 'wsrep%'"
Không có nhận xét nào:
Đăng nhận xét