How to install and configure the MARIADB galera CentOS-7 cluster

Source: Internet
Author: User
Tags node server rsync haproxy

192.168.3.130 Clustera GALERA-DB01
192.168.3.131 Clusterb GALERA-DB02
192.168.3.129 Clusterc galera-db03

The following 1-3 steps are required to perform the three
1: Uninstall MySQL (because MySQL and mariadb are incompatible with MySQL)
Yum Erase mysql-server MySQL mysql-devel mysql-libs-y
Rm-rf/var/lib/mysql

2: Create mariadb Galera Repository, MARIADB official yum Source configuration:
Vim/etc/yum.repos.d/mariadb.repo
Vim does not install Yum install-y vim*

[MARIADB]
Name = MariaDB
BaseURL = Http://yum.mariadb.org/10.0/centos7-amd64
Gpgkey=https://yum.mariadb.org/rpm-gpg-key-mariadb
Gpgcheck=1

3:setenforce 0 Shutdown selinux
Install firewall and launch settings allow port
Yum install firewalld firewall-config
Systemctl start Firewalld
Firewall-cmd--add-rich-rule ' rule family=ipv4 source address=192.168.3.129 port port=3306 protocol=tcp Accept '-- Permanent
Firewall-cmd--add-rich-rule ' rule family=ipv4 source address=192.168.3.130 Port port=3306 protocol=tcp Accept '--permanent
firewall-cmd--add-rich-rule ' rule family=ipv4 source address=192.168.3.131 Port port=3306 Protocol=tcp Accept '--permanent
firewall-cmd--add-rich-rule ' rule family=ipv4 source address=192.168.3.129 port port=4567 protocol=tcp Accept '--permanent
firewall-cmd--add-rich-rule ' rule Family=ipv4 source address= 192.168.3.130 Port port=4567 protocol=tcp Accept '--permanent
firewall-cmd--add-rich-rule ' rule Family=ipv4 source address=192.168.3.131 Port port=4567 protocol=tcp Accept '--permanent

The following 4-6 steps operate on the cluster MARIADB node server
4: Install MARIADB Galera Server and client, rsync and xinetd
Yum install mariadb-galera-server mariadb-client rsync galera-y

If MySQL is present in the system, the following error will occur

If you want to customize the file directory for MARIADB, do the following (in the case of customizing the/data/directory)
Rm-rf/var/lib/mysql
Mkdir-p/data/{mariadb,tmp,logs} && chown-r mysql:mysql/data/{mariadb,tmp,logs} building directory and Permissions
Ln-s/data/mariadb/var/lib/mysql
Edit the/etc/my.cnf file and set optimization parameters, you can configure MARIADB cluster with reference to CENTOS6
mysql_install_db--DEFAULTS-FILE=/ETC/MY.CNF--user=mysql--datadir=/data/mariadb Initialization

5: Start mariadb and add boot and hardening
Service MySQL start start mariadb
Chkconfig--add MySQL && chkconfig MySQL on
/usr/bin/mysql_secure_installation Reinforcing mariadb Safety:

[Email protected] ~]#/usr/bin/mysql_secure_installation

Note:running all PARTS of this SCRIPT are 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 would be blank,
So, should just press ENTER here.

Enter current password to 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] n here to set the root password, formal environment settings Select Y
... skipping.

By default, a MariaDB installation have an anonymous user, allowing anyone
To log into MariaDB without has to has a user account created for
them. This was intended only for testing, and 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 is allowed to connect from ' localhost '. This
Ensures that someone cannot guess at the root of password from the network.

Disallow Root login remotely? [y/n] n
... skipping.

By default, MariaDB comes with a database named ' test ' that anyone can
Access. This was 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 would ensure that all changes made so far
would 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 is secure.

Thanks for using mariadb!

The first is to set the password, you will be prompted to enter the password
Enter current password to root (enter for none): <– First run direct carriage return
Set Password
Set root Password? [y/n] <– whether to set the root user password, enter Y and return or direct enter
New Password: <– Set the root user's password
Re-enter new password: <– Enter the password you set again
Other configurations
Remove anonymous users? [y/n] <– whether to delete anonymous users, enter
Disallow Root login remotely? [y/n] <– whether root login is forbidden, enter,
Remove test database and access to it? [y/n] <– whether to delete test database, enter
Reload privilege tables now? [y/n] <– whether to reload the permissions table, enter

6: Create user and authorize
Mysql-uroot Login database, formally set password using mysql-uroot-p password
Create a user and authorize the general use of the first command, the second command three parameters is authorized to create the user has the right to create his own, the experiment when the third command to execute

GRANT all privileges on . To ' cluster-user ' @ '% ' identified by ' Clusterpass ' with GRANT OPTION;
GRANT all privileges on . To ' cluster-user ' @ ' localhost ' identified by ' Clusterpass ' with GRANT OPTION;
GRANT all privileges on . To ' cluster-user ' @ ' 192.168.3.130 ' identified by ' Clusterpass ' with GRANT OPTION;
GRANT all privileges on . To ' cluster-user ' @ ' 192.168.3.131 ' identified by ' Clusterpass ' with GRANT OPTION;
GRANT all privileges on . To ' cluster-user ' @ ' 192.168.3.129 ' identified by ' Clusterpass ' with GRANT OPTION;

Flush privileges;
Exit
Service MySQL Stop

7: Node configuration configured on MARIADB1
Add under Vim/etc/my.cnf.d/server.cnf [mariadb-10.0]

