热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

MySQL集群自动安装脚本_MySQL

MySQL集群自动安装脚本
Mysql集群


  1. 在MySQL源代码目录下新建脚本 install.sh,把下面的代码添加到这个脚本中:

#!/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="{GetProperty(Content)}"

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:"

推荐阅读
  • 本文介绍了在MacOS系统上安装MySQL的步骤,并详细说明了如何设置MySQL服务的开机启动和如何修改MySQL的密码。通过下载MySQL的macos版本并按照提示一步一步安装,在系统偏好设置中可以找到MySQL的图标进行设置。同时,还介绍了通过终端命令来修改MySQL的密码的具体操作步骤。 ... [详细]
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • 在数据分析工作中,我们通常会遇到这样的问题,一个业务部门由若干业务组构成,需要筛选出每个业务组里业绩前N名的业务员。这其实是一个分组排序的 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • 本文介绍了Hyperledger Fabric外部链码构建与运行的相关知识,包括在Hyperledger Fabric 2.0版本之前链码构建和运行的困难性,外部构建模式的实现原理以及外部构建和运行API的使用方法。通过本文的介绍,读者可以了解到如何利用外部构建和运行的方式来实现链码的构建和运行,并且不再受限于特定的语言和部署环境。 ... [详细]
  • 本文介绍了在Mac上配置环境变量,实现Python3的命令行调用的步骤。首先通过官网下载或使用brew安装Python3,并找到安装路径。然后将该路径添加到环境变量中,可以通过编辑.bash_profile文件或执行source命令来实现。配置完成后,即可在命令行中直接调用Python3。 ... [详细]
  • 成功安装Sabayon Linux在thinkpad X60上的经验分享
    本文分享了作者在国庆期间在thinkpad X60上成功安装Sabayon Linux的经验。通过修改CHOST和执行emerge命令,作者顺利完成了安装过程。Sabayon Linux是一个基于Gentoo Linux的发行版,可以将电脑快速转变为一个功能强大的系统。除了作为一个live DVD使用外,Sabayon Linux还可以被安装在硬盘上,方便用户使用。 ... [详细]
  • 本文介绍了Linux Shell中括号和整数扩展的使用方法,包括命令组、命令替换、初始化数组以及算术表达式和逻辑判断的相关内容。括号中的命令将会在新开的子shell中顺序执行,括号中的变量不能被脚本余下的部分使用。命令替换可以用于将命令的标准输出作为另一个命令的输入。括号中的运算符和表达式符合C语言运算规则,可以用在整数扩展中进行算术计算和逻辑判断。 ... [详细]
  • 本文介绍了Shell中for命令的基本格式和用法,通过提供一个值列表来迭代执行一系列命令。同时还介绍了如何读取列表中的值,并给出了for命令与其他命令的结合使用示例。 ... [详细]
  • 【shell】网络处理:判断IP是否在网段、两个ip是否同网段、IP地址范围、网段包含关系
    本文介绍了使用shell脚本判断IP是否在同一网段、判断IP地址是否在某个范围内、计算IP地址范围、判断网段之间的包含关系的方法和原理。通过对IP和掩码进行与计算,可以判断两个IP是否在同一网段。同时,还提供了一段用于验证IP地址的正则表达式和判断特殊IP地址的方法。 ... [详细]
  • 树莓派语音控制的配置方法和步骤
    本文介绍了在树莓派上实现语音控制的配置方法和步骤。首先感谢博主Eoman的帮助,文章参考了他的内容。树莓派的配置需要通过sudo raspi-config进行,然后使用Eoman的控制方法,即安装wiringPi库并编写控制引脚的脚本。具体的安装步骤和脚本编写方法在文章中详细介绍。 ... [详细]
  • 本文总结了Linux下多线程执行shell脚本的4种方法,包括切换到工作目录执行、使用绝对路径执行、直接使用bash或sh执行。同时介绍了为什么需要加上"./"来执行脚本的原因。 ... [详细]
  • 从U ... [详细]
  • crontab 自动执行定时任务时,命令无法执行的解决方案
    为什么80%的码农都做不了架构师?最近在工作中需要使用crontab执行定时任务,处理memcacheq消息队列里的数据,但是发现在 ... [详细]
  • 本文介绍了在Android Studio中使用命令行build gradle的方法,并解决了一些常见问题,包括手动配置gradle环境变量和解决External Native Build Issues的方法。同时提供了相关参考文章链接。 ... [详细]
author-avatar
蓬从蓉Tahirah
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有