#!/bin/bash
function help()
(
cat << EOF
$ [-h]
$ -c <CharaterSet>
EOF
exit
)
-------------------------------------------
# 判断用户是否存在,不存在就新增mysql用户

check_and_add_user()
{
# create a user if the specified user doesn't exists
local userCnt
userCnt=$(cat /etc/passwd|grep ${MYSQL_USER}|grep -v grep|wc -l)
if [ ${userCnt} -eq ];then
/usr/sbin/groupadd ${MYSQL_GROUP}
/usr/sbin/useradd ${MYSQL_USER} -g ${MYSQL_GROUP}
echo "user ${MYSQL_USER} added"
else
echo "user ${MYSQL_USER} already exists, skipping this step !"
fi
userCnt=$(cat /etc/passwd|grep ${AGENT_USER}|grep -v grep|wc -l)
if [ ${userCnt} -eq ];then
/usr/sbin/groupadd ${AGENT_GROUP}
/usr/sbin/useradd -s /bin/false -g ${AGENT_GROUP} ${AGENT_USER}
echo "user ${AGENT_USER} added"
else
echo "user ${AGENT_USER} already exists, skipping this step !"
fi
} 运行结果如下:
check rpm done at Tue Jan :: CST
...... check user ......starting at Tue Jan :: CST
user mysql added
user agent added
check user done at Tue Jan :: CST
----------------------------------------------------
#检查目录是否新建,若无则建立目录:
/data/mysql_data,/data/mysql_data/binlog,/data/mysql_data/tmpdir check_directory()
{
# get DATA directory
get_data_dir
if [ -d ${DATA_DIR} ];then
echo "directory ${DATA_DIR} already exists, please check and remove this directory and rerun this script "
echo "exiting "
echo "mysql installation failed !"
exit
fi mkdir -p ${INSTALL_DIR}
mkdir -p ${DATA_DIR}/binlog
mkdir -p ${DATA_DIR}/tmpdir
} 运行结果如下:
...... check directory ......starting at Tue Jan :: CST
check directory done at Tue Jan :: CST
...... install mysql ......starting at Tue Jan :: CST
------------------------------------------ get_data_dir()
{
for DF in $(df -h|awk '{print $6}'|grep -e "^/");do
if [ ${DF} == "${DIR_KEY}" ];then
DATA_DIR=${DF}/$(basename ${DATA_DIR})
TOTAL_SIZE=$(df -k|awk '$6== "'${DIR_KEY}'" {print $2}') # DIR_KEY="/data1" 这个变量先已经定义了
break
else
TOTAL_SIZE=$(df -k|awk '$6== "/data" {print $2}')
fi
done
} ----------------------------------------------------------------------------------------------------
# 安装基础依赖包:gcc gcc-c++ make cmake autoconf automake ncurses-devel bison perl-Number-Format perl-Statistics-Descriptive perl-TermReadKey perl-DBD-MySQL perl-Statistics-Basic perl-Sys-Statistics-Linux perl perl-devel libaio libaio-devel perl-Time-HiRes numactl.x86_64 libev.x86_64 perl-IO-Socket-
SSL bc

