mysql5.5在linux下的集群,同步和配置优化

最近想本身去搭建mysql集群和读写分类,由于没有实际项目,全部一切都是我本身搭建的方法,若有问题还望指教mysql

1 在虚拟机上准备mysql 5.5*的环境 mysql -Vgit

1)centos6.5  192.168.239.129  msyql 5.5.27  打算用做从服务器github

 2)ubuntu14 192.168.239.128  mysql 5.5.39  主服务器sql

2 主服务上的配置数据库

查看mysql是否启动:ps aux |grep mysqldubuntu

经过命令行登陆管理MySQL服务器: ./usr/local/mysql/bin/mysql -u root –pcentos

个人数据库是全部人都链接,因此不用受权,如须要受权则:GRANT REPLICATION SLAVE ON *.* to 'rep1'@'192.168.239.129' identified‘password’;服务器

而后查看主数据库状态:show master status;ide

image

PS:记录下mysql-bin.000007  107spa

3 配置从数据库

修改从服务器的配置文件/etc/my.cnf

将 server-id = 1修改成 server-id = 10,并确保这个ID没有被别的MySQL服务所使用。

重启mysql数据库:/ete/init.d/mysqld restart

image

而后进去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

image

其中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)

image

在从服务器上查看      
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)      
=============================      
记录也已经存在

image

由此,整个MySQL主从复制的过程就完成了,接下来,咱们进行MySQL读写分离的安装与配置。

3、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 等

相关文章
相关标签/搜索