欢迎投稿

今日深度:

mariadb数据库主从复制,mariadb数据库主从

mariadb数据库主从复制,mariadb数据库主从


准备环境两台centos7.2,安装MariaDB做主从复制,一台9.110.187.131 一台9.110.187.132

1)主从两台服务器的准备环境都一样
一、时间同步
yum -y install wget net-tools ntp ntpdate lrzsz
systemctl restart ntpdate.service ntpd.service
systemctl enable ntpd.service ntpdate.service

二、关闭防火墙和selinux
systemctl disable firewalld.service
systemctl stop firewalld.service
sed -i "s/SELINUX=enforcing/SELINUX=disabled/"   /etc/selinux/config
reboot  重启服务器

三、配置本地mariadb YUM源,我这是使用我测试openstack的源(百度云:https://pan.baidu.com/s/1cfPwMa)
vi /etc/yum.repos.d/openstack-newton.repo
[openstack-newton]
name=openstack-newton
baseurl=http://9.110.187.125/openstack-newton/
gpgcheck=0
enabled=1
[ha-pcs]
name=ha-pcs
baseurl=http://9.110.187.125/pcs/
gpgcheck=0
enabled=1
[ha-clustering]
name=ha-clustering
baseurl=http://9.110.187.125/ha-clustering/CentOS_CentOS-7/
gpgcheck=0
enabled=1
[epel]
name=epel
baseurl=http://9.110.187.125/epel/7/x86_64/
gpgcheck=0
enabled=1
[mariadb]
name=mariadb10.1
baseurl=http://9.110.187.125/mariadb10.1/
gpgcheck=0
enabled=1
[CentOS7.2]
name=CentOS7.2
baseurl=http://9.110.187.125/centos7.2/os/x86_64/
gpgcheck=0
enabled=1

四、安装mariadb
yum clean all
yum makecache
yum -y install MariaDB-server MariaDB-client galera xinetd rsync ntp ntpdate bash-completion percona-xtrabackup socat gcc gcc-c++
systemctl restart mariadb.service
mysql_secure_installation



2)
配置主服务器:
一、配置主服务器的配置文件:
[root@localhost ~]# cat /etc/my.cnf.d/server.cnf | grep -v '^$' | grep -v '^#'
[mysqld]   //mysqld下面添加如下内容
datadir=/var/lib/mysql
innodb-data-home-dir = /var/lib/mysql
log-bin=master-bin
server-id=1     
socket = /var/lib/mysql/mysql.sock

二、授权用户给从服务器进行连接:
[root@localhost ~]# mysql -uroot -pdevops
MariaDB [(none)]> grant all privileges on *.* to 'grafana'@'%' identified by 'grafana';
MariaDB [(none)]> flush privileges;

重启服务配查看mysql主的信息:
systemctl restart mariadb.service

[root@localhost ~]# mysql -uroot -pdevops
MariaDB [(none)]> show master status;
+-------------------+----------+--------------+------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000002 |      729 |              |                  |
+-------------------+----------+--------------+------------------+


3)
配置从服务器:
[root@localhost ~]# cat /etc/my.cnf.d/server.cnf | grep -v '^$' | grep -v '^#'
[mysqld]    //mysqld下面添加如下内容
log-bin=master-bin
server-id=2



二、使用从数据库命令行方式配置:
[root@localhost ~]# mysql -uroot -pdevops
MariaDB [(none)]> change master to master_host='9.110.187.131',master_user='grafana',master_password='grafana',master_log_file='master-bin.000001',master_log_pos=314;
请注意以下几点:
 1)master_host是指主服务器的IP
 2)master_user是指使用哪个用户登录主服务器
 3)master_password是指登录密码
 4)master_log_file是指在第4个步骤中的File名称
 5)master_log_pos是指在第4个步骤中的Position

三、启用从数据库复制功能(这个步骤是在从数据库的MySQL中配置)在命令行中录入
MariaDB [(none)]> start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)



四、查看是否连接成功:
MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 9.110.187.131   #主数据库地址
                  Master_User: grafana     #使用哪个用户登录
                  Master_Port: 3306     #连接端口
                Connect_Retry: 60
              Master_Log_File: master-bin.000002
          Read_Master_Log_Pos: 729                  #同步读取二进制日志的位置,必须大于或等于下面的
               Relay_Log_File: localhost-relay-bin.000006
                Relay_Log_Pos: 953
        Relay_Master_Log_File: master-bin.000002
             Slave_IO_Running: Yes      #必须为Yes,否则需要查找原因
            Slave_SQL_Running: Yes      #必须为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: 729
              Relay_Log_Space: 1255
              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: 1
               Master_SSL_Crl:
           Master_SSL_Crlpath:
                   Using_Gtid: No
                  Gtid_IO_Pos:
      Replicate_Do_Domain_Ids:
  Replicate_Ignore_Domain_Ids:
                Parallel_Mode: conservative
1 row in set (0.00 sec)

www.htsjk.Com true http://www.htsjk.com/mariadb/37191.html NewsArticle mariadb数据库主从复制,mariadb数据库主从 准备环境两台centos7.2,安装MariaDB做主从复制,一台9.110.187.131 一台9.110.187.132 1)主从两台服务器的准备环境都一样 一、时间同步 yum -y install wge...
相关文章
    暂无相关文章
评论暂时关闭