Centos6.4 安装Nginx以及与FastDFS的结合【引】

一、在每台Storage上安装Nginx

1,环境:

Nginx版本:nginx-1.10.1

pcre版本:8.31  用于支持rewrite模块

zlib版本:1.2.8  用于支持gzip模块

FastDFS版本:v5.06

FastDFS的Nginx插件使用最新版本:fastdfs-nginx-module-master,位置https://github.com/happyfish100/fastdfs-nginx-module

2,安装各个软件(此前FastDFS已经安装完成,参见以前博客)

下载好以上软件,假设文件位置在root目录下

解压:

tar zxf  nginx-1.10.1.tar.gz

tar zxf  prec-8.31.tar.gz

tar zxf  zlib-1.2.8.tar.gz

tar zxf  fastdfs-nginx-module-master.tar.gz

3,建立Nginx用户

groupadd nginx

useradd nginx -g nginx -s /bin/false

4,修改fastdfs-nginx-module-master的配置文件

cd fastdfs-nginx-module-master/src

vi config

修改以下内容:

CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"    指定需要的FastDFS文件路径

这里需要根据自己安装FastDFS时指定的安装路径,可以回到FastDFS/make.sh中查看。我的安装路径是/usr/fdfs,所以修改为:

CORE_INCS="$CORE_INCS /usr/fdfs/include/fastdfs /usr/local/include/fastcommon/"

5,安装Nginx

进入Nginx目录,cd /root/nginx-1.10.1

./configure --prefix=/root/lnginx --add-module=/root/fastdfs-nginx-module-master/src --with-pcre=/root/pcre-8.31/ --with-zlib=/root/zlib-1.2.8

除了指定Nginx的安装目录外,还需要包含fastdfs-nginx-module、pcre、zlib的路径

得到类似如下:

Configuration summary
  + using PCRE library: /root/pcre-8.31/
  + OpenSSL library is not used
  + using builtin md5 code
  + sha1 library is not found
  + using zlib library: /root/zlib-1.2.8


  nginx path prefix: "/root/nginx"
  nginx binary file: "/root/nginx/sbin/nginx"
  nginx modules path: "/root/nginx/modules"
  nginx configuration prefix: "/root/nginx/conf"
  nginx configuration file: "/root/nginx/conf/nginx.conf"
  nginx pid file: "/root/nginx/logs/nginx.pid"
  nginx error log file: "/root/nginx/logs/error.log"
  nginx http access log file: "/root/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

执行make

如果出现/usr/bin/ld: cannot find -lfdfsclient错误,说明找不到libfdfsclient.so

找到FasfDFS/make.sh中指定的安装位置,从其子目录fastdfs/lib64中复制libfdfsclient.so到/usr/local/lib64下

我的libfdfsclient.so在/usr/local/fastdfs/lib64下,执行cp /usr/local/fastdfs/lib64/libfdfsclient.so /usr/local/lib64/libfdfsclient.so

重新执行make

执行make  install

6,复制

cp /root/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/

cp /root/FastDFS/conf/http.conf  /etc/fdfs

cp /root/FastDFS/conf/mime.types /etc/fdfs

7,配置nginx.conf

cd /root/nginx/conf

vi nginx.conf

修改如下:FastDFS中client.conf中的端口应与Nginx的端口号一致

server {
        listen       80;
        server_name  localhost;


        charset utf-8;


        location /M00 {
                root /data/fdfs/data;
                ngx_fastdfs_module;
        }

   8,配置mod_fastdfs.conf

根据实际情况需要修改的内容有:

base_path

tracker_server

group_name

store_path_count

store_path0(1,2..)

group_count

[group1]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/home/fdfs/storage

[group2]
group_name=group3
storage_server_port=23001
store_path_count=1
store_path0=/home/fdfs/storage1

等等。。。视具体情况而定。

   9,启动Nginx

cd /root/lnginx/sbin

./nginx

如果出现./nginx: error while loading shared libraries: libfdfsclient.so: cannot open shared object file: No such file or directory错误,

执行:

cat /etc/ld.so.conf   得到:include ld.so.conf.d/*.conf

echo "/usr/local/lib64" >> /etc/ld.so.conf

ldconfig

重新启动Nginx.

 

10,查看端口进程

netstat -tupnl |grep nginx

tcp       19      0 0.0.0.0:80              0.0.0.0:*               LISTEN      5885/nginx: master 

11,查看日志

cat /root/lnginx/logs/error.log

12,测试Nginx

在浏览器中输入Ip:80

如果出现403Forbidden,原因可能有以下:

1,进入nginx.cong ,在起始行加:user  root;

2,查看location/{

root  /root/html;

index  index.html index.html;

}

在root下查看是否存在index.html,我的目录是在/root/lnginx/html

3,设置root所在目录的读写权限

chmod -R 777 /root

 

 引自:http://blog.csdn.net/edisonyuan/article/details/52250186
 
posted @ 2017-03-26 22:49  mslog  阅读(1280)  评论(0编辑  收藏  举报