mysql5.5在linux下的集群,同步和配置优化
2019獨角獸企業重金招聘Python工程師標準>>>
最近想自己去搭建mysql集群和讀寫分類,因為沒有實際項目,所有一切都是我自己搭建的方法,如有問題還望指教
1 在虛擬機上準備mysql 5.5*的環境 mysql -V
1)centos6.5? 192.168.239.129? msyql 5.5.27 ?打算用作從服務器
?2)ubuntu14 192.168.239.128??mysql 5.5.39  主服務器
2 主服務上的配置
查看mysql是否啟動:ps aux |grep mysqld
通過命令行登錄管理MySQL服務器: ./usr/local/mysql/bin/mysql -u root –p
我的數據庫是所有人都連接,所以不用授權,如需要授權則:GRANT REPLICATION SLAVE ON *.* to 'rep1'@'192.168.239.129' identified‘password’;
然后查看主數據庫狀態:show master status;
PS:記錄下mysql-bin.000007 ?107
3 配置從數據庫
修改從服務器的配置文件/etc/my.cnf
將 server-id = 1修改為 server-id = 10,并確保這個ID沒有被別的MySQL服務所使用。
重啟mysql數據庫:/ete/init.d/mysqld restart
然后進去mysql庫中:執行如下配置
change master to ? ? ?
master_host='192.168.239.128', ? ? ?
master_user='rep1', ? ? ?
master_password='root', ? ? ?
master_log_file='mysql-bin.000007', ? ? ?
master_log_pos=256;
正確執行后啟動Slave同步進程 ? ? ?
mysql> start slave;
主從同步檢查 ? ? ?
mysql> show slave status\G
其中Slave_IO_Running 與 Slave_SQL_Running 的值都必須為YES,才表明狀態正常。
如果主服務器已經存在應用數據,則在進行主從復制時,需要做以下處理: ? ? ?
(1)主數據庫進行鎖表操作,不讓數據再進行寫入動作 ? ? ?
mysql> FLUSH TABLES WITH READ LOCK;
(2)查看主數據庫狀態 ? ? ?
mysql> show master status;
(3)記錄下 FILE 及 Position 的值。 ? ? ?
將主服務器的數據文件(整個/opt/mysql/data目錄)復制到從服務器,建議通過tar歸檔壓縮后再傳到從服務器解壓。
(4)取消主數據庫鎖定 ? ? ?
mysql> UNLOCK TABLES;
主服務器上的操作 ? ? ?
在主服務器上創建數據庫first_db ? ? ?
mysql> create database first_db; ? ? ?
Query Ok, 1 row affected (0.01 sec)
在主服務器上創建表first_tb ? ? ?
mysql> create table first_tb(id int(3),name char(10)); ? ? ?
Query Ok, 1 row affected (0.00 sec)
在主服務器上的表first_tb中插入記錄 ? ? ?
mysql> insert into first_tb values (001,’myself’); ? ? ?
Query Ok, 1 row affected (0.00 sec)
在從服務器上查看 ? ? ?
mysql> show databases; ? ? ?
============================= ? ? ?
+--------------------+ ? ? ?
| Database | ? ? ?
+--------------------+ ? ? ?
| information_schema | ? ? ?
| first_db | ? ? ?
| mysql | ? ? ?
| performance_schema | ? ? ?
| test | ? ? ?
+--------------------+ ? ? ?
5 rows in set (0.01 sec) ? ? ?
============================= ? ? ?
數據庫first_db已經自動生成
mysql> use first_db ? ? ?
Database chaged
mysql> show tables; ? ? ?
============================= ? ? ?
+--------------------+ ? ? ?
| Tables_in_first_db | ? ? ?
+--------------------+ ? ? ?
| first_tb | ? ? ?
+--------------------+ ? ? ?
1 row in set (0.02 sec) ? ? ?
============================= ? ? ?
數據庫表first_tb也已經自動創建
mysql> select * from first_tb; ? ? ?
============================= ? ? ?
+------+------+ ? ? ?
| id | name | ? ? ?
+------+------+ ? ? ?
| 1 | myself | ? ? ?
+------+------+ ? ? ?
1 rows in set (0.00 sec) ? ? ?
============================= ? ? ?
記錄也已經存在
由此,整個MySQL主從復制的過程就完成了,接下來,我們進行MySQL讀寫分離的安裝與配置。
三、MySQL讀寫分離
數據庫Master主服務器:192.168.239.128
數據庫Slave從服務器:192.168.239.129
MySQL-Proxy調度服務器:192.168.239.129
 
安裝配置MySQL-Proxy
目前做讀寫分離的中間件有Qihoo 360 Atlas、阿里包包的 cobar?、Amoeba 和mysql-proxy、MariaDB 宣布其旗下的 MaxScale 等
?
轉載于:https://my.oschina.net/lifei123/blog/519421
總結
以上是生活随笔為你收集整理的mysql5.5在linux下的集群,同步和配置优化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用Maven构建Dubbo服务的可运行
- 下一篇: MySQL实战课程---通过录像手把手带