MySQL5.7 Multi-Instance Automation deployment script

Source: Internet
Author: User
Tags mkdir mysql version

First, installation instructions

Mysql5.7.10_onekey_ The Automation deployment script supports mysql5.7.10 initialization installation, multi-instance creation, and the use of optimized my.cnf configuration files and Mysql.server startup scripts in centos6.5_x86_ 64 operating system tests passed. The deployment is as follows:

650) this.width=650; "src=" Http:// "alt=" Wkiol1z5-gmaqq0gaabewfnc9ck868.png "/>

1. Installation method

The files you need to prepare are as follows, put in the same directory, and execute the shell script:

./ 3307

Port customization, requires integers, and does not conflict with server ports

# Tree Mysql5.7.10_onekey_install







① if MySQL is installed for the first time, all required preinstallation environments are built and the first instance is created; ② if it is not the first time that MySQL is installed, it will create a multi-instance on the original basis;

2. Install the software version

-Operating system: Centos6.5_x86_64-mysql version: mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz (latest version 5.7.10)

3. Installation directory Planning

Upload Package directory:/home/zkyw/installmysql program directory:/opt/application/mysqlmysql instance data file directory:/data/$Port

4. Program Start-Stop operation

Start MySQL instance:/data/$Port/mysql.server start stop MySQL instance:/data/$Port/mysql.server Stop view MySQL instance status:/data/$Port/ Mysql.server status

5. Script Execution Process

The first step: To determine the incoming parameters (port number), the request is an integer and can not conflict with the server has a port number; the second step: if the server has not installed MySQL, then the initial installation, automatic configuration of the required installation environment; Step three: If MySQL is already installed on the server, multiple instances will be created Fourth Step: Initialize the installation process: Delete MSYQL related RPM package → install Libaio package → Create the user directory required for installation → Install mysql→ configure MySQL Fifth step: Create a multi-instance process: Create a directory and authorize → install mysql→ configure MySQL

II. Automated Deployment scripts

