一、安装nginx:
1. 安装pcre库,nginx的rewrite模板需用到pcre库:

  1. mkdir -p /works  
  2. cd /works  
  3. wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.20.tar.gz  
  4. tar -zxvf pcre-8.20.tar.gz  
  5. ./configure  
  6. make && make install  
  7. cd ..  

2. 安装nginx:

  1. wget http://nginx.org/download/nginx-1.0.10.tar.gz  
  2. tar -zxvf nginx-1.0.10.tar.gz  
  3. cd nginx-1.0.10  
  4. ./configure  
  5. make && make install  
  6. cd ..  

3. 新建用户和组:

  1. groupadd www  
  2. useradd -r -g www www  

二、安装PHP5
1. 安装依赖包:

  1. libcurl:  
  2. wget http://curl.haxx.se/download/curl-7.23.1.tar.gz  
  3. tar -zxvf curl-7.23.1.tar.gz  
  4. cd curl-7.23.1/  
  5. ./configure  
  6. make && make install  
  7. cd ..  


libxml2:

  1. wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz  
  2. tar -zxvf libxml2-2.7.6.tar.gz  
  3. cd libxml2-2.7.6  
  4. ./configure  
  5. make && make install  
  6. cd ..   

libxslt:

  1. wget ftp://xmlsoft.org/libxml2/libxslt-1.1.24.tar.gz  
  2. tar -zxvf libxslt-1.1.24.tar.gz  
  3. cd libxslt-1.1.24  
  4. ./configure  make && make install  
  5. cd ..   

freetype:

  1. wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.6.tar.gz  
  2. tar -zxvf freetype-2.4.6.tar.gz  
  3. cd freetype-2.4.6  ./configure  
  4. make && make install  
  5. cd ..  

libpng:

  1. wget "http://prdownloads.sourceforge.net/libpng/libpng-1.5.6.tar.gz?download" 
  2. tar -zxvf libpng-1.5.6.tar.gz  
  3. cd libpng-1.5.6  ./configure  
  4. make && make install  
  5. cd ..  

libjpeg:

  1. wget http://ijg.org/files/jpegsrc.v8c.tar.gz  
  2. tar -zxvf jpegsrc.v8c.tar.gz  
  3. cd jpeg-8c/  
  4. ./configure  
  5. make && make install  
  6. cd ..  

2. 安装php5和php-fpm:

  1. wget http://museum.php.net/php5/php-5.2.16.tar.gz  
  2. wget http://php-fpm.org/downloads/php-5.2.16-fpm-0.5.14.diff.gz  
  3. tar -zxvf php-5.2.16.tar.gz   
  4. gunzip php-5.2.16-fpm-0.5.14.diff.gz   
  5. cd php-5.2.16/  
  6. patch -p1 < ../php-5.2.16-fpm-0.5.14.diff  
  7.  
  8. ./configure \  
  9. --with-curl \  
  10. --enable-calendar \  
  11. --with-xsl \  
  12. --with-libxml-dir \  
  13. --enable-ftp \  
  14. --with-gd \  
  15. --with-freetype-dir \  
  16. --with-jpeg-dir \  
  17. --with-png-dir \  
  18. --enable-mbstring \  
  19. --with-zlib \  
  20. --enable-shared \  
  21. --with-mysql \  
  22. --enable-fastcgi \  
  23. --enable-fpm   
  24. ./configure && make && make install  

修改php-fpm的配置文件/usr/local/etc/php-fpm.conf,设置执行php-fpm的用户和组名:
大约在第62行:

  1. Unix user of processes  
  2. <!--<value name="user">nobody</value>-->                              
  3. Unix group of processes  
  4. <!--<value name="group">nobody</value>-->  

修改为:

  1. Unix user of processes  
  2. <value name="user">www</value>                            
  3. Unix group of processes  
  4. <value name="group">www</value> 

启动php-fpm:

  1. /usr/local/sbin/php-fpm start  
  2. lsof -i:9000  
  3. netstat -ant|grep 9000    
  4. #9000为php-fpm的默认端口,可以在/usr/local/etc/php-fpm.conf中修改。  

