当前位置:主页 > 数据库 > Mysql >

生产库自动化MySQL5.6安装部署详细教程

时间:2023-03-21 09:48:07 | 栏目:Mysql | 点击:

自动化运维是一个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/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

您可能感兴趣的文章:

相关文章