MySQL集群自动安装脚本

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介:

#!/bin/bash 
##################################################### 
## Title: MySQL 4.1 Cluster Installation Script    ## 
## Version: 1.0                                    ## 
## Date: 2004-11-11                                ## 
## Author: yipsilon                                ## 
## Email:                          ## 
## License: General Public License (GPL)           ## 
## Copyright(c) 2004, 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 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 toINST_PATH/1 and listen 3306 port.   #     The second server will be installed toINST_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="# -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 inINST_SERVER ]   then    echo "Now, installing the MySQL servers..."        #Loop to install mysql servers    INSTALLED_SERVER_COUNT=1    for PORT inINST_PORTS 
 do 
  #Define the current mysql server installation path 
   MYSL_PATH=INSTPATH/INSTALLED_SERVER_COUNT 
    
   #Configure mysql server 
   echo "Exec ./configure --prefix=MYSLPATHwithpthreadwithunixsocketpath=MYSL_PATH/var/mysql.sock --with-mysqld-user=root --with-tcp-port=PORTwithcharset=gbkwithndbcluster">;>;install.log./configureprefix=MYSL_PATH --with-pthread --with-unix-socket-path=MYSLPATH/var/mysql.sockwithmysqlduser=rootwithtcpport=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 "CreateMYSL_PATH/var/my.cnf" >;>; install.log 
   echo "[client]" >; MYSLPATH/var/my.cnfecho"port=PORT" >;>; MYSLPATH/var/my.cnfecho"socket=MYSL_PATH/var/mysql.sock" >;>; MYSLPATH/var/my.cnfecho"">;>;MYSL_PATH/var/my.cnf 
   echo "[mysqld]" >;>; MYSLPATH/var/my.cnfecho"ndbcluster">;>;MYSL_PATH/var/my.cnf 
   echo "ndb_connectstring=host=MGMHOST:MGM_PORT" >;>; MYSLPATH/var/my.cnfecho"user=root">;>;MYSL_PATH/var/my.cnf 
   echo "port=PORT">;>;MYSL_PATH/var/my.cnf 
   echo "basedir=MYSLPATH/">;>;MYSL_PATH/var/my.cnf 
   echo "datadir=MYSLPATH/var/">;>;MYSL_PATH/var/my.cnf 
   echo "socket=MYSLPATH/var/mysql.sock">;>;MYSL_PATH/var/my.cnf 
   echo "default-character-set=gbk" >;>; MYSLPATH/var/my.cnfecho"defaultstorageengine=INNODB">;>;MYSL_PATH/var/my.cnf 
   echo "max_connections=500" >;>; MYSLPATH/var/my.cnfecho"">;>;MYSL_PATH/var/my.cnf 
   echo "query_cache_size=33M" >;>; MYSLPATH/var/my.cnfecho"tablecache=1520">;>;MYSL_PATH/var/my.cnf 
   echo "tmp_table_size=16M" >;>; MYSLPATH/var/my.cnfecho"threadcache=38">;>;MYSL_PATH/var/my.cnf 
   echo "" >;>; MYSL_PATH/var/my.cnf      echo "#MyISAM Specific options" >;>;MYSL_PATH/var/my.cnf 
   echo "#skip-myisam" >;>; MYSLPATH/var/my.cnfecho"">;>;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 "ExecMYSL_PATH/bin/mysql_install_db" >;>; install.log 
   MYSL_PATH/bin/mysql_install_db            #Create mysql control script      if [ -eMYSL_PATH/share/mysql/mysql.server ] 
   then 
    
    #Use default mysql control script 
     
    #Create mysql server start script 
    echo "Create MYSLPATH/start">;>;install.logecho"MYSL_PATH/share/mysql/mysql.server start" >; MYSLPATH/startecho"Chmod755MYSL_PATH/start" >;>; install.log 
    chmod 755 MYSL_PATH/start              #Create mysql server stop script       echo "CreateMYSL_PATH/stop" >;>; install.log 
    echo "MYSLPATH/share/mysql/mysql.serverstop">;MYSL_PATH/stop 
    echo "Chmod 755 MYSLPATH/stop">;>;install.logchmod755MYSL_PATH/stop 
     
    #Create mysql server restart script 
    echo "Create MYSLPATH/restart">;>;install.logecho"MYSL_PATH/share/mysql/mysql.server restart" >; MYSLPATH/restartecho"Chmod755MYSL_PATH/restart" >;>; install.log 
    chmod 755 MYSL_PATH/restart      else              #Use custom mysql control script               #Create mysql server start script       echo "CreateMYSL_PATH/start" >;>; install.log 
    echo "MYSL_PATH/libexec/mysqld &" >;MYSL_PATH/start 
    echo "Chmod 755 MYSLPATH/start">;>;install.logchmod755MYSL_PATH/start 
     
    #Create mysql server stop script 
    echo "Create MYSLPATH/stop">;>;install.logecho"MYSL_PATH/bin/mysqladmin -u root -p shutdown" >; MYSLPATH/stopecho"Chmod755MYSL_PATH/stop" >;>; install.log 
    chmod 755 MYSL_PATH/stop              #Create mysql server restart script       echo "CreateMYSL_PATH/restart" >;>; install.log 
    echo "MYSLPATH/bin/mysqladminurootpshutdown">;MYSL_PATH/restart 
    echo "MYSL_PATH/libexec/mysqld &" >;>;MYSL_PATH/restart 
    echo "Chmod 755 MYSLPATH/restart">;>;install.logchmod755MYSL_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 INSTCLUSTER]thenif[eINST_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 -pCLST_PATH" >;>; install.log 
   mkdir -p CLST_PATH          #Copy cluster binaries      echo "Exec cpINST_PATH/1/bin/ndb* CLSTPATH/">;>;install.logcpINST_PATH/1/bin/ndb* CLSTPATH/echo"ExeccpINST_PATH/1/libexec/ndb* CLSTPATH/">;>;install.logcpINST_PATH/1/libexec/ndb* CLST_PATH/          #Create config.ini      echo "CreateCLST_PATH/config.ini" >;>; install.log 
      
     #Write default global configuration 
    echo "[TCP DEFAULT]" >;>; CLSTPATH/config.iniecho"">;>;CLST_PATH/config.ini 
    echo "[MGM DEFAULT]" >;>; CLSTPATH/config.iniecho"">;>;CLST_PATH/config.ini 
    echo "[DB DEFAULT]" >;>; CLSTPATH/config.iniecho"NoOfReplicas=1">;>;CLST_PATH/config.ini 
    echo "" >;>; CLSTPATH/config.iniecho"[APIDEFAULT]">;>;CLST_PATH/config.ini 
    echo "" >;>; CLST_PATH/config.ini              #Write computers configuration       COMPUTER_ID=1       for COMPUTER inCOMPUTERS 
    do 
      echo "[COMPUTER]" >;>; CLSTPATH/config.iniecho"Id=COMPUTER_ID" >;>; CLSTPATH/config.iniecho"HostName=COMPUTER" >;>; CLSTPATH/config.iniecho"">;>;CLST_PATH/config.ini 
       
      COMPUTER_ID=((COMPUTER_ID + 1)) 
    done 
     
    #Write management server configuration 
    for MGM in MGMSdoecho"[MGM]">;>;CLST_PATH/config.ini 
      echo "  HostName=MGM">;>;CLST_PATH/config.ini 
      echo "" >;>; CLST_PATH/config.ini       done              #Write storage nodes configuration       for DB inDBS 
    do 
      echo "[DB]" >;>; CLSTPATH/config.iniecho"ExecuteOnComputer=DB" >;>; CLSTPATH/config.iniecho"">;>;CLST_PATH/config.ini 
    done 
     
    #Write mysql servers configuration 
    for API in APISdoecho"[API]">;>;CLST_PATH/config.ini 
      if [ 0 -ne API]thenecho"ExecuteOnComputer=API" >;>; CLSTPATH/config.inifiecho"">;>;CLST_PATH/config.ini 
    done 
     
  #Create Ndb.cfg 
  echo "Create CLSTPATH/Ndb.cfg">;>;install.logecho"host=MGM_HOST:MGMPORT">;>;CLST_PATH/Ndb.cfg 
  echo "" >;>; CLSTPATH/Ndb.cfgecho"Configurations!Clusterprogramshasbeeninstalledsuccessfully."echo""echo"1.Tostartmanagementserver(MGM),usethefollowingcommand:"echo"cdCLST_PATH" 
   echo "  ./ndb_mgmd" 
   echo "" 
   echo "2. To start stroage node(DB), use the following command:" 
   echo "  cd CLSTPATH"echo"./ndbd"echo""echo"3.Tomanagethecluster,usethefollowingcommand:"echo"cdCLST_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 
1. 在MySQL源代码目录下新建脚本 install.sh,把下面的代码添加到这个脚本中:
2. 设置脚本权限,让它可执行:chmod 755 install.sh 
3. 执行该脚本:./install.sh 或者 ./install <MySQL安装目录>;




      本文转自glying 51CTO博客,原文链接:http://blog.51cto.com/liying/967695,如需转载请自行联系原作者



相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
打赏
0
0
0
0
348
分享
相关文章
MySQL 备份 Shell 脚本:支持远程同步与阿里云 OSS 备份
一款自动化 MySQL 备份 Shell 脚本,支持本地存储、远程服务器同步(SSH+rsync)、阿里云 OSS 备份,并自动清理过期备份。适用于数据库管理员和开发者,帮助确保数据安全。
容器技术实践:在Ubuntu上使用Docker安装MySQL的步骤。
通过以上的操作,你已经步入了Docker和MySQL的世界,享受了容器技术给你带来的便利。这个旅程中你可能会遇到各种挑战,但是只要你沿着我们划定的路线行进,你就一定可以达到目的地。这就是Ubuntu、Docker和MySQL的灵魂所在,它们为你开辟了一条通往新探索的道路,带你亲身感受到了技术的力量。欢迎在Ubuntu的广阔大海中探索,用Docker技术引领你的航行,随时准备感受新技术带来的震撼和乐趣。
48 16
云数据库:从零到一,构建高可用MySQL集群
在互联网时代,数据成为企业核心资产,传统单机数据库难以满足高并发、高可用需求。云数据库通过弹性扩展、分布式架构等优势解决了这些问题,但也面临数据安全和性能优化挑战。本文介绍了如何从零开始构建高可用MySQL集群,涵盖选择云服务提供商、创建实例、配置高可用架构、数据备份恢复及性能优化等内容,并通过电商平台案例展示了具体应用。
Docker Compose V2 安装常用数据库MySQL+Mongo
以上内容涵盖了使用 Docker Compose 安装和管理 MySQL 和 MongoDB 的详细步骤,希望对您有所帮助。
228 42
CentOS7仅安装部署MySQL80客户端
通过上述步骤,你可以在CentOS 7上成功安装并配置MySQL 8.0客户端。这个过程确保你能够使用MySQL客户端工具连接和管理远程的MySQL数据库,而不需要在本地安装MySQL服务器。定期更新MySQL客户端可以确保你使用的是最新的功能和安全修复。
347 16
《docker基础篇:8.Docker常规安装简介》包括:docker常规安装总体步骤、安装tomcat、安装mysql、安装redis
《docker基础篇:8.Docker常规安装简介》包括:docker常规安装总体步骤、安装tomcat、安装mysql、安装redis
181 7
《docker高级篇(大厂进阶):1.Docker复杂安装详说》包括:安装mysql主从复制、安装redis集群
《docker高级篇(大厂进阶):1.Docker复杂安装详说》包括:安装mysql主从复制、安装redis集群
160 14
Windows Server 安装 MySQL 8.0 详细指南
安装 MySQL 需要谨慎,特别注意安全配置和权限管理。根据实际业务需求调整配置,确保数据库的性能和安全。
481 9
【MySQL基础篇】MySQL概述、Windows下载MySQL8.0超详细图文安装教程
在这一章节,主要介绍两个部分,数据库相关概念及MySQL数据库的介绍、下载、安装、启动及连接。接着,详细描述了MySQL 8.0的版本选择与下载,推荐使用社区版(免费)。安装过程包括自定义安装路径、配置环境变量、启动和停止服务、以及客户端连接测试。此外,还提供了在同一台电脑上安装多个MySQL版本的方法及卸载步骤。最后,解释了关系型数据库(RDBMS)的特点,即基于二维表存储数据,使用SQL语言进行操作,格式统一且便于维护。通过具体的结构图展示了MySQL的数据模型,说明了数据库服务器、数据库、表和记录之间的层次关系。
【MySQL基础篇】MySQL概述、Windows下载MySQL8.0超详细图文安装教程
Linux安装jdk、mysql、redis
Linux安装jdk、mysql、redis
284 7
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等