修改nginx配置文件/usr/local/nginx/conf/nginx.conf,我的nginx配置文件如下:

  1. worker_processes  10;  
  2. events {  
  3.     worker_connections  1024;  
  4. }  
  5. http {  
  6.     include       mime.types;  
  7.     default_type  application/octet-stream;  
  8.     sendfile        on;  
  9.     keepalive_timeout  65;  
  10.     gzip  on;  
  11.     server {  
  12.         listen       80;  
  13.         server_name  ead;  
  14.  root /data/faceshow/www;  
  15.         location / {  
  16.             root   html;  
  17.             index  index.php index.html index.htm;  
  18.         }  
  19.         error_page   500 502 503 504  /50x.html;  
  20.         location = /50x.html {  
  21.             root   html;  
  22.         }  
  23.    
  24.  #此段代码为关键  
  25.         location  ~ \.php$ {  
  26.             fastcgi_pass   127.0.0.1:9000; #对应php-fmp的端口  
  27.             fastcgi_index  index.php;  
  28.             fastcgi_param  SCRIPT_FILENAME  /data/faceshow/www/$fastcgi_script_name;    
  29.          #php文件的物理路径  
  30.             include        fastcgi_params;  
  31.         }  
  32.    
  33.  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$  
  34.      {  
  35.         expires      30d;  
  36.      }  
  37.      location ~ .*\.(js|css)?$  
  38.      {  
  39.         expires      1h;  
  40.      }      
  41.     }  
  42. }  
  43.  

启动nginx:

  1. /usr/local/nginx/bin/nginx   
  2. /usr/local/nginx/bin/nginx -s reload  

三、常见问题:
问题: nginx ./configure时报如下错误

  1. ./configure: error: the HTTP rewrite module requires the PCRE library.  
  2. You can either disable the module by using --without-http_rewrite_module  
  3. option, or install the PCRE library into the system, or build the PCRE library  
  4. statically from the source with nginx by using --with-pcre=<path> option.  

解决:这是由于未PCRE库,请安装PCRE库在运行./configure。也可以使用带--without-http_rewrite_module参数进行./configure,但是这将导致nginx不支持rewrite功能!

四、相关文件下载地址:
libcurl: http://curl.haxx.se/download.html
libxml2: ftp://xmlsoft.org/libxml2/
libxslt: ftp://xmlsoft.org/libxml2/
libpng: http://www.libpng.org/pub/png/libpng.html
libjpeg: http://ijg.org/files/
freetype:http://download.savannah.gnu.org/releases/freetype/
pcre:http://www.pcre.org/

nginx:http://nginx.org/en/download.html
php-fpm:http://php-fpm.org/
php5:http://www.php.net/releases/
MySQL:http://www.mysql.com/downloads/mirror.php?id=404683#mirrors

本日志由 Admin 于 2011-11-29 16:32:12 发表到 Linux/Unix 中,目前已经被浏览 297 次,评论 1 次;

作者添加了以下标签: LinuxUnixNginxPhp

一、安装MYSQL
下载页面:http://www.mysql.com/downloads/mirror.php?id=404683#mirrors
1. 添加用户帐号和安装依赖包

  1. groupadd mysql  
  2. useradd -r -g mysql mysql  
  3. yum install gcc gcc-c++ libtool autoconf automake imake libxml2-devel expat-devel ncurses-devel cmake bison 

2. 下载、解压源码包

  1. mkdir -p /data/temp
  2. cd /data/temp
  3. wget ftp://ftp.fi.muni.cz/pub/mysql/Downloads/MySQL-5.5/mysql-5.5.18.tar.gz  
  4. tar -zxvf mysql-5.5.18.tar.gz  
  5. cd mysql-5.5.18 

