最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2017年02月08日 08:59:58   作者:姚一號  
本篇文章主要介紹了centos7 mariadb主從復制配置搭建詳解步驟,具有一定的參考價值,感興趣的小伙伴們可以參考一下。

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

環(huán)境:

虛擬機:vm8; centos7 版本:7.2.1511; mariadb 版本:centos7.2內(nèi)置的

主庫服務器: 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/mysql
socket=/var/lib/mysql/mysql.sock

`# 新添加的部分
# 配置主從時需要添加以下信息 start
innodb_file_per_table=NO
log-bin=/var/lib/mysql/master-bin #log-bin沒指定存儲目錄,則是默認datadir指向的目錄
binlog_format=mixed
server-id=200 
#每個服務器都需要添加server_id配置,各個服務器的server_id需要保證唯一性,實踐中通常設置為服務器IP地址的最后一位
#配置主從時需要添加以下信息 end 
`
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-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.log
pid-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的權(quán)限

從庫,從主庫復制數(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ù)

[root@localhost ~]# mysql -uroot -p < db.sql

2.從服務器/etc/my.cnf配置,設置relay-log

my.cnf文件中添加一行relay_log=relay-bin

如果不設置,默認是按主機名 + “-relay-bin”生成relay log。

[root@localhost ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

`#配置主從時需要添加以下信息 start
innodb_file_per_table=NO
server-id=201 #一般與服務器ip的最后數(shù)字一致
relay-log=/var/lib/mysql/relay-bin
#配置主從時需要添加以下信息 end 
`
# 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.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

3.重啟服務

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

4.登錄mariadb

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

5.設置主從復制

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='10.69.5.200',MASTER_USER='root', MASTER_PASSWORD='admin', MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS= 694;
Query OK, 0 rows affected (0.02 sec)

這個命令完成以下幾個任務:

a.設置當前服務器為主服務器(10.69.5.200)的從庫

b.提供當前數(shù)據(jù)庫(從庫)從主庫復制數(shù)據(jù)時所需的用戶名和密碼,即上面的GRANT REPLICATION SLAVE ON *.* TO 'root'@'10.69.5.%' IDENTIFIED BY 'admin';設置的

c.指定從庫開始復制主庫時需要使用的日志文件和文件位置,即上面主庫執(zhí)行SHOW MASTER STATUS;顯示結(jié)果中的File和Position

6.開啟主從復制

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

7.查看從庫狀態(tài)

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
        Slave_IO_State: Waiting for master to send event
         Master_Host: 10.69.5.200
         Master_User: root
         Master_Port: 3306
        Connect_Retry: 60
       Master_Log_File: master-bin.000001
     Read_Master_Log_Pos: 694
        Relay_Log_File: relay-bin.000003
        Relay_Log_Pos: 530
    Relay_Master_Log_File: master-bin.000001
       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: 694
       Relay_Log_Space: 818
       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: 200
1 row in set (0.00 sec)

注意:結(jié)果中Slave_IO_Running和Slave_SQL_Running必須為Yes,如果不是,需要根據(jù)提示的錯誤修改。

驗證

主服務器:

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

MariaDB [(none)]> use mytest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mytest]> select * from user;
+----+------+
| id | name |
+----+------+
| 1 | t  |
| 2 | t2  |
| 3 | t3  |
+----+------+
3 rows in set (0.00 sec)

MariaDB [mytest]> insert into user(name) values('t4');
Query OK, 1 row affected (0.01 sec)

MariaDB [mytest]> select * from user;
+----+------+
| id | name |
+----+------+
| 1 | t  |
| 2 | t2  |
| 3 | t3  |
| 4 | t4  |
+----+------+
4 rows in set (0.00 sec)

查看從服務器數(shù)據(jù)是否變化:

MariaDB [(none)]> use mytest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mytest]> select * from user;
+----+------+
| id | name |
+----+------+
| 1 | t  |
| 2 | t2  |
+----+------+
2 rows in set (0.00 sec)

