Keepalive實現Mysql主主複製,高可用羣集

一、安裝前準備

關閉iptables:

service iptables stop;

chkconfig iptables off

 

關閉SELinux

vi /etc/selinux/config


 

查詢系統是否有安裝mysql,如有則移除。

rpm -qa | grep mysql

 

移除已安裝的mysql:

yum remove mysql-libs-5.1.66-2.el6_3.x86_64

 

二、安裝數據庫

安裝需要的插件:

yum install perl perl-devel libaiolibaio-devel

 

安裝MySQL-shared-compat 替換mysql-libs,如果不替換,在刪除mysql-libs,會提示postfix依賴於mysql-libs

rpm -ivh MySQL-shared-compat-5.6.26-1.el6.x86_64.rpm

 

安裝服務端:

rpm -ivh MySQL-server-5.6.26-1.el6.x86_64.rpm

 

安裝客戶端:

rpm -ivh MySQL-client-5.6.26-1.el6.x86_64.rpm

 

設置開機自動啓動:

chkconfig mysql on

 

啓動mysql

service mysql start

 

停止mysql

service mysql stop

 

獲取root的密碼:
more /root/.mysql_secret  

 

修改root密碼並刪除匿名賬戶:

/usr/bin/mysql_secure_installation--user=mysql

 

修改主機名:

vi /etc/sysconfig/network

vi /etc/hosts

 

修改主服務器配置文件(配置文件見附件):

vi /usr/my.cnf

 

 

 

修改從服務器配置文件(配置文件見附件):

 

 

進入mysql:

mysql -u root -p

 

show master status

show global variables like '%uuid%'

 

在兩臺機器上都創建複製賬戶並授權:

grant replication slave on *.* to 'mysql'@'192.168.2.%'identified by 'mysql';

flush privileges;   #重加載權限

 

從庫連接主庫:

change master to master_host='192.168.2.61',master_user='mysql',master_password='mysql', master_port=3306,master_auto_position=1;

start slave;

 

主庫連接從庫:

change master to master_host='192.168.2.62',master_user='mysql',master_password='mysql', master_port=3306,master_auto_position=1;

start slave;

 

三、安裝並配置keepalived(配置文件見附件)

yum install keepalived

vi /etc/keepalived/keepalived.conf

 

四、測試:

grant all privileges on *.* to 'root'@'%'identified by '123456';

mysql -h "192.168.2.60" -u root –p

show variables like "server_id";

 

 

show processlist;

show databases;

show slave status\G;

show master status\G;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章