MySQL Cluster setup-multi-Master mode

Source: Internet
Author: User
Tags mysql cluster setup pack

MySQL Cluster setup-multi-Master mode

This article uses the Galera build MySQL cluster, realizes each MySQL is the main server, does not have the master-slave division.


Environment:

Three mysql5.7 servers.

To install the MySQL cluster:

Preparation before installation:

# echo ' 192.168.1.2 mysql1 ' >>/etc/hosts

# echo ' 192.168.1.4 mysql2 ' >>/etc/hosts

# echo ' 192.168.1.7 mysql3 ' >>/etc/hosts

# echo ' net.ipv4.tcp_tw_recycle = 1 ' >>/etc/sysctl.conf

# echo ' net.ipv4.tcp_tw_recycle = 1 ' >>/etc/sysctl.conf

# sysctl-p

General installation mysql5.7 Steps (This method cannot be used by the cluster):

First download a mysql5.7 bundle from the official website and unzip it.

# TAR-XVF Mysql-5.7.22-1.el6.x86_64.rpm-bundle.tar

# yum-y Install mysql-community-common-5.7.22-1.el6.x86_64.rpm

# yum-y Install mysql-community-libs-5.7.22-1.el6.x86_64.rpm

# yum-y Install mysql-community-client-5.7.22-1.el6.x86_64.rpm

# yum-y Install mysql-community-server-5.7.22-1.el6.x86_64.rpm

Start the service:

# service Mysqld Start

The Mysql5.7 version automatically generates a temporary password for ' [email protected] ', which exists in the MySQL error log file (/var/log/mysqld.log). Remove Password:

# grep ' Temporary password '/var/log/mysqld.log

2018-05-02t14:08:24.018468z 1 [Note] A temporary password is generated for [email protected]: gqs*tpo-8i) K

Reference official website: https://dev.mysql.com/doc/refman/8.0/en/linux-installation-rpm.html

Log in and change your password:

# mysql-uroot-p

Mysql > ALTER USER ' root ' @ ' localhost ' identified by ' 123456 ';


MySQL cluster installation:

Download the MySQL patch pack (http://releases.galeracluster.com/mysql-wsrep-5.7.21-25.14/centos/6/x86_64/).

Download Galera installation Package

(http://releases.galeracluster.com/galera-3/centos/6/x86_64/)

Check to see if there is a MySQL presence, if there is an uninstall.

# rpm-qa|grep MySQL

# yum Remove mysql-libs*

To install the MySQL patch pack:

# yum Install mysql-wsrep-common-5.7-5.7.21-25.14.el6.x86_64.rpm

# yum Install mysql-wsrep-devel-5.7-5.7.21-25.14.el6.x86_64.rpm

# yum Install mysql-wsrep-libs-compat-5.7-5.7.21-25.14.el6.x86_64.rpm

# yum Install mysql-wsrep-libs-5.7-5.7.21-25.14.el6.x86_64.rpm

# yum Install mysql-wsrep-client-5.7-5.7.21-25.14.el6.x86_64.rpm

# yum Install mysql-wsrep-server-5.7-5.7.21-25.14.el6.x86_64.rpm

# yum Install galera-3-25.3.23-2.el6.x86_64.rpm

Start MySQL

# service Mysqld Start

# ps-ef|grep MySQL

To query the initial password for MySQL:

# cat/var/log/mysqld.log|grep ' Temporary password '

Change Password:

# mysql-uroot-p

Mysql> ALTER USER ' root ' @ ' localhost ' identified by ' 1qaz! QAZ ';

Mysql>grant all privileges on * * to [e-mail protected] '% ' identified by ' 123456 '; #创建新用户

mysql> FLUSH privileges;

# Service Mysqld Stop

Configure/ETC/MY.CNF

[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

Wsrep_cluster_name=mycluster #你的cluster名, the same on every machine

Wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so #不同版本这个路径可能不同, it is necessary to determine the installation Galera to generate this lib File

wsrep_cluster_address= "gcomm://" #第一台机器需要这样配置

#wsrep_cluster_address = "gcomm://192.168.1.2,192.168.1.4,192.168.1.7" #其他 the cluster machine needs to configure the synchronization source path

Wsrep_node_name=node1 #当前机器的节点名

wsrep_node_address=192.168.1.12 #当前机器ip

Wsrep_sst_method=rsync #同步方式

Wsrep_sst_auth=myroot:[email protected]

[Mysql_safe]

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

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

Start the first machine:

# service Mysqld Start--wsrep-new-cluster

Where the--wsrep-new-cluster as long as the initialization of the cluster can be used, after the service restart is not used, this time can see the cluster status:

# mysql-uroot-p

Mysql> "Show status Like ' wsrep_% '"

| wsrep_incoming_addresses | 192.168.1.2:3306 |

| Wsrep_cluster_size | 3 |

To start another node:

# service Mysqld Start

Review the cluster information again:

# Mysql-uroot-p-E "show status Like ' wsrep_% '"

So the whole cluster is good, testing on any node to build a library, on other nodes to view, can be synchronized to other nodes.

Reference links (http://galeracluster.com/documentation-webpages/startingcluster.html)


MySQL Cluster setup-multi-Master mode

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.