#!/bin/sh#auto install mysql5.7.10   #setting  default directoryport=$1softdir= "/ Home/zkyw/install "tarbag=" mysql-5.7.10-linux-glibc2.5-x86_64 "basedir="/opt/application/mysql "DataDir="/data/$ Port "   #remove  before being installed mysqlfunction rmmysql ()  {         yum -y erase mysql >/dev/null 2>& 1        yum -y erase mysql-server >/dev/null  2>&1        ret= ' Rpm -aq | grep -i   "mysql-5"  | wc -l '         num= ' rpm -aq  | grep -i  "Mysql-server"  | wc -l '          test  $ret  -eq 1 && echo  "mysql uninstall failed"   && exit 1        test  $num  -eq 1 &&   echo  "mysql-server uninstall failed"  && exit 2} #libaio  package  is needed for mysql5.7.10function chkenv ()  {         yum -y install libaio >/dev/null 2>&1         res= ' Rpm -aq|grep libaio | wc -l '          test  $res  -ne 1 && echo  "libaio  Package install failed " && exit 3}   #create  mysql user  and group, authorization, extractfunction preinstall ()  {         /usr/sbin/groupadd mysql        / Usr/sbin/useradd -r -g mysql -s /bin/false mysql        mkdir -p $ basedir        mkdir -p  $DataDir/data         chown mysql.mysql  $DataDir          if test -f  $SoftDir/$tarbag .tar.gz           then                cd   $SoftDir  && tar -zxf  $tarbag .tar.gz                 cd  $SoftDir/$tarbag &NBSP;&AMP;&AMP;&NBSP;CP  -r *  $BaseDir           else                 echo  "$tarbag. tar.gz  is not found ... "                exit 10         fi}  function multpreinstall ()  {     mkdir -p  $DataDir/data        chown  mysql.mysql  $DataDir}  function install_mysql ()  {          #initialize  mysql database         $BaseDir/bin/ mysqld         --initialize          --user=mysql         --basedir= $BaseDir           --datadir= $DataDir/data          --character-set-server=utf8         -- collation-server=utf8_general_ci &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;--INITIALIZE-INSECURE&NBSP;&GT;/DEV/NULL&NBSP;2&GT;&AMP;1} #get  my.cnf and start/stop script, attention alter parameters by your  envionmentfunction conf_mysql ()  {        cp $ softdir/my.cnf  $DataDir         cp  $SoftDir/mysql.server   $DataDir/usr/bin/vim  $DataDir/my.cnf<<eof >/dev/null 2>&1:%s/3306/$Port/g :wqeof        sed -i  "s/port=3306/port= $Port/"   $DataDir /mysql.server        sed -i  "s%CmdPath=\" \ "%CmdPath=\" ${ Basedir}\/bin\ "%"   $DataDir/mysql.server        sed -i  " S%mysql_sock=\ "\"%mysql_sock=\ "${datadir}\/mysql.sock\"% "  $DataDir/mysql.server         chmod 600  $DataDir/my.cnf        chmod 700  $DataDir/ mysql.server         $DataDir/mysql.server start >/dev/ null 2>&1        sleep 3#         ren= ' netstat -natp|grep mysqld | grep  "$" &NBSP;|&NBSP;WC  -l '               if test  -e  $DataDir/mysql.sock;then        echo  "$DataDir/ Mysql.sock "                 echo -e  "\033[33;1mmysql install success...\033[0m"          pro= ' grep  $BaseDir  /root/.bash_profile | wc -l '          if test&nBSP; " $pro " -ne 1;then            sed -i   "s%path=\ $PATH \:\ $HOME \/bin%path=\ $PATH \:\ $HOME \/bin\: $BaseDir \/bin%"  /root/.bash_profile             source /root/.bash_profile                 fi         else                 echo -e  "\033[31;1mmysql install failed...\033[0m"          fi}  if [[  "$"  =~ ^[0-9]+$ ]]; then    inport= ' netstat -natp | grep  "mysqld"  | grep  "LISTEN"  | awk  ' {print $4} '  | cut -b 4-'    if test !  -z  "$inPort"; then        for myPort in  $inPort            do             if test  "$myPort"  -eq  "$";then                 echo -e  "\033[33;1m$1 instance has already  existed...\033[0m "                 exit 1            fi         done       echo -e  "\033[32; 1m===========================================\033[0m "       echo -e   "\033[32;1mstarting create new instance $1\033[0m"         multpreinstall&nbSp;      install_mysql       echo -e   "\033[32;1m===========================================\033[0m"         echo -e  "\033[32;1mconfiguration and starting $1 instance...\033[0m"         conf_mysql   else       echo  -e  "\033[32;1m===========================================\033[0m"         echo -e  "\033[32;1mremove before being installed mysql...\033[0m"        rmMysql       echo -e  " \033[32;1m===========================================\033[0m "       echo  -e  "\033[32;1minstall libaio package...\033[0m"         Chkenv       echo -e  "\033[32;1m===========================================\033[0m"         echo -e  "\033[32;1mget ready install envionment ... \033[0m "         preInstall        echo -e  "\033[32;1m===========================================\033[0m"         echo -e  "\033[32;1mstarting install mysql ver5.7.10...\033[0m "       install_mysql       echo -e   "\033[32;1m===========================================\033[0m"         echo -e  "\033[32;1mconfiguration mysql and starting mysql...\033[0m"         conf_mysql   fielse   echo  "usage: $0  Port  (port&Nbsp;is inteager) "fi 

Third, MySQL optimized configuration file (MY.CNF)

