真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

MySQL主主復(fù)制+Keepalived打造高可用MySQL集群的步驟

這篇文章主要介紹“MySQL主主復(fù)制+Keepalived打造高可用MySQL集群的步驟”,在日常操作中,相信很多人在MySQL主主復(fù)制+Keepalived打造高可用MySQL集群的步驟問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”MySQL主主復(fù)制+Keepalived打造高可用MySQL集群的步驟”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

玉屏網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,玉屏網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為玉屏上1000+提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請找那個(gè)售后服務(wù)好的玉屏做網(wǎng)站的公司定做!


以下內(nèi)容均是實(shí)驗(yàn)環(huán)境,請根據(jù)實(shí)際情況修改響應(yīng)參數(shù)
實(shí)驗(yàn)環(huán)境:
mysql1 ip:10.1.1.20
mysql2 ip:10.1.1.21
mysql vip:10.1.1.25

三臺(tái)機(jī)器均安裝centos 6.5_x64(虛擬機(jī)環(huán)境)
實(shí)驗(yàn)開始
一、安裝mysql,并打造主主同步。
相信主從同步大家都會(huì)做,一樣的道理,主主同步就是兩臺(tái)機(jī)器互為主的關(guān)系,在任何一臺(tái)機(jī)器上寫入都會(huì)同步。
安裝mysql的過程不解釋,yum就好啦

配置主主同步
1.配置 /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-bin=binlog  #開啟binlog功能
log-bin-index=binlog.index
sync_binlog=0
server_id = 1    #兩臺(tái)機(jī)器不能重復(fù)一個(gè)server_id=1一個(gè)server_id=2

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


2.分別在兩臺(tái)機(jī)器上配置同步賬號
10.1.1.20機(jī)器上:
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with; or \g.
Your MySQL connection id is 2
Server version: 5.0.77-log Sourcedistribution

Type 'help;' or '\h' for help. Type '\c' toclear the buffer.
mysql> GRANT replication slave ON *.* TO'ab'@'%' identified by '123';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

10.1.1.21機(jī)器上:
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with; or \g.
Your MySQL connection id is 2
Server version: 5.0.77-log Sourcedistribution

Type 'help;' or '\h' for help. Type '\c' toclear the buffer.
mysql> GRANT replication slave ON *.* TO'ab'@'%' identified by '123';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
注:由于本文是實(shí)驗(yàn)環(huán)境下編寫,所以沒考慮任何安全性問題,同步賬號也是最高權(quán)限,請根據(jù)實(shí)際情況設(shè)置響應(yīng)權(quán)限??!

3.設(shè)置同步
10.1.1.20機(jī)器上:
mysql> flush tables with read lock;
mysql> show master status;
+---------------+----------+--------------+------------------+
| File          | Position | Binlog_Do_DB |Binlog_Ignore_DB  |
+---------------+----------+--------------+------------------+
| binlog.000003 | 365      |              |                  |
+---------------+----------+--------------+------------------+
1 row in set (0.03 sec)

mysql> unlock tables;
Query OK, 0 rows affected (0.03 sec)