MariaDB [mytest]> select * from user;
+----+------+
| id | name |
+----+------+
| 1 | t  |
| 2 | t2  |
| 4 | t4  |
+----+------+
3 rows in set (0.00 sec)

可以看到,從服務器更新了數(shù)據(jù)

搭建過程中遇到的問題及解決方法

問題1:從服務器設置主從復制出現(xiàn)錯誤:

MariaDB [mytest]> start slave;
ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MariaDB error log

發(fā)現(xiàn) 

Slave_IO_Running: No
Slave_SQL_Running: No

進一步發(fā)現(xiàn)我輸入的是:CHANGE MASTER TO MASTER_HOST='192.168.71.151',MASTER_USER='slave_user', MASTER_PASSWORD='bigs3cret', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS= 469;

重新輸入:MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='10.69.5.200',MASTER_USER='root', MASTER_PASSWORD='admin', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS= 469;
報錯:ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MariaDB error log

于是看錯誤日志:/var/log/mariadb/mariadb.log

錯誤日志的位置在/etc/my.cnf中配置:log-error=/

[root@localhost ~]# cat /var/log/mariadb/mariadb.log
160915 12:52:02 [ERROR] Failed to open the relay log './mariadb-relay-bin.000001' (relay_log_pos 4)
160915 12:52:02 [ERROR] Could not find target log during relay log initialization

通過查找答案: 刪除/var/lib/mysql/路徑下the ‘master.info' ‘mysqld-relay-bin.*' ‘relay-log.info' ‘relay-log-index.*'

運行命令:rm -rf master.info,rm -rf *relay*

重啟服務:[root@localhost mysql]# systemctl restart mariadb.service

進入mariadb:

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

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

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

重新設置主從復制關系:

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='10.69.5.200',MASTER_USER='root', MASTER_PASSWORD='admin', MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS= 694;
Query OK, 0 rows affected (0.02 sec)

這次成功了。

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.01 sec)

查看從庫狀態(tài):

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
        Slave_IO_State: Connecting to master
         Master_Host: 10.69.5.200
         Master_User: root
         Master_Port: 3306
        Connect_Retry: 60
       Master_Log_File: master-bin.000001
     Read_Master_Log_Pos: 694
        Relay_Log_File: relay-bin.000001
        Relay_Log_Pos: 4
    Relay_Master_Log_File: master-bin.000001
      Slave_IO_Running: Connecting
      Slave_SQL_Running: Yes
  ···
  ···
  ···
 Replicate_Ignore_Server_Ids: 
       Master_Server_Id: 0
1 row in set (0.00 sec)

發(fā)現(xiàn)問題2.Slave_IO_Running: Connecting

問題2.Slave_IO_Running: Connecting

查看錯誤日志

[root@localhost ~]# cat /var/log/mariadb/mariadb.log
···
160915 13:17:56 [Note] Slave SQL thread initialized, starting replication in log 'master-bin.000001' at position 694, relay log '/var/lib/mysql/relay-bin.000001' position: 4
160915 13:17:56 [ERROR] Slave I/O: error connecting to master 'root@10.69.5.200:3306' - retry-time: 60 retries: 86400 message: Can't connect to MySQL server on '10.69.5.200' (113), Error_code: 2003

這時運行telnet命令

[root@localhost ~]# telnet 10.69.5.200 3306

-bash: telnet: 未找到命令

安裝telnet

[root@localhost ~]# yum -y install telnet-server.x86_64

安裝成功后重啟telnet服務

[root@localhost ~]# systemctl start telnet.socket
[root@localhost ~]# systemctl enable telnet.socket
[root@localhost ~]# telnet 10.69.5.200 3306

-bash: telnet: 未找到命令

還是不行

這回我reboot重啟虛擬機,運行命令

注意:這回不是"yum -y install telnet-server.x86_64"了,這回沒有telnet-server了

[root@localhost ~]# yum install telnet.x86_64

運行成功了

接著