3. cmake进行编译

  1. cmake . \  
  2. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \  
  3. -DDEFAULT_CHARSET=utf8 \  
  4. -DEXTRA_CHARSETS=all \  
  5. -DDEFAULT_COLLATION=utf8_general_ci \  
  6. -DMYSQL_USER=mysql  
  7.  
  8. make  
  9. make install   
  10. cd /usr/local/mysql  
  11. chown -R mysql .  
  12. chgrp -R mysql .  
  13. scripts/mysql_install_db --user=mysql  
  14. chown -R root .  
  15. chown -R mysql data  
  16. cp support-files/my-medium.cnf /etc/my.cnf  
  17. bin/mysqld_safe --user=mysql &    
  18. cp support-files/mysql.server /etc/init.d/mysqld  
  19. cd /usr/local/bin  
  20. ln -fs /usr/local/mysql/bin/mysql mysql 

4. 把mysql 添加为系统启动服务

  1. cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld  
  2. cd /etc/rc.d/init.d  
  3. chkconfig --add mysqld         
  4. service mysqld start/stop 

二、安装Apache
下载页面:http://www.apache.org/dist/httpd/
1. 安装apache:

  1. wget http://www.apache.org/dist/httpd/httpd-2.2.21.tar.gz  
  2. tar -zxvf httpd-2.2.21.tar.gz  
  3. cd httpd-2.2.21  
  4. ./configure --enable-modules=so --enable-rewrite  
  5. make && make install 

2. 安装扩展:

  1. cd srclib/apr  
  2. make  
  3. make install  
  4.  
  5. cd ../apr-util/  
  6. ./configure --with-apr=../apr  
  7. make   
  8. make install  

二、安装PHP5
1. 安装依赖包:
libcurl:

  1. wget http://curl.haxx.se/download/curl-7.23.1.tar.gz  
  2. tar -zxvf curl-7.23.1.tar.gz  
  3. cd curl-7.23.1/  
  4. ./configure  
  5. make && make install  
  6. cd .. 

libxml2:

  1. wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz  
  2. tar -zxvf libxml2-2.7.6.tar.gz  
  3. cd libxml2-2.7.6  
  4. ./configure  
  5. make && make install  
  6. cd .. 

libxslt:

  1. wget ftp://xmlsoft.org/libxml2/libxslt-1.1.24.tar.gz  
  2. tar -zxvf libxslt-1.1.24.tar.gz  
  3. cd libxslt-1.1.24  
  4. ./configure  
  5. make && make install  
  6. cd .. 

freetype:

  1. http://download.savannah.gnu.org/releases/freetype/freetype-2.4.6.tar.gz  
  2. tar -zxvf freetype-2.4.6.tar.gz  
  3. cd freetype-2.4.6  
  4. ./configure   
  5. make && make install  
  6. cd .. 

libpng:

  1. wget "http://prdownloads.sourceforge.net/libpng/libpng-1.5.6.tar.gz?download" 
  2. tar -zxvf libpng-1.5.6.tar.gz   
  3. cd libpng-1.5.6  
  4. ./configure   
  5. make && make install  
  6. cd .. 

libjpeg:

  1. wget http://ijg.org/files/jpegsrc.v8c.tar.gz  
  2. tar -zxvf jpegsrc.v8c.tar.gz  
  3. cd jpeg-8c/  
  4. ./configure   
  5. make && make install  
  6. cd .. 

2. 安装PHP:

  1.  
  2. wget http://cn2.php.net/get/php-5.2.17.tar.bz2/from/hk.php.net/mirror  
  3. cat php-5.2.17.tar.bz2 |bunzip2 | tar xvf -   
  4. cd php-5.2.17   
  5. ./configure --with-apxs2=/usr/local/apache2/bin/apxs  \  
  6.  --with-curl \  
  7.  --enable-calendar \  
  8.  --with-xsl \  
  9.  --with-libxml-dir \  
  10.  --enable-ftp \  
  11.  --with-gd \  
  12.  --with-freetype-dir \  
  13.  --with-jpeg-dir \  
  14.  --with-png-dir \  
  15.  --enable-mbstring \  
  16.  --with-zlib \  
  17.  --enable-shared \  
  18.  --with-mysql   
  19. make && make install  
  20. cd ..  

3. 让apache加载php模块:

  1. vim /usr/local/apache2/conf/httpd.conf  
  2. #确保下面三行在httpd.conf配置文件中存在
  3. LoadModule php5_module modules/libphp5.so  
  4. AddType application/x-httpd-php .php  
  5. AddType application/x-httpd-php-source .phps  

