Mysql分布式数据库变更自动化部署(一)

2015-07-24 06:09:43 · 作者: · 浏览: 8

MySQL数据库变更自动部署

?

概述:
这个Mysql数据库发布程序,可以自动、快速、并发的发布数据变更并记录结果。把部署内容从部署server传输到所有部署database并执行部署内容。
本程序主要用于分布式数据库部署,比如把一个部署脚本需要同时部署到多台database上。

\

?

?

\

?

测试环境:
deploydb:
[root@deploydb skate]# ll autodeploy
total 36
-rw-r--r-- 1 root root 9378 Feb 26 20:23 autodeploy
-rw-r--r-- 1 root root 120 Feb 26 18:40 autodeploy_config.txt
drwxr-xr-x 2 root root 4096 Feb 26 18:50 ex_dbrelease
drwxr-xr-x 2 root root 4096 Feb 26 18:50 log
drwxr-xr-x 2 root root 4096 Feb 26 18:50 post_dbrelease
[root@deploydb skate]#

目录:
ex_dbrelease:用于存放即将部署的文件
post_dbrelease:已经成功部署的文件
log: 日志文件
autodeploy_config.txt:配置文件
autodeploy: 主程序


部署环境:
1.部署server到database之间ssh可联通的.
2.rsync 被安装在部署server和database
3.数据库部署脚本需要有schema前缀,如:database.tablename


使用步骤:
1.本部署程序只负责部署数据库变更脚本,所以需要自己事先做好备份工作


2.如果你想知道数据库变更前后影响的行数,需要在执行部署内容前后执行“select count (*) from table”(本程序本身也会显示变更影响的行数)


3.编辑配置文件, 配置文件共有三块内容,deployfirst代表部署测试节点,deploynode代表其余部署节点,ftpnode代表部署文件需要被ftp的节点

There are three sections in this configuration file,eg:
[root@deploydb autodeploy]# vi autodeploy_config.txt
[deployfirst]
db1.server
[/deployfirst]


[deploynode]
db2.server
db3.server
[/deploynode]


[ftpnode]
db1.server
db2.server
db3.server
[/ftpnode]


4.把部署文件放到部署server的ex_dbrelease目录下


5.部署文件被并发的ftp到所有指定节点上
eg:

[root@deploydb autodeploy]# sh autodeploy -h
Usage: [-t mode] [-u upload_dir] [-f release_file] [-r retention_time]
-t Operatation mode(ftp/deploy)
-f Release file
-h Display basic help


[root@deploydb autodeploy]# sh autodeploy -t ftp

Please confirm that you have put the FTP into directory /home/skate/autodeploy/ex_dbrelease [Y/N]: Y

The following is the transmitted release file:
********************************
t1.sql
********************************
Are you sure you want to upload the above files to all specified nodes[Y/N]? Y
[t1.sql] is transferd to dfng1db4.se2 success.

ALL release files are transferd to all specified nodes
[root@deploydb autodeploy]#

The command with ftp parameter will transfer all release files from directory ex_dbrelease.

6.尝试部署一个节点,如果成功则会自动部署到剩余节点上

eg:
[root@deploydb autodeploy]# sh autodeploy -t deploy -f t1.sql
*************************************************
[2015-02-26 18:49:48]: Preparing to deploy t1.sql to [dfng1db4.se2]...
*************************************************
You deployed success this file ago on first node,Please delete file [/home/skate/autodeploy/issucess] if you want to continue.
[root@deploydb autodeploy]# rm /home/skate/autodeploy/issucess
rm: remove regular file `/home/skate/autodeploy/issucess'? y

[root@deploydb autodeploy]# sh autodeploy -t deploy -f t1.sql
*************************************************
[2015-02-26 18:50:22]: Preparing to deploy t1.sql to [dfng1db4.se2]...
*************************************************
Warning: Using a password on the command line interface can be insecure.
[2015-02-26 18:50:22]: The release file [t1.sql] have been deployed to dfng1db4.se2 success.
The detail you refer to [/home/skate/autodeploy/log/deploy_201502261850_deploy.log].
Are you sure you want to continut deploy to remaining nodes[Y/N]? Y
Warning: Using a password on the command line interface can be insecure.
[t1.sql] is deployed success on all special nodes,the detail you refer to [/home/skate/autodeploy/log/deploy_201502261850_deploy.log]
[root@deploydb autodeploy]#


Questions:
1.部署文件已经被成功