MariaDB单机双实例主从复制

MariaDB其实和mysql一样,非有啥不一样那就是名字不一样~.~!

开始~上篇实验是MariaDB的单机多实例安装

双实例端口3307主库,3308从库

3307主实例的mysqld配置

[mysqld2]
port=3307
socket=/tmp/mysql3307.sock
pid-file=/tmp/mysql3307.pid
max_allowed_packet=1M
net_buffer_length=2k
table_open_cache=4
sort_buffer_size=64k
thread_stack=128k
basedir=/usr/local/mysql
datadir=/data/mydata2
server-id=244
log-bin = master3307-bin
log-bin-index = master3307-bin.index
thread_concurrency=4
innodb_file_per_table = 1
#mysql_pwd=‘teleframe‘

3308从实例的mysqld配置

[mysqld3]
port=3308
socket=/tmp/mysql3308.sock
pid-file=/tmp/mysql3308.pid
max_allowed_packet=1M
net_buffer_length=2k
table_open_cache=4
sort_buffer_size=64k
thread_stack=128k
basedir=/usr/local/mysql
datadir=/data/mydata3
innodb_file_per_table = 1
server-id=245
log-bin=mysql3308-bin
relay-log = relay-log
relay-log-index = relay-log-index
thread_concurrency=4
read-only = on

开始主从配置

步骤1、连接到主库上授权一个REPLICATION SLAVE 帐号,并且刷新授权表

[[email protected] mysql]# mysql -uroot -h127.0.0.1 -P3307 -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.0.15-MariaDB-log Source distribution

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

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

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| test1              |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [(none)]> grant replication slave on *.* to ‘repl‘@‘192.168.0.%‘ identified by ‘repl‘;
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 |
+-----------------------+----------+--------------+------------------+
| master3307-bin.000005 |      632 |              |                  |
+-----------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

MariaDB [(none)]>

2、连接到从库上指定主库,启动slave

[[email protected] ~]# mysql -uroot -p‘teleframe‘ -h127.0.0.1 -P3308
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.0.15-MariaDB-log Source distribution

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

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

MariaDB [(none)]> change master to master_host=‘192.168.0.244‘,master_user=‘repl‘,master_password=‘repl‘,master_port=3307,master_log_file=‘master3307-bin.000005‘,master_log_pos=632;
ERROR 1201 (HY000): Could not initialize master info structure for ‘‘; more error messages can be found in the MariaDB error log #我这报错了,如果你跟我一样报错就执行下面的命令
MariaDB [(none)]> reset slave;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> change master to master_host=‘192.168.0.244‘,master_user=‘repl‘,master_password=‘repl‘,master_port=3307,;
Query OK, 0 rows affected (0.22 sec) #好了现在连接上了      master_log_file=‘master3307-bin.000005‘,master_log_pos=632  表示从主服务器那个二进制日志文件开始复制因为这是复制授权信息,所以没必要复制,在主服务器上可以查看show master status; 查看内容show binglog events in ‘master-bin.000001‘;
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 192.168.0.244
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: master3307-bin.000005
          Read_Master_Log_Pos: 632
               Relay_Log_File: relay-log.000002
                Relay_Log_Pos: 4
        Relay_Master_Log_File: master3307-bin.000005
             Slave_IO_Running: No  #  从服务器有没有正常工作主要是看这个值是否YES
            Slave_SQL_Running: No  #
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 632
              Relay_Log_Space: 248
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 0
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
                   Using_Gtid: No
                  Gtid_IO_Pos: 
1 row in set (0.00 sec)
MariaDB [(none)]> start slave;  #好启动slave
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.0.244
                  Master_User: repl
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: master3307-bin.000005
          Read_Master_Log_Pos: 632
               Relay_Log_File: relay-log.000003
                Relay_Log_Pos: 540
        Relay_Master_Log_File: master3307-bin.000005
             Slave_IO_Running: Yes  #表示从服务器正常工作了
            Slave_SQL_Running: Yes  #
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 632
              Relay_Log_Space: 831
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 244
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
                   Using_Gtid: No
                  Gtid_IO_Pos:

来测试!

在主的上面创建一个库看从的是否可以复制到

主上创建

MariaDB [(none)]> create database kcwtest;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kcwtest            |
| mysql              |
| performance_schema |
| test               |
| test1              |
+--------------------+
6 rows in set (0.00 sec)

从上查看

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kcwtest            |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

可以复制!这样就实现单机实例复制,我做的3个实例,3306端口给默认的用,3307,3308端口做主从复制。

时间: 2024-08-04 02:49:47

