centos7 maiadb主从复制搭建

  

需求:

由于要使用saltstack,部署环境,先手动搭建了下主从环境,发现原来的词资料都找不到了,所以这次赶紧的记录到博客当中! !

环境:

两台设备,ip地址分别为:

node1:192.168.56.11 node2:192.168.56.12

系统:Centos7

软件包:使用系统自带的百胜来安装的mariadb

==========================================================================================

安装:

分别在两台设备上安装数据库mariadb,使用yum来安装的,可以更换成过内的百胜源来操作

命令:yum安装- y mariadb mariadb-server

配置:

先配置node1上的主配置

[root@salt-node1  ~] #,。vim /etc/my . cnf中所做      (mysqld)   innodb_file_per_table=没有   log-bin=/var/lib/mysql/master-bin  #这里如果不指定路径默认是在datadir下面生成   binlog_format=混合   时间=server-id  11 #这个主节点一定要是唯一的   datadir=/var/lib/mysql   套接字=/var/lib/mysql/mysql.sock   #,Disabling  symbolic-links  is  recommended 用prevent  assorted  security 风险   符号链接=0   #,Settings  user 以及group 断开连接;ignored  when  systemd  is 使用。   #,If 你;need 用run  mysqld  under  a  different  user 或是团体,   #,customize  your  systemd  unit  file  for  mariadb  according 用   #,instructions 拷贝;http://fedoraproject.org/wiki/Systemd      (mysqld_safe)   日志错误=/var/log/mariadb/mariadb.log   pid文件=/var/运行/mariadb/mariadb.pid      #   #,include  all  files 得到,config 目录   #   ! includedir /etc/my.cnf.d

重启node1上的mysql服务

systemctl  restart  mariadb。服务

登录mysql:

mysql  -uroot  - p   我这里测试就没有设置密码

创建帐号并赋予复制的权限。从库,主从库复制数据时需要使用这个帐号进行

grant  replication  slave 提醒*。*,用“根”@“192.168.56. %”,identified  by “123456”,

加锁:

实际工作中,需要禁止数据库的写入,要给数据库上锁

FLUSH  TABLES  WITH  READ 锁;

记录主库的binlog日志文件和位置信息(这个信息,要在从库配置的时候用到)

MariaDB [(一)]祝辞,show  master 地位;   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +   |,File ,,,,,,,,,,,,, |, Position  |, Binlog_Do_DB  | Binlog_Ignore_DB  |   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +   | |,master-bin.000001 ,,,,, 398, |,,,,,,,,,,,,,, |,,,,,,,,,,,,,,,,, |   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +   1,row  set 拷贝;(0.00,sec)

备份主库的数据:

mysqldump  -uroot  -p ——all-databases 在/tmp/db。sql

==========================================================================================

下面开始配置从库:

导入数据到从库当中

mysql  -uroot  -p  & lt;/tmp/db.sql

修改配置文:件my . cnf中所做

[root@salt-node2  ~] #,。cat /etc/my . cnf中所做   (mysqld)   innodb_file_per_table=没有   # log-bin=mysql-bin   binlog_format=混合   server-id =12   时间=relay-log /var/lib/mysql/relay-bin   # log_slave_updates =1   read_only =,   datadir=/var/lib/mysql   套接字=/var/lib/mysql/mysql.sock   #,Disabling  symbolic-links  is  recommended 用prevent  assorted  security 风险   符号链接=0   #,Settings  user 以及group 断开连接;ignored  when  systemd  is 使用。   #,If 你;need 用run  mysqld  under  a  different  user 或是团体,   #,customize  your  systemd  unit  file  for  mariadb  according 用   #,instructions 拷贝;http://fedoraproject.org/wiki/Systemd      (mysqld_safe)   日志错误=/var/log/mariadb/mariadb.log   pid文件=/var/运行/mariadb/mariadb.pid      #   #,include  all  files 得到,config 目录   #   ! includedir /etc/my.cnf.d

centos7 maiadb主从复制搭建