天天看點

httpd-2.2.21 + php-5.3.8 自動安裝腳本

httpd-2.2.21 + php-5.3.8 自動安裝腳本

#!/bin/bash  

#================================================================================  

# lamp installing script by neo <[email protected]>  

# http://netkiller.sourceforge.net/  

# $id$  

src_dir=$(pwd)  

prefix_dir=/srv  

[email protected]  

httpd_src='httpd-2.2.21.tar.gz'  

php_src='php-5.3.8.tar.gz'  

mysql_src='mysql-5.5.9.tar.gz'  

mysql_libs_src='mysql-5.1.50.tar.gz'  

mysql_bin='mysql-5.1.50-linux-x86_64-glibc23.tar.gz'  

java_bin='jdk-6u20-linux-x64.bin'  

httpd_dir=${httpd_src%%.tar.gz}  

php_dir=${php_src%%.tar.*}  

mysql_dir=${mysql_src%%.tar.*}  

mysql_libs_dir=${mysql_libs_src%%.tar.*}  

if [ -z "$( egrep "centos|redhat" /etc/issue)" ]; then  

    echo 'only for redhat or centos'  

    exit  

fi  

function clean(){  

        rm -rf $httpd_dir  

        rm -rf $php_dir  

        rm -rf $mysql_dir  

        rm -rf $mysql_libs_dir  

}  

