(16) MySQL cluster galera implementation

(1) Environment introduction

galera官网:http://galeracluster.com/downloads/
# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 

(2) The following configurations are the same for all three servers

  • Turn off firewall and selinux

    systemctl disable firewalld 
    systemctl stop firewalld
    sed -ri '/SELINUX=/cSELINUX=disabled' /etc/selinux/config
    setenforce 0
  • Configure yum source

    cat >>/etc/yum.repos.d/galera.repo<<EOF
    [galera1]
    name=galera1
    baseurl=http://releases.galeracluster.com/mysql-wsrep-5.7/centos/7/x86_64/
    gpgcheck=0
    [galera2]
    name=galera2
    baseurl=http://releases.galeracluster.com/galera-3/centos/7/x86_64/
    gpgcheck=0
    EOF
  • Install mysql and galera plugins

    yum repolist
    yum list | egrep "wsrep|galera"
    yum -y install mysql-wsrep-server-5.7.x86_64 
    yum install galera-3.x86_64 -y
  • start mysqld

    systemctl start mysqld
    systemctl enable mysqld
    newpass=$(grep "temporary password" /var/log/mysqld.log | awk '{print $NF}')
    mysqladmin -uroot -p"$newpass" password 'Redhat@123'
  • Create a user for data synchronization

    mysql -uroot -pRedhat@123 -e "grant all on *.* to 'copy'@'192.168.1.%' identified by 'Copy@123'"
    mysql -uroot -pRedhat@123 -e "flush privileges;"

    (3) Modify the configuration file: the three are different

  • node1:192.168.1.31

    #vi /etc/my.cnf
    binlog_format=row
    default_storage_engine=InnoDB
    innodb_autoinc_lock_mode=2
    bind-address=0.0.0.0
    wsrep_on=ON
    wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
    wsrep_cluster_address="gcomm://"
    wsrep_cluster_name="Cluster"
    wsrep_node_address="192.168.1.31"
    wsrep_node_name="node1"
    wsrep_sst_auth=copy:Copy@123
    wsrep_sst_method=rsync
    重启mysqld服务器:systemctl restart mysqld
    验证端口状态:ss -anltup | egrep "3306|4567"

    View the status on the node1 node

  • node2:192.168.1.32

    #vi /etc/my.cnf
    binlog_format=row
    default_storage_engine=InnoDB
    innodb_autoinc_lock_mode=2
    bind-address=0.0.0.0
    wsrep_on=ON
    wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
    wsrep_cluster_address="gcomm://192.168.1.31"
    wsrep_cluster_name="test"
    wsrep_node_address="192.168.1.31,192.168.1.32,192.168.1.33"
    wsrep_node_name="node2"
    wsrep_sst_auth=copy:Copy@123
    wsrep_sst_method=rsync
    重启mysqld服务器:systemctl restart mysqld
    验证端口状态:ss -anltup | egrep "3306|4567"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325023271&siteId=291194637