[Client]port = 3306socket = /data/3306/mysql.sockcharacter-set-server = utf8   [mysql]no-auto-rehash  [mysqld]user    = mysqlport     = 3306character-set-server = utf8socket  = /data/3306/ Mysql.sockbasedir = /opt/application/mysqldatadir = /data/3306/dataexplicit_defaults_for_ Timestamp = trueskip-sslsecure-file-priv = nulllower_case_table_names = 1back_ log = 300max_connections = 3000max_connect_errors = 100table_open_cache =  4096external-locking = FALSEmax_allowed_packet = 32Msort_buffer_size =  16mjoin_buffer_size = 16mthread_cache_size = 16query_cache_size = 128mquery_ Cache_limit = 4mft_min_word_len = 8thread_stack = 512ktransaction_isolation  = repeatable-readtmp_table_size&nbsP;= 128mmax_heap_table_size = 128m  ###*** slow query parameterslong_ query_time = 6slow_query_logslow_query_log_file = /data/3306/slow.log  ###***  binlog parameterslog-bin = /data/3306/mysql-binbinlog_cache_size = 4mmax_binlog _cache_size = 16mmax_binlog_size = 32mbinlog_format = mixedexpire_logs_days  = 7  ###*** relay-log parameters#relay-log = /data/3307/relay-bin# relay-log-info-file = /data/3307/ = table# relay-log-info-repository = table#relay-log-recovery = 1  #*** myisam  parameterskey_buffer_size = 16mread_buffer_size = 1mread_rnd_buffer_size =  16mbulk_insert_buffer_size = 1m   #skip-name-resolve  ###*** master-slave  replication parametersserver-id = 105slave-skip-errors = all  #*** innodb storage engine  parametersinnodb_buffer_pool_size = 6ginnodb_data_file_path = ibdata1:10m:autoextend# Innodb_file_io_threads = 8innodb_thread_concurrency = 16innodb_flush_log_at_trx_commit  = 2innodb_log_buffer_size = 16minnodb_log_file_size = 512minnodb_log_files_in_ Group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_ file_per_table = on  [mysqldump]quickmax_allowed_packet = 32m  [ Myisamchk]key_buffer = 16msort_buffer_size = 16mread_buffer = 8mwrite_buffer  = 8m  [mysqld_safe]open-files-limit = 8192log-error=/data/3306/mysql_3306. Errpid-file=/data/3306/

Iv. MySQL startup script (Mysql.server)

#!/bin/sh # this is an interactive program, we needthe current  locale [ -f /etc/profile.d/ ] && . /etc/profile.d/ # we can ' t japanese on normal console atboot time,  so force. if [  "$LANG"  =  "ja"  -o  "$LANG"  =  "JA_JP.EUCJP"  ]; then   if [  "$TERM"  =  "Linux"  ] ; then        lang=c    fifi    # source  function library. . /etc/init.d/functions  #initport =3306mysql_user= "root" mysql_pwd= " "Cmdpath=" "mysql_sock=" "  #startup  functionfunction_start_mysql () {    if [  ! -e  "$mysql _sock"  ];then      printf  "starting  mysql...\n "   &Nbsp;  ${cmdpath}/mysqld_safe --defaults-file=/data/${port}/my.cnf --ledir=${cmdpath}  2>&1 > /dev/null &      sleep 2     else      printf  "mysql is running...\n"        exit    fi}  #stop  functionfunction_stop_mysql () {     if [ ! -e  "$mysql _sock"  ];then        printf  "mysql is stopped...\n"        exit     else       printf  "stoping mysql...\n"         ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd}  -s  $mysql _sock shutdown       sleep 2   fi}   #restart  functionFunction_restart_mysql () {    printf  "restarting mysql...\n"      function_stop_mysql    sleep 2    function_start_mysql}  case $1 instart)     function_start_mysql;; Stop)     function_stop_mysql;; Restart)     function_restart_mysql;; Status)     status mysqld;; *)     printf  "usage: /data/${port}/mysql {start|stop|restart|status}\n" Esac

This article from "Flat Light is true" blog, please be sure to keep this source

MySQL5.7 Multi-Instance Automation deployment script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.