Constructing separate read and write database cluster

Three virtual machines, set up two virtual machines from the master database, a client to do.

Referring to build the master database from step 1 to 3 and a fifth step.

Modify the host officiating: db1 from: db2 client is: mycat

The three virtual machines for domain name resolution:

vi /etc/hosts

192168150100 db1

192168150110 db2

192.168.150.120   mycat

Yum source node configuration to two (vi /etc/yum.repos.d/local.repo follows:

[Centos]

name=centos

baseurl = file: /// opt / CentOS

gpgcheck=0

enabled=1

[yum]

name=yum

baseurl = file: /// opt / gpmall-repo

gpgcheck=0

enabled=1

Clear cache: yum clean all

yum repolist

 db1,, db2 .. mariadb two service nodes and restart the service installation:

yum install mariadb-server –y

Systemctl restart mariadb

Installation mycat auxiliary packet node: yum install bash-completion -y

   Install java packages: yum install java

       Yum install java-1.8.0-openjdk  java-1.8.0-openjdk-devel.x86_64  -y

      Java -version

Modify db1 node configuration file: vi /etc/my.cnf

      [mysql]

server_id=100

log_bin=mysql-bin

binlog-ignore-db=keystone

Db2 modify node configuration file: vi /etc/my.cnf

      [mysql]

server_id=110

log_bin=mysql-bin

binlog-ignore-db=keystone

Restart the service: systemctl restart mariadb

 

 Two nodes are operating: mysql_secure_installation (up point y, the password is 000000) to install the database

Here it is: n means:

db1:  mysql  -uroot  -p000000

     Access to the database

create  user  ‘zhao’@’%’ identified  by  ‘000000’;

grant  replication  slave  on  *.*  to  ‘zhao’@’%’ ;

show master status

 

db2:  mysql  -uroot  -p000000

change master to master_host=’192.168.150.100’,master_user=’zhao’,master_password=’000000’,master_log_fire=’mysql-bin.000002’,master_log_pos=659; 

 

start slave;

 

search result

show slave status\G;

 

Mycat Node: Query java version: Java -version

Extract the package: tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -c / usr / local /

Cd /usr/local/

ls

Chown  777  /usr/local/mycat/

Ll

Chown  root  /usr/local/mycat/

Chomd  777 mycat/

Chomd  777  mycat/  -R

Ll

 

Cd conf /

ls

 

 

Modify the first configuration file: vi /schema.xml(/usr/local/mycat/conf/schema.xml)

     Name = 'testdb' to userdb

     Database = 'db $ 0-743' to test

     Writehost  host=’hostM1’ url=’loalhost:3306’  user=’root’改为Writehost  host=’hostM1’ url=’192.168..150.100:3306’  user=’root’

      Readhost the url =; 192.168.150.110: 3306 password = '123456'

(Schema.xml modify user permissions: chown root: root / usr / local / conf / schema.xml)

 

 

Second: vi server.xml

Delete the last four lines

Instead userdb

/bin/bash /usr/local/mycat/bin/mycat  start

Yum install net

Yum install net-tools.x86_64  -y

Netstat  -ntlp

There are two ports 8066 and 9066

 

Verify separate read and write

Installation maeiaDB-client services on a virtual machine mycat

   Yum intall –y MariaDB-client

Mysql –uroot –p000000

 Show database;

 Use USERDB;

  Show tables;

Select *from company;

(2) Use MYcat sql command on a virtual machine to add data (2, "basketall", "usa") table company, after completion of adding information table is added

   insert into company values(2,”bastetball”,”usa”);

select * from company;

  Verify mycat service operation to separate the database to read and write, using the MySQL command by separating the information on the 9066 port query database read and write operations

   Mysql –h (mycat ip) –P9066 –uroot –p123456 –e ‘show  @@datasource;’

 

 

Authorized on any client machine as the root user can log database

Grant all privileges  on *.* to root@’%’ identified by “123456”

Creating a user so that the user is connected from node db2 and give from node synchronization master node database permissions

   Grant replication slave  on *.* to ‘user’@’db2’identified  by ‘123456’

 

 

 

Published 18 original articles · won praise 0 · Views 455

Guess you like

Origin blog.csdn.net/weixin_45678149/article/details/104602359