第14周作业作业

#### 1 MariaDB主从复制原理

  MariaDB主从复制是指数据可以从一个数据库服务器主节点复制到一个或多个从节点。

  MAriaDB默认采用异步复制方式,这样从节点不用一直访问主服务器来更新自己的数据,数据的更新可以在远程连接上进行,从节点可以复制主数据库中的所有数据库或者特定的数据库,或者特定的表。

#### 2 MariaDB一主一从架构构建

准备两台纯新的CentOS7.6服务器,其中主机称为node1的服务器地址为192.168.130.132,主机称为node2的服务器地址为192.168.130.133

   #配置主服务器192.168.130.132

  yum -y install mariadb-server

  vim /etc/my.cnf.d/mariadb-server.cnf

  [mysqld]

  server-id=1

  log-bin

  systemctl restart mariadb

  mysql -uroot -p123456

  grant replocation slave on *.* to repluser@'192.168.130.%' identified by 'magedu';

  #查看二进制文件和位置

  show master logs;

  #配置从服务器192.168.130.133

  yum -y install mariadb-server 

  vim /etc/my.cnf.d/mariadb-server.cnf

  [mysqld]

  server-id=2

  systemctl restart mariadb

  mysql -uroot -p123456

Mari aDB [ (none)]> CHANGE MASTER ToMASTER_ HOST= '192.168.130.132', MASTER_ _USER=' repluser',MASTER_ PASSWORD= ' magedu ',MASTER_ PORT=3306, MASTER_ _LOG_ FILE= 'mari adb-bin .000002',MASTER_ .LOG_ POS=545;

start slave;

show slave status\G

#### 3 MariaDB级联复制

上一节中我们完成了一主一从的MariaDB的主从复制架构,但是有的时候,我们期望有一个后备的MariaDB的节点,用只

动词}备份存储数据,不需要对外提供服务。为了实现该功能,我们可以在之前的一主一从架构上进行调整,即将从节点的二进

制文件打开,然后给他配置一个远程同步数据用户,接着使用一台新的服务器做为从服务器的从属,同步从服务器数据的即

柯林斯,下面我们在原来的架构上添加一台新的CentOS7.6,作为节点3,IP地址为192.168.132.134

  #在192.168.130.132充当master

  #在192.168.130.133充当级联slave

  #在192.168.130.134充当slave

  #配置master服务器

  yum -y install mariadb-server

  vim /etc/my.cnf.d/mariadb-server.cnf

  [mysqld]

  server-id=1

  log-bin

  systemctl restart mariadb

  mysql -uroot -p123456

  grant replocation slave on *.* to repluser@'192.168.130.%' identified by 'magedu';

  mysqldump -A -F --single-transaction --master-data=1 > /data/all.sql

  scp /data/all.sql 192.168.130.133:/data

  scp /data/all.sql 192.168.130.134:/data

  #在中间级联slave实现  配置从服务器192.168.130.133

  yum -y install mariadb-server 

  vim /etc/my.cnf.d/mariadb-server.cnf

  [mysqld]

  server-id=2

  log-bin

  read-only

  log-slave-updates

  systemctl restart mariadb

  还原数据库

  vim /data/all.sql

Mari aDB [ (none)]> CHANGE MASTER ToMASTER_ HOST= '192.168.130.132', MASTER_ _USER=' repluser',MASTER_ PASSWORD= ' magedu ',MASTER_ PORT=3306, MASTER_ _LOG_ FILE= 'mari adb-bin .000002',MASTER_ .LOG_ POS=545;

mysql -uroot -p123456

set sql_log_bin=0;

source /data/all.sql

show master logs;

set sql_log_bin=0;

start slave;

#在第三个节点slave上实现  配置192.168.130.134服务器

vim /etc/my.cnf.d/mariadb-server.cnf

[mysqld]

server-id=3

read-only

systemctl restart mariadb

vim /data/all.sql

CHANGE MASTER ToMASTER_ HOST= '192.168.130.132', MASTER_ _USER=' repluser',MASTER_ PASSWORD= ' magedu ',MASTER_ PORT=3306, MASTER_ _LOG_ FILE= 'mari adb-bin .000002',MASTER_ .LOG_ POS=545;

mysql -uroot -p123456 < /data/all.sql

mysql -utoot -p123456 -e 'start slave;'

 

#### 4 MariaDB半同步复制

  #在master实现,启用半同步功能

  vim /etc/my.cnf.d/mariadb-server.cnf

  [mysqld]

  server-id=8

  log-bin

  plugin-load-add = semisync_master

  rpl_semi_sync_master_enabled=ON

  rpl_semi_sync_master_timeout=3000

   systemctl restart mariadb

  #在其他所以slave节点上都实现,启用半同步功能

  vim /etc/my.cnf.d/mariadb-server.cnf

  [mysqld]

  server-id=2

  plugin_load-add = semisync_slave

  rpl_semi_sync__slave_enabled=ON

  systemctl restart mariadb

#### 5 MariaDB高可用方案MHA

准备三台新安装的CentOS7.6服务器,并使用yum安装MariaDB10.2.23,主机名分别为node1,node2,node3,

IP地址分别为192.168.130.132-134

   #在所有服务器上安装mha4mysql-node

  yum -y install mha4mysql-node-0.56-0.e16.noarch.rpm

  ssh-keygen

  ssh-copy-id 192.168.130.132

  rsyns -av .ssh 192.168.130.133:/root/

  rsyns -av .ssh 192.168.130.134:/root/

  在node1上建立配置文件

  mkdir /etc/mastermha/

  vim /etc/mastermha/app1,cnf

  [server default]

  user=mhauser

  password=magedu

  manager_workdir=/data/master/app1/manager.log

  remote_workdir=/data/mastermha/app1/

  ssh_user=root

  repl_user=repluser

  repl_password=magedu

  ping_interval=1

  master_ip_failover_script=/usr/local/bin/master_ip_failover

  report_script=/usr/local/bin/sendmail.sh

  check_repl_delay=0

  [server1]

  hostname=192.168.130.133

  candidate_master=1

  [server2]

  hostname=192.168.130.134

  candidate_master=1

  #实现master

  vim /etc/my.cnf

  [mysqld]

  server_id=1

  log-bin

  skip_name_resolve=1

  general_log

  mysql -uroot -p123456

  show master logs

  grant replocation slave on *.* to repluser@'192.168.130.%' identified by 'magedu';

  grant all on *.* to mhauser@'192.168.130.%' identified by 'magedu';

  实现slave

  vim /etc/my.cnf

  [mysqld]

  server_id=2

  log-bin

  read_only 

  relay_log_purhe=0

  skip_name_resolve=1

CHANGE MASTER ToMASTER_ HOST= '192.168.130.132', MASTER_ _USER=' repluser',MASTER_ PASSWORD= ' magedu ',MASTER_ PORT=3306, MASTER_ _LOG_ FILE= 'mari adb-bin .000002',MASTER_ .LOG_ POS=545;

start slave;

masterha_ .check_ ssh --conf=/etc/ maste rmha/ app1. cnf

masterha_ .check_ rep1 --conf=/etc/mastermha/app1. cnf

nohup masterha_manager --conf=/etc/mastermha/appl.cnf &>/dev/nu17

 

posted @ 2020-09-03 17:03  guobang  阅读(167)  评论(0编辑  收藏  举报