首页 > 数据库 > MySQL > 正文

发布MySQL集群自动安装脚本1.0!

2024-07-24 12:54:57
字体:
来源:转载
供稿:网友
经过几天的测试,终于可以发布了!

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

#!/bin/bash####################################################### title: mysql 4.1 cluster installation script #### version: 1.0 #### date: 2004-11-11 #### author: yipsilon #### email: [email protected] #### 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 programsinst_server=1#mysql installation pathinst_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 informationmgm_host="192.168.1.253"mgm_port="2200"#################################################### mysql cluster config ########################################################determine to install cluster#"0" means do not install cluster programsinst_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.252computers="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.252mgms="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=2dbs="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=2apis="1 0 2 2"################################################################################ starting to install programs, do not modify them! ###############################################################################echo "starting to install programs" > install.log#find installation pathif [ $# -gt 0 ] then inst_path="$1"else inst_path="/usr/local/mysql"fiif [ 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 programsif [ 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!" fifi

2. 设置脚本权限,让它可执行:chmod 755 install.sh
3. 执行该脚本:./install.sh 或者 ./install <mysql安装目录>

具体使用说明,英语好的看脚本注释吧;英语不好的,那就再等等,过几天会release出来。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表