本脚用来直接部署LNMP,方便快捷,有错误的地方,欢迎指出,及时更改
此脚本在CentOS 5.5/6.2 x86_64环境下通过
使用方法:保存脚本名为 install_lnmp.sh
执行./install_lnmp 参数名[db|nginx|php|memcached]
软件包下载到脚本当前目录的Packages 下
脚本内容:
- drwxr-xr-x. 3 root root 4096 Aug 7 20:09 Config
- -rwxr-xr-x. 1 root root 7879 Aug 7 19:58 install-lnmp.sh
- drwxr-xr-x. 2 root root 4096 Aug 7 18:16 Packages
- #! /bin/sh
- #-------------------------------------------------------
- # Link: http://blog.51bbo.com/
- # Version: V2.0 CentOS X86_64 5.5 6.2
- # wget http://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2
- # wget http://acelnmp.googlecode.com/files/eaccelerator-0.9.6.1.tar.bz2
- # wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2
- # wget https://github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz
- # wget http://nchc.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
- # wget http://memcached.googlecode.com/files/memcached-1.4.14.tar.gz
- # wget http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.23.tar.gz
- # wget http://pecl.php.net/get/memcache-2.2.5.tgz
- # wget http://nginx.org/download/nginx-1.2.1.tar.gz
- # wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
- # wget http://cn.php.net/distributions/php-5.2.17.tar.gz
- #-------------------------------------------------------
- ServerName=01314.cn
- MyPath=`pwd`
- Packages=$MyPath/Packages
- Config=$MyPath/Config
- echo "Starting install Package ..."
- myyum=`cat /etc/yum.conf |grep exclude`
- if [ `uname -i` = "x86_64" ] && [ -z "$myyum" ]; then
- echo "exclude=*.i?86" >> /etc/yum.conf
- fi
- yum install -y gcc gcc-c++ autoconf cmake bison bison-devel patch mhash-devel pcre pcre-devel ncurses ncurses-devel libpng libpng-devel libjpeg libjpeg-devel libxml2 libxml2-devel zlib zlib-devel bzip2 bzip2-devel curl curl-devel openssl openssl-devel openldap openldap-devel gdbm-devel db4-devel freetype freetype-devel fontconfig fontconfig-devel gmp gmp-devel libtool-ltdl libtool-ltdl-devel gd
- clear
- in_nginx ()
- {
- echo "Starting install Nginx-1.2.1..."
- cd $Packages
- tar zxf nginx-1.2.1.tar.gz
- cd nginx-1.2.1
- ./configure --with-http_stub_status_module --with-http_ssl_module
- make && make install
- mkdir -p /data/logs/nginx/
- if [ ! -d /usr/local/nginx/conf/vhost ]; then
- mkdir -p /usr/local/nginx/conf/vhost
- fi
- \cp $Config/nginx.conf /usr/local/nginx/conf
- \cp $Config/01314.conf /usr/local/nginx/conf/vhost/$ServerName.conf
- sed -i "s/01314.cn/$ServerName/g" /usr/local/nginx/conf/vhost/$ServerName.conf
- mkdir -p /data/website/$ServerName
- cp $Config/info.php /data/website/$ServerName
- echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local
- /usr/local/nginx/sbin/nginx
- echo -e "Nginx is running with PID: [\033[1m\033[32m`pidof nginx`\033[0m]"
- }
- in_mysql ()
- {
- echo "Starting install Mysql-5.5.23..."
- cd $Packages
- tar zxf mysql-5.5.23.tar.gz
- cd mysql-5.5.23
- useradd mysql
- cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DINSTALL_DATADIR=/data/db/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_SSL=bundled -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1
- make && make install
- \cp $Config/my.cnf /etc/my.cnf #/usr/local/mysql/support-files目录下有my.cnf文件供选择使用
- /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/db --user=mysql
- cp support-files/mysql.server /etc/init.d/mysqld
- chmod +x /etc/init.d/mysqld
- mkdir -p /data/logs/mysql; chown mysql.mysql /data/logs/mysql; chmod 777 -R /data/logs/mysql
- chkconfig mysqld on
- /etc/init.d/mysqld start
- echo -e "Mysql is running with PID: [\033[1m\033[32m`pidof mysqld`\033[0m]"
- }
- in_libmcrypt ()
- {
- cd $Packages
- tar zxf 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
- 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/bin/libmcrypt-config /usr/bin/libmcrypt-config
- }
- in_mhash ()
- {
- cd $Packages
- tar jxf mhash-0.9.9.9.tar.bz2
- cd mhash-0.9.9.9
- ./configure
- make && make install
- 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
- }
- in_mcrypt ()
- {
- cd $Packages
- tar zxf mcrypt-2.6.8.tar.gz
- cd mcrypt-2.6.8
- /sbin/ldconfig
- ./configure
- make && make install
- }
- in_php ()
- {
- echo "Starting install php-5.2.17..."
- mkdir -p /etc/php5.2/php.d
- cd $Packages
- if [ ! -d "php-5.2.17" ]; then
- tar zxf php-5.2.17.tar.gz
- gzip -cd php-5.2.17-fpm-0.5.14.diff.gz |patch -d php-5.2.17 -p1
- fi
- if [ `uname -i` = "x86_64" ]; then
- ln -s /usr/lib64/libjpeg.so /usr/lib
- ln -s /usr/lib64/libpng.so /usr/lib
- ln -s /usr/lib64/libldap.so /usr/lib
- fi
- cd php-5.2.17
- ln -s /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config
- ./configure --prefix=/usr/local/php --with-config-file-path=/etc/php5.2 --with-config-file-scan-dir=/etc/php5.2/php.d --with-mysql-sock=/tmp/mysql.sock --with-mysql=shared,/usr/local/mysql --with-mysqli=shared,/usr/local/mysql/bin/mysql_config --with-iconv=shared --disable-debug --enable-pic --enable-shared --enable-inline-optimization --with-gettext=shared --with-gd=shared --with-curl=shared --with-curlwrappers --with-mcrypt=shared --with-jpeg-dir --with-png-dir --with-zlib=shared --with-libxml-dir=/usr --with-gdbm --with-openssl=shared --with-gmp --with-bz2=shared --with-freetype-dir --enable-fastcgi --enable-fpm --enable-mbstring=shared --enable-safe-mode --enable-sockets=shared --enable-sysvsem=shared --enable-sysvshm=shared --enable-xml --enable-session --enable-zip=shared --enable-pdo --with-pdo-mysql --with-pdo-sqlite --enable-dbase=shared --enable-wddx --enable-shmop=shared --enable-soap=shared --enable-calendar=shared --enable-bcmath=shared --enable-discard-path --with-ldap=shared --with-ldap-sasl --with-xmlrpc=shared
- make && make install
- if [ `uname -i` = "x86_64" ]; then
- \cp $Config/x86_64/ZendOptimizer.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
- chmod +x /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ZendOptimizer.so
- else
- \cp $Config/ZendOptimizer.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
- chmod +x /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ZendOptimizer.so
- fi
- \cp $Config/php-fpm.conf /usr/local/php/etc
- echo "/usr/local/php/sbin/php-fpm start" >> /etc/rc.local
- \cp $Config/php.ini /etc/php5.2/
- }
- in_eaccelerator ()
- {
- cd $Packages
- tar jxf 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
- make && make install
- mkdir /dev/shm/eaccelerator
- chmod 777 /dev/shm/eaccelerator
- echo "mkdir /dev/shm/eaccelerator ; chmod 777 /dev/shm/eaccelerator" >> /etc/rc.local
- }
- in_memcache ()
- {
- cd $Packages
- tar zxf memcache-2.2.5.tgz
- cd memcache-2.2.5
- /usr/local/php/bin/phpize
- ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config
- make && make install
- }
- in_libevent ()
- {
- cd $Packages
- tar zxf libevent-2.0.19-stable.tar.gz
- cd libevent-2.0.19-stable
- ./configure --prefix=/usr/local/libevent
- make && make install
- }
- in_memcached ()
- {
- echo "Starting install memcached-1.4.14..."
- cd $Packages
- tar xzf memcached-1.4.14.tar.gz
- cd memcached-1.4.14
- ./configure --with-libevent=/usr/local/libevent --prefix=/usr/local/memcached
- make && make install
- echo "/usr/local/memcached/bin/memcached -d -m 1024 -u root -c 2048" >> /etc/rc.local
- }
- case $1 in
- nginx)
- in_nginx
- ;;
- db)
- in_mysql
- ;;
- php)
- in_libmcrypt
- in_mhash
- in_mcrypt
- in_php
- in_eaccelerator
- in_memcache
- /usr/local/php/sbin/php-fpm start
- ;;
- memcached)
- in_libevent
- in_memcached
- ;;
- esac
原始地址:http://blog.51bbo.com/archives/1358