国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > 建站經(jīng)驗 > 正文

centos7 mariadb主從復制配置搭建詳解步驟

2019-11-02 17:00:24
字體:
來源:轉載
供稿:網(wǎng)友

花了小一天的時間,終于實現(xiàn)了centos7 mariadb主從復制配置搭建,下面記錄一下過程

環(huán)境:

虛擬機:vm8; centos7 版本:7.2.1511; mariadb 版本:centos7.2內置的

主庫服務器: 10.69.5.200,CentOS 7,MariaDB 10已安裝,有數(shù)據(jù)。

從庫服務器1: 10.69.5.201,CentOS 7,MariaDB 10已安裝,無應用數(shù)據(jù)。

主服務器配置

以下操作在主服務器192.168.71.151的/etc/my.cnf上進行。

1.修改配置文件,命令:vim /etc/my.cnf,輸入下列代碼:

[root@localhost ~]# cat /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock`# 新添加的部分# 配置主從時需要添加以下信息 startinnodb_file_per_table=NOlog-bin=/var/lib/mysql/master-bin #log-bin沒指定存儲目錄,則是默認datadir指向的目錄binlog_format=mixedserver-id=200 #每個服務器都需要添加server_id配置,各個服務器的server_id需要保證唯一性,實踐中通常設置為服務器IP地址的最后一位#配置主從時需要添加以下信息 end `# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-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[mysqld_safe]log-error=/var/log/mariadb/mariadb.logpid-file=/var/run/mariadb/mariadb.pid## include all files from the config directory#!includedir /etc/my.cnf.d

最后,:wq!保存退出

2.重啟mariadb服務,輸入命令

[root@localhost ~]# systemctl restart mariadb.service

3.登錄mariadb

[root@localhost ~]# mysql -u root -padmin 

注:-p后是密碼,中間沒有空格

4.創(chuàng)建帳號并賦予replication的權限

從庫,從主庫復制數(shù)據(jù)時需要使用這個帳號進行

MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'root'@'10.69.5.%' IDENTIFIED BY 'admin';Query OK, 0 rows affected (0.00 sec)

5.備份數(shù)據(jù)庫數(shù)據(jù),用于導入到從數(shù)據(jù)庫中

加鎖

實際工作中,備份的時候是不讓往庫中寫數(shù)據(jù)的,所以數(shù)據(jù)庫要加鎖,只能讀

MariaDB [(none)]> FLUSH TABLES WITH READ LOCK;Query OK, 0 rows affected (0.00 sec)

記錄主庫log文件及其當前位置

MariaDB [(none)]> SHOW MASTER STATUS;+------------------+----------+--------------+------------------+| File       | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000001 |   694 |       |         |+------------------+----------+--------------+------------------+

記住File和Position的部分,從服務器會用到

備份數(shù)據(jù),輸入命令:

[root@localhost ~]# mysqldump -uroot -p --all-databases > /root/db.sql

解鎖 主庫

數(shù)據(jù)備份完成后,就可以釋放主庫上的鎖:

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

從服務器配置

以下在從服務器上的操作

1.導入主庫的數(shù)據(jù)

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 松江区| 贵港市| 平利县| 谢通门县| 德保县| 康保县| 兴业县| 静安区| 建始县| 大庆市| 沾化县| 昭觉县| 临泽县| 延川县| 那坡县| 社会| 陕西省| 仪征市| 织金县| 霞浦县| 灵丘县| 佛山市| 定日县| 积石山| 石台县| 确山县| 四川省| 靖远县| 读书| 松原市| 齐齐哈尔市| 板桥市| 手游| 城步| 深州市| 永川市| 都安| 邯郸县| 江北区| 拉萨市| 阿克苏市|