Inception是集审核、执行、回滚于一体的一个SQL自动化运维系统,基于MySQL代码修改,官方文档地址:https://mysql-inception.github.io/inception-document/

一、Inception部署篇

官方部署说明:https://mysql-inception.github.io/inception-document/install/

我的环境:centos7.4

我的安装步骤:

1. 安装依赖

yum -y install gcc gcc-c++ make cmake openssl-devel ncurses-devel perl unzip m4 MySQL-python perl-ExtUtils-Embed perl-DBI perl-DBD-MySQL perl-Digest-MD5 perl-Data-Dumper

(Ubuntu下执行apt-get install cmake libncurses5-dev libssl-dev g++ m4,没有perl的话也要安装)

2. 安装bison,官方建议2.6版本之前

wget -c https://static.saintic.com/download/inception/bison-2.5.1.tar && tar xf bison-2.5.1.tar && cd bison-2.5.1 && ./configure && make && make install

3. 安装percona-toolkit,在线修改大表用的工具

wget -c https://static.saintic.com/download/inception/percona-toolkit-2.2.20.tar.gz && tar zxf percona-toolkit-2.2.20.tar.gz && cd percona-toolkit-2.2.20 && perl Makefile.PL && make install

4. 安装主程序inception

git clone https://github.com/mysql-inception/inception && cd inception

编译inception可以用官方的方法,sh inception_build.sh,也可以cmake编译,我这里用cmake演示(因为后面docker编译用cmake没有问题)。

cmake -DWITH_DEBUG=OFF -DCMAKE_INSTALL_PREFIX=/Inception -DMYSQL_DATADIR=/Inception/data -DWITH_SSL=bundled -DCMAKE_BUILD_TYPE=RELEASE -DWITH_ZLIB=bundled -DMY_MAINTAINER_CXX_WARNINGS="-Wall -Wextra -Wunused -Wno-dev -Wwrite-strings -Wno-strict-aliasing -Wno-unused-parameter -Woverloaded-virtual" -DMY_MAINTAINER_C_WARNINGS="-Wall -Wextra -Wno-dev -Wunused -Wwrite-strings -Wno-strict-aliasing -Wdeclaration-after-statement" && make && make install

注意红色部分,编译好的程序目录即可,可执行命令在这目录的bin下。

5. 启动

/Inception/bin/Inception --defaults-file=/etc/inception.cnf   #此配置文件参见底部附录

二、Docker镜像

上述过程已经被我打包成镜像,基于centos7.4,可以直接使用,镜像支持OSC,默认配置文件为官方推荐配置(参见底部附录),可以自定义挂载覆盖/etc/inception.cnf,默认了以下参数可以设置环境变量:

bind_address,默认127.0.0.1。
port,默认6669
inception_support_charset,字符集,默认utf8mb4
inception_remote_backup_host,远程备份服务器的地址
inception_remote_backup_port,远程备份服务器的端口
inception_remote_system_user,远程备份服务器的用户
inception_remote_system_password,远程备份服务器的密码
inception_osc_on, 是否开启osc,1是开启,0是关闭(默认)
  1. 拉取镜像

    docker pull registry.cn-beijing.aliyuncs.com/staugur/inception:v0.1

  2. 运行镜像(可以跳过第一步,此处假定远程备份地址127.0.0.1,端口3306,账号root,密码123456)

    docker run -tdi –name inception -e bind_address=0.0.0.0 -e port=6669 -e inception_remote_backup_host=127.0.0.1 -e inception_remote_backup_port=3306 -e inception_remote_system_user=root -e inception_remote_system_password=123456 –net=host registry.cn-beijing.aliyuncs.com/staugur/inception:v0.1

  3. 查看日志:docker logs inception

    The inception listens for 0.0.0.0:6669

    2018-07-19 03:40:15 0 [Note] Welcome to use Inception2.1.50

    2018-07-19 03:40:15 6 [Note] Server hostname (bind-address): ‘0.0.0.0’; port: 6669

    2018-07-19 03:40:15 6 [Note] - ‘0.0.0.0’ resolves to ‘0.0.0.0’;

    2018-07-19 03:40:15 6 [Note] Server socket created on IP: ‘0.0.0.0’.

三、访问

使用mysql命令即可,需要指定inception的ip地址和端口,如mysql \-h127.0.0.1 \-P6669

登录成功界面如下图,此时执行 inception get variables; 命令可以获取系统参数。

QQ截图20180719114556

四、附录