function depend(){  

        yum install gcc gcc-c++ make autoconf -y  

        yum install curl-devel libmcrypt-devel gd-devel libjpeg-devel libpng-devel libxpm-devel libxml2-devel libxslt-devel mhash-devel openldap-devel -y  

        yum install ncurses-devel -y  

#        yum install mysql-devel -y  

        yum install libevent-devel -y  

    yum install e4fsprogs -y  

    yum install net-snmp-devel -y  

    yum install setuptool ntsysv system-config-network-tui -y  

    #rpm -uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm  

function httpd(){  

rm -rf $httpd_dir  

tar zxf $httpd_src  

cd $httpd_dir  

retval=$?  

[[ $retval != 0 ]] && echo "static: "$retval &&  exit $?  

vim server/mpm/worker/worker.c <<end > /dev/null 2>&1  

:%s/#define default_server_limit 16/#define default_server_limit 256/  

:%s/#define default_thread_limit 64/#define default_thread_limit 1024/  

:wq  

end  

#define max_server_limit 20000  

#define max_thread_limit 20000  

[[ $? -ne 0 ]] && echo "step: server/mpm/worker/worker.c" &&  exit $?  

./configure --prefix=$prefix_dir/$httpd_dir \  

--with-mpm=worker \  

--enable-modules="so dir mime rewrite deflate vhost_alias include" \  

--enable-mods-shared="alias filter expires headers  setenvif status info ssl usertrack cache mem-cache file-cache disk-cache version mod_unique_id " \  

--disable-authn_file \  

--disable-authn_default \  

--disable-authz_groupfile \  

--disable-authz_user \  

--disable-authz_default \  

--disable-auth_basic \  

--disable-version \  

--disable-env \  

--disable-autoindex \  

--disable-asis \  

--disable-cgid \  

--disable-cgi \  

--disable-negotiation \  

--disable-actions \  

--disable-userdir \  

--enable-so \  

--enable-file-cache \  

--enable-cache \  

--enable-disk-cache \  

--enable-mem-cache \  

--enable-expires \  

--enable-headers \  

--enable-ssl \  

--enable-info \  

--enable-rewrite  

#--with-mpm=worker \  

#--enable-so \  

#--enable-mods-shared=all \  

#--disable-alias  

#--disable-include \  

#--disable-status \  

[[ $? -ne 0 ]] && echo "step: configure" &&  exit $?  

make clean  

make  

[[ $? -ne 0 ]] && echo "step: make" &&  exit $?  

make install  

[[ $? -ne 0 ]] && echo "step: make install" &&  exit $?  

cd ..  

ln -s $prefix_dir/$httpd_dir $prefix_dir/httpd  

ln -s $prefix_dir/httpd $prefix_dir/apache  

cp $prefix_dir/httpd/conf/httpd.conf  $prefix_dir/httpd/conf/httpd.conf.original  

mkdir -p /www/logs/error  

vim $prefix_dir/httpd/conf/httpd.conf <<end > /dev/null 2>&1  

:%s/user daemon/user nobody/  

:%s/group daemon/group nobody/  

:%s/serveradmin [email protected]/serveradmin $email/  

:%s!#servername www.example.com:80!#servername www.example.com:80\rservername 127.0.0.1!  

:%s#$prefix_dir/$httpd_dir/htdocs#/www#g  

:%s/#\n    allowoverride none/#\r    allowoverride all/  

:%s#    directoryindex index.html#    directoryindex index.html index.php#  

:%s=    #addtype text/html .shtml=    addtype text/html .shtml=  

:%s=    #addoutputfilter includes .shtml=    addoutputfilter includes .shtml=  

:%s=addoutputfilter includes .shtml=addoutputfilter includes .shtml\r\r    addtype application/x-httpd-php .php .phtml\r    addtype application/x-httpd-php-source .phps\r=  

:%s#errorlog "logs/error_log"#errorlog "| $prefix_dir/httpd/bin/rotatelogs /www/logs/error/error.%y-%m-%d.log 86400 480"#  

:%s=#include conf/extra/httpd-info.conf=include conf/extra/httpd-info.conf=  

:%s=#include conf/extra/httpd-mpm.conf=include conf/extra/httpd-mpm.conf=  

:%s=#include conf/extra/httpd-languages.conf=include conf/extra/httpd-languages.conf=  

:%s=#include conf/extra/httpd-vhosts.conf=include conf/extra/httpd-vhosts.conf=  

:%s=#include conf/extra/httpd-default.conf=include conf/extra/httpd-default.conf=  

#:%s!listen 80!listen 0.0.0.0:80!  

#:%s!#servername www.example.com:80!#servername www.example.com:80\rservername *!  

#vim $prefix_dir/httpd/conf/extra/httpd-mpm.conf <<end > /dev/null 2>&1  

#:%s/<ifmodule mpm_worker_module>/<ifmodule mpm_worker_module>\r    serverlimit         16\r    threadlimit         128/  

#:%s/startservers          2/startservers        8/  

#:%s/maxclients          150/maxclients          2048/  

#:%s/minsparethreads      25/minsparethreads     64/  

#:%s/maxsparethreads      75/maxsparethreads     128/  

#:%s/threadsperchild      25/threadsperchild     128/  

#:%s/maxrequestsperchild   0/maxrequestsperchild 10000/  

#:wq  

#end  

vim $prefix_dir/httpd/conf/extra/httpd-mpm.conf <<end > /dev/null 2>&1  

:%s/<ifmodule mpm_worker_module>/<ifmodule mpm_worker_module>\r    serverlimit         16\r    threadlimit         256/  

:%s/startservers          2/startservers        8/  

:%s/maxclients          150/maxclients          4096/  

:%s/minsparethreads      25/minsparethreads     64/  

:%s/maxsparethreads      75/maxsparethreads     256/  

:%s/threadsperchild      25/threadsperchild     256/  

:%s/maxrequestsperchild   0/maxrequestsperchild 10000/  

vim $prefix_dir/httpd/conf/extra/httpd-languages.conf <<end > /dev/null 2>&1  

:%s/languagepriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-br ru sv tr zh-cn zh-tw/#languagepriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-br ru sv tr zh-cn zh-tw/  

:%s/forcelanguagepriority prefer fallback/#forcelanguagepriority prefer fallback/  

echo -ne "  

adddefaultcharset utf-8  

" >> $prefix_dir/httpd/conf/extra/httpd-languages.conf  

vim $prefix_dir/httpd/conf/extra/httpd-info.conf <<end > /dev/null 2>&1  

:%s/allow from .example.com/allow from 127.0.0.1 172.16.1 113.106.63.1/g  

vim $prefix_dir/httpd/conf/extra/httpd-default.conf <<end > /dev/null 2>&1  

:%s/servertokens full/servertokens prod/  

$prefix_dir/httpd/bin/apachectl start  

" >> /etc/rc.local  

function php(){  

#ln -s /usr/lib64/mysql/* /usr/lib64/ 

#ln -s /srv/mysql/bin/mysql_config /usr/local/bin/ 

rm -rf $php_dir 

tar zxf $php_src 

cd $php_dir 

./configure --prefix=$prefix_dir/$php_dir \ 

--with-config-file-path=$prefix_dir/$php_dir/etc \ 

--with-config-file-scan-dir=$prefix_dir/$php_dir/etc/conf.d \ 

--with-apxs2=$prefix_dir/$httpd_dir/bin/apxs \ 

--with-curl \ 

--with-gd \ 

--with-jpeg-dir \ 

--with-png-dir \ 

--with-freetype-dir \ 

--with-xpm-dir \ 

--with-iconv \ 

--with-zlib-dir \ 

--with-xmlrpc \ 

--with-openssl \ 

--with-mcrypt \ 

--with-mhash=shared \ 

--with-mysql=/srv/mysql-5.1.50-linux-x86_64-glibc23 \ 

--with-pdo-mysql=/srv/mysql-5.1.50-linux-x86_64-glibc23 \ 

--with-sqlite=shared \ 

--with-pdo-sqlite=shared \ 

--with-ldap=shared \ 

--with-snmp=shared \ 

--with-xsl=shared \ 

--with-pear \ 

--enable-sockets \ 

--enable-soap \ 

--enable-mbstring \ 

--enable-magic-quotes \ 

--enable-inline-optimization \ 

--enable-gd-native-ttf \ 

--enable-zip \ 

--enable-xml \ 

--enable-ftp 

#--with-mysqli=/srv/mysql-5.1.50-linux-x86_64-glibc23/bin/mysql_config \ 

#--enable-embedded-mysqli \ 

#--enable-fpm \ 

#--with-fpm-user=nobody \ 

#--with-fpm-group=nobody \ 

#--with-mysql=/srv/mysql-5.5.9-linux2.6-x86_64 \ 

#--with-pdo-mysql=/srv/mysql-5.5.9-linux2.6-x86_64 \ 

[[ $? -ne 0 ]] && echo "step: configure" &&  exit $? 

#make && make test && make install 

#make &&  make install 

make 

[[ $? -ne 0 ]] && echo "step: make" &&  exit $? 

make install 

[[ $? -ne 0 ]] && echo "step: make install" &&  exit $? 

mkdir -p $prefix_dir/$php_dir/etc/conf.d 

cp $prefix_dir/src/$php_dir/php.ini-production $prefix_dir/$php_dir/etc/php.ini 

ln -s $prefix_dir/$php_dir $prefix_dir/php 

cp $prefix_dir/$php_dir/etc/php.ini $prefix_dir/$php_dir/etc/php.ini.original 

vim $prefix_dir/php/etc/php.ini <<eof > /dev/null 2>&1 

:%s!;include_path = ".:/php/includes"!;include_path = ".:/php/includes"\rinclude_path = ".:$prefix_dir/$php_dir/lib/php"! 

:%s:;extension_dir = "./":extension_dir = "$prefix_dir/$php_dir/lib/php/extensions": 

:%s/memory_limit = 128m/memory_limit = 64m/ 

:%s/log_errors = off/log_errors = on/ 

:%s#;error_log = php_errors.log#error_log = php_errors.log# 

:%s#;open_basedir =#open_basedir = /www/:/tmp/# 

:%s/upload_max_filesize = 2m/upload_max_filesize = 8m/ 

:wq 

eof 

#:%s/mysql.allow_persistent = on/mysql.allow_persistent = off/ 

#:%s/register_long_arrays = on/register_long_arrays = off/ 

#:%s/display_errors = on/display_errors = off/ 

#:%s/output_buffering = off/output_buffering = on/ 

#:%s/allow_call_time_pass_reference = on/allow_call_time_pass_reference = off/ 

#:%s#;error_log = php_errors.log#error_log = /www/logs/php_errors.log# 

    read -p "php memcache module? [y/n]" -n 1 key 

    echo 

    if [ $key = 'y' ]; then 

$prefix_dir/php/bin/pecl install memcache 

cp $prefix_dir/$php_dir/lib/php/extensions/no-debug-zts-*/memcache.so $prefix_dir/$php_dir/lib/php/extensions/  

cat > $prefix_dir/php/etc/conf.d/memcache.ini <<eof  

extension=memcache.so  

eof  

#> /dev/null 2>&1  

#memcache.default_timeout_ms=30  

    fi  

    read -p "php apc module? [y/n]" -n 1 key  

    echo  

    if [ $key = 'y' ]; then  

$prefix_dir/php/bin/pecl install apc  

cp $prefix_dir/$php_dir/lib/php/extensions/no-debug-zts-*/apc.so $prefix_dir/$php_dir/lib/php/extensions/  

cat > $prefix_dir/php/etc/conf.d/apc.ini <<eof  

extension=apc.so  

# > /dev/null 2>&1  

function mysql(){  

rm -rf $mysql_dir  

tar zxf $mysql_src  

cd $mysql_dir  

./configure \  

--prefix=$prefix_dir/$mysql_dir \  

--with-mysqld-user=mysql \  

--with-unix-socket-path=/tmp/mysql.sock \  

--with-charset=utf8 \  

--with-collation=utf8_general_ci  

--with-extra-charsets=complex \  

--with-big-tables \  

--with-readline \  

--with-ssl \  

--with-embedded-server \  

--with-plugins=innobase \  

--without-ndb-debug \  

--without-debug \  

--without-bench  

--without-docs \  

--localstatedir=/data/mysql/data \  

--enable-assembler \  

--enable-thread-safe-client \  

--enable-local-infile \  

make && make install  

ln -s $prefix_dir/$mysql_dir $prefix_dir/mysql  

$prefix_dir/$mysql_dir/bin/mysql_install_db --user=mysql  

chown mysql.mysql -r $prefix_dir/$mysql_dir  

cp $prefix_dir/src/$mysql_dir/support-files/mysql.server /etc/init.d/mysql  

/etc/init.d/mysql start  

$prefix_dir/$mysql_dir/bin/mysqladmin -u root password '9s5wxcvpmy'  

function java(){  

    java_dir=${java_bin%%.bin}  

        #yum install java-1.6.0-openjdk -y  

        chmod +x $java_bin  

        ./$java_bin  

        mv $java_dir ..  

        ln -s $prefix_dir/$java_dir $prefix_dir/java  

echo -ne '  

export java_home=$prefix_dir/java  

export classpath=$java_home/lib:$java_home/jre/lib:$classpath  

export path=$java_home/bin:$java_home/jre/bin:$homr/bin:$path  

export path=$path:$prefix_dir/httpd/bin:$prefix_dir/php/bin:$prefix_dir/mysql/bin:$prefix_dir/resin/bin:$prefix_dir/python/bin  

' >> /etc/profile  

function resin(){  

        tar zxf resin-4.0.6.tar.gz  

        mv resin-4.0.6 $prefix_dir/  

    echo 'export resin_home=$prefix_dir/resin' >> /etc/profile  

function memcache(){  

        memcached_pkg=memcached-1.4.5.tar.gz  

        memcached_src=memcached-1.4.5  

        rm -rf $memcached_src  

        tar zxf $memcached_pkg  

        cd $memcached_src  

        ./configure --prefix=$prefix_dir/memcached-1.4.5  

        make && make install  

function vsftpd(){  

    yum install -y vsftpd  

    adduser --home-dir /www/target/logs/ --shell /sbin/nologin --password logs.xiu.com logs  

    echo logs >> /etc/vsftpd/chroot_list  

    vim /etc/vsftpd/vsftpd.conf <<vim > /dev/null 2>&1  

:%s/#chroot_list_enable=yes/chroot_list_enable=yes/  

:%s/#chroot_list_file/chroot_list_file/  

vim  

    chkconfig vsftpd on  

    service vsftpd start  

# see how we were called.  

case "$1" in  

  clean)  

        clean  

        ;;  

  httpd)  

        httpd  

  php)  

        php  

  mysql)  

        if [ -f $0 ] ; then  

                mysql  

        fi  

  depend)  

        depend  

  java)  

        java  

  resin)  

        resin  

  profile)  

        profile  

  memcache)  

        memcache  

  lamp)  

        echo ##################################################  

        echo # $mysql_dir installing...  

        mysql  

        echo # $httpd_dir installing...  

        echo # $php_dir installing...  

  vsftpd)  

    vsftpd  

    ;;  

  optimization)  

    optimization  

  *)  

        echo $"usage: $0 {depend|clean}"  

        echo "      {httpd|php|mysql|vsftpd}"  

        echo "      {java|resin}"  

        echo "      {memcache}"  

        echo "      {optimization}"  

        echo "      {ntp|snmp|nagios|nrpe}"  

        retval=2  

esac  

exit $retval