2.21.1 前言

目前服务器架构通常采用:CentOs + Nginx + php-fpm + MySql [+ Memcached],现将部署方案安装方法、遇到的问题和解决方法、启动方式总结如下,以便后期服务器快速部署。

  1. 以下文档的是经过几个深夜整理并在阿里云服务器真实部署通过,运行良好,整个过程熟悉后约共半小时,可以进一步考虑做成自动化部署脚本。
  2. 如是,请把脚本也邮件发我一份。^_^

2.21.2 统一约定

  • 全部使用编译安装
  • 安装路径路径:/usr/local/
  • 安装包存放位置:/home/apps/web/

特别注意:请尽量不要使用root账号操作服务器,特别是对外服务器,谢谢。

2.21.3 依赖库和开发工具

  1. 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 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
  2. # nginx
  3. yum -y install pcre-devel zlib-devel
  4. # php
  5. yum -y install gd-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel curl-devel freetype-devel
  6. # mysql
  7. yum -y install bison gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libtool-ltdl-devel* mysql-devel
  8. # sz rz
  9. yum install lrzsz

2.21.4 安装Nginx 1.6.0

参考官方网站

  1. http://wiki.nginx.org/Install

(1)安装

  1. ./configure --prefix=/usr/local/nginx
  2. make
  3. make install

(2)启动

  1. /usr/local/nginx/sbin/nginx

(3)重启

  1. /usr/local/nginx/sbin/nginx -t
  2. /usr/local/nginx/sbin/nginx -s reload

(4)更多配置

  1. server {
  2. listen 80;
  3. server_name test.wetime.com;
  4. root /home/apps/projects/test.wetime.com;
  5. charset utf-8;
  6. access_log logs/test.wetime.com.access.log;
  7. error_log logs/test.wetime.com.error.log;
  8. location / {
  9. index index.html index.htm index.php;
  10. }
  11. location ~ \.php$ {
  12. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  13. fastcgi_pass 127.0.0.1:9000;
  14. fastcgi_index index.php;
  15. include fastcgi_params;
  16. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  17. }
  18. }

2.21.5 安装PHP-FPM 5.3.5

(1)参考

  1. http://blog.csdn.net/dc_726/article/details/9519619

(2)安装

  1. ./configure --prefix=/usr/local/php --with-mcrypt --with-zlib --with-curl --with-gd --disable-debug --enable-fpm --enable-mbstring --enable-sockets --enable-zip --enable-xml --enable-pdo

温馨提示

如果提示以下错误:

  1. If configure fails try --with-jpeg-dir=<DIR>
  2. configure: error: libpng.(a|so) not found.

则需要执行以下命令:

  1. cp -frp /usr/lib64/libjpeg.* /usr/lib/
  2. ln -s /usr/lib64/libpng.so /usr/lib/libpng.so
  3. yum install libmcrypt libmcrypt-devel mcrypt mhash
  4. yum install unixODBC-devel

(3)启动

  1. /usr/local/php/sbin/php-fpm -y=/usr/local/php/etc/php-fpm.conf -c=/usr/local/php/etc/php.ini

(4)重启

  1. /usr/local/php/sbin/php-fpm -y=/usr/local/php/etc/php-fpm.conf -c=/usr/local/php/etc/php.ini -t
  2. killall php
  3. /usr/local/php/sbin/php-fpm -y=/usr/local/php/etc/php-fpm.conf -c=/usr/local/php/etc/php.ini

(5)错误处理与依赖

  1. cp -frp /usr/lib64/libjpeg.* /usr/lib/
  2. ln -s /usr/lib64/libpng.so /usr/lib/libpng.so
  3. yum install libmcrypt libmcrypt-devel mcrypt mhash
  4. yum install unixODBC-devel
  5. 我们可以在命令下输入:
  6. yum localinstall nogpgcheck http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
  7. yum localinstall nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/x86_64/rpmfusion-free-release-6-1.noarch.rpm
  8. yum localinstall nogpgcheck http://download1.rpmfusion.org/nonfree/el/updates/6/x86_64/rpmfusion-nonfree-release-6-1.noarch.rpm
  9. 安装这3个东东后,我们就可以直接使用yum install libmcrypt来安装啦~

