搜尋
首頁資料庫mysql教程MySQL集群自动安装脚本

MySQL集群自动安装脚本

Jun 07, 2016 pm 04:04 PM
mysql安裝原始碼腳本自動叢集

1. 在MySQL源代码目录下新建脚本 install.sh,把下面的代码添加到这个脚本中: #!/bin/bash##################################################### MySQL Server Config ###########################################################Determine to install M

1. 在MySQL源代码目录下新建脚本 install.sh,把下面的代码添加到这个脚本中:
<code>
#!/bin/bash

############################################
######### MySQL Server Config ##############
############################################
#Determine to install MySQL server
#"0" means do not install server programs
INST_SERVER=1
#MySQL installation path
INST_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 first server will be installed to $INST_PATH/1 and listen 3306 port.
#     The second server will be installed to $INST_PATH/2 and listen 3307 port.
#     ... ...
INST_PORTS="3306"
#The management server information
MGM_HOST="192.168.1.253"
MGM_PORT="2200"
###########################################
######### MySQL Cluster Config ############
###########################################
#Determine to install cluster
#"0" means do not install cluster programs
INST_CLUSTER=1
#Define COMPUTERs in config.ini, intput strings of HostName with 
#whitespace separated.
#The Id attribute is auto increment and start with 1.
#e.g. "192.168.1.253 192.168.252" will generate the following code
#  [COMPUTER]
#    Id=1
#    HostName=192.168.1.253
#  [COMPUTER]
#    Id=2
#    HostName=192.168.1.252
COMPUTERS="192.168.1.253 192.168.1.252"
#Define MGMs in config.ini, intput strings of HostName with whitespace separated.
#e.g. "192.168.1.253 192.168.252" will generate the following code
#  [MGM]
#    HostName=192.168.1.253
#  [MGM]
#    HostName=192.168.1.252
MGMS="192.168.1.253"
#Define DBs in config.ini, intput ids of ExecuteOnComputer with whitespace separated.
#e.g. "1 2" will generate the following code
#  [DB]
#    ExecuteOnComputer=1
#  [DB]
#    ExecuteOnComputer=2
DBS="1"
#Define APIs in config.ini, intput ids of ExecuteOnComputer with whitespace separated.
#e.g. "1 0 1 2" will generate the following code
#  [API]
#    ExecuteOnComputer=1
#  [API]
#  [API]
#    ExecuteOnComputer=1
#  [API]
#    ExecuteOnComputer=2
APIS="1 0 2 2"
######################################################################
########## Starting to install programs, do not modify them! #########
######################################################################
echo "Starting to install programs" > install.log
#Find installation path
if [ $# -gt 0 ] 
then 
  INST_PATH="$1"
else 
  INST_PATH="/usr/local/mysql"
fi
if [ 0 -lt $INST_SERVER ]
then
 echo "Now, installing the MySQL servers..."
 
 #Loop to install mysql servers
 INSTALLED_SERVER_COUNT=1
 for PORT in $INST_PORTS
 do
  #Define the current mysql server installation path
   MYSL_PATH=$INST_PATH/$INSTALLED_SERVER_COUNT
   
   #Configure mysql server
   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" >> install.log
   make && make install
   
   #Create 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=500" >> $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 Specific 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_PATH/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 server start script
    echo "Create $MYSL_PATH/start" >> install.log
    echo "$MYSL_PATH/share/mysql/mysql.server start" > $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/share/mysql/mysql.server stop" > $MYSL_PATH/stop
    echo "Chmod 755 $MYSL_PATH/stop" >> install.log
    chmod 755 $MYSL_PATH/stop
    
    #Create mysql server restart script
    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 start 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
    echo "Chmod 755 $MYSL_PATH/stop" >> install.log
    chmod 755 $MYSL_PATH/stop
    
    #Create mysql server restart script
    echo "Create $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
   make clean
   
   INSTALLED_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 ""
 echo "3. To restart mysql server, use the following command:"
 echo "  cd <mysql_installation_path>"
 echo "  ./restart"
fi

#Install cluster programs
if [ 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/" >> 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 DEFAULT]" >> $CLST_PATH/config.ini
    echo "  NoOfReplicas=1" >> $CLST_PATH/config.ini
    echo "" >> $CLST_PATH/config.ini
    echo "[API DEFAULT]" >> $CLST_PATH/config.ini
    echo "" >> $CLST_PATH/config.ini
    
    #Write computers configuration
    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))
    done
    
    #Write management server configuration
    for MGM in $MGMS
    do
      echo "[MGM]" >> $CLST_PATH/config.ini
      echo "  HostName=$MGM" >> $CLST_PATH/config.ini
      echo "" >> $CLST_PATH/config.ini
    done
    
    #Write storage nodes configuration
    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
    for API in $APIS
    do
      echo "[API]" >> $CLST_PATH/config.ini
      if [ 0 -ne $API ]
      then
        echo "  ExecuteOnComputer=$API" >> $CLST_PATH/config.ini
      fi
      echo "" >> $CLST_PATH/config.ini
    done
    
  #Create Ndb.cfg
  echo "Create $CLST_PATH/Ndb.cfg" >> install.log
  echo "host=$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 not use cluster programs in this machine!"
 fi
fi
</mysql_installation_path></mysql_installation_path></mysql_installation_path></code>
2. 设置脚本权限,让它可执行:chmod 755 install.sh
3. 执行该脚本:./install.sh 或者 ./install
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
在MySQL中使用視圖的局限性是什麼?在MySQL中使用視圖的局限性是什麼?May 14, 2025 am 12:10 AM

mysqlviewshavelimitations:1)他們不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinsOrsubqueries.2)他們canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

確保您的MySQL數據庫:添加用戶並授予特權確保您的MySQL數據庫:添加用戶並授予特權May 14, 2025 am 12:09 AM

porthusermanagementinmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

哪些因素會影響我可以在MySQL中使用的觸發器數量?哪些因素會影響我可以在MySQL中使用的觸發器數量?May 14, 2025 am 12:08 AM

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)複雜的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)

mysql:存儲斑點安全嗎?mysql:存儲斑點安全嗎?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

mySQL:通過PHP Web界面添加用戶mySQL:通過PHP Web界面添加用戶May 14, 2025 am 12:04 AM

通過PHP網頁界面添加MySQL用戶可以使用MySQLi擴展。步驟如下:1.連接MySQL數據庫,使用MySQLi擴展。 2.創建用戶,使用CREATEUSER語句,並使用PASSWORD()函數加密密碼。 3.防止SQL注入,使用mysqli_real_escape_string()函數處理用戶輸入。 4.為新用戶分配權限,使用GRANT語句。

mysql:blob和其他無-SQL存儲,有什麼區別?mysql:blob和其他無-SQL存儲,有什麼區別?May 13, 2025 am 12:14 AM

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而ilenosqloptionslikemongodb,redis和calablesolutionsolutionsolutionsoluntionsoluntionsolundortionsolunsonstructureddata.blobobobissimplobisslowdeperformberbutslowderformandperformancewithlararengedata;

mySQL添加用戶:語法,選項和安全性最佳實踐mySQL添加用戶:語法,選項和安全性最佳實踐May 13, 2025 am 12:12 AM

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

MySQL:如何避免字符串數據類型常見錯誤?MySQL:如何避免字符串數據類型常見錯誤?May 13, 2025 am 12:09 AM

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollat​​ionsEttingSefectery.1)usecharforfixed lengengtrings,varchar forvariable-varchar forbariaible length,andtext/blobforlargerdataa.2 seterters seterters seterters

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具