check_rpm()
{
rmpList=(gcc gcc-c++ make cmake autoconf automake ncurses-devel bison perl-Number-Format perl-Statistics-Descriptive perl-TermReadKey perl-DBD-MySQL perl-Statistics-Basic perl-Sys-Statistics-Linux perl perl-devel libaio libaio-devel perl-Time-HiRes numactl.x86_64 libev.x86_64 perl-IO-Socket-SSL bc)
for thisRpm in ${rmpList[*]};do
installFlag=$(rpm -q ${thisRpm}|grep "not installed"|wc -l)
if [ ${installFlag} -ne ];then
echo "${thisRpm} not installed"
yum install -y ${thisRpm}
fi
done
} 安装结果如下:
...... check rpm ......starting at Tue Jan :: CST cmake not installed
Installed:
cmake.x86_64 :2.8.12.2-.el6
Dependency Installed:
libarchive.x86_64 :2.8.-.el6_8 perl-Number-Format not installed
Installed:
perl-Number-Format.noarch :1.73-.el6 perl-Statistics-Descriptive not installed
Installed:
perl-Statistics-Descriptive.noarch :3.0200-.el6 perl-TermReadKey not installed
Installed:
perl-TermReadKey.x86_64 :2.30-.el6 perl-DBD-MySQL not installed
Installed:
perl-DBD-MySQL.x86_64 :4.013-.el6
Dependency Installed:
perl-DBI.x86_64 :1.609-.el6 perl-Statistics-Basic not installed
Installed:
perl-Statistics-Basic.noarch :1.6611-.el6 perl-Sys-Statistics-Linux not installed
Installed:
perl-Sys-Statistics-Linux.noarch :0.59-.el6 Dependency Installed:
perl-Time-HiRes.x86_64 :1.9721-.el6 Dependency Updated:
perl.x86_64 :5.10.-.el6 perl-Compress-Raw-Zlib.x86_64 :2.021-.el6 perl-Compress-Zlib.x86_64 :2.021-.el6
perl-IO-Compress-Base.x86_64 :2.021-.el6 perl-IO-Compress-Zlib.x86_64 :2.021-.el6 perl-Module-Pluggable.x86_64 :3.90-.el6
perl-Pod-Escapes.x86_64 :1.04-.el6 perl-Pod-Simple.x86_64 :3.13-.el6 perl-libs.x86_64 :5.10.-.el6
perl-version.x86_64 :0.77-.el6 perl-devel not installed
Installed:
perl-devel.x86_64 :5.10.-.el6
Dependency Installed:
perl-ExtUtils-MakeMaker.x86_64 :6.55-.el6 perl-ExtUtils-ParseXS.x86_64 :2.2003.-.el6 perl-Test-Harness.x86_64 :3.17-.el6 libaio-devel not installed
Installed:
libaio-devel.x86_64 :0.3.-.el6 libev.x86_64 not installed
Installed:
libev.x86_64 :4.03-.el6 perl-IO-Socket-SSL not installed
Installed:
perl-IO-Socket-SSL.noarch :1.31-.el6_8.
Dependency Installed:
perl-Net-LibIDN.x86_64 :0.12-.el6 perl-Net-SSLeay.x86_64 :1.35-.el6_8. ---------------------------------------------------------------------------------------------------------
# 安装当前目录下的percona的RPM包:percona-release-0.1-4.noarch percona-toolkit-2.2.20-1.noarch percona-xtrabackup-24-2.4.5-1
.el6.x86_64