(6)php扩展安装

  1. #安装mysql扩展
  2. ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysql=/usr/local/mysql/
  3. make
  4. make install
  5. #安装mysqli扩展
  6. ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysqli=/usr/local/mysql/bin/mysql_config
  7. make
  8. make install

扩展包位置在./php-5.3.5/ext/mysql,需要使用到 /usr/local/php/bin/phpize,扩展so应该放到:/usr/lib/php/modules/

此外,

  1. #PHP之pdo_mysql扩展安装步骤
  2. # http://www.smallbigcake.com/2012/08/05/1572/
  3. # http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
  4. ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
  5. 如果提示“libmysqlclient.so.18: cannot open shared object file: No such file or directory in ”错误则参考 http://blog.itpub.net/26230597/viewspace-1161322/,
  6. 或进行软链:
  7. ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18

2.21.6 安装MYSQL 5.6.10

(1)参考

  1. http://www.cnblogs.com/xiongpq/p/3384681.html

(2)mysql-5.6.10.tar.gz下载

  1. http://pan.baidu.com/share/link?shareid=3729862999&uk=1327790029

(3)前期清理和依赖

  1. rpm -e mysql //普通删除模式
  2. rpm -e --nodeps mysql // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
  3. yum -y install make gcc-c++ cmake bison-devel ncurses-devel

(4)安装

  1. cmake \
  2. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
  3. -DMYSQL_DATADIR=/usr/local/mysql/data \
  4. -DSYSCONFDIR=/etc \
  5. -DWITH_MYISAM_STORAGE_ENGINE=1 \
  6. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  7. -DWITH_MEMORY_STORAGE_ENGINE=1 \
  8. -DWITH_READLINE=1 \
  9. -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
  10. -DMYSQL_TCP_PORT=3306 \
  11. -DENABLED_LOCAL_INFILE=1 \
  12. -DWITH_PARTITION_STORAGE_ENGINE=1 \
  13. -DEXTRA_CHARSETS=all \
  14. -DDEFAULT_CHARSET=utf8 \
  15. -DDEFAULT_COLLATION=utf8_general_ci
  16. make && make install

(5)ERROR! The server quit without updating PID file

  1. #去掉干扰的配置
  2. mv /etc/my.cnf /etc/my.cnf.bak
  3. #添加日记纪录
  4. vim /usr/local/mysql/my.cnf
  5. log-error=/var/log/mysqld.log
  6. innodb_force_recovery=1

2.21.7 [可选]MEMCACHE 1.4.20

(1)参考官网

  1. http://www.memcached.org/downloads

(2)更多参考

  1. http://crtlib.blog.163.com/blog/static/133158013201392661912837/

(3)先安装依赖包

  1. ./configure --prefix=/usr/local/libevent/
  2. make
  3. make install

(4)安装

  1. wget http://memcached.org/latest tar -zxvf memcached-1.x.x.tar.gz cd memcached-1.x.x ./configure && make && make test && sudo make install

(5)最后成功安装后启动

  1. /usr/local/memcached/bin/memcached -d -m 64 -u root -l 127.0.0.1 -p 11211 -c 128 -P /tmp/memcached.pid

(6)memcached 扩展

  1. #http://blog.sina.com.cn/s/blog_66ac09390101drxc.html
  2. #http://www.linuxidc.com/Linux/2013-07/87743.htm
  3. #准备依赖包
  4. ./configure --prefix=/usr/local/libmemcached --with-memcached
  5. make
  6. make install
  7. #安装 扩展
  8. /usr/local/php/bin/pecl install memcached
  9. 接着输入
  10. libmemcached directory [no] : /usr/local/libmemcached

原文: https://www.phalapi.net/wikis/2-21.html