首页 数据库 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教程
1667
14
CakePHP 教程
1426
52
Laravel 教程
1328
25
PHP教程
1273
29
C# 教程
1255
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