码迷,mamicode.com
首页 > 数据库 > 详细

MySQL基于 amoeba.xml的读写分离

时间:2019-12-21 14:03:12      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:type   restart   fir   color   pass   span   ted   firewalld   NPU   

1、准备两台服务器  centos7

192.168.52.35

192.168.52.36

2、关闭防火墙

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

3、两台都下载mysql

yum -y install mariadb mariadb-server

4、编辑MySQL配置文件

第一台:

[root@localhost ~]# vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

server-id=1     #添加
log-bin=mysql-bin    #添加
relay-log=mysql-relay   #添加

第二台:

[root@localhost ~]# vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

server-id=2   #添加
log-bin=mysql-bin   #添加
relay-log=mysql-relay    #添加

5、开启mysql服务

systemctl restart mariadb

6、进入第一台主的服务器

[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server

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

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

MariaDB [(none)]> create user tom;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all on *.* totom@192.168.52.36 identified by 123;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 |      529 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> 

打开第二台的mysql

[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.64-MariaDB MariaDB Server

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

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

MariaDB [(none)]> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)

MariaDB [(none)]> change master to
    -> master_host=192.168.52.35,
    -> master_password=123,
    -> master_user=tom,
    -> master_log_file=mysql-bin.000003,
    -> master_log_pos=529;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)

技术图片

Slave_IO_Running: Yes    #这俩个要变成yes才算成功
Slave_SQL_Running: Yes

MySQL基于 amoeba.xml的读写分离

标签:type   restart   fir   color   pass   span   ted   firewalld   NPU   

原文地址:https://www.cnblogs.com/Zrecret/p/12076466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!