首頁 資料庫 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

熱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

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

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1666
14
CakePHP 教程
1426
52
Laravel 教程
1328
25
PHP教程
1273
29
C# 教程
1253
24
laravel入門實例 laravel入門實例 Apr 18, 2025 pm 12:45 PM

Laravel 是一款 PHP 框架,用於輕鬆構建 Web 應用程序。它提供一系列強大的功能,包括:安裝: 使用 Composer 全局安裝 Laravel CLI,並在項目目錄中創建應用程序。路由: 在 routes/web.php 中定義 URL 和處理函數之間的關係。視圖: 在 resources/views 中創建視圖以呈現應用程序的界面。數據庫集成: 提供與 MySQL 等數據庫的開箱即用集成,並使用遷移來創建和修改表。模型和控制器: 模型表示數據庫實體,控制器處理 HTTP 請求。

MySQL和PhpMyAdmin:核心功能和功能 MySQL和PhpMyAdmin:核心功能和功能 Apr 22, 2025 am 12:12 AM

MySQL和phpMyAdmin是強大的數據庫管理工具。 1)MySQL用於創建數據庫和表、執行DML和SQL查詢。 2)phpMyAdmin提供直觀界面進行數據庫管理、表結構管理、數據操作和用戶權限管理。

MySQL與其他編程語言:一種比較 MySQL與其他編程語言:一種比較 Apr 19, 2025 am 12:22 AM

MySQL与其他编程语言相比,主要用于存储和管理数据,而其他语言如Python、Java、C 则用于逻辑处理和应用开发。MySQL以其高性能、可扩展性和跨平台支持著称,适合数据管理需求,而其他语言在各自领域如数据分析、企业应用和系统编程中各有优势。

laravel框架安裝方法 laravel框架安裝方法 Apr 18, 2025 pm 12:54 PM

文章摘要:本文提供了詳細分步說明,指導讀者如何輕鬆安裝 Laravel 框架。 Laravel 是一個功能強大的 PHP 框架,它 упростил 和加快了 web 應用程序的開發過程。本教程涵蓋了從系統要求到配置數據庫和設置路由等各個方面的安裝過程。通過遵循這些步驟,讀者可以快速高效地為他們的 Laravel 項目打下堅實的基礎。

解決MySQL模式問題:TheliaMySQLModesChecker模塊的使用體驗 解決MySQL模式問題:TheliaMySQLModesChecker模塊的使用體驗 Apr 18, 2025 am 08:42 AM

在使用Thelia開發電商網站時,我遇到了一個棘手的問題:MySQL模式設置不當,導致某些功能無法正常運行。經過一番探索,我找到了一個名為TheliaMySQLModesChecker的模塊,它能夠自動修復Thelia所需的MySQL模式,徹底解決了我的困擾。

在MySQL中解釋外鍵的目的。 在MySQL中解釋外鍵的目的。 Apr 25, 2025 am 12:17 AM

在MySQL中,外鍵的作用是建立表與表之間的關係,確保數據的一致性和完整性。外鍵通過引用完整性檢查和級聯操作維護數據的有效性,使用時需注意性能優化和避免常見錯誤。

比較和對比Mysql和Mariadb。 比較和對比Mysql和Mariadb。 Apr 26, 2025 am 12:08 AM

MySQL和MariaDB的主要區別在於性能、功能和許可證:1.MySQL由Oracle開發,MariaDB是其分支。 2.MariaDB在高負載環境中性能可能更好。 3.MariaDB提供了更多的存儲引擎和功能。 4.MySQL採用雙重許可證,MariaDB完全開源。選擇時應考慮現有基礎設施、性能需求、功能需求和許可證成本。

SQL與MySQL:澄清兩者之間的關係 SQL與MySQL:澄清兩者之間的關係 Apr 24, 2025 am 12:02 AM

SQL是一種用於管理關係數據庫的標準語言,而MySQL是一個使用SQL的數據庫管理系統。 SQL定義了與數據庫交互的方式,包括CRUD操作,而MySQL實現了SQL標準並提供了額外的功能,如存儲過程和触發器。

See all articles