遊戲資料庫部署指令碼

來源:互聯網
上載者:User

 考慮到遊戲大量上線的問題,寫了一個遊戲mysql的部署指令碼,因系統內容一樣,所以指令碼中並不是去安裝mysql,而是將編譯好了mysql直接拿過來用




#!/bin/bash#2013/11/20#Email:SongShouJiong@gyyx.cncat << EOF ====================================================|此指令碼用於XXXX資料庫安裝.                  ||-------------------------------------------------- ||程式目錄:/usr/local/mysql5.5                      ||-------------------------------------------------- ||資料目錄:/home/mysql/data                         ||-------------------------------------------------- ||指令碼已耗用時間由程式下載速度決定,請耐心等候.......  | ====================================================EOFurl=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_diskadd_userdown_mysqlstart_mysqlcreate_database


指令碼的指定步驟大概是:檢測磁碟是否符合資料庫掛載要求------>建立mysql使用者------>下載mysql程式包並解壓------>啟動mysql並添加到開機啟動------>建立遊戲資料庫。


指令碼僅供參考,如果您有什麼好的建議或者意見,歡迎您Send mail:SongShouJiong@gyyx.cn.


本文出自 “我的未來不是夢。” 部落格,請務必保留此出處http://song49.blog.51cto.com/4480450/1333221

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.