使用MHA做MySQL的高可用

來源:互聯網
上載者:User

主庫:192.168.0.11

備選主庫:192.168.0.12

從庫:192.168.0.13

監控機:192.168.0.10

首先在三台機器上安裝mysql(監控機的mysql先不裝,以後再說)。

我使用percona server(一個mysql的改進版。據說比mysql效能更好些)。

[root@cluster1 ~]# tar zxvf Percona-Server-5.5.21-rel25.1-234.Linux.i686.tar.gz -C /usr/local/

[root@cluster1 ~]# cd /usr/local/

[root@cluster1 local]# mv Percona-Server-5.5.21-rel25.1-234.Linux.i686 mysql

[root@cluster1 local]# useradd -s /bin/false -M mysql

[root@cluster1 mysql]# cd /usr/local/mysql/

[root@cluster1 mysql]# chown -R mysql.mysql .

[root@cluster1 mysql]# cp support-files/my-medium.cnf /etc/my.cnf

[root@cluster1 mysql]# ./scripts/mysql_install_db --user=mysql

[root@cluster1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@cluster1 mysql]# chmod +x /etc/init.d/mysqld

[root@cluster1 mysql]# echo "/usr/local/mysql/lib" >> /etc/ld.so.conf

[root@cluster1 mysql]# ldconfig

[root@cluster1 mysql]# /etc/init.d/mysqld start

[root@cluster1 mysql]# chkconfig --add mysqld

[root@cluster1 mysql]# chkconfig --level 235 mysqld on

 

注意“my.cnf”拷貝過去之後最好指定“basedir”和“datadir”以及二進位日誌和“server-id”

以上是三台機器安裝mysql,一定記得“server-id”不能相同。

 

Mysql5.5以後新增了半同步複製功能。在使用replication時,主伺服器把要提交的事物至少傳給了一個備庫。增加了主庫和從庫之間事物的一致性。MHA配合半同步複製效果更佳。雖然啟用半同步複製會降低一些效能。但為保持整個系統的正常運行還是值得的。

 

開啟半同步複製:

主庫:

[root@cluster1 mysql]# cp /usr/local/mysql/lib/plugin/*.so /usr/local/mysql/lib/mysql/plugin/

不拷貝的話預設找不到模組檔案。

mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';

mysql> set global rpl_semi_sync_master_enabled=1;

mysql> set global rpl_semi_sync_master_timeout=1000;

可以show一下驗證是否開啟了semisync功能。

mysql> show global status like 'rpl%';

為了讓mysql在重啟時自動載入該功能,在/etc/my.cnf中加入:

rpl_semi_sync_master_enabled=1

rpl_semi_sync_master_timeout=1000

1000為1000ms的逾時時間。

備選主庫(從庫):

mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';

mysql> set global rpl_semi_sync_master_enabled=1;

mysql> set global rpl_semi_sync_master_timeout=1000;

mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';

mysql> set global rpl_semi_sync_slave_enabled=1;

在/etc/my.cnf中加入:

rpl_semi_sync_master_enabled=1

rpl_semi_sync_master_timeout=1000

rpl_semi_sync_slave_enabled=1

 

從庫:

mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';

mysql> set global rpl_semi_sync_slave_enabled=1;

在/etc/my.cnf中加入:

rpl_semi_sync_slave_enabled=1

 

在備用節點和從節點的/etc/my.cnf中加入選項:

read_only=1
relay_log_purge=0

  • 1
  • 2
  • 3
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.