自动化运维是一个DBA应该掌握的技术,其中,自动化安装数据库是一项基本的技能,本文中的安装脚本已通过测试,作为生产库来说没有问题,鉴于每个公司存储规划要求不同,可以按需自行修改脚本。
脚本中已经注释说明一些基本的安装信息
本脚本默认启用5.6部分新特性
innodb_buffer_pool_dump_at_shutdown=1 它dump的不是数据,是Id号innodb_buffer_pool_load_at_startup=1 |
开启这个两个参数当数据库重启后把这些热数据重新加载回去
只有正常关库才会dump热数据块,宕机和kill -9不会
部分参数按需整改,例如innodb_buffer_pool_size = 512M,本文给的512M,一般给内存的50%-80%。
来看一下脚本的具体情况[root@HE3 ~]# cat mysql_auto_install.sh
######二进制自动安装数据库脚本root密码MANAGER将脚本和安装包放在/root目录即可#####################数据库目录/usr/local/mysql##################数据目录/data/mysql##################日志目录/log/mysql##################端口号默认3306其余参数按需自行修改###############################author:rrhelei@126.com####################!/bin/bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:~/binexportPATH#Checkifuserisrootif[$(id-u)!="0"];thenecho"Error:Youmustberoottorunthisscript,pleaseuseroottoinstall"exit1ficlearecho"========================================================================="echo"Atooltoauto-compile&installMySQL5.6.25onRedhat/CentOSLinux"echo"========================================================================="cur_dir=$(pwd)#setmysqlrootpasswordecho"==========================="mysqlrootpwd="MANAGER"echo-e"Pleaseinputtherootpasswordofmysql:"read-p"(Defaultpassword:MANAGER):"mysqlrootpwdif["$mysqlrootpwd"=""];thenmysqlrootpwd="MANAGER"fiecho"==========================="echo"MySQLrootpassword:$mysqlrootpwd"echo"==========================="#whichMySQLVersiondoyouwanttoinstall?echo"==========================="isinstallmysql56="n"echo"InstallMySQL5.6.25,Pleaseinputy"read-p"(Pleaseinputy,n):"isinstallmysql56case"$isinstallmysql56"iny|Y|Yes|YES|yes|yES|yEs|YeS|yeS)echo"YouwillinstallMySQL5.6.25"isinstallmysql56="y";;*)echo"INPUTerror,YouwillexitinstallMySQL5.6.25"isinstallmysql56="n"exitesacget_char(){SAVEDSTTY=`stty-g`stty-echosttycbreak#ddif=/dev/ttybs=1count=12>/dev/nullstty-rawsttyechostty$SAVEDSTTY}echo""echo"Pressanykeytostart...orPressCtrl+ctocancel"char=`get_char`#Initializetheinstallationrelatedcontent.functionInitInstall(){cat/etc/issueuname-aMemTotal=`free-m|grepMem|awk'{print$2}'`echo-e"/nMemoryis:${MemTotal}MB"#Settimezonerm-rf/etc/localtimeln-s/usr/share/zoneinfo/Asia/Shanghai/etc/localtime#DeleteOldMysqlprogramrpm-qa|grepmysqlrpm-emysql#yum-yremovemysql-servermysqlmysql-libs#yum-yremovephp-mysql#yum-yinstallyum-fastestmirror#yum-yupdate#DisableSeLinuxif[-s/etc/selinux/config];thensed-i's/SELINUX=enforcing/SELINUX=disabled/g'/etc/selinux/configfisetenforce0}#Installationofdependonandoptimizationoptions.functionInstallDependsAndOpt(){cd$cur_dircat>>/etc/security/limits.conf<>/etc/sysctl.conf}#InstallMySQLfunctionInstallMySQL56(){echo"============================InstallMySQL5.6.22=================================="cd$cur_dir#Backupoldmy.cnf#rm-f/etc/my.cnfif[-s/etc/my.cnf];thenmv/etc/my.cnf/etc/my.cnf.`date+%Y%m%d%H%M%S`.bakfi#mysqldirectoryconfigurationgroupaddmysql-g512useradd-u512-gmysql-s/sbin/nologin-d/home/mysqlmysqltarxvf/root/mysql-5.6.25-linux-glibc2.5-x86_64.tar.gzmv/root/mysql-5.6.25-linux-glibc2.5-x86_64/usr/local/mysqlmkdir-p/data/mysqlmkdir-p/log/mysqlchown-Rmysql:mysql/data/mysqlchown-Rmysql:mysql/usr/local/mysqlchown-Rmysql:mysql/log#edit/etc/my.cnfSERVERID=`ifconfigeth0|grep"inetaddr"|awk'{print$2}'|awk-F.'{print$4"3306"}'`cat>>/etc/my.cnf<>/etc/ld.so.conf.d/mysql-x86_64.conf<>/etc/profile</tmp/mysql_sec_script<&1|tee/root/mysql-install.logCheckAndDownloadFiles2>&1|tee-a/root/mysql-install.logInstallDependsAndOpt2>&1|tee-a/root/mysql-install.logInstallMySQL562>&1|tee-a/root/mysql-install.logCheckInstall2>&1|tee-a/root/mysql-install.log |