One of the MySQL series key installation scripts----Single-instance/multi-instance

Source: Internet
Author: User

I 've been doing MySQL lately, because I've been testing things a lot. Therefore, a one-click installation script is written.


Scripting uses:

Single-instance or multi-instance environment for rapid deployment of MySQL on Centos/rhel 6.x systems


Script Description:

The script runs well against the script, each step of the command execution of the right and wrong judgment and the alert is very eye-catching, can help the performer quickly locate the error source script a lot of content to declare variables, increase the flexibility of the script and extensibility script to do the modular processing, corresponding function corresponding function, convenient SA quickly change and understand the script


The script uses considerations:

1, to be able to public network or MySQL source package has been placed in the/USR/LOCAL/SRC directory 2, the script running environment requires that Yum source has been equipped with 3, note the use of the MySQL version, in order to stabilize the period, the script temporarily stable support after 5.5 MySQL source package. This script uses the 5.6.16 version of the source package by default. If you need to use a different version, please change the mysql_soft variable and the download path of the source package 4, the MySQL installation default location is/usr/local/mysql, if you need to change the Install_path variable 5, because I basically every command has to make comments, Therefore, some other parameter modification, please own study, here no longer verbose 6, system environment requirements Centos/rhel 6.x version


The following is the script content:

#!/bin/bash## the script used in centos/rhel 6. x system  Automatically deploy mysql single instance and multiple instances of  the environment# written by sunsky# mail : [email protected]#  qq   : 274546888# date : 2014-7-19 14:23:00#. /etc/init.d/ functionstac  ()  {if [ $? == 0 ];thenaction  '  /bin/trueelseaction   '  /bin/falsefi}pre_instance  ()  {echo  '   -- add mysql user <1> ' useradd -r -u 306 mysql;tacecho  '   -- install some  Packages<1> ' ls &> /dev/null;tacecho  '   -- Downloading  Mysql<2> '  cd /usr/local/src;tacls &> /dev/null ;tacecho  '    -- unpack the sOurce code package<2> ' Tar -zxf /usr/local/src/${mysql_soft}.tar.gz -c /usr /local/src/;taccd /usr/local/src/${mysql_soft};tacecho  '   -- install mysql<3 > ' ls &> /dev/null;tacls &>/dev/null;tacls &> /dev/null; tacecho  '   -- Change the directory owner and group<1> ' chown  -R mysql.mysql /usr/local/mysql;tacecho  '   -- Create my.cnf<1> ' Echo |cp /usr/local/src/${mysql_soft}/support-files/my-default.cnf /etc/my.cnf ;tacecho   '   -- Create Mysqld Scripts<2> ' echo |cp /usr/local/mysql/ Support-files/mysql.server /etc/init.d/mysqld;tacchmod a+x /etc/init.d/mysqld;tac}single_ instance  ()  {echo  '    -- initialized mysql database, the  default port 3306<1> ' $INIT _db --datadir= $DATA _dir &> /dev/null;tac echo  '    - - start mysqld service test<1> '/etc/init.d/mysqld start > /dev/ null;tacecho  '    -- View MySQL Database Status<1> '/etc/init.d/ mysqld status | grep  "SUCCESS"  > /dev/null;tacif [ $? ==  0 ];then action  '    -- mysql install done! '  /bin/true;else action  '    -- mysql install failed! '  false;fiaction  '    -- MySQL Command Global Path<2> ' echo   ' export path=/usr/local/mysql/bin/: $PATH '  >> /etc/profile;tacsleep 1source  /etc/profile;tac}single_of_multiple  ()  {action  '     -- Add  Mysqld_multi user<2> ' user= "MySQL"; tacpassword="Sunsky";tacaction  '     -- Stop MySQL Database<1> '/etc/init.d/ mysqld stop &> /dev/null;tacaction  "    -- mysqld_multi  Configure<2> "sed -i  ' s/^[^#]/#/g '  /etc/my.cnf;taccat > /etc/my.cnf  << EOF[mysqld_multi] mysqld = /usr/local/mysql/bin/mysqld_safemysqladmin  = /usr/local/mysql/bin/mysqladminuser =  $user  password =  $password  [ mysqld3306]server-id = 1port = 3306socket = /tmp/mysql3306.sockpid-file =  /tmp/mysql3306.pidbasedir = /usr/local/mysqldatadir = /usr/local/mysql/datakey_ Buffer_size = 16kmax_allowed_packet = 1mtable_open_cache = 4sort_buffer_size  = 64kread_buffer_size = 256kread_rnd_buffer_size = 256knet_buffer_length =  2kthread_stack = 128keoftacecho  '     -- prepare my_default_print<1> ' ECHO&NBSP;|&NBSP;CP  /usr/local/mysql/bin/my_print_defaults /usr/bin/;tacsleep 1action  "     -- Initialize multiple instance of the 3306 instance<1> "Echo   '     -- Start multiple instances of the 3306  Instance<1> ' $MULTI _db 3306;tacsleep 5action  "    -- examples  of 3306 authorized users<1> "$MYSQL _db -s /tmp/mysql3306.sock -e   "grant shutdown on *.* to  ' $user ' @ '% '  identified by  ' $password ';"; tacaction  "    -- instance 3306 has user and password  to shutdown<1> "}multiple_instances  ()  {user=" MySQL "password=" Sunsky "For port  in $*;d O&NBSP;NETSTAT&NBsp;-lntp | grep  $port  &> /dev/null if [ $? -eq 0  ];then  action  "    -- Instance  $port  is running <1> "  else  cat /etc/my.cnf | grep mysqld${port} >  /dev/null  if [ $? -eq 0 ];then   echo  "     --  $port  instance is already exists,please input other  port number! "     $MULTI _db  $port  && action  "   -- instance   $port  open to complete " /bin/true | |  action  "   -- Instance  $port  open failed"  /bin/false   elsecat >> /etc/my.cnf << eof[mysqld${port}]server-id = $[${ port}%3305]port = ${port}socket = /tmp/mysql${port}.sockpid-file = /tmp/mysql${port}.pidbasedir = /usr/local/mysqldatadir  = /usr/local/mysql/data${port}key_buffer_size = 16kmax_allowed_packet = 1mtable _open_cache = 4sort_buffer_size = 64kread_buffer_size = 256kread_rnd_buffer_size  = 256Knet_buffer_length = 2Kthread_stack = 128KEOFecho  "     -- Create  $port  Instance Datadir<2> "  mkdir -p ${data_dir} ${port};tac  chown -r mysql.mysql ${data_dir}${port};tacecho  "     -- Initialize multiple instance of the  $port  instance<1>     $INIT _db --datadir=${data_dir}${port} &> /dev/null ;tac echo  "     -- Start multiple instances of the  $port  instance <1> " &nbSP; $MULTI _db  $port  && action      -- Instance  $port  open to complete " | |  action  "    -- Instance  $port  open failed";tacecho  "     -- Examples of  $port  authorized users "  sleep  3   $MYSQL _db -s /tmp/mysql${port}.sock -e  "Grant shutdown on *.*  to  ' $user ' @ ' localhost '  identified by  ' $password '; && action  "    -- Instance  $port  has user and  password to shutdown " /bin/true| |  action      -- Instance  $port  has user and  Password to shutdown " /bin/false fifidone}# mysql install path install _path= '/usr/local/mysql ' # mysql data_drdata_dir= "$INSTALL _patH/data "# mysql command pathinstall_db=" $INSTALL _path/scripts/mysql_install_db "MYSQL_DB=" $ Install_path/bin/mysql "mysql_multi=" $INSTALL _path/bin/mysqld_multi "init_db=" $INSTALL _db --user=mysql  --basedir= $INSTALL _path --defaults-file=/etc/my.cnf "multi_db=" $MYSQL _multi --defaults-file=/ Etc/my.cnf start "mysql_soft= ' mysql-5.6.16 ' Case $# in0) cat << eofthe system  administrator, hello! This is a key to install mysql single instance and multiple  instances of the scriptYou can use the name in the  script with the upper slogans, to define several instances  installed! Example:[[email protected] ~]# bash auto_install_mysql_instance. Sh 3306 3307install two mysql instance, port numbers 3306 and  3307 respeCtively. if you are familiar with shell, are free to change the  script! if you are not familiar with, please do not change! EOF;; 1) echo  ' > now begin to single instance database initialization ' echo   ' >> step one : prepare the mysql environment ' Pre_instanceecho   ' >>> step two : install the mysql single instance ' single_instanceecho  ' >>>> setp three : mysql single instance  installation is complete! ';; *) echo  ' > now start multi-instance database initialization ' echo  ' > > step one : prepare the mysql environment ' Pre_instancesingle_ instanceecho  ' &GT;&GT;&GT;&NBSP;STEP&NBSP;TWO&NBSP;:&NBSP;INSTALL&NBSP;THE&NBSP;MYSQL&NBSp;single of multiple instance ' single_of_multipleecho  ' >>>> STEP  Three : install the mysql others of multiple instance ' Multiple_ instances $*echo  ' >>>>> SETP FOUR : MySQL multiple  Instance installation is complete ';; Esac


