Publish MySQL cluster auto install Script 1.0!

Source: Internet
Author: User
Tags define chmod config ini mysql socket stop script mysql database
mysql| Script | Automatic installation After a few days of testing, finally can be released!

1. Under the MySQL source code directory to create a new script install.sh, add the following code to this script:

#!/bin/bash####################################################### title:mysql 4.1 Cluster Installation Script version:1.0 # date:2004-11-11 # author:yipsilon # email:yipsilon@163.com # license:general Public License (GPL) the Copyright (c), Yipsilon all Rights Reserved ######################################################### Changelog ######################################################### Installation Guide # 1. Copy the script file into MySQL source path # 2. Change script file ' s permission to 755 # 3. Execute it and wait for ... ######################################################################################## #################### MySQL Server Config ########################################################## #Determine to Install MySQL server# "0" means do not install server Programsinst_server=1#mysql installation Pathinst_path= "/usr/local/ MySQL "#Define the ports of MySQL installation, intput strings of PORT with whitespace separated. #e. G. "3306 3307" means install two MySQL servers:# the $INST installed and _PATH/1 listen He second server is installed to $INST _PATH/2 and listen 3307 port.# ... inst_ports= "3306" #The Management Server informationmgm_host= "192.168.1.253" mgm_port= "2200" ####################### ############################# MySQL Cluster Config ######################################################## Determine to install cluster# "0" means does not install cluster the programsinst_cluster=1#define in COMPUTERs, Config.ini T strings of HostName with whitespace separated. #The Id are auto increment and start with 1. #e. G. "192.168.1.253 192.168.252 "would generate the following code# [computer]# id=1# hostname=192.168.1.253# [computer]# id=2#] hostname=192.1 68.1.252computers= "192.168.1.253 192.168.1.252" #Define mgms in Config.ini, intput strings to HostName with whitespace Sep Arated. #e. G. "192.168.1.253 192.168.252" to generate the following code# [mgm]# hostname=192.168.1.253# [mgm]# hostname=192.168.1.252mgms= "192.168.1.253" #Define DBs in Config.ini, intput IDs of Executeoncomputer with whitespace separated. #e. G. "1 2" to generate the following code# [db]# executeoncomputer=1# [db]# executeoncomputer=2dbs= "1" #Define APIs in Config.ini, intput IDs of Executeoncomputer with whitespace separated. #e. G. "1 0 1 2 "would generate the following code# [api]# executeoncomputer=1# [api]# [api]# executeoncomputer=1#] [api]# Executeonco Mputer=2apis= "1 0 2 2" ################################################################################ Starting to Install programs, do not modify them! ############################################################################## #echo "Starting to install programs" > Install.log#find installation pathif [$#-GT 0] then inst_path= "$" Else inst_path= "/usr/local/mysql" Fiif [0-lt $I Nst_server]then echo "Now, installing the MySQL servers ..." #Loop to install MySQL servers installed_server_count=1 for P ORT in $INST _portS do #Define the current MySQL server installation path mysl_path= $INST _path/$INSTALLED _server_count #Configure mysql Serv Er echo "Exec./configure--prefix= $MYSL _path--with-pthread--with-unix-socket-path= $MYSL _path/var/mysql.sock-- With-mysqld-user=root--with-tcp-port= $PORT--with-charset=gbk--with-ndbcluster ">> install.log/configure- prefix= $MYSL _path--with-pthread--with-unix-socket-path= $MYSL _path/var/mysql.sock--with-mysqld-user=root- with-tcp-port= $PORT--with-charset=gbk--with-ndbcluster #Make mysql server echo "Exec make && make install" >& Gt Install.log make && make install #Create the var directory for MySQL data mkdir-p $MYSL _path/var #Create my.cnf Echo "Create $MYSL _path/var/my.cnf" >> install.log echo "[Client]" > $MYSL _path/var/my.cnf echo "port= $PORT" > > $MYSL _path/var/my.cnf echo "socket= $MYSL _path/var/mysql.sock" >> $MYSL _path/var/my.cnf echo "" >> $ Mysl_path/var/my.cnf echo "[mysqld]" >> $MYSL _path/var/my.cnf echo "Ndbcluster" >> $MYSL _path/var/my.cnf echo "ndb_connectstring=host= $MGM _host: $MGM _port" >> $MYSL _path/var/my.cnf echo "User=root" >> $MYSL _path/var/my.cnf echo "port= $PORT" >> $MYSL _path/var/my.cnf echo "basedir= $MYSL _path/" >> $MYSL _path/var/my.cnf echo "datadir= $MYSL _path/var/" >> $MYSL _path/var/ my.cnf echo "socket= $MYSL _path/var/mysql.sock" >> $MYSL _path/var/my.cnf echo "DEFAULT-CHARACTER-SET=GBK" > > $MYSL _path/var/my.cnf echo "Default-storage-engine=innodb" >> $MYSL _path/var/my.cnf echo "max_connections= ">> $MYSL _path/var/my.cnf echo" ">> $MYSL _path/var/my.cnf echo" query_cache_size=33m ">> $MYSL _ path/var/my.cnf echo "table_cache=1520" >> $MYSL _path/var/my.cnf echo "tmp_table_size=16m" >> $MYSL _path/ var/my.cnf echo "thread_cache=38" >> $MYSL _path/var/my.cnf echo ">> $MYSL _path/var/my.cnf echo" #MyISAM Spe Cific Options ">> $MYSL _path/var/my.cnf echo" #skip-myisAm ">> $MYSL _path/var/my.cnf echo" ">> $MYSL _path/var/my.cnf echo" #INNODB specific Options ">> $MYSL _p ath/var/my.cnf echo "#skip-innodb" >> $MYSL _path/var/my.cnf chmod 755 $MYSL _path/var/my.cnf #Install MySQL Database echo "Exec $MYSL _path/bin/mysql_install_db" >> install.log $MYSL _path/bin/mysql_install_db #Create MySQL control script if [e $MYSL _path/share/mysql/mysql.server] then #Use default MySQL control script #Create MySQL SE RVer start Script echo "Create $MYSL _path/start" >> install.log echo "$MYSL _path/share/mysql/mysql.server start" &G T $MYSL _path/start echo "Chmod 755 $MYSL _path/start" >> install.log Chmod 755 $MYSL _path/start #Create MySQL Server St Op script echo "Create $MYSL _path/stop" >> install.log echo "$MYSL _path/share/mysql/mysql.server Stop" > $MYSL _p Ath/stop echo "Chmod 755 $MYSL _path/stop" >> install.log Chmod 755 $MYSL _path/stop #Create MySQL server restart SCRI PT echo "Create $MYSL _path/restart" >> Install.log echo "$MYSL _path/share/mysql/mysql.server restart" > $MYSL _path/restart echo "Chmod 755 $MYSL _path/ Restart ">> install.log chmod 755 $MYSL _path/restart Else #Use custom MySQL control script #Create MySQL server star T script echo "Create $MYSL _path/start" >> install.log echo "$MYSL _path/libexec/mysqld &" > $MYSL _path/start echo "Chmod 755 $MYSL _path/start" >> install.log Chmod 755 $MYSL _path/start #Create mysql server stop script Echo Create $MYSL _path/stop ">> install.log echo" $MYSL _path/bin/mysqladmin-u root-p shutdown "> $MYSL _path/stop ech O "Chmod 755 $MYSL _path/stop" >> install.log Chmod 755 $MYSL _path/stop #Create MySQL server restart script echo Cre Ate $MYSL _path/restart ">> install.log echo" $MYSL _path/bin/mysqladmin-u root-p shutdown "> $MYSL _path/restart echo "$MYSL _path/libexec/mysqld &" >> $MYSL _path/restart echo "Chmod 755 $MYSL _path/restart" >> install. Log chmod 755 $MYSL _path/restaRT fi #Clean MySQL server to get ready for the next installation echo ' Exec make clean ' >> install.log stalled_server_count=$ (($INSTALLED _server_count + 1)) done echo "configurations! MySQL servers has been installed successfully. "echo" "echo" 1. To start MySQL server, use the following command: "echo" CD <MYSQL_INSTALLATION_PATH> "echo"./start "echo" "echo" "2. To stop MySQL server, use the following command:" echo "CD <MYSQL_INSTALLATION_PATH>" echo "./stop" echo "" E Cho "3. To restart MySQL server, use the following command: "echo" CD <MYSQL_INSTALLATION_PATH> "echo"./restart "Fi#instal L cluster programsif [0-lt $INST _cluster]then If [-e $INST _PATH/1] then echo "Now, installing the cluster programs ... . "#Define the cluster installation path clst_path= $INST _path/cluster #Create cluster directory echo" Exec mkdir-p $CLST _ PATH ">> install.log mkdir-p $CLST _path #Copy cluster binaries echo" Exec cp $INST _path/1/bin/ndb* $CLST _path/">> install.log cp $INST _path/1/bin/ndb* $CLST _path/echo" Exec cp $INST _path/1/libexec/ndb* $CLST _path/"&GT;&G T Install.log CP $INST _path/1/libexec/ndb* $CLST _path/#Create config.ini echo "Create $CLST _path/config.ini" >> Install.log #Write Default global configuration echo "[TCP default]" >> $CLST _path/config.ini echo "" >> $CLST _path/config.ini echo "[MGM DEFAULT]" >> $CLST _path/config.ini echo ">> $CLST _path/config.ini echo" [DB DEFA ULT] ">> $CLST _path/config.ini echo" Noofreplicas=1 ">> $CLST _path/config.ini echo" ">> $CLST _path/co Nfig.ini echo "[API DEFAULT]" >> $CLST _path/config.ini echo "" >> $CLST _path/config.ini #Write Computers confi Guration computer_id=1 for COMPUTER in $COMPUTERS do echo [COMPUTER] ">> $CLST _path/config.ini echo" Id= $COMPUTER _ ID ">> $CLST _path/config.ini echo" hostname= $COMPUTER >> $CLST _path/config.ini echo "" >> $CLST _path/ Config.ini computer_id=$ ($COmputer_id + 1) #Write Management Server configuration for MGM in $MGMS do echo "[MGM]" >> $CLST _path/config.in I echo "hostname= $MGM" >> $CLST _path/config.ini echo "" >> $CLST _path/config.ini done #Write storage Nodes Co Nfiguration for DB in $DBS do echo "[DB]" >> $CLST _path/config.ini echo "executeoncomputer= $DB" >> $CLST _path /config.ini echo "" >> $CLST _path/config.ini done #Write mysql servers configuration the for APIs in $APIS do Echo [API] ">> $CLST _path/config.ini if [0-ne $API] then echo" executeoncomputer= $API ">> $CLST _path/config.ini fi E Cho "" >> $CLST _path/config.ini done #Create ndb.cfg echo "Create $CLST _path/ndb.cfg" >> install.log echo hos t= $MGM _host: $MGM _port ">> $CLST _path/ndb.cfg echo" ">> $CLST _path/ndb.cfg echo" configurations! Cluster programs has been installed successfully. "echo" "echo" 1. To start Management Server (MGM), use the following command: "echo" CD $CLST _path "echo"./NDB_MGMD "echo" "echo" 2. To start Stroage node (DB), use the following command: "echo" CD $CLST _path "echo"./ndbd "echo" "echo" 3. To manage the cluster, use the following command: "echo" CD $CLST _path "echo"./ndb_mgm "echo" "echo" 4. else, nothing to do.;) "echo" "echo" Enjoy yourself. "Else echo" Cluster installation has been stopped, the reason is: "; Echo ' No database server installed. ' echo ' so ' you can ' ' cluster programs in this machine! ' Fifi

2. Set script permissions to allow it to execute: chmod 755 install.sh
3. Execute the script:./install.sh or./install <mysql installation directory >

The specific use of instructions, English good to see the script annotation bar, English is not good, then wait a few days will release out.

Related Article

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.