AWS EC2 MySQL迁移到RDS案例
Amazon Relational Database Service (Amazon RDS) 是一种Web 服务,可让用户更轻松地在云中设置、操作和扩展关系数据库。它可以为行业标准关系数据库提供经济高效且可以调节大小的容量,并管理常见
数据库管理任务。
现有的环境如下,计划将MySQL主库billingdb迁移到RDS上,减少运维成本.

计划迁移之后的环境如下

现在开始迁移过程
1. 在当前的RDS slave上记录需要过滤的表(RDS有自己的系统表,当RDS slave变成master后,这些表不需要被同步到EC2上的slave上)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.188.102.92
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000861
Read_Master_Log_Pos: 18626649
Relay_Log_File: relaylog.005026
Relay_Log_Pos: 685
Relay_Master_Log_File: mysql-bin.000861
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table: mysql.rds_sysinfo,innodb_memcache.cache_policies,mysql.rds_replication_status,innodb_memcache.config_options,mysql.rds_history,mysql.plugin,mysql.rds_monitor
2. 在RDS slave上创建复制及相关账户(创建RDS作为备库的时候,并没有导入系统表,所以不会有主库上的数据库用户)
mysql> grant replication slave on *.* to 'repl'@'%' identified by 'repl';
mysql> flush privileges;
3. 修改RDS slave上二进制日志保留时间(默认情况下,RDS并不会保留二进制日志,这样RDS切为master后就没有二进制日志,也就谈不上将EC2转换为slave连上RDS了)
mysql> call mysql.rds_show_configuration;
mysql> call mysql.rds_set_configuration('binlog retention hours', 72);
4. 记录当前master的session连接信息
/usr/local/mysql/bin/mysql -u root -p -e "show processlist"|awk '{print $3}'|grep ":"|awk '{print substr($0,0,index($0,":")-1) }'|sort|uniq -c
10.188.100.36
10.188.104.196
ec2-backoffice-.mypna.com
ec2-billingcommerce-.mypna.com
ec2-billingcommerce-.mypna.com
ec2-billingen-.mypna.com
ec2-billingen-.mypna.com
ec2-billingengines-.mypna.com
ec2-billingentest-.mypna.com
ec2-billingentest-.mypna.com
ec2-billingiden-.mypna.com
ec2-billingiden-.mypna.com
ec2-billingoffer-.mypna.com
ec2-billingoffer-.mypna.com
ec2-billingoffer-.mypna.com
ec2-billingui-.mypna.com
ec2-billingui-.mypna.com
ec2-cliwebreport-.mypna.com
ec2-dbmon-.mypna.com
5. 准备第4步主机名到IP地址的解析(RDS并不能解析出客户端主机名,迁移到RDS后,检查session连接的时候会方便很多)
|
IP address |
Hostname |
|
10.188.100.36 |
ec2-billingdb-04 |
|
10.188.104.196 |
ec2-csr-tracking-01 |
|
10.188.3.22 |
ec2-backoffice-01.mypna.com |
|
10.188.1.102 |
ec2-billingcommerce-01.mypna.com |
|
10.188.1.105 |
ec2-billingcommerce-02.mypna.com |
|
10.188.1.252 |
ec2-billingen-01.mypna.com |
|
10.188.1.59 |
ec2-billingen-02.mypna.com |
|
10.188.1.189 |
ec2-billingengines-01.mypna.com |
|
10.188.1.246 |
ec2-billingentest-01.mypna.com |
|
10.188.1.232 |
ec2-billingentest-02.mypna.com |
|
10.188.1.15 |
ec2-billingiden-01.mypna.com |
|
10.188.1.16 |
ec2-billingiden-02.mypna.com |
|
10.188.101.54 |
ec2-billingoffer-01.mypna.com |
|
10.188.101.128 |
ec2-billingoffer-02.mypna.com |
|
10.188.101.63 |
ec2-billingoffer-03.mypna.com |
|
10.188.1.235 |
ec2-billingui-01.mypna.com |
|
10.188.1.236 |
ec2-billingui-02.mypna.com |
|
10.188.102.92 |
ec2-cliwebreport-01.mypna.com |
|
10.188.100.65 |
ec2-dbmon-01.mypna.com |
|
10.188.102.92 |
ec2-cliwebreport-01.mypna.com |
6. 将主库master重启到只读状态,并记录当前的master日志位置信息(这样做是为了让所有的slave都达到一致性状态)
/etc/init.d/mysql restart --read-only mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000865
Position: 120
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)
7. 稍等片刻,检查所有EC2 slave,确保所有的EC2的slave已经赶上master的二进制日志位置
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.188.100.73
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000865 #看该行
Read_Master_Log_Pos: 120 #看该行
Relay_Log_File: ec2-billingdb-04-relay-bin.000047
Relay_Log_Pos: 279
Relay_Master_Log_File: mysql-bin.000865
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 120 #看该行
Relay_Log_Space: 618
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0 #看该行
8. EC2的机器ec2-billingdb-06是RDS的master,所以RDS的二进制日志要看是否追上ec2-billingdb-06
- 在ec2-billingdb-06查看
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000861
Position: 18626649
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)
- 在RDS上查看
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.188.102.92
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000861 #这里和上一步骤06机器的二进制日志一致
Read_Master_Log_Pos: 18626649 #这里和上一步骤06的机器的二进制日志一致
Relay_Log_File: relaylog.005026
Relay_Log_Pos: 685
Relay_Master_Log_File: mysql-bin.000861
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table: mysql.rds_sysinfo,innodb_memcache.cache_policies,mysql.rds_replication_status,innodb_memcache.config_options,mysql.rds_history,mysql.plugin,mysql.rds_monitor
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 18626649 #这里和上一步骤06机器的二进制日志一致
Relay_Log_Space: 79732
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
8. 将master主库数据库关机
/etc/init.d/mysql stop
9. 记录RDS slave的二进制日志信息
mysql> show master status;
*************************** 1. row ***************************
File: mysql-bin-changelog.007492
Position: 120
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)
10. 清除RDS的slave信息,使其作为独立的主库运行
mysql>CALL mysql.rds_stop_replication;
mysql>CALL mysql.rds_reset_external_master;
mysql>show slave status\G;
mysql>show master status\G;
File: mysql-bin-changelog.007492
Position: 1025
11. 将步骤1中需要过滤的表添加到原master的配置文件/etc/my.cnf里
replicate-ignore-table=mysql.rds_sysinfo
replicate-ignore-table=innodb_memcache.cache_policies
replicate-ignore-table=mysql.rds_replication_status
replicate-ignore-table=innodb_memcache.config_options
replicate-ignore-table=mysql.rds_history
replicate-ignore-table=mysql.plugin
replicate-ignore-table=mysql.rds_monitor
replicate-ignore-table=mysql.rds_heartbeat2
12. 将原master以只读的方式启动(确保应用不会连接进来写脏数据)
/etc/init.d/mysql start --read-only
13. 将原master作为slave连接到RDS
mysql> change master to
master_host='RDS endpoint name',
master_user='repl',
master_password='repl',
master_port=3306,
master_log_file='mysql-bin-changelog.xxxxxx',
master_log_pos=xxx;
mysql> start slave;
mysql> show slave status\G;
14, 将应用解析到RDS上,并检查RDS的session信息,确保应用可以正常接入
AWS EC2 MySQL迁移到RDS案例的更多相关文章
- ssh tunneling应用案例-AWS EC2 vnc图形化桌面的支持
一般地,无论是AWS EC2还是阿里云的云主机,linux系统默认都只提供ssh登录方式.如果你是一个技术控,非常希望把图形化界面给折腾出来,这其中就不需有vnc server的支持,除此之外,还涉及 ...
- AWS EC2笔记
朋友想搭一个境外网站,找我帮忙,希望服务器.域名都在境外.我没有在境外建站的经历,只能先尝试.于是上网搜索了一下境外服务器,大家比较常用的是Digital Ocean和AWS,我索性打开这两家的官网, ...
- 亚马逊AWS EC2云实例AMI安装LNMP环境(3)——Mysql5.5
概括:这里选择亚马逊EC2的Linux AMI实例,该Linux服务器是亚马逊预配置的Linux环境,内置多个YUM源,属于亚马逊首推的稳定Linux服务器.默认登录用户名为ec2-user,执行ro ...
- mysql转ElasticSearch的案例分析
前言 最近工作中在进行一些技术优化,为了减少对数据库的压力,对于只读操作,在程序与db之间加了一层-ElasticSearch.具体实现是db与es通过bin-log进行同步,保证数据一致性,代码调用 ...
- AWS EC2中部署Apache服务器(LAMP)
关键词: 1.新建aws ec2实例 2.使用putty连接到aws ec2 实例(SSH协议) 3.使用filezilla连接到aws ec2实例(SFTP协议) 4.在aws ec2上部署apac ...
- 将数据从MySQL迁移到Oracle的注意事项
将数据从MySQL迁移到Oracle的注意事项1.自动增长的数据类型处理MYSQL有自动增长的数据类型,插入记录时不用操作此字段,会自动获得数据值.ORACLE没有自动增长的数据类型,需要建立一个自动 ...
- Linux 上从 MySQL 迁移到 MariaDB 的简单步骤
大家好!这是一篇介绍如何在服务器或个人电脑上从MySQL迁移到MariaDB的教程.也许你会问为什么我们要将数据库管理从MySQL迁移到MariaDB.往下看我们告诉你为什么这样做.为什么要用Mari ...
- AWS EC2首次使用VPS
看到AWS有免费一年的试用期,就申请了一个账号.想搭建一个自己的网站.申请之前,你还需要有一张信用卡. 申请AWS账号,登陆控制台 进入AWS官网即可申请账号,进入控制台后,就可以新建一个AWS EC ...
- Amazon AWS EC2开启Web服务器配置
在Amazon AWS EC2申请了一年的免费使用权,安装了CentOS + Mono + Jexus环境做一个Web Server使用. 在上述系统安装好之后,把TCP 80端口开启(iptable ...
随机推荐
- 在服务器端对sshd做白名单
1.添加用户 #useradd aaa #passwd aaa -->输入密码:123456 添加3个用户,bbb和ccc与aaa添加一样 2.添加白名单 #vim /etc/ssd/sshd_ ...
- Leetcode167-Two Sum II Input array is sorted-Easy
Given an array of integers that is already sorted in ascending order, find two numbers such that the ...
- 【Python】【Web开发】
# [[Web开发]] ''' 最早的软件都是运行在大型机上的,软件使用者通过“哑终端”登陆到大型机上去运行软件.后来随着PC机的兴起,软件开始主要运行在桌面上,而数据库这样的软件运行在服务器端,这种 ...
- JS绘制拓扑图示例 (JTopo)
目前在做的项目是渔政的监控,需要用到的设备包括雷达,光电,站点信息等,想要更直观的展现设备之间的连接关系和状态信息,这时候需要画一张拓扑图 在做拓扑图之前,首先要学习一下,html里面另一个比较常用的 ...
- 使用fiddler轻轻松松制造客户端接口time out的情况
1.打开fiddler,过滤出你想要的请求 2.复制出你想要中断的请求 3.设置中断这个请求,bpu+请求,回车(详情请百度fiddle默认命令) 4.ctrl+x(清楚所有的请求),刷新页面,重新获 ...
- P4001 [BJOI2006]狼抓兔子
传送门 思路: 不少题解都是用网络流来做最小割(网络流是什么),但对于一个不会网络流的蒟蒻来做这题相当困难. 听机房daolao说可以重构图做最短路.然后就baidu将平面图转换成一个对偶图,因为网络 ...
- ashx和aspx的区别
1. ashx是一般处理程序,一般返回的数据有两种,一种是html页面,一种是只返回一个字符串. 2. aspx是web窗体程序,每次新建都回自带一个界面和一个后台处理程序. 3. 根据以上两点,可以 ...
- 学习笔记18—circos应用集
一.在线画图(行列分别最大为75) 相信大家都听说过circos图,但是亲自画过的人可能就很少,这主要因为软件的安装和使用稍微有一点麻烦.其实,circos图也是可以在线绘制的,这样就简单多了!一起来 ...
- 全排列问题Ⅰ(Java实现)
给定一个没有重复数字的序列,返回其所有可能的全排列. 示例: 输入: [1,2,3] 输出: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1 ...
- RPG游戏中如何判断敌人是否在玩家的攻击范围之内
// 方式1:通过主角和场景中的所有敌人比较 private void AtkCondition1(float _range,float _angle) { // 搜索所有敌人列表(在动态创建敌人时生 ...