install_percona()
{
ptRpmList=(percona-release-0.1-.noarch percona-toolkit-2.2.-.noarch percona-xtrabackup--2.4.-.el6.x86_64)
for ptRpm in ${ptRmpList[*]};do
installFlag=$(rpm -q ${ptRpm}|grep "not installed"|wc -l)
if [ ${installFlag} -ne ];then
echo "${thisRpm} not installed"
rpm -ivh ${ptRpm}.rpm
fi
done
}
-----------------------------------------------------------------------------------------------------------
# 正式安装MySQL
install_mysql()
{
cd ${PWDDIR}
collation=`awk '$1 ~ /^'${charset}'$/ {print $2}' ${CHARSET_COLLATION_FILE}` rm -rf "mysql-${MYSQL_VERSION}"
tar zxvf ${MYSQL_FILE}
cd "mysql-${MYSQL_VERSION}"
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \
-DMYSQL_DATADIR=${DATA_DIR} \
-DWITH_INNOBASE_STORAGE_ENGINE= \
-DWITH_MYISAM_STORAGE_ENGINE= \
-DWITH_ARCHIVE_STORAGE_ENGINE= \
-DWITH_PARTITION_STORAGE_ENGINE= \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE= \
-DDEFAULT_CHARSET=${charset} \
-DDEFAULT_COLLATION=${collation} \
-DWITH_DEBUG= \
-DENABLE_DOWNLOADS= \
-DMYSQL_UNIX_ADDR=${SOCK_FILE} make -j && make install
# init mysql
chmod +x scripts/mysql_install_db
scripts/mysql_install_db --basedir=${INSTALL_DIR} --datadir=${DATA_DIR} --user=${MYSQL_USER}
# change ownership
/bin/chown -R ${MYSQL_USER}:${MYSQL_GROUP} ${INSTALL_DIR}
/bin/chown -R ${MYSQL_USER}:${MYSQL_GROUP} ${DATA_DIR}
} -------------------------------------------------
get_mysql_parameters()
{
> ${MYSQL_PARA_FILE}
# set max_conntions and innodb buffer size
MEM_SIZE=$(free -g|grep Mem|awk '{print $2}')
SSD_FLAG=$(MegaCli -PDList -aAll|grep "SSD"|wc -l)
INNODB_BUFFER=$(echo ${MEM_SIZE}*0.75|bc)
INNODB_BUFFER=${INNODB_BUFFER%.*}
if [ ${SSD_FLAG} -gt ];then
# for SSD
INNODB_IO_CAPACITY=
INNODB_IO_CAPACITY_MAX=
else
# for SAS
INNODB_IO_CAPACITY=
INNODB_IO_CAPACITY_MAX=
fi echo "<MAX_CONNECTION>=${MAX_CONNECTION}" >> ${MYSQL_PARA_FILE}
echo "<INNODB_BUFFER>=${INNODB_BUFFER}" >> ${MYSQL_PARA_FILE}
echo "<INNODB_IO_CAPACITY>=${INNODB_IO_CAPACITY}" >> ${MYSQL_PARA_FILE}
echo "<INNODB_IO_CAPACITY_MAX>=${INNODB_IO_CAPACITY_MAX}" >> ${MYSQL_PARA_FILE} # set server id
SERVER_ID=$(/sbin/ifconfig|grep inet|head -|awk '{print $2}'|awk -F: '{print $2}'|awk -F. '{print $3$4}')
echo "<SERVER_ID>=${SERVER_ID}" >> ${MYSQL_PARA_FILE} #set data directory
echo "<DATA_DIR>=${DATA_DIR}" >> ${MYSQL_PARA_FILE}
} replace_parameters()
{
cp ${TEMPLATE_CONF_FILE} ${TMP_CONF_FILE} while read LINE;do
KEY=$(echo ${LINE}|awk -F= '{print $1}'|sed 's/\//\\\//g')
VALUE=$(echo ${LINE}|awk -F= '{print $2}'|sed 's/\//\\\//g')
sed -i 's/'${KEY}'/'${VALUE}'/g' ${TMP_CONF_FILE}
done < ${MYSQL_PARA_FILE}
# set innodb_flush_method
MEM_SIZE=$(cat /proc/meminfo |grep MemTotal|awk '{print $2}')
if [ ${MEM_SIZE} -lt ];then
sed -i 's/innodb_flush_method/#innodb_flush_method/g' ${TMP_CONF_FILE}
fi
if [ ${charset} != "utf8" ]
then
sed -i 's/init_connect/#init_connect/g' ${TMP_CONF_FILE}
fi } set_mysql_parameters()
{
cd ${PWDDIR}
get_data_dir
get_mysql_parameters
replace_parameters
cp ${TMP_CONF_FILE} ${INSTALL_DIR}
}
--------------------------------------------------------
# 上传mysqld的启动文件到/etc/init.d/
目录下面并启动数据库
do_post_tasks()
{
# configuration file
rm -f /etc/my.cnf
cd /etc
ln -s ${INSTALL_DIR}/my.cnf
cd /usr/local
ln -s ${INSTALL_DIR} zftmysql
# /usr/local/mysql/bin/mysqld_safe &
cd ${PWDDIR}
cp mysqld /etc/init.d
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start
} ----------------------------------------------------------------
安装db_agent,
install_db_agent()
{
local userCnt
/usr/bin/killall - db_agent
cd ${PWDDIR}
tar zxvf db_agent.tar.gz -C /usr/local
cp db_agentd /etc/init.d
chmod +x /etc/init.d/db_agentd
chkconfig db_agentd on
/bin/chown -R ${AGENT_USER}.${AGENT_GROUP} /usr/local/db_agent
sleep
/usr/local/db_agent/bin/db_agent -c /usr/local/db_agent/etc/db_agent.cfg -d
/usr/local/mysql/bin/mysql -e "grant usage,select,replication client,replication slave,PROCESS on *.* to db_monitor@10.20.126.32 identified by 'Mo0219oi1pqX';"
/usr/local/mysql/bin/mysql -e "grant usage,select,replication client,replication slave,PROCESS on *.* to db_monitor@10.20.126.33 identified by 'Mo0219oi1pqX';"
/usr/local/mysql/bin/mysql -e "grant select,insert,update,delete,super,reload on *.* to db_failover@10.20.126.44 identified by 'FKbnqxEw6htuDBSk';"
/usr/local/mysql/bin/mysql -e "grant select,insert,update,delete,super,reload on *.* to db_failover@10.20.126.43 identified by 'FKbnqxEw6htuDBSk';"
/usr/local/mysql/bin/mysql -e "grant select,insert,update,delete,super,reload on *.* to db_failover@10.20.126.49 identified by 'FKbnqxEw6htuDBSk';"
userCnt=$(cat /etc/sudoers|grep ${AGENT_USER}|grep -v grep|wc -l)
if [ ${userCnt} -eq ];then
echo "agent ALL=(root) NOPASSWD:/usr/local/db_agent/libexec/check_raid.pl,/usr/sbin/MegaCli,/usr/local/db_agent/libexec/check_dirsize11.sh,/usr/local/db_agent/libexec/check_logfiles" >> /etc/sudoers
echo "sudo user ${AGENT_USER} added"
else
echo "sudo user ${AGENT_USER} already exists, skipping this step !"
fi
} echo_start()
{
local STR="$1"
echo "...... ${STR} ......starting at $(date)"
} echo_end()
{
local STR="$1"
echo "${STR} done at $(date)"
} main()
{
# set env
charset=utf8
MYSQL_USER=mysql
MYSQL_GROUP=mysql
AGENT_USER=agent
AGENT_GROUP=agent
DIR_KEY="/data1"
INSTALL_DIR="/usr/local/mysql"
DATA_DIR="/data/mysql_data"
SOCK_FILE="/tmp/mysql.sock"
CNF_DIR=${DATA_DIR}
MYSQL_VERSION="5.6.35"
CUR_DIR=$(dirname $)
MYSQL_FILE="mysql-${MYSQL_VERSION}.tar.gz"
MYSQL_PARA_FILE=${CUR_DIR}/conf/para.txt
TMP_CONF_FILE=${CUR_DIR}/conf/my.cnf
TEMPLATE_CONF_FILE=${CUR_DIR}/conf/my.cnf.template
CHARSET_COLLATION_FILE=${CUR_DIR}/charset_collation.txt
cd ${CUR_DIR}
PWDDIR=$(pwd) echo_start "check rpm"
check_rpm
echo_end "check rpm"
echo_start "check user"
check_and_add_user
echo_end "check user"
echo_start "check directory"
check_directory
echo_end "check directory"
echo_start "install mysql"
install_mysql
echo_end "install mysql"
echo_start "set mysql parameters"
set_mysql_parameters
echo_end "set mysql parameters"
echo_start "post tasks"
do_post_tasks
echo_end "post tasks"
echo_start "install db agent"
install_db_agent
echo_end "install db agent"
echo_start "install percona tools"
install_percona
echo_end "install percona tools"
echo "###### all done ########"
} D_CHAR=utf8 while getopts :hc: OPTION;do
case $OPTION in
h) help
exit
;;
c) D_CHAR=$OPTARG
#echo ${D_CHAR}
;;
\?)
help
exit
;;
esac
done main $

