游戏数据库部署脚本
时间:2021-07-01 10:21:17
帮助过:30人阅读
考虑到游戏批量上线的问题,写了一个游戏mysql的部署脚本,因系统环境一样,所以脚本中并不是去安装mysql,而是将编译好了mysql直接拿过来用#!/bin/bash#2013/11
考虑到游戏批量上线的问题,写了一个游戏mysql的部署脚本,因系统环境一样,,所以脚本中并不是去安装mysql,而是将编译好了mysql直接拿过来用
#!/bin/bash
#2013/11/20
#Email:SongShouJiong@gyyx.cn
cat << EOF
====================================================
|此脚本用于XXXX数据库安装.
|
|-------------------------------------------------- |
|程序目录:/usr/local/mysql5.5
|
|-------------------------------------------------- |
|数据目录:/home/mysql/data
|
|-------------------------------------------------- |
|脚本运行时间由程序下载速度决定,请耐心等候....... |
====================================================
EOF
url=http://XXXXXX
#------------------- check disk ------------------------
echo "------------------------------------------"
check_disk(){
if fdisk -l | grep -q /dev/[sh]db;then
if df -h | grep -q /data;then
echo "Partition is ok!"
else
echo "You must mount /data!"
fi
else
echo "You must have two disk and mount it!"
fi
echo "------------------------------------------"
}
#----------------- add user ---------------------------
add_user(){
useradd mysql
if [ $? -eq 0 ];then
echo "Useradd Mysql Success!"
else
echo "Mysql User is Exits!!!"
fi
echo "--------------------------------------------"
}
#---------------- down install mysql5 and mysql ----------
down_mysql(){
cd /usr/local
wget $url/mysql5.tgz > /dev/null 2>&1
if [ $? -eq 0 ];then
echo "Download MysqlServer.tgz Success!"
else
echo "Download MysqlServer.tgz Error!!!"
fi
echo "--------------------------------------------"
tar zxvf mysql5.tgz > /dev/null 2>&1
if [ $? -eq 0 ];then
echo "Unzip MysqlServer.tgz Success!"
else
echo "Unzip MysqlServer.tgz Error!!!"
fi
echo "/usr/local/mysql5.5/bin/mysqld_safe --defaults-file=/usr/local/mysql5.5/etc/my.cnf --user=mysql &" >> /etc/rc.local
echo "--------------------------------------------"
#mkdir -p /data/mysql/
cd /data/
wget $url/mysql.tgz > /dev/null 2>&1
if [ $? -eq 0 ];then
echo "Download Mysql_Database Success!"
else
echo "Download Mysql_Database Error!!!"
fi
echo "--------------------------------------------"
tar zxvf mysql.tgz > /dev/null 2>&1
if [ $? -eq 0 ];then
echo "Unzip Mysql_Database Success!"
else
echo "Unzip Mysql_Database Error!!"
fi
chown -R mysql.mysql /data/mysql/
ln -s /data/ /home/mysql/
echo "--------------------------------------------"
}
#------------------Start Mysql--------------------------
start_mysql(){
/usr/local/mysql5.5/bin/mysqld_safe --defaults-file=/usr/local/mysql5.5/etc/my.cnf --user=mysql & > /dev/null 2>&1
sleep 3
a=`netstat -tunpl | grep :7036 | wc -l`
if [ $a -gt 0 ];then
echo "Start Mysql Success!"
else
echo "Start Mysql Error!"
fi
echo "--------------------------------------------"
}
#------------------Create Game Database-------------------
create_database(){
#
host=`ifconfig eth0 | grep "inet addr:" | awk '{print $2}' | cut -d: -f2`
wget $url/DB.sql > /dev/null 2>&1
if [ $? -eq 0 ];then
echo "Download DB.sql Success!"
else
echo "Download DB.sql Error!"
fi
echo "----------------------------------------"
wget $url/DB2.sql > /dev/null 2>&1
if [ $? -eq 0 ];then
echo "Download DB2.sql Success!"
else
echo "Download DB2.sql Error!!!"
fi
echo "----------------------------------------"
user=XXXX
passwd=XXXXX
/usr/local/mysql5.5/bin/mysql -u${user} -p${passwd} -e"source DB.sql;"
sleep 3
/usr/local/mysql5.5/bin/mysql -u${user} -p${passwd} -e"source DB2.sql;"
sleep 3
if [ $? -eq 0 ];then
echo "Create Game Database Success!"
else
echo "Create Game Database Error!"
fi
echo "---------------------------------------------"
}
check_disk
add_user
down_mysql
start_mysql
create_database
脚本的指定步骤大概是:检测磁盘是否符合数据库挂载要求------>新建mysql用户------>下载mysql程序包并解压------>启动mysql并添加到开机启动------>新建游戏数据库。
脚本仅供参考,如果您有什么好的建议或者意见,欢迎您Send mail:SongShouJiong@gyyx.cn.
本文出自 “我的未来不是梦。” 博客,请务必保留此出处