自動化運維是一個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:[email protected]# ################## #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:~/bin export PATH #Check ifuserisroot if[$(id -u)!="0"];then echo"Error:Youmustberoottorun thisscript,pleaseuseroottoinstall" exit1 fi clear echo "=========================================================================" echo "Atooltoauto-compile&installMySQL5.6.25onRedhat/CentOSLinux " echo "=========================================================================" cur_dir=$(pwd) #set mysqlrootpassword echo"===========================" mysqlrootpwd="MANAGER" echo-e"Pleaseinputtherootpasswordofmysql:" read-p"(Defaultpassword:MANAGER):"mysqlrootpwd if["$mysqlrootpwd"=""];then mysqlrootpwd="MANAGER" fi echo"===========================" echo"MySQLrootpassword:$mysqlrootpwd" echo"===========================" #which MySQLVersiondoyouwanttoinstall? echo "===========================" isinstallmysql56="n" echo"InstallMySQL5.6.25,Pleaseinputy" read-p"(Pleaseinputy,n):"isinstallmysql56 case"$isinstallmysql56"in y|Y|Yes|YES|yes|yES|yEs|YeS|yeS) echo"YouwillinstallMySQL5.6.25" isinstallmysql56="y" ;; *) echo"INPUTerror,YouwillexitinstallMySQL5.6.25" isinstallmysql56="n" exit esac get_char() { SAVEDSTTY=`stty-g` stty-echo sttycbreak #ddif=/dev/ttybs=1count=12>/dev/null stty-raw sttyecho stty$SAVEDSTTY } echo"" echo"Pressanykeytostart...orPressCtrl+ctocancel" char=`get_char` # Initializetheinstallationrelated content. function InitInstall() { cat/etc/issue uname-a MemTotal=`free-m|grepMem|awk'{print$2}'` echo-e"\nMemoryis:${MemTotal}MB" #Settimezone rm-rf/etc/localtime ln-s/usr/share/zoneinfo/Asia/Shanghai/etc/localtime #DeleteOldMysqlprogram rpm-qa|grepmysql rpm-emysql #yum-yremovemysql-servermysqlmysql-libs #yum-yremovephp-mysql #yum-yinstallyum-fastestmirror #yum-yupdate #DisableSeLinux if[-s/etc/selinux/config];then sed-i's/SELINUX=enforcing/SELINUX=disabled/g'/etc/selinux/config fi setenforce0 } #Installation ofdependonandoptimizationoptions. function InstallDependsAndOpt() { cd $cur_dir cat >>/etc/security/limits.conf<>/etc/sysctl.conf } #Install MySQL function InstallMySQL56() { echo "============================InstallMySQL 5.6.22==================================" cd $cur_dir #Backup oldmy.cnf #rm-f /etc/my.cnf if[-s /etc/my.cnf];then mv/etc/my.cnf/etc/my.cnf.`date +%Y%m%d%H%M%S`.bak fi #mysql directoryconfiguration groupadd mysql-g512 useradd-u512-gmysql-s/sbin/nologin-d/home/mysqlmysql tarxvf/root/mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz mv/root/mysql-5.6.25-linux-glibc2.5-x86_64/usr/local/mysql mkdir-p/data/mysql mkdir-p/log/mysql chown-Rmysql:mysql/data/mysql chown-Rmysql:mysql/usr/local/mysql chown-Rmysql:mysql/log #edit/etc/my.cnf SERVERID=`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.log CheckAndDownloadFiles2>&1|tee-a/root/mysql-install.log InstallDependsAndOpt2>&1|tee-a/root/mysql-install.log InstallMySQL562>&1|tee-a/root/mysql-install.log CheckInstall2>&1|tee-a/root/mysql-install.log
執行腳本後,輸入用戶名密碼(默認MANAGER)後登錄數據庫成功。
wKioL1fOIHTQR5ktAAElfoh_FOg089.jpg-wh_50
以上所述是小編給大家介紹的生產庫自動化MySQL5.6安裝部署詳細教程,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對幫客之家網站的支持!