4. 启动HTTP服务及测试

  1. /usr/local/apache2/bin/httpd -k restart  
  2. echo "<?php phpinfo(); ?>" > /usr/local/apache2/htdocs/index.php   
  3. #使用浏览器打开URL:http://ip/index.php 


常见错误:
1. 现象:make install时报"dlname not found in /usr/local/apache2/modules/libphp5.la."
    解答:这是由于apache与php的libtool版本不一致引起的。

  1. /usr/local/apache2/build/libtool --version  
  2. ltmain.sh (GNU libtool) 1.5.26 (1.1220.2.492 2008/01/30 06:40:56)  
  3. ./libtool --version  
  4. ltmain.sh (GNU libtool) 1.5.22 (1.1220.2.365 2005/12/18 22:14:06)  

    解决方法:使php安装目录下的libtool与apache的libtool版本一致,再重新安装,操作如下:

  1. cd /data/temp/  
  2. cp /usr/local/apache2/build/libtool .  
  3. make clean  
  4. make install  
  5.  


相关文件下载地址:依赖包下载地址:
libcurl: http://curl.haxx.se/download.html
libxml2: ftp://xmlsoft.org/libxml2/
libxslt: ftp://xmlsoft.org/libxml2/
libpng: http://www.libpng.org/pub/png/libpng.html
libjpeg: http://ijg.org/files/
freetype:http://download.savannah.gnu.org/releases/freetype/

apache:http://www.apache.org/dist/httpd/
PHP:http://www.php.net/downloads.php
MySQL:http://www.mysql.com/downloads/mirror.php?id=404683#mirrors

本日志由 Admin 于 2011-11-28 17:29:19 发表到 Linux/Unix 中,目前已经被浏览 332 次,评论 1 次;

作者添加了以下标签: LinuxApachePhpMySQL

本日志由 Admin 于 2011-11-28 09:19:58 发表到 资料类 中,目前已经被浏览 205 次,评论 1 次;

作者添加了以下标签: 考试公务员试题答案

1、 在用"Python setup.py"命令安装PostgreSQL的Python驱动时:

  1. running build_ext   
  2. error: No such file or directory  

解决办法:在文件"setup.cfg"设置"pg_config"未正确的完整路径,如"pg_config=/usr/bin/pg_config"。如果当前系统中不存在"pg_config",请先安装"postgresql-devel-*.*.rpm"包。
2、连接PostgreSQL数据库时报如下错误:

  1. psql: 致命错误:  用户 "***" Ident 认证失败 

  1. psql: FATAL: Ident authentication failed for user “username”, mais pourquoi donc ? 

解决办法:修改"pg_hba.conf"文件中认证方式"METHOD"为"md5"或"trust",具体参考文件中的说明。
3、在用"make"编译软件时提示:

  1. "Makefile", line 88: Missing dependency operator  
  2. "Makefile", line 89: Missing dependency operator  
  3. "Makefile", line 91: Need an operator  
  4. "Makefile", line 92: Need an operator  
  5. "Makefile", line 93: Missing dependency operator  
  6. "Makefile", line 94: Missing dependency operator  
  7. Error expanding embedded variable. 

解决办法:用"gmake"编译就OK了。

本日志由 Admin 于 2011-03-02 18:32:10 发表到 Linux/Unix 中,目前已经被浏览 1121 次,评论 27 次;

作者添加了以下标签: LinuxUnixError

  MongoDB是C++开发的一款开源、无模式的文档型数据库,具有高性能、易部署、易使用、数据存储方便等特点;MongoDB采用Bson(binary json)的形式存储数据,无锁,无事务,有索引,支持集群和分片功,可动态增删结点。

实验环境:
系统:FreeBSD 8.1-RELEASE
版本:mongodb v1.6.6

安装:
  目前,官网上并没有FreeBSD下MongoDB的pkg包下载,所以FreeBSD下MongoDB的安装方式只有两种:ports方式和源码方式。其中Ports方式十分简单,但是由于网速等因数影响,可能要很久才能完成安装;而在MongoDB依赖包安装不全的的情况下,使用源码方式安装MongoDB相对会更为复杂。