[root@localhost ~]# systemctl enable telnet.socket
[root@localhost ~]# systemctl start telnet.socket
[root@localhost ~]# firewall-cmd --add-service=telnet --permanent 
success
[root@localhost ~]# telnet
telnet>

telnet終于安裝成功了

從最新版本的centos7系統(tǒng)開始,默認的是 Mariadb而不是mysql!

使用系統(tǒng)自帶的repos安裝很簡單:

yum install mariadb mariadb-server
  • systemctl start mariadb ==> 啟動mariadb
  • systemctl enable mariadb ==> 開機自啟動
  • mysql_secure_installation ==> 設置 root密碼等相關
  • mysql -u root -p 123456 ==> 測試登錄!

結(jié)束!

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • linux控制臺下實現(xiàn)2048小游戲

    linux控制臺下實現(xiàn)2048小游戲

    2048小游戲已經(jīng)火了很久了,各種程序版本的都有,今天我們就來給大家分享一個在Linux控制臺中實現(xiàn)2048小游戲的代碼,希望大家能夠喜歡。
    2015-03-03
  • linux掛載本地yum源問題

    linux掛載本地yum源問題

    這篇文章主要介紹了linux掛載本地yum源問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • 教你如何搭建一個安全的Linux服務器教程

    教你如何搭建一個安全的Linux服務器教程

    在當前很多php程序都使用了linux服務器,因為php在linux下運行效果更佳,很多大網(wǎng)站采用了linux服務器
    2012-04-04
  • 騰訊云服務器部署前后分離項目之前端部署

    騰訊云服務器部署前后分離項目之前端部署

    本文主要介紹了騰訊云服務器部署前后分離項目之前端部署,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-06-06
  • Centos7下Samba服務器配置(實戰(zhàn))

    Centos7下Samba服務器配置(實戰(zhàn))

    這篇文章主要介紹了Centos7下Samba服務器配置(實戰(zhàn)),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-11-11
  • Linux實現(xiàn)項目的自動化部署

    Linux實現(xiàn)項目的自動化部署

    這篇文章介紹了Linux實現(xiàn)項目自動化部署的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-07-07
  • Linux如何實現(xiàn)批量注釋

    Linux如何實現(xiàn)批量注釋

    文章介紹了在Linux中批量注釋和取消注釋代碼行的快捷方法,具體步驟包括使用Ctrl+V進入塊選擇模式,上下鍵選擇需要操作的行,然后按Shift+I輸入注釋符號(//或#),按ESC鍵保存
    2025-03-03
  • Linux與Windows文件互傳(VMWare)

    Linux與Windows文件互傳(VMWare)

    這篇文章主要介紹了Linux與Windows文件互傳的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • .httacces文件的配置技巧

    .httacces文件的配置技巧

    我要介紹的.htaccess的第一個應用是自定義錯誤頁面,這將使你可以擁有自己的、個性化的錯誤頁面(例如找不到文件時),而不是你的服務商提供的錯誤頁或沒有任何頁面。
    2008-06-06
  • linux通過掛載系統(tǒng)光盤搭建本地yum倉庫的方法

    linux通過掛載系統(tǒng)光盤搭建本地yum倉庫的方法

    linux通過掛載系統(tǒng)光盤搭建本地yum倉庫,使用yum命令加上 list 參數(shù)就可以查看倉庫了。本文介紹的非常詳細,具有參考借鑒價值,感興趣的朋友一起看看吧
    2016-10-10

最新評論

沾化县| 弥渡县| 巧家县| 兴隆县| 武义县| 克东县| 南木林县| 阳城县| 宁乡县| 肥东县| 瑞丽市| 奉节县| 饶阳县| 忻州市| 新郑市| 元江| 蓬莱市| 阳春市| 郁南县| 东明县| 永顺县| 怀远县| 喀喇沁旗| 区。| 和静县| 都兰县| 缙云县| 志丹县| 汉阴县| 阳江市| 武清区| 张北县| 班戈县| 鱼台县| 鹿泉市| 新乡市| 抚州市| 航空| 白玉县| 甘南县| 青岛市|