上一节已经完成了TokuDB数据库引擎的配置过程,回顾一下操作:
1 停掉mysql服务 2 目录创建 3 文件移动 4 修改/etc/my.cnf配置文件 5 重启mysql
系列的操作,还是挺多的,可以脚本化来完成,今天就完成了这样一个脚本,以简化MySQL的配置操作。
按照手动操作的流程,编写脚本,先备份my.cnf后向其中写入标准的配置。需要注意的是需要找到malloc-lib的配置信息,再写入其中。
创建一个tokudb_varset.sh脚本如下:
#!/bin/sh #stop mysql service mysql stop #make directory of tokudb mkdir -p /usr/tokudb/data mkdir -p /usr/tokudb/log mkdir -p /usr/tokudb/temp chown -R mysql:mysql /usr/tokudb/ #move tokudb file to tokudb directory cd /var/lib/mysql mv __tokudb_lock_dont_delete_me_data /usr/tokudb/data mv __tokudb_lock_dont_delete_me_environment /usr/tokudb/data mv __tokudb_lock_dont_delete_me_temp /usr/tokudb/temp mv __tokudb_lock_dont_delete_me_logs /usr/tokudb/log mv __tokudb_lock_dont_delete_me_recovery /usr/tokudb/log #move other log file to log directory logFile=$(find . -name log*.tokulog*) mv $logFile /usr/tokudb/log # find malloc-lib malloclib=$(more /etc/my.cnf | grep 'malloc-lib=' | awk -F= '{print $2}') #backup /etc/my.cnf #create new /etc/my.cnf and write new configurations mv /etc/my.cnf /etc/my.cnf.bak -f #edit /etc/my.cnf and set tokudb dir variables #standard my.cnf file is like this cat <<end>>/etc/my.cnf # # The Percona Server 5.7 configuration file. # # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # Please make any edits and changes to the appropriate sectional files # included below. # !includedir /etc/my.cnf.d/ !includedir /etc/percona-server.conf.d/ [mysqld] character_set_server=utf8 max_allowed_packet=16M max_connections=256 tokudb_directio=ON tokudb_commit_sync=OFF tokudb_fsync_log_period=1000 tokudb_row_format=tokudb_zlib tokudb_data_dir=/usr/tokudb/data tokudb_log_dir=/usr/tokudb/log tokudb_tmp_dir=/usr/tokudb/temp [mysqld_safe] malloc-lib=$malloclib end chmod 755 /etc/my.cnf #start mysql service mysql start保存后,在安装好TokuDB引擎之后,就可以执行该脚本,完成相关的配置操作了。
shell脚本真的很方便,是解放双手、复用操作的好工具。简单重复的操作,想想能不能用脚本来实现,既能锻炼shell编程的能力,也能简化配置流程。
这是本人第二次写自动化配置脚本,好处颇多,尤其是放在部署文档中,极大地方便测试人员进行环境部署,省了我很多时间。