|
转自:http://renzhenxing.blog.iyunv.com/
centos 6.4 下的lnmp 生产环境搭建及安装脚本
近期公司打算从lamp 更换到lnmp 平台,所以研究了一下lnmp的安装。将这个整理成了一个脚本.后面会附带给大家的,脚本写的很烂,基本没有什么判断,希望大家能够谅解.可以提出意见 我尽力改正。
http://renzhenxing.blog.iyunv.com/728846/1321572
软件版本:
12345678910111213libiconv-1.13.tar.gzlibmcrypt-2.5.8.tar.gzmcrypt-2.6.8.tar.gzmhash-0.9.9.9.tar.gzmemcache-2.2.5.tgzPDO_MYSQL-1.0.2.tgzimagick-3.1.2.tgzpcre-8.21.tar.gzmysql-5.5.30.tar.gzImageMagick.tar.gzphp-5.4.21.tar.gznginx-1.4.0.tar.gzeaccelerator-eaccelerator-42067ac.tar.gz (为1.0-dev版)
系统安装需求:
1centos 6.4 *86_64 mini安装,关闭selinux,iptables
1 安装解决依赖关系:
1yum install-y wget gcc gcc-c++ autoconf libjpeg libjpeg-devel perl perl* perl-CPAN libpng libpng-devel freetype freetype-devellibxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-develbzip2bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-develkrb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers png jpeg autoconf gcc cmakemakegcc-c++ gcc ladp ldap* ncurses ncurses-devel zlib zlib-devel zlib-static pcre pcre-devel pcre-static openssl openssl-devel perl libtoolt openldap-devel libxml2-devel ntpdate cmake gd* gd2ImageMagick-devel jpeg jpeg* pcre-dev* fontconfig libpng libxml2 zip unzipgzip
2 下载所有使用到的软件:
1wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.13.tar.gz1wget http://lcmp.googlecode.com/files/libmcrypt-2.5.8.tar.gz1wget http://jaist.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz1wget http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz1wget http://vps.googlecode.com/files/memcache-2.2.5.tgz1wget http://vps.googlecode.com/files/PDO_MYSQL-1.0.2.tgz1wget http://pecl.php.net/get/imagick-3.1.2.tgz1wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz1wget http://netcologne.dl.sourceforge.net/project/mysql.mirror/MySQL%205.5.30/mysql-5.5.30.tar.gz1wget http://mynginx.googlecode.com/files/ImageMagick.tar.gz1wget http://us3.php.net/get/php-5.4.21.tar.gz/from/cn2.php.net/mirror1wget https://lnamp-web-server.googlecode.com/files/eaccelerator-eaccelerator-42067ac.tar.gz1wget http://nginx.org/download/nginx-1.4.0.tar.gz
3 安装mysql-5.5.0
123456789101112131415161718192021222324252627groupadd mysqluseraddmysql -g mysqltar -zxvf mysql-5.5.30.tar.gzcd mysql-5.5.30cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql\ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DMYSQL_DATADIR=/data/mysql/\ -DMYSQL_USER=mysql \ -DMYSQL_TCP_PORT=3306make && make installmkdir-p/data/mysqlchownmysql.mysql -R/data/mysqlmv /etc/my.cnf /etc/my.cnf-oldcp support-files/my-medium.cnf/etc/my.cnfchmod755 scripts/mysql_install_dbscripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql--datadir=/data/mysql/cp support-files/mysql.server/etc/init.d/mysqldchmod755/etc/init.d/mysqldchkconfig mysqld onservice mysqld start
设置mysql的root密码为123456
1/usr/local/mysql/bin/mysqladmin-u root password'123456' 4 安装php的扩展库:libiconv
1234tar zxvf libiconv-1.13.tar.gzcd libiconv-1.13/./configure--prefix=/usr/localmake && make install
5 安装php扩展库:libmcrypt
123456789tar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configuremake && make install/sbin/ldconfig### 注:这里不要退出去了。cd libltdl/./configure--enable-ltdl-installmake && make install
6 安装php扩展库:mhash
1234tar zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9/./configuremake && make install
7 做库的软连接:
12345678910ln -s /usr/local/lib/libmcrypt.la/usr/lib/libmcrypt.laln -s /usr/local/lib/libmcrypt.so/usr/lib/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4/usr/lib/libmcrypt.so.4ln -s /usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8ln -s /usr/local/lib/libmhash.a/usr/lib/libmhash.aln -s /usr/local/lib/libmhash.la/usr/lib/libmhash.laln -s /usr/local/lib/libmhash.so/usr/lib/libmhash.soln -s /usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2ln -s /usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1ln -s /usr/lib64/libldap*/usr/lib/
8 安装php扩展包:mcrypt
12345tar zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8//sbin/ldconfig./configuremake && make install
9 安装php-5.4.21:
123tar -zxvf php-5.4.21.tar.gzcd php-5.4.21 ./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-gd --enable-gd-native-ttf --with-libxml-dir=/usr--enable-xml--disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath--enable-shmop --enable-sysvsem --enable-inline-optimization--with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm--enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-openssl --with-mhash --enable-pcntl--enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap--without-pear
123456ln -s /usr/local/mysql/lib/libmysqlclient.so.18/usr/lib64/make ZEND_EXTRA_LIBS='-liconv'make installcp -f php.ini-production /usr/local/php/etc/php.iniln -s /usr/local/php/etc/php.ini/usr/local/php/php.inicp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
10 安装php扩展库:memcache
12345tar zxvf memcache-2.2.5.tgzcd memcache-2.2.5//usr/local/php/bin/phpize./configure--with-php-config=/usr/local/php/bin/php-configmake && make install
11 安装php加速:eaccelerator
12345tar -zxvf eaccelerator-eaccelerator-42067ac.tar.gzcd eaccelerator-eaccelerator-42067ac/usr/local/php/bin/phpize./configure--enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-configmake && make install
12 修改php.ini增加memcache,ea等软件信息
添加memcache库的位置:
12345vim /usr/local/php/php.iniextension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525"extension = "memcache.so"extension = "pdo_mysql.so"extension = "imagick.so" 添加eaccelerator库的位置信息:
12345678910111213141516171819;eaccelerator[eaccelerator]zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so"eaccelerator.shm_size="1"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"eaccelerator.keys ="disk_only"eaccelerator.sessions ="disk_only"eaccelerator.content ="disk_only"
12mkdir -p /usr/local/eaccelerator_cachechmod 0777 /usr/local/eaccelerator_cache
13 :安装php扩展库:PDO_MYSQL
123456tar zxvf PDO_MYSQL-1.0.2.tgzcd 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/mysqlln -s /usr/local/mysql/include/*/usr/local/include/make && make install
14 :安装php扩展库: ImageMagick
123tar zxvf ImageMagick.tar.gzcd ImageMagick-6.5.1-2/./configure&&make&& make install
15:安装php扩展库:imagick
123456tar zxvf imagick-3.1.2.tgzcd imagick-3.1.2//usr/local/php/bin/phpizeln -s /usr/local/include/ImageMagick-6 /usr/local/include/ImageMagick./configure--with-php-config=/usr/local/php/bin/php-configmake && make install
16:添加WWW用户,为系统运行nginx专用用户:
12345678/usr/sbin/groupaddwww/usr/sbin/useradd-g www wwwmkdir -p /var/log/nginxchmod +w /var/log/nginxchown -R www:www /var/log/nginxmkdir -p /data0/wwwchmod +w /data0/wwwchown -R www:www /data0/www
17:修改php-fpm.conf的配置:
vim /usr/local/php/etc/php-fpm.conf
12345678#去掉/更改 配置文件中的;pm.max_children = 64pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 1024user = wwwgroup = www
#检查语法是否正确
123/usr/local/php/sbin/php-fpm-t NOTICE: configurationfile/usr/local/php/etc/php-fpm.conftestissuccessful看到上面的信息 证明php配置文件正常,可以启动了。
18: 添加环境变量:
123echo "export PATH=\$PATH:/usr/local/php/sbin/" >>/etc/profileecho "export PATH=\$PATH:/usr/local/php/bin/" >>/etc/profile. /etc/profile
19:安装nginx的 pcre
12tar -zxvf pcre-8.21.tar.gzcd pcre-8.21 && ./configure && make && make install
20:编译安装 nginx
1234tar -zxvf nginx-1.4.0.tar.gzcd nginx-1.4.0/./configure--user=www --group=www --prefix=/usr/local/nginx--sbin-path=/usr/local/nginx/sbin/nginx--conf-path=/usr/local/nginx/conf/nginx.conf--with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.21 --lock-path=/var/run/nginx.lock --pid-path=/var/run/nginx.pidmake && make install
21:修改nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
1234567891011121314#修改一些参数,别直接替换文件,这只是一部分user www;events {use epoll;worker_connections 1024;} location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
22:写一个php的测试文件:phpinfo
12345cat >>/usr/local/nginx/html/index.php<<EOF<?php phpinfo(); ?> EOF
23:添加开机启动:
123echo "/usr/local/supper/php/sbin/php-fpm" >> /etc/rc.localecho "/usr/local/nginx/sbin/nginx" >> /etc/rc.localecho "/etc/init.d/mysqld restart" >> /etc/rc.local
24:浏览器访问:
访问之前建议先关闭selinux,iptables
看到以上信息可以确定我们的lnmp 环境初步搭建完成。关于优化的事情,待研究之后再次释出。 |
|
|
|
|
|
|