mysql源码安装脚本分享

 更新时间:2014年03月05日 10:28:28   作者:  
这篇文章主要介绍了mysql源码安装的脚本,配置文件的内容是针对mysql5.6的,需要的朋友可以参考下

复制代码 代码如下:

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
clear;
SysName=""
SysBit=""
CpuNum=""
RamTotal=""
RamSwap=""
FileMax=""
MysqlVersion="Percona-Server-5.6.15-rel63.0"
MysqlLine="http://www.percona.com/downloads/Percona-Server-5.6/LATEST/source"
MysqlPath="/usr/local/mysql"
MysqlDataPath="$MysqlPath/data"
MysqlLogPath="/var/log/mysql"
MysqlConfigPath="$MysqlPath/conf"
MysqlPass="test123"
SYSTEM_CHECK(){
 [[ $(id -u) != '0' ]] && echo '[Error] Please use root to install PUPPET.' && exit;
 egrep -i "centos" /etc/issue && SysName='centos';
 egrep -i "ubuntu" /etc/issue && SysName='ubuntu';
 [[ "$SysName" == '' ]] && echo '[Error] Your system is not supported this script' && exit;
 SysBit='32' && [ `getconf WORD_BIT` == '32' ] && [ `getconf LONG_BIT` == '64' ] && SysBit='64';
 CpuNum=`cat /proc/cpuinfo |grep 'processor'|wc -l`;
 RamTotal=`free -m | grep 'Mem' | awk '{print $2}'`;
 RamSwap=`free -m | grep 'Swap' | awk '{print $2}'`;
 FileMax=`cat /proc/sys/fs/file-max`
}
INSTALL_BASE_PACKAGES()
{
 SYSTEM_CHECK
 if [ "$SysName" == 'centos' ]; then
  echo '[yum-fastestmirror Installing] ************************************************** >>';
  yum -y install yum-fastestmirror;
  cp /etc/yum.conf /etc/yum.conf.lnmp
  sed -i 's:exclude=.*:exclude=:g' /etc/yum.conf
  for packages in gcc gcc-c++ openssl-devel ncurses-devel wget crontabs iptables bison cmake automake make readline-devel logrotate openssl; do
   echo "[${packages} Installing] ************************************************** >>";
   yum -y install $packages;
  done;
  mv -f /etc/yum.conf.lnmp /etc/yum.conf;
 else
  apt-get remove -y mysql-client mysql-server mysql-common;
  apt-get update;
  for packages in gcc g++ cmake make ntp logrotate cron bison libncurses5-dev libncurses5 libssl-dev openssl curl openssl; do
   echo "[${packages} Installing] ************************************************** >>";
   apt-get install -y $packages --force-yes;apt-get -fy install;apt-get -y autoremove;
  done;
 fi;
}
INSTALL_MYSQL(){
 INSTALL_BASE_PACKAGES
 cd /tmp/
 echo "[${MysqlVersion} Installing] ************************************************** >>";
 [ ! -f ${MysqlVersion}.tar.gz ] && wget -c ${MysqlLine}/${MysqlVersion}.tar.gz
 tar -zxf /tmp/$MysqlVersion.tar.gz;
 cd /tmp/$MysqlVersion;
 groupadd mysql;
 useradd -s /sbin/nologin -g mysql mysql;
 cmake -DCMAKE_INSTALL_PREFIX=$MysqlPath  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=complex -DWITH_READLINE=ON -DENABLED_LOCAL_INFILE=ON -DWITH_INNODB_MEMCACHED=ON -DWITH_UNIT_TESTS=OFF;
 make -j $Cpunum;
 make install;
 for path in $MysqlLogPath $MysqlPath $MysqlConfigPath/conf.d $MysqlDataPath;do
  [ ! -d $path ] && mkdir -p $path
  chmod 740 $path;
  chown -R mysql:mysql $path;
 done
# EOF **********************************
cat > $MysqlConfigPath/my.cnf<<EOF;
[mysqld]
user  = mysql
server-id = 1
pid-file = /var/run/mysqld.pid
socket  = /var/run/mysqld.sock
port  = 3306
basedir  = $MysqlPath
datadir  = $MysqlDataPath
bind-address = 0.0.0.0
skip-name-resolve
skip-external-locking
thread_concurrency = `expr $CpuNum \* 2`
max_connections = `expr $FileMax \* $CpuNum \* 2 / $RamTotal`
max_connect_errors = 30
table_open_cache = `expr $RamTotal + $RamSwap`
max_allowed_packet = `expr $RamTotal \* 2 / 1000`M
binlog_cache_size = 4M
max_heap_table_size = `expr $RamTotal / 100`M
sort_buffer_size = `expr $RamTotal \* 2 / 1000`M
join_buffer_size = `expr $RamTotal \* 2 / 1000`M
query_cache_size = `expr $RamTotal / 100`M
thread_cache_size = 30
thread_concurrency = `expr $CpuNum \* 4`
connect_timeout  = 1200
wait_timeout  = 1200
general_log = 1
general_log_file = $MysqlLogPath/mysql.log
log_error = $MysqlLogPath/mysql-err.log
slow_query_log = 1
slow_query_log_file = $MysqlLogPath/mysql-slow.log
long_query_time = 3
log_bin = $MysqlLogPath/mysql-bin
log_bin_index = $MysqlLogPath/mysql-bin.index
expire_logs_days = 7
max_binlog_size = `expr $(df -m $MysqlLogPath |awk 'NR==2{printf "%s\n",$4}') / 10000`M
default_storage_engine = InnoDB
innodb_buffer_pool_size = `expr $RamTotal / 100`M
innodb_log_buffer_size = 8M
innodb_file_per_table = 1
innodb_open_files = `expr $FileMax \* $CpuNum / $RamTotal`
innodb_io_capacity = `expr $FileMax \* $CpuNum / $RamTotal`
innodb_flush_method = O_DIRECT

!includedir $$MysqlConfigPath/conf.d
[mysqld_safe]
open_files_limit = `expr $FileMax / $CpuNum / 100`
[isamchk]
key_buffer  = 16M
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
EOF
# **************************************
 $MysqlPath/scripts/mysql_install_db --user=mysql --defaults-file=$MysqlConfigPath/my.cnf --basedir=$MysqlPath --datadir=$MysqlDataPath;
# EOF **********************************
cat > /etc/ld.so.conf.d/mysql.conf<<EOF
/usr/local/mysql/lib/mysql
/usr/local/lib
EOF
# **************************************
 ldconfig;
 if [ "$SysBit" == '64' ] ; then
  ln -s $MysqlPath/lib/mysql /usr/lib64/mysql;
 else
  ln -s $MysqlPath/lib/mysql /usr/lib/mysql;
 fi;
 cp $MysqlPath/support-files/mysql.server /etc/init.d/mysqld;
 chmod 775 /etc/init.d/mysqld;
 /etc/init.d/mysqld start;
 ln -s $MysqlPath/bin/mysql /usr/bin/mysql;
 ln -s $MysqlPath/bin/mysqladmin /usr/bin/mysqladmin;
 $MysqlPath/bin/mysqladmin password $MysqlPass;
 rm -rf $MysqlDataPath/test;
# EOF **********************************
mysql -hlocalhost -uroot -p$MysqlPass <<EOF
USE mysql;
DELETE FROM user WHERE user='';
UPDATE user set password=password('$MysqlPass') WHERE user='root';
DELETE FROM user WHERE not (user='root');
DROP USER ''@'%';
FLUSH PRIVILEGES;
EOF
# **************************************
 echo "[OK] ${MysqlVersion} install completed.";
}
INSTALL_MYSQL