MariaDB单机双实例主从复制的相关文章

mariadb单机多实例主从复制

准备工作: 停掉数据库服务: systemctl stop mariadb.service 将主库的数据库文件拷贝一份作为从库数据: cp -a -r /data/mysql_data/mysql/* /data/mysql_data/mysql2/ 拷贝完启动: systemctl start mariadb.service 步骤1:配置主库和从库多实例的cnf文件 主库和从库共用一个cnf文件, /etc/my.cnf [mysqld] log-bin=mysql-bin-log serve

ElasticSearch单机双实例的配置方法

ElasticSearch单机双实例的配置方法https://knktc.com/2016/06/10/elasticsearch-multiple-instances/Don't Cross 32 GB!https://www.elastic.co/guide/en/elasticsearch/guide/current/heap-sizing.html#compressed_oopsElasticSearch术语https://www.cnblogs.com/chenny7/p/431172

MariaDB单机多实例

我们在同一台服务器上运行3个mysql服务分别开启3306,3307,3308端口#################################################            安装mariadb                        ################################################略 #################################################            初始化环

突破单机多实例Elasticsearch

默认大家都是单机单实例es,在实验环境下想尽可能模拟各种场景.单机多实例就出来了... 实验拓扑图 01.es安装这里就不说了 详情:http://www.cnblogs.com/xiaochina/p/6852677.html 02.讲elasticsearch.yml配置 要做到单机上开多个实例,需要修改ES的默认配置: node.max_local_storage_nodes: 2   #单机开启2个实例 配置限制了单节点上可以开启的ES存储实例的个数 http.port: 9200 配置

Docker 快速验证 tomcat 单机多实例方案

概述 主要讲的是解决问题的思路.当然也附带了尽可能详细的步骤,感兴趣的童鞋可以一步一步跟着来实践一把.因为运维职业的缘故,基本上是把事故当故事来写了,希望能够喜欢. 缘起 至少10年了,没在一线玩过 Tomcat 了,这次客户现场就来了一场遭遇战.虽然客户说了他来搭建,但是项目进度不等人,还是自己动手吧.当然了,新服务器是要走流程申请的,只能在现有服务器想办法.犹记得当年解决 Tomcat 部署这些都是小菜,没想到在苛刻的商业环境中,处处是坑,步步有雷.不过,咱干过开发也干过运维,这点儿动手的事

MySQL(mariadb)多实例应用与多实例主从复制

MySQL多实例 mysql多实例,简单理解就是在一台服务器上,mysql服务开启多个不同的端口(如3306.3307,3308),运行多个服务进程.这些 mysql 服务进程通过不同的 socket来监听不同的数据端口,进而互不干涉的提供各自的服务. 在同一台服务器上,mysql 多实例会去共用一套 mysql 应用程序,因此在部署 mysql的时候只需要部署一次 mysql程序即可,无需多次部署.但是,mysql多实例之间会各自使用不同的 my.cnf 配置文件.启动程序和数据文件.在提供服

MySQL单机多实例安装并配置主从复制

单机多实例据说可以最大程度提高硬件使用,谁知道呢,但是以前的公司喜欢这样搞,我最近也在学习复制什么的,电脑搞不起两台虚拟机,刚好单机多实例可以解救我.下面就说说步骤. 承上文http://www.cnblogs.com/wingsless/p/4002806.html,我已经安装好了MySQL,不过这个是单实例的,要更改也可以,但是担心会出现问题,于是我将下面的东西删掉: 1 #rm -f /etc/init.dmysql 2 $rm -f /home/mysql/data 建立这么几个目录:

redis单机多实例_主从复制

上一篇讲到了redis单机单实例的安装http://my.oschina.net/xinxingegeya/blog/389155, 这一篇主要安装单机多实例,以及主从复制的配置.这就是一个redis的集群了. 单机多实例的配置 [[email protected] redis_7000]# pwd /opt/redis-2.8.19/redis_7000 [[email protected] redis_7000]# ./src/redis-cli -p 7000 127.0.0.1:7000

单机多实例MYSQL主从复制

今天有时间写写,不然心坎里总有点不爽.单机多实例一直都是屌丝的处事风格... 实验环境 RHEL6.5 172.24.0.130  3306 172.24.0.130  3307 01.本次采用的MYSQL二进制快速安装 下载地址: https://dev.mysql.com/downloads/mysql/ http://pan.baidu.com/s/1qYI0ybq http://pan.baidu.com/s/1pLHM2TH 密码: pg5t #截图操作 #根据需求选择对应的版本 02