MairaDB Galera Cluster安装文档

使用MariaDB Galera方案,可以方便的搭建出HA的数据库Cluster,不是主备模式,而是双活模式,也就是说,没有主节点和备份节点,每个节点都可以看做是主节点,都可以进行读写,由Galera来实现底层的数据同步。

安装完成后,可以通过HAProxy设置VIP的方式来实现负载均衡。

安装步骤如下:

0、关闭防火墙和selinux

[root@node1 ~]# setenforce 0

[root@node1 ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config

[root@node1 ~]# systemctl stop firewalld

[root@node1 ~]# systemctl disable firewalld

rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'

rm '/etc/systemd/system/basic.target.wants/firewalld.service'

可执行如下命令:

systemctl disable firewalld; systemctl stop firewalld; setenforce 0;  sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config

1、安装软件包

yum localinstall boost-program-options-1.53.0-25.el7.x86_64.rpm  galera-25.3.15-1.rhel7.el7.centos.x86_64.rpm MariaDB-Galera-5.5.49-centos7-x86_64-server.rpm MariaDB-5.5.49-centos7-x86_64-common.rpm MariaDB-5.5.49-centos7-x86_64-client.rpm  perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm perl-Data-Dumper-2.145-3.el7.x86_64.rpm perl-DBI-1.627-4.el7.x86_64.rpm  perl-IO-Compress-2.061-2.el7.noarch.rpm perl-Net-Daemon-0.48-5.el7.noarch.rpm perl-PlRPC-0.2020-14.el7.noarch.rpm MariaDB-5.5.49-centos7-x86_64-shared.rpm

2、修改配置文件

(1)node1

[root@node1 ~]# cat /etc/my.cnf

#

# This group is read both both by the client and the server

# use it for options that affect everything

#

[client-server]

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Ensure that the binary log format is set to use row-level replication, as opposed to statement-level replication.

binlog_format=ROW

bind-address=0.0.0.0

# Ensure that the default storage engine is InnoDB

default_storage_engine=innodb

innodb_autoinc_lock_mode=2

innodb_flush_log_at_trx_commit=0

innodb_buffer_pool_size=122M

wsrep_provider=/usr/lib64/galera/libgalera_smm.so

wsrep_provider_options="gcache.size=300M; gcache.page_size=1G"

wsrep_cluster_name="blkart_cluster"

wsrep_cluster_address="gcomm://10.100.203.216,10.100.203.134,10.100.203.232"

wsrep_node_name="node1"

wsrep_node_address="10.100.203.216"

wsrep_sst_method=rsync

#

# [mysql_safe]

log-error=/var/log/mysqld.log

#pid-file=/var/run/mysqld/mysqld.pid

(2)node2

[root@node2 ~]# cat /etc/my.cnf

#

# This group is read both both by the client and the server

# use it for options that affect everything

#

[client-server]

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Ensure that the binary log format is set to use row-level replication, as opposed to statement-level replication.

binlog_format=ROW

bind-address=0.0.0.0

# Ensure that the default storage engine is InnoDB

default_storage_engine=innodb

innodb_autoinc_lock_mode=2

innodb_flush_log_at_trx_commit=0

innodb_buffer_pool_size=122M

wsrep_provider=/usr/lib64/galera/libgalera_smm.so

wsrep_provider_options="gcache.size=300M; gcache.page_size=1G"

wsrep_cluster_name="blkart_cluster"

wsrep_cluster_address="gcomm://10.100.203.216,10.100.203.134,10.100.203.232"

wsrep_node_name="node2"

wsrep_node_address="10.100.203.134"

wsrep_sst_method=rsync

#

# [mysql_safe]

log-error=/var/log/mysqld.log

#pid-file=/var/run/mysqld/mysqld.pid

(3)node3

[root@node3 ~]# cat /etc/my.cnf

#

# This group is read both both by the client and the server

# use it for options that affect everything

#

[client-server]

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Ensure that the binary log format is set to use row-level replication, as opposed to statement-level replication.

binlog_format=ROW

bind-address=0.0.0.0

# Ensure that the default storage engine is InnoDB

default_storage_engine=innodb

innodb_autoinc_lock_mode=2

innodb_flush_log_at_trx_commit=0

innodb_buffer_pool_size=122M

wsrep_provider=/usr/lib64/galera/libgalera_smm.so

wsrep_provider_options="gcache.size=300M; gcache.page_size=1G"

wsrep_cluster_name="blkart_cluster"

wsrep_cluster_address="gcomm://10.100.203.216,10.100.203.134,10.100.203.232"

wsrep_node_name="node3"

wsrep_node_address="10.100.203.232"

wsrep_sst_method=rsync

#

# [mysql_safe]

log-error=/var/log/mysqld.log

#pid-file=/var/run/mysqld/mysqld.pid

3、启动服务

(1)初始化数据库(node1)

[root@node1 ~]# mysql_install_db

Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...

160511 23:06:01 [Note] /usr/sbin/mysqld (mysqld 5.5.49-MariaDB-wsrep) starting as process 91118 ...

OK

Filling help tables...

160511 23:06:02 [Note] /usr/sbin/mysqld (mysqld 5.5.49-MariaDB-wsrep) starting as process 91126 ...

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !

To do so, start the server, then issue the following commands:

'/usr/bin/mysqladmin' -u root password 'new-password'

'/usr/bin/mysqladmin' -u root -h node1 password 'new-password'

Alternatively you can run:

'/usr/bin/mysql_secure_installation'

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the

MySQL manual for more instructions.

You can start the MariaDB daemon with:

cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl

cd '/usr/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.

You can find additional information about the MySQL part at:

http://dev.mysql.com

Support MariaDB development by buying support/new features from MariaDB

Corporation Ab. You can contact us about this at [email protected].

Alternatively consider joining our community based development effort:

http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

(2)启动第一个节点

[root@node1 ~]# /etc/init.d/mysql start --wsrep-new-cluster

Starting MySQL.... SUCCESS!

(3)初始化数据库(node2)

[root@node2 ~]# mysql_install_db

Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...

160511 23:15:19 [Note] /usr/sbin/mysqld (mysqld 5.5.49-MariaDB-wsrep) starting as process 6931 ...

OK

Filling help tables...

160511 23:15:20 [Note] /usr/sbin/mysqld (mysqld 5.5.49-MariaDB-wsrep) starting as process 6939 ...

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !

To do so, start the server, then issue the following commands:

'/usr/bin/mysqladmin' -u root password 'new-password'

'/usr/bin/mysqladmin' -u root -h node2 password 'new-password'

Alternatively you can run:

'/usr/bin/mysql_secure_installation'

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the

MySQL manual for more instructions.

You can start the MariaDB daemon with:

cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl

cd '/usr/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.

You can find additional information about the MySQL part at:

http://dev.mysql.com

Support MariaDB development by buying support/new features from MariaDB

Corporation Ab. You can contact us about this at [email protected].

Alternatively consider joining our community based development effort:

http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

(4)启动第二个节点

[root@node2 ~]# service mysql start

Starting MySQL....SST in progress, setting sleep higher. SUCCESS!

(5)初始化数据库(node3)

[root@node3 ~]# mysql_install_db

Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...

160511 23:56:53 [Note] /usr/sbin/mysqld (mysqld 5.5.49-MariaDB-wsrep) starting as process 5772 ...

OK

Filling help tables...

160511 23:56:54 [Note] /usr/sbin/mysqld (mysqld 5.5.49-MariaDB-wsrep) starting as process 5781 ...

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !

To do so, start the server, then issue the following commands:

'/usr/bin/mysqladmin' -u root password 'new-password'

'/usr/bin/mysqladmin' -u root -h node3 password 'new-password'

Alternatively you can run:

'/usr/bin/mysql_secure_installation'

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the

MySQL manual for more instructions.

You can start the MariaDB daemon with:

cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl

cd '/usr/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.

You can find additional information about the MySQL part at:

http://dev.mysql.com

Support MariaDB development by buying support/new features from MariaDB

Corporation Ab. You can contact us about this at [email protected].

Alternatively consider joining our community based development effort:

http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

(6)启动第三个节点

[root@node3 ~]# service mysql start

Starting MySQL....SST in progress, setting sleep higher. SUCCESS!

(7)在各节点验证

[root@node3 ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 4

Server version: 5.5.49-MariaDB-wsrep MariaDB Server, wsrep_25.14.r9949137

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_size';

+--------------------+-------+

| Variable_name      | Value |

+--------------------+-------+

| wsrep_cluster_size | 3    |

+--------------------+-------+

1 row in set (0.00 sec)

MariaDB [(none)]>

4、验证数据库

(1)在node3创建数据库

[root@node3 ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 4

Server version: 5.5.49-MariaDB-wsrep MariaDB Server, wsrep_25.14.r9949137

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_size';

+--------------------+-------+

| Variable_name      | Value |

+--------------------+-------+

| wsrep_cluster_size | 3    |

+--------------------+-------+

1 row in set (0.00 sec)

MariaDB [(none)]> CREATE DATABASE galeratest;

Query OK, 1 row affected (0.02 sec)

MariaDB [(none)]>

MariaDB [(none)]> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| galeratest        |

| mysql              |

| performance_schema |

| test              |

+--------------------+

5 rows in set (0.00 sec)

(2)在node1和node2验证

[root@node1 ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 4

Server version: 5.5.49-MariaDB-wsrep MariaDB Server, wsrep_25.14.r9949137

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| galeratest        |

| mysql              |

| performance_schema |

| test              |

+--------------------+

5 rows in set (0.00 sec)

[root@node2 ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 5

Server version: 5.5.49-MariaDB-wsrep MariaDB Server, wsrep_25.14.r9949137

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| galeratest        |

| mysql              |

| performance_schema |

| test              |

+--------------------+

5 rows in set (0.00 sec)

MariaDB [(none)]>

你可能感兴趣的:(MairaDB Galera Cluster安装文档)