1. Ports方式安装MongoDB:

  1. cd /usr/ports/databases/mongodb  
  2. make  
  3. make install 

  Ports方式安装MongoDB十分简单,就以上三条命令。但由于网络问题或Ports树太旧等原因可能会报错。如出现错误终止,请仔细观察错误代码,删除/usr/ports/distfiles/下未下载完成的文件或更新Ports树后重新Make。
  如果你有多台FreeBSD主机要安装MongoDB,而且这些主机的硬件平台几乎相同,为了提高工作效率,你可以将Ports方式安装的MongoDB、以及MongoDB的依赖包,打包成pkg包,然后通过scp方式复制到其他主机上使用pkg_add命令安,效率会成倍的提高。具体打包方式如下:

  1. cd /var/db/pkg 
  2. pkg_create -R -b mongodb-1.*   # 把*号换成版本号,-R参数为连同依赖包一起打包 
  3. ls *.tbz            # 查看打好的包 

  按以上方式打好包后,即可以拷贝到其他主机上,使用pkg_add mongodb-1.*.tbz进行安装。
2. 源码的方式安装:
①. 下载MongoDB:
打开www.mongodb.org/downloads页面,在最后一列找到你要需要版本的源码(我这里是v1.6.6),然后执行下列命令:

  1. #安装依赖包 
  2. cd /usr/ports/lang/spidermonkey && make && make install 
  3. cd /usr/ports/devel/scons && make && make install  #在弹出的窗口中选上"python" 
  4. cd /usr/ports/devel/boost-all && make && make install 
  5. cd /usr/ports/devel/libexecinfo && make && make install 
  6. cd /usr/ports/devel/pcre && make && make install    #官方的文档中没此项,会报错 
  7.  
  8. #下载,解压,编译 
  9. cd /usr/local 
  10. fetch http://downloads.mongodb.org/src/mongodb-src-r1.6.5.tar.gz 
  11. tar -zxvf mongodb-src-r1.6.5.tar.gz 
  12. mv mongodb-src-r1.6.5 mongodb-1.6.5 
  13. cd mongodb-1.6.5 
  14. scons .                # 然后等待完成 
  15.  
  16. # 设置环境变量 
  17. export PATH=$PATH:/usr/local/mongodb-1.6.5 

启动MongoDB服务:
  MongoDB的服务端运行模式有三种,分别是:单台模式、主从模式、分片模式。
1. 单台模式的Mongodb的启动

  1. mkdir -p /data/db  
  2. mongod --dbpath /data/db --logpath /data/db/db.log  --fork 
  3.  
  4. # 查看状态 
  5. mongo 127.0.0.1:27017 
  6. show dbs #显示数据库 
  7. help 

2. 主从(Master、Slave)模式的Mongodb的启动:
Master主机( ip为10.0.0.1):

  1. mongod --master --dbpath /data/master --logpath /data/master/master.log  --fork 
  2. cat /data/master/master.log 

Slave主机(ip为10.0.0.2):

  1. mongod --slave --dbpath /data/slave --logpath /data/slave/slave.log  --source 10.0.0.1:27017 --fork 
  2. cat /data/slave/slave.log 

测试:

  1. # 查看状态 
  2. mongo 10.0.0.1:27017 
  3. show dbs #显示数据库 
  4. help

3. 分片模式:
由于分片模式配置相对复杂,在另篇文章详细介绍。

相关网站:
1. MongoDB下载:www.mongodb.org/downloads
2. 各种平台的安装帮助: http://www.mongodb.org/display/DOCS/BUILDING
3. 他们在使用MongoDB: http://www.mongodb.org/display/DOCS/Production+Deployments
4. 开发驱动:http://www.mongodb.org/display/DOCS/Drivers

本日志由 Admin 于 2011-01-11 14:15:42 发表到 数据库 中,目前已经被浏览 1709 次,评论 40 次;

作者添加了以下标签: FreeBSDMongoDB

301/6