Query_cache_size=0
Binlog_format=row
Default_storage_engine=innodb
innodb_autoinc_lock_mode=2
Wsrep_provider=/usr/lib64/galera/libgalera_smm.so
Wsrep_cluster_address= "gcomm://192.168.3.130,192.168.3.131,192.168.3.129"
Wsrep_cluster_name= "Cluster1"
Wsrep_node_address= "192.168.3.130"
Wsrep_node_name= "GALERA-DB01"
Wsrep_sst_method=rsync
Wsrep_sst_auth=cluster-user:clusterpass

Query_cache_size query cache, 0 off
Binlog_format=row Copy Mode
Wsrep_cluster_address IP for all nodes
Wsrep_cluster_name Cluster Name
Wsrep_node_address current server IP, which is the IP of each node itself
Wsrep_node_name the current server name, which is the name of each node itself
Wsrep_provider=/usr/lib64/galera/libgalera_smm.so
32 bit is/usr/lib/galera/libgalera_smm.so
64 bit is/usr/lib64/galera/libgalera_smm.so
Do not fill in the correct startup after the cluster is always found

8: On the server MARIADB1, we use the following command to boot the cluster:
/etc/init.d/mysql Bootstrap

Mysql-u root-e "Show status Like ' wsrep% '" view state

8: Node configuration configured on MARIADB2
Add under Vim/etc/my.cnf.d/server.cnf [mariadb-10.0]

Query_cache_size=0
Binlog_format=row
Default_storage_engine=innodb
innodb_autoinc_lock_mode=2
Wsrep_provider=/usr/lib64/galera/libgalera_smm.so
Wsrep_cluster_address= "gcomm://192.168.3.130,192.168.3.131,192.168.3.129"
Wsrep_cluster_name= "Cluster1"
Wsrep_node_address= "192.168.3.131"
Wsrep_node_name= "GALERA-DB02"
Wsrep_sst_method=rsync
Wsrep_sst_auth=cluster-user:clusterpass

/etc/init.d/mysql start

Mysql-u root-e "Show status Like ' wsrep% '" view state

9: Node configuration configured on MARIADB3
Add under Vim/etc/my.cnf.d/server.cnf [mariadb-10.0]

Query_cache_size=0
Binlog_format=row
Default_storage_engine=innodb
innodb_autoinc_lock_mode=2
Wsrep_provider=/usr/lib64/galera/libgalera_smm.so
Wsrep_cluster_address= "gcomm://192.168.3.130,192.168.3.131,192.168.3.129"
Wsrep_cluster_name= "Cluster1"
Wsrep_node_address= "192.168.3.131"
Wsrep_node_name= "GALERA-DB03"
Wsrep_sst_method=rsync
Wsrep_sst_auth=cluster-user:clusterpass

/etc/init.d/mysql start

Mysql-u root-e "Show status Like ' wsrep% '" view state

Verifying the Cluster
1. Any one, create DATABASES clustertest Creating library
In the other two, you can view and create the Clustertest library.
2. Delete the Clustertest library in any one, and the other two can also view the deleted
3.dump drop MariaDB1 Nic Ifdown nic name, try to create test table, write data in table, CREATE TABLE test ( id int (4), name char (40)), and then start the MariaDB1 NIC, ifup The NIC name, and then to MAriaDB1 view the data that was written select * from Test;

10. Using the HAPORXY agent, operate on the proxy server (the following command is used in the cluster with only two units as quorum)
Yum Erase mysql-server MySQL mysql-devel mysql-libs-y
Rm-rf/var/lib/mysql
Yum Install-y Galera
Which GARBD
Garbd-a gcomm://192.168.1.130:4567-g cluster1-l/tmp/1.out-d
MariaDB1 above execution
Mysql-u root-e "Show status Like ' wsrep% '" view state again
Wsrep_cluster_sixe value has changed

11. Installation Configuration Haproxy
Yum Install-y haproxy

/etc/haproxy/haproxy.cfg
Vim!$
Global
Log 127.0.0.1 Local2
Chroot/var/lib/haproxy
Pidfile/var/run/haproxy.pid
Maxconn 4000
User Haproxy
Group Haproxy
Daemon
Stats Socket/var/lib/haproxy/stats
Defaults
Mode TCP
#mode http
Option Httplog
Log Global
Option Dontlognull
Option Redispatch
Option Tcpka
Retries 3
Timeout Queue 1m
Timeout Connect 10s
Timeout Client 1m
Timeout Server 1m
Timeout Check 10s
Timeout Http-keep-alive 10s
Maxconn 10000

Frontend main *:3306
Bind 192.168.3.135:3306
Default_backend app

backend app         balance roundrobin         server app1 192.168.3.130:3306  maxconn 151 check         server  app2 192.168.3.131:3306  maxconn 151 check         server  app3  192.168.3.129:3306  maxconn 151 check

Haproxy join boot and start up
Chkconfig Haproxy on
Service Haproxy Start

Authentication Agent
Mysql-u cluster-use-p clusterpass-h 192.168.3.135-p 3306-e "SELECT @ @hostname;"

If necessary, you can configure the MARIADB character set
Vi/etc/my.cnf
Add under the [Mysqld] tab
init_connect= ' SET collation_connection = Utf8_unicode_ci '
init_connect= ' SET NAMES UTF8 '
Character-set-server=utf8
Collation-server=utf8_unicode_ci
Skip-character-set-client-handshake
Vi/etc/my.cnf.d/client.cnf
Add in [client]
Default-character-set=utf8

Vi/etc/my.cnf.d/mysql-clients.cnf
Add in [MySQL]
Default-character-set=utf8
Complete configuration, restart MARIADB
Systemctl Restart MARIADB
Then enter MARIADB to view the character set
Mysql> Show variables like "%character%", show variables like "%collation%";

How to install and configure the MARIADB galera CentOS-7 cluster

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.