mysql5.6.35的安装脚本的更多相关文章

  1. MySQL5.7.18自动化安装脚本

    背景 很好的朋友邱启明同学,擅长MySQL,目前任职某大型互联网业MySQL DBA,要来一套MySQL自动安装的Shell脚本,贴出来保存一些. 此版本为 MySQL 5.7.18 ###### 自 ...

  2. MySQL5.6.36 自动化安装脚本

    背景 很好的朋友邱启明同学,擅长MySQL,目前任职某大型互联网业MySQL DBA,要来一套MySQL自动安装的Shell脚本,贴出来保存一些. 此版本为 MySQL 5.6.365 ###### ...

  3. MySQL5.7.35的安装

    Step①: 下载安装包,MySQL下载地址:百度 Step②: 解压至你的安装路径,我个人是在E盘存放.  Step③: 配置环境变量. ①:在系统属性中,点击环境变量. ②:找到环境变量-> ...

  4. [Deepin 15] 编译安装 MySQL-5.6.35

    在 Ubuntu 下,先前一直是 二进制包解压安装,详情参考: http://www.cnblogs.com/52php/p/5680906.html 现改为 源码编译安装: #!/bin/bash ...

  5. 64位CentOs7源码安装mysql-5.6.35过程分享

    首先安装依赖包,避免在安装过程中出现问题 [root@bogon liuzhen]# yum -y install gcc gcc-c++[root@bogon liuzhen]# yum -y in ...

  6. CentOS6.5源码安装MySQL5.6.35

    CentOS6.5源码安装MySQL5.6.35 一.卸载旧版本 1.使用下面的命令检查是否安装有mysql [root@localhost tools]# rpm -qa|grep -i mysql ...

  7. CentOS6.5下源码安装MySQL5.6.35

    接上一篇文章使用RPM包安装MySQL,确实很方便.但是安装后却不知道各文件保存在哪个文件夹下!尝试使用源码安装~本文主要参考:CentOS 6.4下编译安装MySQL 5.6.14一.卸载旧版本 . ...

  8. 在CentOs7源码安装mysql-5.6.35单实例数据库

    首先安装依赖包,避免在安装过程中出现问题 [root@bogon liuzhen]# yum -y install gcc gcc-c++[root@bogon liuzhen]# yum -y in ...

  9. mysql5.7一键安装脚本

    0. 概述 最近鼓捣出了一个mysql安装脚本,将该脚本,mysql的my.cnf文件,mysql的安装包这三个文件放在同一个目录下面,执行sh mysql-auto-install.sh就可以完成m ...

