mysql安装脚本
- #!/bin/bash
- ###### variables ###################
- GLOABLE_VARIABLE_FILE="./global_variables.sh"
- SOURCE_FILENAME="mysql-5.1.41.zip"
- UNPACK_DIR_NAME="mysql-5.1.41"
- #########OK and failed ########
- GREEN_OK="\e[0;32m\033[1mOK\e[m"
- RED_FAILED="\e[0;31m\033[1mFAILED\e[m"
- #### source the global variable #####
- source ${GLOABLE_VARIABLE_FILE}
- #######lots of functions ##########
- error()
- {
- local FORMAT="$1"
- shift
- printf "${RED_FAILED} - ${FORMAT}\n" "$@" >&1
- }
- info()
- {
- local FORMAT="$1"
- shift
- printf "INFO - ${FORMAT}\n" "$@" >&1
- }
- warning()
- {
- local FORMAT="$1"
- shift
- print "WARNING - ${FORMAT}\n" "$@" >&1
- }
- check_source()
- {
- info "Checking source file %s.\n" "${SOURCE_FILENAME}"
- if [ -f ${SOURCE_DIR}/${SOURCE_FILENAME} ]
- then
- info "Mysql file %s is ${GREEN_OK}.\n" "${SOURCE_FILENAME}"
- else
- error "%s file not found.\n" "${SOURCE_FILENAME}"
- exit $?
- fi
- }
- unpack_file()
- {
- info "Unpack the source file %s .\n" "${SOURCE_FILENAME}"
- unzip ${SOURCE_DIR}/${SOURCE_FILENAME} -d ${UNPACK_DIR} 1>/dev/null
- if [[ $? != 0 ]]
- then
- error "Can not unpack file %s.\n" "${SOURCE_FILENAME}"
- exit $?
- else
- info "Unpack %s done.${GREEN_OK}\n" "${SOURCE_FILENAME}"
- fi
- }
- install_file()
- {
- cd ${UNPACK_DIR}/${UNPACK_DIR_NAME}
- local CONFIG_VARIABLE="--prefix=${INSTALL_ROOT}/mysql --localstatedir=${INSTALL_ROOT}/var/mysql/var --with-unix-socket-path=${INSTALL_ROOT}/mysql/mysql.sock --with-mysqld-user=mysql --with-plugins=archive,partition,myisam,innobase,heap,csv --with-extra-charsets=gbk,gb2312,utf8,ascii --with-charset=utf8 --with-collation=utf8_general_ci --with-big-tables --enable-assembler --enable-profiling --enable-local-infile --enable-thread-safe-client --with-fast-mutexes --with-pthread --with-zlib-dir=bundled --with-readline --without-geometry --without-embedded-server --without-debug --without-ndb-debug --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static"
- info "Now configure the mysql,this will take serveral minutes...\n"
- useradd mysql
- ./configure ${CONFIG_VARIABLE} 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "Mysql configure ${GREEN_OK}. Now make and make install. this will take serveral minutes... \n"
- make 1>/dev/null && make install 1>/dev/null
- if [[ $? == 0 ]]
- then
- cp -a support-files/my-medium.cnf.sh /etc/my.cnf
- info "Mysql installed ${GREEN_OK}.\n"
- else
- error "Mysql not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- ################## main ##########################
- #check file
- check_source
- #unpack the file
- unpack_file
- #install file
- info "Begin to install the mysql service.\n"
- install_file
php安装脚本
- #!/bin/bash
- ###### variables ###################
- GLOABLE_VARIABLE_FILE="./global_variables.sh"
- SOURCE_FILENAME="php-5.2.9.tar.gz"
- UNPACK_DIR_NAME="php-5.2.9"
- DB4="db4.tar.gz"
- #########OK and failed ########
- GREEN_OK="\e[0;32m\033[1mOK\e[m"
- RED_FAILED="\e[0;31m\033[1mFAILED\e[m"
- #### source the global variable #####
- source ${GLOABLE_VARIABLE_FILE}
- #######lots of functions ##########
- error()
- {
- local FORMAT="$1"
- shift
- printf "${RED_FAILED} - ${FORMAT}\n" "$@" >&1
- }
- info()
- {
- local FORMAT="$1"
- shift
- printf "INFO - ${FORMAT}\n" "$@" >&1
- }
- warning()
- {
- local FORMAT="$1"
- shift
- print "WARNING - ${FORMAT}\n" "$@" >&1
- }
- check_source()
- {
- info "Checking source file %s.\n" "${SOURCE_FILENAME}"
- if [ -f ${SOURCE_DIR}/${SOURCE_FILENAME} ]
- then
- info "PHP file %s is ${GREEN_OK}.\n" "${SOURCE_FILENAME}"
- else
- error "%s file not found.\n" "${SOURCE_FILENAME}"
- exit $?
- fi
- }
- unpack_file()
- {
- info "Unpack the source file %s .\n" "${SOURCE_FILENAME}"
- tar -zxf ${SOURCE_DIR}/${SOURCE_FILENAME} -C ${UNPACK_DIR}
- if [[ $? != 0 ]]
- then
- error "Can not unpack file %s.\n" "${HTTPD_SOURCE_FILENAME}"
- exit $?
- else
- info "Unpack %s done.${GREEN_OK}\n" "${HTTPD_SOURCE_FILENAME}"
- fi
- }
- install_file()
- {
- cd ${UNPACK_DIR}/${UNPACK_DIR_NAME}
- local CONFIG_VARIABLE="--prefix=${INSTALL_ROOT}/php --with-apxs2=${INSTALL_ROOT}/httpd/bin/apxs --with-mysql=${INSTALL_ROOT}/mysql/ --with-curl --with-freetype-dir --enable-gd-native-ttf --with-ttf --with-sybase --with-mssql --with-zlib --with-gd --with-jpeg-dir --enable-mbstring=all --enable-mbregex --enable-soap --with-mcrypt --enable-sockets --enable-ftp --enable-zip --with-iconv --with-xsl --with-xmlrpc --with-png-dir --with-openssl --with-db4=${INSTALL_ROOT}/db4/php_db4/"
- info "Now configure the php,this will take serveral minutes...\n"
- ./configure ${CONFIG_VARIABLE} 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "PHP configure ${GREEN_OK}. Now make and make install. this will take serveral minutes... \n"
- make 1>/dev/null && make install 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "PHP installed ${GREEN_OK}.\n"
- else
- error "PHP not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- install_apc()
- {
- local APC_FILENAME="APC-3.1.9.tgz"
- local APC_DIR="APC-3.1.9"
- info "Unpack the apc file %s\n" "${APC_FILENAME}"
- tar -zxf ${SOURCE_DIR}/${APC_FILENAME} -C ${UNPACK_DIR}
- if [[ $? == 0 ]]
- then
- info "unpack %s done.${GREEN_OK}\n" "${APC_FILENAME}"
- else
- error "unpack %s failed.\n" "${APC_FILENAME}"
- exit $?
- fi
- cd ${UNPACK_DIR}/${APC_DIR}
- info "Now configure the apc,this will take serveral minutes...\n"
- ${INSTALL_ROOT}/php/bin/phpize 1>/dev/null
- ./configure --with-php-config=${INSTALL_ROOT}/php/bin/php-config 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "APC configure ${GREEN_OK}. Now make . this will take serveral minutes... \n"
- make 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "APC installed ${GREEN_OK}.\n"
- info "copy the apc.so to ${INSTALL_ROOT}/php/lib/php/extensions/ \n"
- cp -a modules/apc.so ${INSTALL_ROOT}/php/lib/php/extensions/
- if [[ $? == 0 ]]
- then
- info "copy apc.so done.${GREEN_OK}\n"
- else
- error "copy apc.so failed.\n"
- exit $?
- fi
- else
- error "APC not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- install_memcache()
- {
- local MEMCACHE_FILENAME="memcache-3.0.6.tgz"
- local MEMCACHE_DIR="memcache-3.0.6"
- info "Unpack the memcache file %s\n" "${MEMCACHE_FILENAME}"
- tar -zxf ${SOURCE_DIR}/${MEMCACHE_FILENAME} -C ${UNPACK_DIR}
- if [[ $? == 0 ]]
- then
- info "unpack %s done.${GREEN_OK}\n" "${MEMCACHE_FILENAME}"
- else
- error "unpack %s failed.\n" "${MEMCACHE_FILENAME}"
- exit $?
- fi
- cd ${UNPACK_DIR}/${MEMCACHE_DIR}
- info "Now configure the apc,this will take serveral minutes...\n"
- ${INSTALL_ROOT}/php/bin/phpize 1>/dev/null
- ./configure --with-php-config=${INSTALL_ROOT}/php/bin/php-config 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "memcache configure ${GREEN_OK}. Now make . this will take serveral minutes... \n"
- make 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "memcache installed ${GREEN_OK}.\n"
- info "copy the memcache.so to ${INSTALL_ROOT}/php/lib/php/extensions/ \n"
- cp -a modules/memcache.so ${INSTALL_ROOT}/php/lib/php/extensions/
- if [[ $? == 0 ]]
- then
- info "copy memcache.so done.${GREEN_OK}\n"
- else
- error "copy memcache.so failed.\n"
- exit $?
- fi
- else
- error "memcache not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- install_ImageMagick()
- {
- local ImageMagick_FILENAME="ImageMagick-6.6.6-10.tar.gz"
- local ImageMagick_DIR="ImageMagick-6.6.6-10"
- info "Unpack the ImageMagick file %s\n" "${ImageMagick_FILENAME}"
- tar -zxf ${SOURCE_DIR}/${ImageMagick_FILENAME} -C ${UNPACK_DIR}
- if [[ $? == 0 ]]
- then
- info "unpack %s done.${GREEN_OK}\n" "${ImageMagick_FILENAME}"
- else
- error "unpack %s failed.\n" "${ImageMagick_FILENAME}"
- exit $?
- fi
- cd ${UNPACK_DIR}/${ImageMagick_DIR}
- info "Now configure the ImageMagick,this will take serveral minutes...\n"
- ./configure 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "ImageMagick configure ${GREEN_OK}. Now make and make install . this will take serveral minutes... \n"
- make 1>/dev/null && make install 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "ImageMagick installed ${GREEN_OK}.\n"
- else
- error "ImageMagick not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- install_imagick()
- {
- local imagick_FILENAME="imagick-3.1.0b1.tgz"
- local imagick_DIR="imagick-3.1.0b1"
- info "Unpack the imagick file %s\n" "${imagick_FILENAME}"
- tar -zxf ${SOURCE_DIR}/${imagick_FILENAME} -C ${UNPACK_DIR}
- if [[ $? == 0 ]]
- then
- info "unpack %s done.${GREEN_OK}\n" "${imagick_FILENAME}"
- else
- error "unpack %s failed.\n" "${imagick_FILENAME}"
- exit $?
- fi
- cd ${UNPACK_DIR}/${imagick_DIR}
- info "Now configure the imagick,this will take serveral minutes...\n"
- ${INSTALL_ROOT}/php/bin/phpize 1>/dev/null
- ./configure --with-php-config=${INSTALL_ROOT}/php/bin/php-config 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "imagick configure ${GREEN_OK}. Now make . this will take serveral minutes... \n"
- make 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "imagick installed ${GREEN_OK}.\n"
- info "copy the imagick.so to ${INSTALL_ROOT}/php/lib/php/extensions/ \n"
- cp -a modules/imagick.so ${INSTALL_ROOT}/php/lib/php/extensions/
- if [[ $? == 0 ]]
- then
- info "copy imagick.so done.${GREEN_OK}\n"
- else
- error "copy imagick.so failed.\n"
- exit $?
- fi
- else
- error "imagick not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- install_MagickWandForPHP()
- {
- local MagickWandForPHP_FILENAME="MagickWandForPHP-1.0.7.tar.gz"
- local MagickWandForPHP_DIR="MagickWandForPHP-1.0.7"
- info "Unpack the MagickWandForPHP file %s\n" "${MagickWandForPHP_FILENAME}"
- tar -zxf ${SOURCE_DIR}/${MagickWandForPHP_FILENAME} -C ${UNPACK_DIR}
- if [[ $? == 0 ]]
- then
- info "unpack %s done.${GREEN_OK}\n" "${MagickWandForPHP_FILENAME}"
- else
- error "unpack %s failed.\n" "${MagickWandForPHP_FILENAME}"
- exit $?
- fi
- cd ${UNPACK_DIR}/${MagickWandForPHP_DIR}
- info "Now configure the MagickWandForPHP,this will take serveral minutes...\n"
- ${INSTALL_ROOT}/php/bin/phpize 1>/dev/null
- ./configure --with-php-config=${INSTALL_ROOT}/php/bin/php-config 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "MagickWandForPHP configure ${GREEN_OK}. Now make . this will take serveral minutes... \n"
- make 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "MagickWandForPHP installed ${GREEN_OK}.\n"
- info "copy the MagickWandForPHP.so to ${INSTALL_ROOT}/php/lib/php/extensions/ \n"
- cp -a modules/magickwand.so ${INSTALL_ROOT}/php/lib/php/extensions/
- if [[ $? == 0 ]]
- then
- info "copy magickwand.so done.${GREEN_OK}\n"
- else
- error "copy magickwand.so failed.\n"
- exit $?
- fi
- else
- error "MagickWandForPHP not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- install_svn()
- {
- local svn_FILENAME="svn-1.0.1.tgz"
- local svn_DIR="svn-1.0.1"
- info "Unpack the svn file %s\n" "${svn_FILENAME}"
- tar -zxf ${SOURCE_DIR}/${svn_FILENAME} -C ${UNPACK_DIR}
- if [[ $? == 0 ]]
- then
- info "unpack %s done.${GREEN_OK}\n" "${svn_FILENAME}"
- else
- error "unpack %s failed.\n" "${svn_FILENAME}"
- exit $?
- fi
- cd ${UNPACK_DIR}/${svn_DIR}
- info "Now configure the svn,this will take serveral minutes...\n"
- ${INSTALL_ROOT}/php/bin/phpize 1>/dev/null
- ./configure --with-php-config=${INSTALL_ROOT}/php/bin/php-config 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "SVN configure ${GREEN_OK}. Now make . this will take serveral minutes... \n"
- make 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "SVN installed ${GREEN_OK}.\n"
- info "copy the svn.so to ${INSTALL_ROOT}/php/lib/php/extensions/ \n"
- cp -a modules/svn.so ${INSTALL_ROOT}/php/lib/php/extensions/
- if [[ $? == 0 ]]
- then
- info "copy svn.so done.${GREEN_OK}\n"
- else
- error "copy svn.so failed.\n"
- exit $?
- fi
- else
- error "svn not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- install_memcached()
- {
- local memcached_FILENAME="memcached-1.4.6.tar.gz"
- local memcached_DIR="memcached-1.4.6"
- info "Unpack the memcached file %s\n" "${memcached_FILENAME}"
- tar -zxf ${SOURCE_DIR}/${memcached_FILENAME} -C ${UNPACK_DIR}
- if [[ $? == 0 ]]
- then
- info "unpack %s done.${GREEN_OK}\n" "${memcached_FILENAME}"
- else
- error "unpack %s failed.\n" "${memcached_FILENAME}"
- exit $?
- fi
- cd ${UNPACK_DIR}/${memcached_DIR}
- info "Now configure the memcached,this will take serveral minutes...\n"
- ./configure --prefix=/usr/local/memcached 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "Memcached configure ${GREEN_OK}. Now make and make install. this will take serveral minutes... \n"
- make 1>/dev/null && make install 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "Memcached installed ${GREEN_OK}.\n"
- else
- error "Memcached not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- install_libmemcached()
- {
- local libmemcached_FILENAME="libmemcached-0.50.tar.gz"
- local libmemcached_DIR="libmemcached-0.50"
- info "Unpack the libmemcached file %s\n" "${libmemcached_FILENAME}"
- tar -zxf ${SOURCE_DIR}/${libmemcached_FILENAME} -C ${UNPACK_DIR}
- if [[ $? == 0 ]]
- then
- info "unpack %s done.${GREEN_OK}\n" "${libmemcached_FILENAME}"
- else
- error "unpack %s failed.\n" "${libmemcached_FILENAME}"
- exit $?
- fi
- cd ${UNPACK_DIR}/${libmemcached_DIR}
- info "Now configure the libmemcached,this will take serveral minutes...\n"
- ./configure --with-memcached=/usr/local/memcached/bin/memcached 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "libmemcached configure ${GREEN_OK}. Now make and make install. this will take serveral minutes... \n"
- make 1>/dev/null && make install 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "libmemcached installed ${GREEN_OK}.\n"
- else
- error "libmemcached not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- install_memcache2()
- {
- local memcache_FILENAME="memcached-2.0.0b2.tgz"
- local memcache_DIR="memcached-2.0.0b2"
- info "Unpack the memcache extension file %s\n" "${memcache_FILENAME}"
- tar -zxf ${SOURCE_DIR}/${memcache_FILENAME} -C ${UNPACK_DIR}
- if [[ $? == 0 ]]
- then
- info "unpack %s done.${GREEN_OK}\n" "${memcache_FILENAME}"
- else
- error "unpack %s failed.\n" "${memcache_FILENAME}"
- exit $?
- fi
- cd ${UNPACK_DIR}/${memcache_DIR}
- info "Now configure the memcache extension,this will take serveral minutes...\n"
- ${INSTALL_ROOT}/php/bin/phpize 1>/dev/null
- ./configure --with-php-config=${INSTALL_ROOT}/php/bin/php-config 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "memcache extension configure ${GREEN_OK}. Now make . this will take serveral minutes... \n"
- make 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "memcache extension installed ${GREEN_OK}.\n"
- info "copy the svn.so to ${INSTALL_ROOT}/php/lib/php/extensions/ \n"
- cp -a modules/memcached.so ${INSTALL_ROOT}/php/lib/php/extensions/
- if [[ $? == 0 ]]
- then
- info "copy memcached.so done.${GREEN_OK}\n"
- else
- error "copy memcached.so failed.\n"
- exit $?
- fi
- else
- error "memcache extension not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- install_snmp()
- {
- info "Now configure the snmp,this will take serveral minutes...\n"
- cd ${UNPACK_DIR}/${UNPACK_DIR_NAME}/ext/snmp/
- ${INSTALL_ROOT}/php/bin/phpize 1>/dev/null
- ./configure --with-php-config=${INSTALL_ROOT}/php/bin/php-config 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "snmp extension configure ${GREEN_OK}. Now make . this will take serveral minutes... \n"
- make 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "snmp extension installed ${GREEN_OK}.\n"
- info "copy the svn.so to ${INSTALL_ROOT}/php/lib/php/extensions/ \n"
- cp -a modules/snmp.so ${INSTALL_ROOT}/php/lib/php/extensions/
- if [[ $? == 0 ]]
- then
- info "copy snmp.so done.${GREEN_OK}\n"
- else
- error "copy snmp.so failed.\n"
- exit $?
- fi
- else
- error "snmp extension not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- ## 2011-07-25 add libmcrypt install ########
- install_libmcrypt()
- {
- local libmcrypt_FILENAME="libmcrypt-2.5.7.tar.gz"
- local libmcrypt_DIR="libmcrypt-2.5.7"
- info "Unpack the libmcrypt file %s\n" "${libmcrypt_FILENAME}"
- tar -zxf ${SOURCE_DIR}/${libmcrypt_FILENAME} -C ${UNPACK_DIR}
- if [[ $? == 0 ]]
- then
- info "unpack %s done.${GREEN_OK}\n" "${libmcrypt_FILENAME}"
- else
- error "unpack %s failed.\n" "${libmcrypt_FILENAME}"
- exit $?
- fi
- cd ${UNPACK_DIR}/${libmcrypt_DIR}
- info "Now configure the libmcrypt,this will take serveral minutes...\n"
- ./configure 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "libmcrypt configure ${GREEN_OK}. Now make and install. this will take serveral minutes... \n"
- make 1>/dev/null && make install 1>/dev/null
- if [[ $? == 0 ]]
- then
- info "libmcrypt installed ${GREEN_OK}.\n"
- else
- error "libmcrypt not installed.\n "
- exit $?
- fi
- else
- error "Configure is not complete.\n"
- exit $?
- fi
- cd -
- }
- ################## main ##########################
- ### install depdendences #####
- yum install -y gd-devel freetds-devel libjpeg-devel libpng-devel libmcrypt-devel libevent-devel libtool-l*
- #### untar the db4 #############
- tar -zxf ${SOURCE_DIR}/${DB4} -C ${INSTALL_ROOT}
- #####copy libsybdb.so to /usr/lib ########
- cp -a /usr/lib64/libsybdb.so.5.0.0 /usr/lib/
- ln -s /usr/lib/libsybdb.so.5.0.0 /usr/lib/libsybdb.so
- ### install libmrcypt ######
- install_libmcrypt
- #Check the php file
- check_source
- #unpack file
- unpack_file
- #install file
- install_file
- #####copy php.ini file ##########
- #cp ${UNPACK_DIR}/${UNPACK_DIR_NAME}/php.ini-production ${INSTALL_ROOT}/php/lib/php.ini
- ######edi
本文转自 waydee 51CTO博客,原文链接:http://blog.51cto.com/waydee/847101,如需转载请自行联系原作者