10.1.1.21機(jī)器上:
mysql> change master tomaster_host='10.1.1.20', master_port=3306, master_user='ab',master_password='123', master_log_file='binlog.000003',master_log_pos=365;
Query OK, 0 rows affected (0.06 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status \G  #執(zhí)行這命令后 注意觀察下面這兩個(gè)參數(shù),必須要都是yes才行
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

同樣的 反過來做相同操作
10.1.1.21機(jī)器上:
mysql> flush tables with read lock;
mysql> show master status;
+---------------+----------+--------------+------------------+
| File          | Position | Binlog_Do_DB |Binlog_Ignore_DB  |
+---------------+----------+--------------+------------------+
| binlog.000004 | 207      |              |                  |
+---------------+----------+--------------+------------------+
1 row in set (0.03 sec)

mysql> unlock tables;
Query OK, 0 rows affected (0.03 sec)

10.1.1.20機(jī)器上:
mysql> change master tomaster_host='10.1.1.21', master_port=3306, master_user='ab',master_password='123', master_log_file='binlog.000004',master_log_pos=207;
Query OK, 0 rows affected (0.06 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status \G  #執(zhí)行這命令后 注意觀察下面這兩個(gè)參數(shù),必須要都是yes才行
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
介此,主主同步打造完成,可以簡單測試一下,分別在兩個(gè)機(jī)器上寫數(shù)據(jù) 看看會(huì)不會(huì)同步到另一臺(tái)機(jī)器上
PS:如果報(bào)錯(cuò)Slave_IO_Running: NO可以檢查同步的賬號是否創(chuàng)建正常!

二、安裝keepalived并設(shè)置監(jiān)控
keepalived是安裝在兩臺(tái)MySQL服務(wù)器上的
首先安裝keepalived過程不解釋就正常解壓安裝就好
安裝后配置vim /etc/keepalived/keepalived.conf內(nèi)容如下
10.1.1.20的配置文件
! Configuration File for keepalived
global_defs {
  notification_email {
    acassen@firewall.loc
    failover@firewall.loc
    sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id LVS_DEVEL
}

vrrp_instance VI_1 {
  state backup                           #兩臺(tái)配置此處均是BACKUP
  interface eth0
  virtual_router_id 51
  priority 100                           #優(yōu)先級,另一臺(tái)改為90
  advert_int 1
  nopreempt                              #不搶占,只在優(yōu)先級高的機(jī)器上設(shè)置即可,優(yōu)先級低的機(jī)器不設(shè)置
  authentication {
      auth_type PASS
      auth_pass 1111
  }
  virtual_ipaddress {
      10.1.1.25

  }
}

virtual_server 10.1.1.25 3306 {
  delay_loop 6
  lb_algo wrr
  lb_kind DR
  persistence_timeout 50                 #會(huì)話保持時(shí)間
  protocol TCP
real_server 10.1.1.20 3306 {
      weight 3
      notify_down /tmp/killprocess.sh    #檢測到mysqld服務(wù)掛了執(zhí)行此腳本(腳本要自己寫)
      TCP_CHECK {
      connect_timeout 10                 #連接超時(shí)時(shí)間
      nb_get_retry 3                     #重連次數(shù)
      delay_before_retry 3               #重連間隔時(shí)間
      connect_port 3306                  #健康檢查端口
        }
      }
}

10.1.1.21的配置文件
! Configuration File for keepalived
global_defs {
  notification_email {
    acassen@firewall.loc
    failover@firewall.loc
    sysadmin@firewall.loc
  }
  notification_email_from Alexandre.Cassen@firewall.loc
  smtp_server 127.0.0.1
  smtp_connect_timeout 30
  router_id LVS_DEVEL
}
vrrp_instance VI_1 {
  state backup
  interface eth0
  virtual_router_id 51
  priority 90
  advert_int 1
  authentication {
      auth_type PASS
      auth_pass 1111
  }
  virtual_ipaddress {
      10.1.1.25
  }
}

virtual_server 10.1.1.25 3306 {
  delay_loop 6
  lb_algo wrr
  lb_kind DR
  persistence_timeout 50
  protocol TCP
real_server 10.1.1.21 3306 {
      weight 3
      notify_down /tmp/killprocess.sh
      TCP_CHECK {
      connect_timeout 10
      nb_get_retry 3
      delay_before_retry 3
      connect_port 3306
          }
      }
}

編寫監(jiān)控mysql服務(wù)是否掛了的腳本,按照上面配置文件的位置編寫腳本。
# vim /tmp/killprocess.sh
#!/bin/sh
pkill keepalived
腳本很簡單就一句,目的是當(dāng)keepalived檢測到mysql服務(wù)掛了之后觸發(fā)該腳本,殺死keepalived進(jìn)程,讓另一臺(tái)服務(wù)器來接管

修改后啟動(dòng)keeplived服務(wù)
# service keeplived start
介此整個(gè)集群搭建完成

三、測試
找臺(tái)機(jī)器用虛擬ip連接mysql
[root@localhost html]# mysql -uab  -h 10.1.1.25 -p123
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 736
Server version: 5.1.66-log Source distribution
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
成功連上了,然后可以任意關(guān)閉某臺(tái)機(jī)器,或者某臺(tái)機(jī)器的mysql服務(wù),看看還能不能連上??!

到此,關(guān)于“MySQL主主復(fù)制+Keepalived打造高可用MySQL集群的步驟”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!


新聞標(biāo)題:MySQL主主復(fù)制+Keepalived打造高可用MySQL集群的步驟
URL標(biāo)題:http://weahome.cn/article/gsshoj.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部