脚本中开源软件版本:
- cmake-2.8.4.tar.gz
- mysql-5.5.10.tar.gz
- libiconv-1.13.1.tar.gz
- libmcrypt-2.5.8.tar.gz
- mhash-0.9.9.9.tar.gz
- mcrypt-2.6.8.tar.gz
- php-5.3.10.tar.gz
- memcache-2.2.5.tgz
- eaccelerator-0.9.6.1.tar.bz2
- PDO_MYSQL-1.0.2.tgz
- ImageMagick-6.6.7-10.tar.gz
- imagick-2.3.0.tgz
- pcre-8.12.tar.gz
- nginx-1.0.10.tar.gz(最新稳定版)
- ngx_cache_purge-1.3.tar.gz
使用方法:
- cd /root
- wget http://blog.linuxeye.com/wp-content/uploads/lnmp.zip
- unzip lnmp.zip
- cd lnmp
- sh lnmp_install.sh
说明:
参考张宴博客(http://blog.s135.com/nginx_php_v6),本人在CentOS 5(32位或者64位)上测试通过,并且在线上使用这个脚本。
脚本内容:
- #!/bin/bash
- #by LinuxEye
- #BLOG: http://blog.linuxeye.com
- yum -y install 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-devel libidn libidn-devel openssl openssl-devel nss_ldap openldap openldap-devel openldap-clients openldap-servers libxslt-devel libevent-devel ntp libtool-ltdl bison libtool vim-enhanced
- #安装mysql-5.5.10
- if [ -e "/root/lnmp" ];then
- echo -e "\e[0;34m start install\e[0m"
- cd /root/lnmp/mysql/
- else
- echo -e "\e[1;31mPlease send lnmp directory moved to /root\e[0m"
- exit 1
- fi
- useradd -M -s /sbin/nologin mysql
- mkdir -p /data/mysql;chown mysql.mysql -R /data/mysql
- tar xzf cmake-2.8.4.tar.gz
- cd cmake-2.8.4
- ./configure
- make && make install
- cd ..
- tar zxf mysql-5.5.10.tar.gz
- cd mysql-5.5.10
- cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
- -DMYSQL_DATADIR=/data/mysql \
- -DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock \
- -DWITH_INNOBASE_STORAGE_ENGINE=1 \
- -DENABLED_LOCAL_INFILE=1 \
- -DMYSQL_TCP_PORT=3306 \
- -DCMAKE_THREAD_PREFER_PTHREAD=1 \
- -DEXTRA_CHARSETS=all \
- -DDEFAULT_CHARSET=utf8 \
- -DDEFAULT_COLLATION=utf8_general_ci \
- -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
- -DWITH_DEBUG=0
- make && make install
- cp support-files/my-medium.cnf /etc/my.cnf
- cp support-files/mysql.server /etc/init.d/mysqld
- chmod 755 /etc/init.d/mysqld
- chkconfig --add mysqld
- chkconfig mysqld on
- #修改配置文件
- sed -i '38a ##############' /etc/my.cnf
- sed -i '39a skip-name-resolve' /etc/my.cnf
- sed -i '40a basedir=/usr/local/mysql' /etc/my.cnf
- sed -i '41a datadir=/data/mysql' /etc/my.cnf
- sed -i '42a user=mysql' /etc/my.cnf
- sed -i '43a #lower_case_table_names = 1' /etc/my.cnf
- sed -i '44a max_connections=1000' /etc/my.cnf
- sed -i '45a ft_min_word_len=1' /etc/my.cnf
- sed -i '46a expire_logs_days = 7' /etc/my.cnf
- sed -i '47a query_cache_size=64M' /etc/my.cnf
- sed -i '48a query_cache_type=1' /etc/my.cnf
- sed -i '49a ##############' /etc/my.cnf
- /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql
- chown mysql.mysql -R /data/mysql
- /sbin/service mysqld start
- echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
- source /etc/profile
- /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'%' identified by 'admin' with grant option;"
- /usr/local/mysql/bin/mysql -e "flush privileges;"
- /usr/local/mysql/bin/mysql -e "delete from mysql.user where password='';"
- /sbin/service mysqld restart
- #php安装
- cd /root/lnmp/php
- tar xzf libiconv-1.13.1.tar.gz
- cd libiconv-1.13.1
- ./configure --prefix=/usr/local
- make && make install
- cd ../
- tar xzf 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 ../../
- tar xzf mhash-0.9.9.9.tar.gz
- cd mhash-0.9.9.9
- ./configure
- make && make install
- cd ../
- if [ -e "/lib64" ];then
- ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
- ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
- ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
- ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
- ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
- ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
- ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
- ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
- ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
- ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
- ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /lib64/libmysqlclient.so.18
- else
- 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
- ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /lib/libmysqlclient.so.18
- fi
- tar xzf mcrypt-2.6.8.tar.gz
- cd mcrypt-2.6.8
- /sbin/ldconfig
- ./configure
- make && make install
- cd ../
- tar xzf php-5.3.10.tar.gz
- useradd -M -s /sbin/nologin www
- cd php-5.3.10
- ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --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-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --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-ftp --enable-zip --enable-soap --disable-debug
- make ZEND_EXTRA_LIBS='-liconv'
- make install
- cp php.ini-production /usr/local/php/lib/php.ini
- cd ../
- tar xzf memcache-2.2.5.tgz
- cd memcache-2.2.5
- /usr/local/php/bin/phpize
- ./configure --with-php-config=/usr/local/php/bin/php-config
- make && make install
- cd ../
- tar xjf 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
- cd ../
- tar xzf 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 ../
- tar xzf ImageMagick-6.6.7-10.tar.gz
- cd ImageMagick-6.6.7-10
- ./configure
- make && make install
- cd ../
- tar xzf imagick-2.3.0.tgz
- cd imagick-2.3.0
- /usr/local/php/bin/phpize
- ./configure --with-php-config=/usr/local/php/bin/php-config
- make && make install
- cd ../
- #修改php.ini
- mkdir /tmp/eaccelerator
- /bin/chown -R www.www /tmp/eaccelerator/
- sed -i '808a extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"' /usr/local/php/lib/php.ini
- sed -i '809a extension = "memcache.so"' /usr/local/php/lib/php.ini
- sed -i '810a extension = "pdo_mysql.so"' /usr/local/php/lib/php.ini
- sed -i '811a extension = "imagick.so"' /usr/local/php/lib/php.ini
- sed -i '134a output_buffering = On' /usr/local/php/lib/php.ini
- sed -i '847a cgi.fix_pathinfo=0' /usr/local/php/lib/php.ini
- sed -i 's@;date.timezone =@date.timezone = Asia/Shanghai@g' /usr/local/php/lib/php.ini
- echo '[eaccelerator]
- zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
- eaccelerator.shm_size="64"
- eaccelerator.cache_dir="/tmp/eaccelerator"
- eaccelerator.enable="1"
- eaccelerator.optimizer="1"
- eaccelerator.check_mtime="1"
- eaccelerator.debug="0"
- eaccelerator.filter=""
- eaccelerator.shm_max="0"
- eaccelerator.shm_ttl="0"
- eaccelerator.shm_prune_period="0"
- eaccelerator.shm_only="0"
- eaccelerator.compress="0"
- eaccelerator.compress_level="9"
- eaccelerator.keys = "disk_only"
- eaccelerator.sessions = "disk_only"
- eaccelerator.content = "disk_only"' >> /usr/local/php/lib/php.ini
- cat > /usr/local/php/etc/php-fpm.conf <<EOF
- ;;;;;;;;;;;;;;;;;;;;;
- ; FPM Configuration ;
- ;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;
- ; Global Options ;
- ;;;;;;;;;;;;;;;;;;
- [global]
- pid = run/php-fpm.pid
- error_log = log/php-fpm.log
- log_level = notice
- emergency_restart_threshold = 30
- emergency_restart_interval = 1m
- process_control_timeout = 5s
- daemonize = yes
- ;;;;;;;;;;;;;;;;;;;;
- ; Pool Definitions ;
- ;;;;;;;;;;;;;;;;;;;;
- [www]
- listen = 127.0.0.1:9000
- listen.backlog = -1
- listen.allowed_clients = 127.0.0.1
- listen.owner = www
- listen.group = www
- listen.mode = 0666
- user = www
- group = www
- pm = dynamic
- pm.max_children = 32
- pm.start_servers = 4
- pm.min_spare_servers = 4
- pm.max_spare_servers = 16
- pm.max_requests = 512
- request_terminate_timeout = 0
- request_slowlog_timeout = 0
- slowlog = log/$pool.log.slow
- rlimit_files = 51200
- rlimit_core = 0
- catch_workers_output = yes
- env[HOSTNAME] = $HOSTNAME
- env[PATH] = /usr/local/bin:/usr/bin:/bin
- env[TMP] = /tmp
- env[TMPDIR] = /tmp
- env[TEMP] = /tmp
- EOF
- echo '/usr/local/php/sbin/php-fpm' >> /etc/rc.local
- /usr/local/php/sbin/php-fpm
- #安装nginx
- mkdir /root/lnmp/nginx
- cd /root/lnmp/nginx
- tar xzf pcre-8.12.tar.gz
- cd pcre-8.12
- ./configure
- make && make install
- cd ../
- tar xzf ngx_cache_purge-1.3.tar.gz
- tar xzf nginx-1.0.12.tar.gz
- cd nginx-1.0.12
- #修改版本信息
- sed -i 's@#define NGINX_VERSION.*$@#define NGINX_VERSION "1.0"@g' src/core/nginx.h
- sed -i 's@#define NGINX_VER.*NGINX_VERSION$@#define NGINX_VER "YWS/" NGINX_VERSION@g' src/core/nginx.h
- ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=../ngx_cache_purge-1.3
- make && make install
- cd /root/lnmp/nginx/
- cp nginx.sh /etc/init.d/nginx
- chmod 755 /etc/init.d/nginx
- chkconfig --add nginx
- chkconfig nginx on
- rm -rf /usr/local/nginx/conf/nginx.conf
- cp nginx.conf /usr/local/nginx/conf/nginx.conf
- echo "LNMP安装成功"
- echo "请按实际需求nginx.conf文件"