MySQL5.6一键部署
# 快速部署单节点MySQL脚本
# 执行方式:将MySQL包,my3302.cnf配置文件,dbtool脚本文件放到一个目录下。然后按照脚本执行就可以。配置文件提前修改好。文章最后附上my.cnf配置文件内容
# 环境:
# Linux:CentOS release 6.6 (Final)
# mysql: Percona-Server-5.6.32-rel78.0-Linux.x86_64.ssl098e.tar.gz # 下载地址 : https://www.percona.com/downloads/Percona-Server-5.6/LATEST/
# 简介:脚本中每一步都定义的函数,通过:./dbtool port cmd 格式 来调用。port:MySQL端口;cmd 每个函数的调用命令简写。例如:./dbtool 3002 sd 启动mysql.
# 大家可以根据需要在下面追加函数,定义功能。比如:mysql的启动、停止、登录。
# 该脚本提供一种思路,大家可以自己扩展
# 脚本名:dbtool
#!/bin/sh
#
PORT=$
Instance_Name="inst01" #实例名:多实例时目录层的区分标志
CMD="$2"
DB_DIR="/data/mysql" # MySQL相关目录文件,本脚本为了方便都放一起了;data和log可以放到单独的分区里
Current_dir=`pwd` INSTALL_RPM()
{
rpmlist="openssl-devel.x86_64 \
openssl098e.x86_64 \
openssl.x86_64 \
readline.x86_64 \
readline-devel.x86_64 \
crypto-utils.x86_64 \
perl-DBD-MySQL.x86_64 \
perl-IO-Socket-SSL.noarch"
echo
echo '------------------------------------------'
echo 'Install rpm :'
echo
for str in ${rpmlist};
do
rpm -qa|grep ${str%.*}>>/dev/null && echo "Installed : "${str} || \
(yum install -y ${str} >> /dev/null && echo "Installed : "${str} )
done
echo
echo '------------------------------------------'
echo
} ADD_USER()
{
echo
echo '------------------------------------------'
groupadd mysql && useradd -g mysql mysql >/dev/null
echo "id mysql :"
id mysql
echo '------------------------------------------'
} MK_DIR()
{
Dir_data="${DB_DIR}/mysqlData/${Instance_Name}"
Dir_log="${DB_DIR}/mysqlLog/${Instance_Name}"
Dir_socket="${DB_DIR}/socket"
Dir_conf="${DB_DIR}/config"
echo '--------------------------------------------'
if [ ! -d "${DB_DIR}" ];then
mkdir -pv ${DB_DIR}
fi mkdir -pv $Dir_data/{data,tmp}
mkdir -pv $Dir_log/logs
mkdir -pv $Dir_socket
mkdir -pv $Dir_conf
echo
echo '[ show dirs : ]'
ls -lh ${DB_DIR}
echo '---------------------------------------------------------'
echo
} TAR_MYSQL()
{
echo '---------------------------------------------------------'
PerconaName=`ls ${Current_dir} |grep Percona-Server`
PerconaVerson=`echo ${PerconaName}|awk -F'-' '{print $3}'|sed 's#\.##g'`
tar -xf ${PerconaName}
mv ${PerconaName%.tar*} percona${PerconaVerson}
ln -s ${Current_dir}/percona${PerconaVerson} /usr/local/mysql
echo '---------------------------------------------------------'
} MOD_CONF()
{
echo '---------------------------------------------------------'
mv ${Current_dir}/my${PORT}.cnf ${DB_DIR}/config/
ls -lh ${DB_DIR}/config/
echo '---------------------------------------------------------'
} GRANT_DIR()
{
echo '---------------------------------------------------------'
chown -R mysql.mysql ${DB_DIR}
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql/
echo '---------------------------------------------------------'
} SET_PATH()
{
echo
echo '---------------------------------------------------------'
echo 'export PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile
cat /etc/profile|grep '/usr/local/mysql/bin'
echo
echo '---------------------------------------------------------'
} INITIALIZE_DB()
{
echo
echo '---------------------------------------------------------'
cd /usr/local/mysql/
./scripts/mysql_install_db --defaults-file=${DB_DIR}/config/my${PORT}.cnf --user=mysql
echo '---------------------------------------------------------'
} START_DB()
{
echo '---------------------------------------------------------'
cd /usr/local/mysql
./bin/mysqld_safe --defaults-file=${DB_DIR}/config/my${PORT}.cnf --user=mysql &
sleep
echo
echo "Check :"
echo "[ps -ef|grep mysql]"
ps -ef|grep mysql
echo "[netstat -ntpl|grep mysql]"
netstat -ntpl|grep mysql echo '---------------------------------------------------------'
} FIRST_LOGIN()
{
echo '---------------------------------------------------------'
echo "Press Enter"
mysql -uroot -p -S ${DB_DIR}/socket/mysql${PORT}.sock -e"delete from mysql.user where host !='localhost' or user=''"
echo "Press Enter"
mysql -uroot -p -S ${DB_DIR}/socket/mysql${PORT}.sock -e"select user,host,password from mysql.user"
echo
echo
echo '---------------------------------------------------------'
} HELP()
{
echo "---------------------------------------------------------------"
printf "%-50s\n" "+ ToolName : dbtool "
printf "%-50s\n" "+ ToolDesc : install single mysql"
printf "%-50s\n" "+ Authors : Chris" printf "%-50s\n" "+ Help:"
printf "%-50s\n" "For example:"
printf "%-50s\n" "+ [root@monitor data]# ./dbtool 3002 in" printf "%-50s\n" "+ Parameter: "
printf "%-50s\n" "+ ir --install rpm for mysql"
printf "%-50s\n" "+ au --add user : mysql "
printf "%-50s\n" "+ md --mkdir "
printf "%-50s\n" "+ tm --tar -xf mysql.xx.tar.gz"
printf "%-50s\n" "+ mc --mv myxx.cnf to config_file"
printf "%-50s\n" "+ gd --grant to dirs"
printf "%-50s\n" "+ sp --set environment"
printf "%-50s\n" "+ in --initialization mysql"
printf "%-50s\n" "+ sd --start mysql"
printf "%-50s\n" "+ fg --first login mysql and delete unuserd users"
echo "---------------------------------------------------------------" } if [ $# -eq ];then
case $ in
'install_rpm'|'ir')
INSTALL_RPM
;;
'add_user'|'au')
ADD_USER
;;
'mk_dir'|'md')
MK_DIR
;;
'tar_mysql'|'tm')
TAR_MYSQL
;;
'mv_conf'|'mc')
MOD_CONF
;;
'grant_dir'|'gd')
GRANT_DIR
;;
'set_path'|'sp')
SET_PATH
;;
'initialization_db'|'in')
INITIALIZE_DB
;;
'start_db'|'sd')
START_DB
;;
'firstlogin'|'fg')
FIRST_LOGIN
;;
'install'|'install') # 一键部署
INSTALL_RPM
ADD_USER
MK_DIR
TAR_MYSQL
MOD_CONF
GRANT_DIR
SET_PATH
INITIALIZE_DB
START_DB
FIRST_LOGIN
;;
*)
HELP
;;
esac
else
HELP
exit
fi
附件:myxx.cnf
注意:innodb_buffer_pool需要更加实际内存情况设置
[client]
port =
socket = /data/socket/mysql3002.sock # The MySQL server
[mysqld]
server-id =
port =
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/mysqlData/inst01/data
tmpdir = /data/mysql/mysqlData/inst01/tmp
socket = /data/mysql/socket/mysql3002.sock
pid-file = /data/mysql/socket/mysql3002.pid
log-bin = /data/mysql/mysqlLog/inst01/logs/mysql-bin
log-error = /data/mysql/mysqlLog/inst01/err.log
slow_query_log_file =/data/mysql/mysqlLog/inst01/slow.log
binlog_format=mixed
#log_short_format
#log-slave-updates
slow_query_log
long_query_time=
wait_timeout=
interactive_timeout=
max_connections=
character_set_server=utf8
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache =
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size =
query_cache_size = 32M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency =
#skip-networking
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
replicate_ignore_db=mysql
replicate_ignore_db=information_schema
expire-logs-days=
skip-slave-start # InnoDB
innodb_data_home_dir = /data/mysql/mysqlData/inst01/data
innodb_log_group_home_dir = /data/mysql/mysqlLog/inst01/logs
innodb_data_file_path = ibdata1:10M:autoextend
innodb_buffer_pool_size = 256M
innodb_additional_mem_pool_size = 5M
innodb_log_file_size = 10M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit =
innodb_lock_wait_timeout =
innodb_file_per_table [mysqldump]
quick
max_allowed_packet = 16M [mysql]
#no-auto-rehash
auto-rehash
[myisamchk]
key_buffer_size = 256K
sort_buffer_size = 256K
read_buffer = 256K
write_buffer = 256K [mysqlhotcopy]
interactive-timeout
MySQL5.6一键部署的更多相关文章
- windows一键部署java项目
windows一键部署java项目 因为公司需求,要在windows的环境上做一键部署启动java项目,同时还要支持从安装界面动态修改配置文件的IP地址.就像安装软件一样将jdk,tomcat,mys ...
- Docker Compose 一键部署LNMP
Docker Compose 一键部署LNMP 目录结构 [root@localhost ~]# tree compose_lnmp/ compose_lnmp/ ├── docker-compose ...
- Shell脚本一键部署——源码编译安装MySQL及自动补全工具
Shell脚本一键部署--源码编译安装MySQL及自动补全工具 编译安装MySQL 1.软件包 Mysql安装包 将安装包拖至/opt目录下,编辑一个脚本文件,将以下内容复制进去,然后source或者 ...
- 一键部署mysql 无修改直接cp 执行 100% 有效
一键部署mysql 无修改直接cp 执行 100% 有效 将安装包拖至/opt目录下,编一个脚本文件,然后source执行脚本,等脚本执行完成, 即可使用mysql -u root -p点击 ...
- 一键部署lnmp
一键部署lnmp 提前将nginx .mysql .php 所需安装包都放在/opt目录下 脚本启动结束时,重启一下nginx 服务,就能在火狐浏览器更新出php测试页 脚本如下:(脚本里的软件 ...
- 一键部署lamp 脚本
一键部署lamp 脚本 如下: #!/bin/bash systemctl stop firewalld systemctl disable firewalld setenforce 0 #----- ...
- mac通过docker一键部署MySQL8
目录 mac通过docker一键部署MySQL8 一.前言 二.系统配置 三.安装步骤 Dockerhub查看镜像地址 1.一键安装 1.1.克隆脚本 1.2.安装程序 1.2.1.安装程序详情 1. ...
- 如何自动化一键部署PHP项目
1.技能需求 完成自动化一键部署PHP需要:PHP(略懂),Shell(略懂),git(略懂) 2.最终效果 输入密码,回车,5~20秒后(一般一天一次持续交付,部署的代码量和sql脚本都不会很大) ...
- Ubantu16.04一键部署Cacti监控服务器
Ubantu16.04一键部署Cacti监控服务器 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 欢迎加入高级运维工程师之路:598432640 一.查看系统环境(关于该系统的安装 ...
随机推荐
- poj 2386:Lake Counting(简单DFS深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18201 Accepted: 9192 De ...
- Linux shell(. /path/filename)
在 /etc/profile 文件中,有一段脚本: if [ -f /etc/bash.bashrc ]; then . /etc/bash.bashrc fi 这里的 “点号 + 空格 + 文件” ...
- iOS-setNeedsLayout等布局方法
列举下iOS layout的相关方法: layoutSubviews layoutIfNeeded setNeedsLayout setNeedsDisplay drawRect sizeThatFi ...
- 《Sqlserver》通过端口 8080 连接到主机 localhost 的 TCP/IP 连接失败。错误:“驱动程序收到意外的登录前响应。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受
1. 点击 开始 --> 所有程序 --> Microsoft SQL Server2005 --> 配置工具-->SQL Server configuration Manag ...
- 洛谷oj U3936(分成回文串) 邀请码:a0c9
题目链接:传送门 题目大意:略 题目思路:DP 先预处理,分别以每个字母为中心处理能形成的回文串,再以两个字母为中心处理能形成的回文串. 然后 dp[i] 表示1~i 能形成的数目最少的回文串. 转移 ...
- cordova添加android平台时选择安装版本: requirements check failed for jdk 1.8
提示如上: 因为android-24 需要 jdk1.8 ,这里指定 android@5.1.1 即可 android-23,如下图
- 【BZOJ2212】[Poi2011]Tree Rotations 线段树合并
[BZOJ2212][Poi2011]Tree Rotations Description Byteasar the gardener is growing a rare tree called Ro ...
- 【BZOJ3798】特殊的质数 分块打表
[BZOJ3798]特殊的质数 Description 求[A,B]之间的质数个数,并且满足X=Q^2+P^2,P,Q是正整数. Input 第一行输入A,B Output 输出有多少组P,Q满足条件 ...
- POJ 2609 Ferry Loading(双塔DP)
Ferry Loading Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1807 Accepted: 509 Sp ...
- 解决----------“win10,不能打字了,已禁用IME”
登录Windows 10系统桌面后,右键点击左下角的开始菜单图标,然后在弹出菜单中选择“计算机管理”菜单项在打开的“计算机管理”窗口中,找到左侧系统工具下的“任务计划程序”菜单项点击任务计划程序前面的 ...