1. 配置文件/etc/inception.cnf

此配置文件基本是官方参数默认值,docker运行时可以使用 -v 你的配置文件:/etc/inception.cnf 覆盖它。

官方参数文档地址:https://mysql-inception.github.io/inception-document/variables/

配置文件内容如下($变量请在在docker运行时覆盖):

[inception]
general_log=1
general_log_file=/var/log/inception.log
#这个参数实际上就是MySQL数据库原来的参数,因为Incpetion没有权限验证过程,那么为了实现更安全的访问,可以给Inception服务器的这个参数设置某台机器(Inception上层的应用程序)不地址,这样
#其它非法程序是不可访问的,那么再加上Inception执行的选项中的用户名密码,对MySQL就更加安全
bind_address=$bind_address
port=$port
socket=/var/run/inception.socket
character-set-client-handshake=0
character-set-server=utf8

#备份相关
#需要开启binlog
inception_remote_system_password=$inception_remote_system_password
inception_remote_system_user=$inception_remote_system_user
inception_remote_backup_port=$inception_remote_backup_port
inception_remote_backup_host=$inception_remote_backup_host

#在DML语句中没有WHERE条件时,是不是要报错
inception_check_dml_where=1
#在DML语句中使用了LIMIT时,是不是要报错
inception_check_dml_limit=1
#在DML语句中使用了Order By时,是不是要报错
inception_check_dml_orderby=1
#Select*时是不是要报错
inception_enable_select_star=1
#order by rand时是不是报错
inception_enable_orderby_rand=1
#创建或者新增列时如果列为NULL,是不是报错
inception_enable_nullable=1
#是不是支持外键
inception_enable_foreign_key=1
#一个索引中,列的最大个数,超过这个数目则报错(1-64)
inception_max_key_parts=5
#在一个修改语句中,预计影响的最大行数,超过这个数就报错(1-max)
inception_max_update_rows=10000
#一个表中,最大的索引数目,超过这个数则报错(1-1024)
inception_max_keys=16
#建表指定的存储引擎不为Innodb,不报错
inception_enable_not_innodb=0
#表示在建表或者建库时支持的字符集,如果需要多个,则用逗号分隔,影响的范围是建表、设置会话字符集、修改表字符集属性等
inception_support_charset=$inception_support_charset
#建表时,表没有注释时报错
inception_check_table_comment=1
#建表时,列没有注释时报错
inception_check_column_comment=1
#建表时,如果没有主键,则报错
inception_check_primary_key=1
#是不是支持分区表
inception_enable_partition_table=0
#是不是支持enum,set,bit数据类型
inception_enable_enum_set_bit=0
#是不是要检查索引名字前缀为"idx_",检查唯一索引前缀是不是"uniq_"
inception_check_index_prefix=1
#自增列是不是要为无符号型
inception_enable_autoincrement_unsigned=1
#当char类型的长度大于这个值时,就提示将其转换为VARCHAR(1-max)
inception_max_char_length=16
#当建表时自增列的值指定的不为1,则报错
inception_check_autoincrement_init_value=1
#当建表时自增列的类型不为int或者bigint时报错
inception_check_autoincrement_datatype=1
#建表时,如果没有为timestamp类型指定默认值,则报错
inception_check_timestamp_default=0
#允许列自己设置字符集
inception_enable_column_charset=0
#建表时,如果指定的自增列的名字不为ID,则报错,说明是有意义的,给提示
inception_check_autoincrement_name=1
#在多个改同一个表的语句出现时,报错,提示合成一个
inception_merge_alter_table=1
#检查在建表、修改列、新增列时,新的列属性是不是要有默认值
inception_check_column_default_value=1
#检查是不是支持BLOB字段,包括建表、修改列、新增列操作
inception_enable_blob_type=1
#检查在SQL语句中,是不是有标识符被写成MySQL的关键字,默认值为报警。
inception_enable_identifer_keyword=1
#这个参数的作用是为了匹配Python客户端每次自动设置auto_commit=0的,如果取消则会报错,针对Inception本身没有实际意义
#auto_commit=0

#打开与关闭Inception对SQL语句中各种名字的检查,如果设置为ON,则如果发现名字中存在除数字字母下划线之外的字符时,报Identifier "invalidname" is invalid, valid options: [a-z,A-Z,0-9,_].
inception_check_identifier=1

#开启对OSC的支持
inception_osc_on=$inception_osc_on
inception_osc_bin_dir=/usr/local/bin/pt-online-schema-change

·End·