- #!/bin/bash
- PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
- export PATH
- echo "/usr/sbin/setenforce 0" >> /etc/rc.local
- /usr/sbin/setenforce 0
- cat >> /etc/sysctl.conf << EOF
- # Add
- net.ipv4.tcp_max_syn_backlog = 65536
- net.core.netdev_max_backlog = 32768
- net.core.somaxconn = 32768
- net.core.wmem_default = 8388608
- net.core.rmem_default = 8388608
- net.core.rmem_max = 16777216
- net.core.wmem_max = 16777216
- net.ipv4.tcp_timestamps = 0
- net.ipv4.tcp_synack_retries = 2
- net.ipv4.tcp_syn_retries = 2
- net.ipv4.tcp_tw_recycle = 1
- #net.ipv4.tcp_tw_len = 1
- net.ipv4.tcp_tw_reuse = 1
- net.ipv4.tcp_mem = 94500000 915000000 927000000
- net.ipv4.tcp_max_orphans = 3276800
- #net.ipv4.tcp_fin_timeout = 30
- #net.ipv4.tcp_keepalive_time = 120
- net.ipv4.ip_local_port_range = 1024 65535
- EOF
- sysctl -p
- clear
- echo "========================================================================="
- echo "install Nginx+MySQL+PHP on Linux "
- echo "The path of some dirs:"
- echo "mysql dir: /usr/local/mysql"
- echo "php dir: /usr/local/php"
- echo "nginx dir: /usr/local/nginx"
- echo "web dir /home/www"
- echo "http://rfyiamcool.blog.51cto.com/ "
- echo "========================================================================="
- cur_dir=$(pwd)
- if [ "$1" != "--help" ]; then
- domain="rfyiamcool.blog.51cto.com"
- echo "Please input domain:"
- read -p "(Default domain: rfyiamcool.blog.51cto.com):" domain
- if [ "$domain" = "" ]; then
- domain="rfyiamcool.blog.51cto.com"
- fi
- echo "==========================="
- echo domain="$domain"
- echo "==========================="
- #set mysql root password
- echo "==========================="
- mysqlrootpwd="root"
- echo "Please input the root password of mysql: mima"
- read -p "(Default password: root):" mysqlrootpwd
- if [ "$mysqlrootpwd" = "" ]; then
- mysqlrootpwd="root"
- fi
- echo "==========================="
- echo mysqlrootpwd="$mysqlrootpwd"
- echo "==========================="
- get_char()
- {
- SAVEDSTTY=`stty -g`
- stty -echo
- stty cbreak
- dd if=/dev/tty bs=1 count=1 2> /dev/null
- stty -raw
- stty echo
- stty $SAVEDSTTY
- }
- echo ""
- echo "Press any key to start..."
- char=`get_char`
- rpm -qa|grep httpd
- rpm -e httpd
- rpm -qa|grep mysql
- rpm -e mysql
- rpm -qa|grep php
- rpm -e php
- yum -y remove httpd*
- yum -y remove php*
- yum -y remove mysql-server mysql
- yum -y remove php-mysql
- yum -y install yum-fastestmirror
- yum -y remove httpd
- #Disable SeLinux
- if [ -s /etc/selinux/config ]; then
- sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
- fi
- LANG=C
- yum -y install path gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
- cd $cur_dir
- wget -c http://rfyiamcool.googlecode.com/files/lnmp-php5.2.17.tar
- tar xvf lnmp-php5.2.17.tar
- tar xvf conf.tar
- if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
- cd $cur_dir
- tar zxvf libunwind-1.0.1.tar.gz
- cd libunwind-1.0.1/
- CFLAGS=-fPIC ./configure
- make CFLAGS=-fPIC
- make CFLAGS=-fPIC install
- cd ../
- cd $cur_dir
- tar zxvf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
- mkdir -p /usr/local/zend/
- cp ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/5_2_x_comp/ZendOptimizer.so /usr/local/zend/
- else
- cd $cur_dir
- tar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
- mkdir -p /usr/local/zend/
- cp ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so /usr/local/zend/
- fi
- cd $cur_dir
- tar zxvf libiconv-1.14.tar.gz
- cd libiconv-1.14/
- ./configure --prefix=/usr/local
- make && make install
- cd ../
- cd $cur_dir
- tar zxvf gperftools-2.0.tar.gz
- cd gperftools-2.0/
- ./configure
- make && make install
- echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
- /sbin/ldconfig
- cd ../
- cd $cur_dir
- tar zxvf libmcrypt-2.5.8.tar.gz
- cd libmcrypt-2.5.8/
- ./configure
- make && make install
- /sbin/ldconfig
- cd libltdl/
- ./configure --enable-ltdl-install
- make && make install
- cd ../../
- cd $cur_dir
- tar zxvf mhash-0.9.9.9.tar.gz
- cd mhash-0.9.9.9/
- ./configure
- make && make install
- cd ../
- ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
- ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
- ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
- ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
- ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
- ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
- ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
- ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
- ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
- ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
- cd $cur_dir
- tar zxvf mcrypt-2.6.8.tar.gz
- cd mcrypt-2.6.8/
- ./configure
- make && make install
- cd ../
- echo "============================mysql install=================================="
- cd $cur_dir
- tar zxvf mysql-5.1.60.tar.gz
- cd mysql-5.1.60/
- ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile
- make && make install
- cd ../
- groupadd mysql
- useradd -s /sbin/nologin -M -g mysql mysql
- cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
- sed -i 's/skip-locking/skip-external-locking/g' /etc/my.cnf
- /usr/local/mysql/bin/mysql_install_db --user=mysql
- chown -R mysql /usr/local/mysql/var
- chgrp -R mysql /usr/local/mysql/.
- cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
- chmod 755 /etc/init.d/mysql
- cat > /etc/ld.so.conf.d/mysql.conf<<EOF
- /usr/local/mysql/lib/mysql
- /usr/local/lib
- EOF
- ldconfig
- ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
- ln -s /usr/local/mysql/include/mysql /usr/include/mysql
- /etc/init.d/mysql start
- ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
- ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
- ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
- /usr/local/mysql/bin/mysqladmin -u root password $mysqlrootpwd
- cat > /tmp/mysql_sec_script<<EOF
- use mysql;
- update user set passwordpassword=password('$mysqlrootpwd') where user='root';
- DELETE FROM user WHERE not (user='root') ;
- DELETE FROM user WHERE user='root' and password='';
- DELETE FROM user WHERE not (host='localhost');
- drop database test;
- DROP USER ''@'%';
- flush privileges;
- EOF
- /usr/local/mysql/bin/mysql -u root -p$mysqlrootpwd -h localhost < /tmp/mysql_sec_script
- rm -f /tmp/mysql_sec_script
- /etc/init.d/mysql restart
- /etc/init.d/mysql stop
- chkconfig --level 345 mysql on
- echo "============================mysql intall finished========================="
- echo "============================php+eaccelerator install======================"
- cd $cur_dir
- tar zxvf php-5.2.17.tar.gz
- gzip -d ./suhosin-patch-5.2.17-0.9.7.patch.gz
- gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
- cd php-5.2.17
- patch -p 1 -i ../suhosin-patch-5.2.17-0.9.7.patch
- mv ../php-5.2.17-max-input-vars.patch ./
- patch -p1 < php-5.2.17-max-input-vars.patch
- ./buildconf --force
- if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
- cp -frp /usr/lib64/libldap* /usr/lib/
- ln -s /usr/lib64/libjpeg.so /usr/lib/
- ln -s /usr/lib64/libpng.so /usr/lib/
- fi
- ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-fpm --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-ftp --disable-debug --without-pear --with-gettext --with-mime-magic --enable-suhosin
- make ZEND_EXTRA_LIBS='-liconv'
- make install
- cp php.ini-dist /usr/local/php/etc/php.ini
- ln -s /usr/local/php/bin/php /usr/bin/php
- cd ../
- cd $cur_dir
- tar zxvf memcache-2.2.6.tgz
- cd memcache-2.2.6
- /usr/local/php/bin/phpize
- ./configure --with-php-config=/usr/local/php/bin/php-config
- make
- make install
- cd ../
- cd $cur_dir
- tar zxvf libevent-2.0.18-stable.tar.gz
- cd libevent-2.0.18-stable
- ./configure --prefix=/usr
- make && make install
- cd ../
- cd $cur_dir
- tar xzvf memcached-1.4.13.tar.gz
- cd memcached-1.4.13
- ./configure -–with-libevent=/usr
- make && make install
- cd ../
- cd $cur_dir
- tar zxvf ImageMagick-6.7.1-6.tar.gz
- cd ImageMagick-6.7.1-6/
- ./configure
- make && make install
- cd ../
- cd $cur_dir
- tar zxvf imagick-3.0.1.tgz
- cd imagick-3.0.1/
- /usr/local/php/bin/phpize
- ./configure --with-php-config=/usr/local/php/bin/php-config
- make && make install
- cd ../
- cd $cur_dir
- tar zxvf PDO_MYSQL-1.0.2.tgz
- cd PDO_MYSQL-1.0.2
- /usr/local/php/bin/phpize
- ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
- make && make install
- cd ../
- cd $cur_dir
- tar jxvf eaccelerator-0.9.6.1.tar.bz2
- cd eaccelerator-0.9.6.1/
- /usr/local/php/bin/phpize
- ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config --with-eaccelerator-shared-memory
- make && make install
- cd ../
- mkdir -p /usr/local/eaccelerator_cache
- cat >>/usr/local/php/etc/php.ini<<EOF
- [eaccelerator]
- zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
- eaccelerator.shm_size="16"
- eaccelerator.cache_dir="/usr/local/eaccelerator_cache"
- eaccelerator.enable="1"
- eaccelerator.optimizer="1"
- eaccelerator.check_mtime="1"
- eaccelerator.debug="0"
- eaccelerator.filter=""
- eaccelerator.shm_max="0"
- eaccelerator.shm_ttl="3600"
- eaccelerator.shm_prune_period="3600"
- eaccelerator.shm_only="0"
- eaccelerator.compress="1"
- eaccelerator.compress_level="9"
- EOF
- sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\nextension = "imagick.so"\n#' /usr/local/php/etc/php.ini
- sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/php/etc/php.ini
- sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 16M/g' /usr/local/php/etc/php.ini
- sed -i 's/post_max_size = 8M/post_max_size = 16M/g' /usr/local/php/etc/php.ini
- sed -i 's/;date.timezone =/date.timezone = PRC/g' /usr/local/php/etc/php.ini
- sed -i 's#mysql.default_socket =#mysql.default_socket = /tmp/mysql.sock#g' /usr/local/php/etc/php.ini
- sed -i 's/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini
- cat >>/usr/local/php/etc/php.ini<<EOF
- [Zend Optimizer]
- zend_optimizer.optimization_level=1023
- zend_extension="/usr/local/zend/ZendOptimizer.so"
- EOF
- groupadd www
- /usr/sbin/useradd -g www www -s /sbin/nologin
- mkdir -p /home/www
- chmod +w /home/www
- mkdir -p /home/www/logs
- chmod 777 /home/www/logs
- chown -R www:www /home/www
- mv /usr/local/php/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf.bak
- cp conf/php-fpm.conf /usr/local/php/etc/php-fpm.conf
- echo "============================php+eaccelerator install finished======================"
- echo "============================nginx install================================="
- cd $cur_dir
- tar zxvf pcre-8.13.tar.gz
- cd pcre-8.13/
- ./configure
- make && make install
- cd ../
- cd $cur_dir
- tar zxvf nginx-1.2.0.tar.gz
- cd nginx-1.2.0
- ./configure --user=www --group=www --prefix=/usr/local/nginx
- make && make install
- cd ../
- mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf_bak
- cp conf/nginx.conf /usr/local/nginx/conf/nginx.conf
- sed -i 's/lvtao.net/'$domain'/g' /usr/local/nginx/conf/servers/lvtao.conf
- mkdir -p /usr/local/nginx/conf/servers
- chown www -R /home/
- chown www /usr/local/nginx/conf/
- chown www /usr/local/php/etc/
- cp conf/index.php /home/www/index.php
- cp conf/rui.conf /usr/local/nginx/conf/servers/rui.conf
- cp conf/location.conf /usr/local/nginx/conf/location.conf
- cp conf/supercache.conf /usr/local/nginx/conf/supercache.conf
- cp conf/dabr.conf /usr/local/nginx/conf/dabr.conf
- cp conf/nginx /etc/init.d/nginx
- cp conf/php-fpm /etc/init.d/php-fpm
- chmod 777 /etc/init.d/nginx
- chmod 777 /etc/init.d/php-fpm
- chkconfig --level 345 nginx on
- chkconfig --level 345 php-fpm on
- service mysql start
- /etc/init.d/php-fpm start
- /etc/init.d/nginx start
- echo "============================nginx install finished================================="
- echo "/usr/sbin/setenforce 0" >> /etc/rc.local
- /usr/sbin/setenforce 0
- tar zxvf phpmyadmin.tar.gz
- mv phpmyadmin /home/www/phpmyadmin/
- cp conf/host /bin/host
- chmod +x /bin/host
- chmod -R 755 /home/www/phpmyadmin/
- service nginx restart
- echo "============================add nginx and php-fpm on startup============================"
- echo "ulimit -SHn 65535" >>/etc/rc.local
- echo "===========================add nginx and php-fpm on startup finished===================="
- sed -i 's#executing mysqld_safe#executing mysqld_safe\nexport LD_PRELOAD=/usr/local/lib/libtcmalloc.so#' /usr/local/mysql/bin/mysqld_safe
- clear
- echo "========================================================================="
- echo ""
- echo "default mysql root password:yourpassword"
- echo "phpinfo test:http://ip"
- echo "mysql_admin test:http://ip/phpmyadmin"
- echo "mysql dir: /usr/local/mysql"
- echo "php dir: /usr/local/php"
- echo "nginx dir: /usr/local/nginx"
- echo "web dir /home/www"
- echo "host 123123.com 增加虚拟机"
- echo "service nginx start|stop|restart|reload"
- echo "service mysql start|stop|restart"
- echo "service php-fpm start|stop|restart"
- echo "===========================ok!!!!!!!!!!!===================================="