The above is the content of the script, which is composed of 5 functions, TAC, Pre_instance, Single_instance, Single_of_multiple, and multiple_instances, respectively.

TAC is responsible for the execution of the command in the script to determine the correct, convenient location error source pre_instance is responsible for preparing the MySQL installation environment, such as user creation, related tool installation, MySQL source package preparation, MySQL software installation and other Single_ Instance is responsible for initializing the single instance database single_instance is responsible for the multi-instance environment, the pure single instance of the instance to make the modification multiple_instances responsible for creating the multi-instance environment


There are several variables declared in the middle of the script.

The following case statement is used to schedule the execution of our entire script. If you execute the script directly and do nothing with it, the help message is displayed by default.

The Help information is as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/3F/8B/wKiom1PKr7-yQ5yJAAI_JZ0lIVg872.jpg "title=" QQ picture 20140720014806.jpg "alt=" Wkiom1pkr7-yq5yjaai_jz0livg872.jpg "/>


Below I list, normal installation Single instance

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/3F/8B/wKioL1PKsHvgOi10AAKHaviAtBk955.jpg "title=" Single.png "alt=" Wkiol1pkshvgoi10aakhaviatbk955.jpg "/>


Normal multi-instance installation

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/3F/8B/wKiom1PKr3njKWdLAAH4PxM6vzg755.jpg "style=" float: none; "title=" 2.png "alt=" Wkiom1pkr3njkwdlaah4pxm6vzg755.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3F/8B/wKioL1PKsJXw6IlxAAKH2LRmaWo672.jpg "style=" float: none; "title=" 3.png "alt=" Wkiol1pksjxw6ilxaakh2lrmawo672.jpg "/>


I hope this script can help you!

If you find anything inappropriate in the script, please let me know in time! Thank you!


This article is from the "not only Linux" blog, so be sure to keep this source http://nolinux.blog.51cto.com/4824967/1440414

One of the MySQL series key installation scripts----Single-instance/multi-instance

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: info-contact@alibabacloud.com 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.