#!/bin/bash #debug info #user:houzc #date:2012/7/27 #Mysql apache nginx install directory , mysqldata diretory configuration. DATA_DIR="/data/mysqldata/" BASE_DIR="/usr/local/mysql/" VERSION="mysql-5.5.15" HTTPVERSION="httpd-2.2.21" PHPVERSION="php-5.3.8" APPA_DIR="/usr/local/apache-2.2.21" NGINXVERSION="nginx-1.2.3" NGPA_DIR="/usr/local/nginx-1.2.3" mysql_install() { if [ -e "MYSQLDIR"];thenecho"Mysqlalreadyexists......................................"exit0elserm−rf/usr/src/VERSION/ mkdir -p /data/mysqldata/ mkdir -p /usr/local/mysql tar zxvf VERSION.tar.gz−C/usr/srccd/usr/src/VERSION/ && echo "cd ok" /usr/bin/cmake -DCMAKE_INSTALL_PREFIX=BASEDIR −DMYSQLDATADIR=DATA_DIR \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DSYSCONFDIR=/etc \ -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_unicode_ci \ -DWITH_DEBUG=0 -DMYSQL_USER=mysql make && echo "make ok" make install && echo "make install ok" cp -r /usr/src/VERSION/support−files/my−large.cnf/etc/my.cnfsh/usr/local/mysql/scripts/mysqlinstalldb−−user=mysql−−basedir=BASE_DIR --datadir=DATADIR−−no−defaultschownmysql:root−RBASE_DIR chown mysql:mysql -R DATADIRsed"26ibasedir={BASE_DIR}" -i /etc/my.cnf sed "27 i datadir=DATADIR"−i/etc/my.cnfcp−r/usr/src/VERSION/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld sed "48 i basedir=BASEDIR"−i/etc/init.d/mysqldsed"49idatadir={DATA_DIR}" -i /etc/init.d/mysqld echo 'PATH=$PATH:/usr/local/mysql/bin/' >> /etc/profile source /etc/profile cd - fi } apache_install() { if [ -e APPADIR];thenecho"httpdalreadyexists.........................."exit0elserm−rf/usr/src/HTTPVERSION tar zxvf HTTPVERSION.tar.gz−C/usr/src/cd/usr/src/HTTPVERSION/srclib/apr ./configure --prefix=/usr/local/apr make && make install && echo "apr is ok................................" sleep 3 cd - cd /usr/src/HTTPVERSION/srclib/apr-util/ ./configure --prefix=/usr/local/apr-util/ \ --with-apr=/usr/local/apr make && make install && echo "apr-util is ok.............................." sleep 3 cd - cd /usr/src/HTTPVERSION ./configure --prefix=$APPA_DIR \ --with-apr=/usr/local/apr/ \ --with-apr-util=/usr/local/apr-util/ \ --enable-so \ --enable-rewrite make && make install && echo "apache is ok.............................." sed -i 's/#ServerName www.example.com:80/ServerName www.example.com:80/' APPADIR/conf/httpd.confAPPA_DIR/bin/apachectl start cd - fi } php_install() { if [ -e "/usr/local/PHPVERSION" ];then echo "php already exists.........................." exit 0 else rm -rf /usr/src/freetype-2.4.3/ tar zxvf freetype-2.4.3.tar.gz -C /usr/src/ cd /usr/src/freetype-2.4.3/ ./configure --prefix=/usr/local/freetype-2.4.3 make && make install && echo "freetype is ok.............................." sleep 3 cd - rm -rf /usr/src/libpng-1.4.4/ tar zxvf libpng-1.4.4.tar.gz -C /usr/src/ cd /usr/src/libpng-1.4.4/ ./configure --prefix=/usr/local/libpng-1.4.4 make && make install && echo "libpng is ok.............................." sleep 3 cd - rm -rf /usr/src/jpeg-8b tar zxvf jpegsrc.v8b.tar.gz -C /usr/src/ cd /usr/src/jpeg-8b/ ./configure --prefix=/usr/local/jpeg-8b make && make install && echo "jpeg-8b is ok.............................." sleep 3 cd - rm -rf /usr/src/gd-2.0.33 tar zxvf gd-2.0.33.tar.gz -C /usr/src/ cp -r gd_png.c /usr/src/gd-2.0.33/ cd /usr/src/gd-2.0.33/ ./configure --prefix=/usr/local/gd-2.0.33 \ --with-jpeg=/usr/local/jpeg-8b \ --with-freetype=/usr/local/freetype-2.4.3 \ --with-png=/usr/local/libpng-1.4.4 \ --with-zlib \ --enable-m4_pattern_allow make && make install && echo "gd is ok.............................." sleep 3 cd - rm -rf /usr/src/PHPVERSION tar zxvf PHPVERSION.tar.gz−C/usr/src/cd/usr/src/PHPVERSION/ ./configure --prefix=/usr/local/PHPVERSION −−with−apxs2=APPA_DIR/bin/apxs \ --with-zlib --with-libxml-dir --enable-gd-native-ttf \ --enable-mbstring --with-gd=/usr/local/gd-2.0.33/ \ --with-mysql=BASE_DIR \ --with-freetype-dir=/usr/local/freetype-2.4.3/ \ --with-jpeg-dir=/usr/local/jpeg-8b/ \ --with-png-dir=/usr/local/libpng-1.4.4/ \ --enable-sockets make && make install && echo "php is ok.............................." cp -r php.ini-development /usr/local/PHPVERSION/lib/php.ini sed -i "54 i AddType application/x-httpd-php .php " APPADIR/conf/httpd.confsed−i′s/DirectoryIndexindex.html/DirectoryIndexindex.htmlindex.php/′APPA_DIR/conf/httpd.conf cd - cp -r info.php APPADIR/htdocs/APPA_DIR/bin/apachectl stop $APPA_DIR/bin/apachectl start fi } nginx_install() { if [ -e NGPADIR];thenecho"nginxalreadyexists.........................."exit0elsegroupadd−rfwwwuseradd−gwwwwww−s/bin/falserm−rf/usr/src/pcre−8.31rm−rf/usr/src/NGINXVERSION tar zxvf pcre-8.31.tar.gz -C /usr/src/ cd /usr/src/pcre-8.31 ./configure make && make install && echo "pcre is ok ..........................." cd - tar zxvf NGINXVERSION.tar.gz−C/usr/src/cd/usr/src/NGINXVERSION ./configure --prefix=NGPA_DIR \ --user=www --group=www \ --with-http_stub_status_module \ --with-openssl=/usr make && make install && echo "nginx is ok ......................." ln -s /usr/local/lib/libpcre.so.1 /libNGPA_DIR/sbin/nginx fi } case "$1" in mysql_install) if [ -f /etc/debian_version ]; then apt-get -y install build-essential cmake libncurses5-dev bison groupadd -r mysql && useradd -r -M -s /usr/sbin/nologin -g mysql mysql echo "The system is bing installed cmake,please waitting..." sleep 3 mysql_install /etc/init.d/mysqld start update-rc.d mysqld defaults else yum -y install gcc gcc-c++ libtermcap-devel ncurses-devel camke bison useradd mysql -M -s /sbin/nologin echo "The system is bing installed cmake,please waitting..." sleep 3 mysql_install /etc/init.d/mysqld start chkconfig --add mysqld fi ;; apache_install) apache_install ;; php_install) if [ -f /etc/debian_version ]; then apt-get -y install zlib1g-dev libxml2-dev && php_install else yum -y install libxml2-devel libxml2 zlib zlib-devel && php_install fi ;; AMP_install) if [ -f /etc/debian_version ]; then apt-get -y install build-essential cmake libncurses5-dev bison groupadd -r mysql && useradd -r -M -s /usr/sbin/nologin -g mysql mysql echo "The system is bing installed cmake,please waitting..." sleep 3 mysql_install /etc/init.d/mysqld start update-rc.d mysqld defaults apache_install apt-get -y install zlib1g-dev libxml2-dev php_install else yum -y install gcc gcc-c++ libtermcap-devel ncurses-devel camke bison useradd mysql -M -s /sbin/nologin echo "The system is bing installed cmake,please waitting..." sleep 3 mysql_install /etc/init.d/mysqld start chkconfig --add mysqld apache_install yum -y install libxml2 libxml2-devel zlib zlib-devel php_install fi ;; nginx_install) nginx_install ;; mysql_remove) PLOCK=`ps aux | grep mysql | grep -v grep | awk '{ print 2 }'` if [ -zPLOCK ];then rm -rf DATADIRrm−rfBASE_DIR else /etc/init.d/mysqld stop rm -rf DATADIRrm−rfBASE_DIR rm -rf /etc/init.d/mysqld fi ;; *) echo "Usage: install_AMP.sh {mysql_install|apache_install|php_install|AMP_install|nginx_install|mysqlremove}" exit ;; esac
本文转自 houzaicunsky 51CTO博客,原文链接:http://blog.51cto.com/hzcsky/977169
|