相关文章

  • linux crontab 实现每秒执行的实例

    linux crontab 实现每秒执行的实例

    下面小编就为大家带来一篇linux crontab 实现每秒执行的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-04-04
  • 浅谈shell的一些循环格式

    浅谈shell的一些循环格式

    这篇文章主要介绍了浅谈shell的一些循环格式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-11-11
  • shell清理指定目录中指定天数之前的旧文件

    shell清理指定目录中指定天数之前的旧文件

    本文主要介绍了shell清理指定目录中指定天数之前的旧文件,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-05-05
  • Linux Shell脚本实现检测tomcat

    Linux Shell脚本实现检测tomcat

    这篇文章主要介绍了Linux Shell脚本实现检测tomcat的方法,推荐给小伙伴们,需要的朋友可以参考下
    2015-03-03
  • linux shell实现守护进程脚本

    linux shell实现守护进程脚本

    这篇文章主要介绍了linux shell实现守护进程脚本,非常简单实用的代码,这里推荐给小伙伴。希望大家能够喜欢。
    2015-03-03
  • linux shell中Grep命令查找多个字符串(grep同时匹配多个关键字或任意关键字)

    linux shell中Grep命令查找多个字符串(grep同时匹配多个关键字或任意关键字)

    grep是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来,下面这篇文章主要给大家介绍了关于linux shell中Grep命令查找多个字符串(grep同时匹配多个关键字或任意关键字)的相关资料,需要的朋友可以参考下
    2022-08-08
  • Shell脚本IF条件判断和判断条件总结

    Shell脚本IF条件判断和判断条件总结

    这篇文章主要介绍了Shell脚本IF条件判断和判断条件总结,本文先是给出了IF条件判断的语法,然后给出了常用的判断条件总结,需要的朋友可以参考下
    2014-10-10
  • Linux 中 ls 命令详解

    Linux 中 ls 命令详解

    这篇文章主要介绍了Linux 中 ls 命令详解的相关资料,需要的朋友可以参考下
    2023-05-05
  • shell实现数字打印从100到200的数

    shell实现数字打印从100到200的数

    按顺序打印从100到200的数的shell脚本,需要的朋友可以参考下
    2013-02-02
  • shell学习之printf命令格式化输出语句

    shell学习之printf命令格式化输出语句

    printf命令模仿C程序库(library)里的printf()库程序(library routine)。它几乎复制了该函数的所有功能。不过在Shell层级的版本上,会有些差异。下面这篇文章就给大家主要介绍了shell中printf命令格式化输出语句的相关资料,需要的朋友可以参考下。
    2017-01-01

最新评论