主主復制

兩個節(jié)點配置文件的設置

[root@centos7 /]# cat etc/my.cnf.d/server.cnf 
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]
server-id = 1   #設定serverID的值
log-bin = mysql.log  #啟用二進制日志并以文件
relay-log=chenxi.log #
skip_name_resolve = ON #關閉名稱解析功能
auto_increment_offset=1
auto_increment_increment=2
# this is only for embedded server
[embedded]

# This group is only read by MariaDB-5.5 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mysqld-5.5]

# These two groups are only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

[mariadb-5.5]

節(jié)點二的設置

[root@localhost ~]# cat /etc/my.cnf.d/server.cnf 
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]
server-id=2    #定義服務器ID
log-bin = chenxi-log
relay_log = relay-log
skip_name_resolve = NO
auto_increment_offset=2
auto_increment_increment=2

# this is only for the mysqld standalone daemon
[mysqld]

# this is only for embedded server
[embedded]

# This group is only read by MariaDB-5.5 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mysqld-5.5]

# These two groups are only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

[mariadb-5.5]

兩個節(jié)點啟動服務

節(jié)點1 的設置
[root@centos7 my.cnf.d]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>  GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO 'repluse'@'172.16.%.%' identified by 'replpass';
Query OK, 0 rows affected (0.00 sec)

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

MariaDB [(none)]>  show master status; 
+--------------+----------+--------------+------------------+
| File         | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------+----------+--------------+------------------+
| mysql.000003 |      505 |              |                  |
+--------------+----------+--------------+------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> change master to master_host='172.16.250.236' ,master_user='repluse',master_password='replpass',master_log_file='mysql.000003',master_log_pos=505;
Query OK, 0 rows affected (0.01 sec)

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

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.250.236
                  Master_User: repluse
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql.000003
          Read_Master_Log_Pos: 505
               Relay_Log_File: chenxi.000002
                Relay_Log_Pos: 525
        Relay_Master_Log_File: mysql.000003
             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: 505
              Relay_Log_Space: 810
              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: 2
1 row in set (0.00 sec)

MariaDB [(none)]> 
節(jié)點2 的設置
MariaDB [(none)]>  GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO 'repluse'@'172.16.%.%' identified by 'replpass';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show grants for 'repluser'@'172.16.%.%';
ERROR 1141 (42000): There is no such grant defined for user 'repluser' on host '172.16.%.%'
MariaDB [(none)]> show grants for 'repluse'@'172.16.%.%';
+-------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for repluse@172.16.%.%                                                                                                                   |
+-------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repluse'@'172.16.%.%' IDENTIFIED BY PASSWORD '*D98280F03D0F78162EBDBB9C883FC01395DEA2BF' |
+-------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]>  show master status; 
+--------------+----------+--------------+------------------+
| File         | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------+----------+--------------+------------------+
| mysql.000003 |      425 |              |                  |
+--------------+----------+--------------+------------------+
1 row in set (0.00 sec)

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

MariaDB [(none)]>  show master status; 
+--------------+----------+--------------+------------------+
| File         | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------+----------+--------------+------------------+
| mysql.000003 |      505 |              |                  |
+--------------+----------+--------------+------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> change master to master_host='172.16.251.203' ,master_user='repluse',master_password='replpass',master_log_file='mysql.000003',master_log_pos=505;
Query OK, 0 rows affected (0.07 sec)

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

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.251.203
                  Master_User: repluse
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql.000003
          Read_Master_Log_Pos: 505
               Relay_Log_File: chenxi.000002
                Relay_Log_Pos: 525
        Relay_Master_Log_File: mysql.000003
             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: 505
              Relay_Log_Space: 810
              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
1 row in set (0.00 sec)

MariaDB [(none)]> 
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市煎饼,隨后出現(xiàn)的幾起案子狞甚,更是在濱河造成了極大的恐慌辕万,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,042評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件廉白,死亡現(xiàn)場離奇詭異促脉,居然都是意外死亡悦污,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,996評論 2 384
  • 文/潘曉璐 我一進店門退子,熙熙樓的掌柜王于貴愁眉苦臉地迎上來岖妄,“玉大人,你說我怎么就攤上這事寂祥〖雠埃” “怎么了?”我有些...
    開封第一講書人閱讀 156,674評論 0 345
  • 文/不壞的土叔 我叫張陵丸凭,是天一觀的道長福扬。 經(jīng)常有香客問我,道長惜犀,這世上最難降的妖魔是什么铛碑? 我笑而不...
    開封第一講書人閱讀 56,340評論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮虽界,結果婚禮上汽烦,老公的妹妹穿的比我還像新娘。我一直安慰自己莉御,他們只是感情好撇吞,可當我...
    茶點故事閱讀 65,404評論 5 384
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著颈将,像睡著了一般梢夯。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上晴圾,一...
    開封第一講書人閱讀 49,749評論 1 289
  • 那天颂砸,我揣著相機與錄音,去河邊找鬼。 笑死人乓,一個胖子當著我的面吹牛勤篮,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播色罚,決...
    沈念sama閱讀 38,902評論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼碰缔,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了戳护?” 一聲冷哼從身側響起金抡,我...
    開封第一講書人閱讀 37,662評論 0 266
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎腌且,沒想到半個月后梗肝,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,110評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡铺董,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,451評論 2 325
  • 正文 我和宋清朗相戀三年巫击,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片精续。...
    茶點故事閱讀 38,577評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡坝锰,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出重付,到底是詐尸還是另有隱情顷级,我是刑警寧澤,帶...
    沈念sama閱讀 34,258評論 4 328
  • 正文 年R本政府宣布堪夭,位于F島的核電站愕把,受9級特大地震影響拣凹,放射性物質發(fā)生泄漏森爽。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,848評論 3 312
  • 文/蒙蒙 一嚣镜、第九天 我趴在偏房一處隱蔽的房頂上張望爬迟。 院中可真熱鬧,春花似錦菊匿、人聲如沸付呕。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,726評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽徽职。三九已至,卻和暖如春佩厚,著一層夾襖步出監(jiān)牢的瞬間姆钉,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,952評論 1 264
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留潮瓶,地道東北人陶冷。 一個月前我還...
    沈念sama閱讀 46,271評論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像毯辅,于是被迫代替她去往敵國和親埂伦。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 43,452評論 2 348

推薦閱讀更多精彩內(nèi)容