随机推荐

  1. Python爬虫学习——获取网页

    通过GET请求获取返回的网页,其中加入了User-agent信息,不然会抛出"HTTP Error 403: Forbidden"异常, 因为有些网站为了防止这种没有User-ag ...

  2. iOS:App 内部更改使用语言/ 重定义系统的宏

    代码部分 #undef NSLocalizedString #define NSLocalizedString(key, comment) \ NSLocalizedStringFromTable(k ...

  3. Android 监听屏幕唤醒和关闭的广播

    今天希望应用程序的服务运行时,可以监听到屏幕的唤醒.继续百度学习法,连同监听闭幕关闭也一同学习了. 此种情况需要动态注册系统广播.在AndroidManifest.xml中静态注册的实际运行中无效. ...

  4. lakala proportion轨迹分析代码

    /** * Created by lkl on 2017/12/7. */ import breeze.numerics.abs import org.apache.spark.sql.SQLCont ...

  5. UNIX环境编程学习笔记(4)——文件I/O之dup复制文件描述符

    lienhua342014-08-23 UNIX 提供了两个函数 dup 和 dup2 用于复制一个现存的文件描述符. #include <unistd.h> int dup(int fi ...

  6. saltstack系列1之salt-api配置与使用

    salt-api salt-api是我们通过restful-api调用salt-master的接口,且调用的时候必须通过认证才能调用,认证的用户为系统用户,下面就说说如何配置salt-api. 不带S ...

  7. 续:纠正:ubuntu【7.04】可以安装,而且完美的安装 ! for《Oracle-10.2.0.1,打补丁10.2.0.5:在 debian 版本4【不含4】以上,及 ubuntu 7.04【不含7.04】以上都可以安装!》

    n次的测试后,最终证明,如下做法,可以完美安装. 中间都不带任何一个错误的!!!完美! dhclient vi /etc/profile ll cd /etc/apt/ mv sources.list ...

  8. get calllog fail

    coolpad Coolpad 8122   Uri smsUri = CallLog.Calls.CONTENT_URI;     Cursor callLogCursor = cr.query(s ...

  9. pdf转换成word转换器免费版

    在平时的办公中,我们只需要有一款比较好用的pdf转换成word转换器,就能提高我们的工作效率,但是国内外的pdf转换成word转换器应该怎么选呢?小编因为是文职工作者,所以在日常的实践中选出了ABBY ...

  10. Bootstrap 轮播(Carousel)详解

    Bootstrap 轮播(Carousel)插件是一种灵活的响应式的向站点添加滑块的方式.除此之外,内容也是足够灵活的,可以是图像.内嵌框架.视频或者其他您想要放置的任何类型的内容.如果您想要单独引用 ...