codecamp

服务器统一部署方案简明版:CentOs + Nginx + php-fpm + MySql [+ Memcached]

2.21.1 前言

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

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

2.21.2 统一约定

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

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

2.21.3 依赖库和开发工具

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

# nginx
yum -y install pcre-devel zlib-devel

# php
yum -y install gd-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel curl-devel freetype-devel

# mysql
yum -y install bison gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libtool-ltdl-devel* mysql-devel

# sz rz
yum install lrzsz

2.21.4 安装Nginx 1.6.0

参考官方网站

http://wiki.nginx.org/Install

(1)安装

./configure --prefix=/usr/local/nginx
make
make install

(2)启动

/usr/local/nginx/sbin/nginx

(3)重启

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload

(4)更多配置

server {
    listen 80;
    server_name test.wetime.com;
    root /home/apps/projects/test.wetime.com;
    charset utf-8;
    access_log logs/test.wetime.com.access.log;
    error_log logs/test.wetime.com.error.log;
    location / {
        index index.html index.htm index.php;
    }
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

2.21.5 安装PHP-FPM 5.3.5

(1)参考

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

(2)安装

./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

温馨提示

如果提示以下错误:

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

则需要执行以下命令:

cp  -frp /usr/lib64/libjpeg.* /usr/lib/
ln -s /usr/lib64/libpng.so /usr/lib/libpng.so

yum install libmcrypt libmcrypt-devel mcrypt mhash
yum install unixODBC-devel

(3)启动

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

(4)重启

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

(5)错误处理与依赖

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

我们可以在命令下输入: 

yum localinstall –nogpgcheck http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum localinstall –nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/x86_64/rpmfusion-free-release-6-1.noarch.rpm
yum localinstall –nogpgcheck http://download1.rpmfusion.org/nonfree/el/updates/6/x86_64/rpmfusion-nonfree-release-6-1.noarch.rpm

安装这3个东东后,我们就可以直接使用yum install libmcrypt来安装啦~

(6)php扩展安装

#安装mysql扩展
 ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysql=/usr/local/mysql/
make
make install

#安装mysqli扩展
 ./configure --with-php-config=/usr/local/php/bin/php-config --with-mysqli=/usr/local/mysql/bin/mysql_config
make
make install

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

此外,

#PHP之pdo_mysql扩展安装步骤

# http://www.smallbigcake.com/2012/08/05/1572/ 
# http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz 

./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql 

如果提示“libmysqlclient.so.18: cannot open shared object file: No such file or directory in ”错误则参考 :http://blog.itpub.net/26230597/viewspace-1161322/, 
或进行软链: 
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18 

2.21.6 安装MYSQL 5.6.10

(1)参考

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

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

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

(3)前期清理和依赖

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

(4)安装

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

make && make install

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

#去掉干扰的配置
mv /etc/my.cnf /etc/my.cnf.bak

#添加日志纪录
vim /usr/local/mysql/my.cnf
log-error=/var/log/mysqld.log
innodb_force_recovery=1

2.21.7 [可选]MEMCACHE 1.4.20

(1)参考官网

http://www.memcached.org/downloads

(2)更多参考

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

(3)先安装依赖包

./configure --prefix=/usr/local/libevent/
make
make install

(4)安装

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)最后成功安装后启动

/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 扩展

#http://blog.sina.com.cn/s/blog_66ac09390101drxc.html
#http://www.linuxidc.com/Linux/2013-07/87743.htm

#准备依赖包
./configure --prefix=/usr/local/libmemcached --with-memcached
make 
make install

#安装 扩展
/usr/local/php/bin/pecl install memcached
接着输入
libmemcached directory [no] : /usr/local/libmemcached

约定编程:架构明显的编程风格
更多工具:精英项目和团队建设
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

八、视频教程

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }