goodmm 发表于 2015-7-29 07:18:55

FastDFS和apache/nginx整合

  因为FastDFS默认自带的http服务器性能不好, 所以一般建议用外置的apache或者nginx 来解决http下载,以应付大并发的情况 注意nginx扩展模块只支持GET和HEAD模式获取文件,需要开发那边配合修改程序
获取nginx和FastDFS的nginx扩展插件
wget http://fastdfs-nginx-module.googlecode.com/files/fastdfs-nginx-module_v1.13.tar.gz
  wget http://nginx.org/download/nginx-1.2.6.tar.gz
解压并编译安装
  备注:如果之前机器上安装了nginx,可以单独安装fastdfs-nginx-module模块,具体方法请参考:如何单独添加NGINX自定义模块
  apt-get install libssl-dev zlib1g-dev libpcre3-dev
  tar zvxf nginx-1.2.6.tar.gz
  tar zvxf fastdfs-nginx-module_v1.13.tar.gz
  cd nginx-1.2.6
  ./configure --prefix=/usr/local/nginx --with-http_gzip_static_module --add-module=/www/soft/fastdfs-nginx-module/src/
make
  make install
  
修改相关配置文件
  1.修改FastDFS的storage.conf
  http.disabled=true
  #关闭内置web server 其它保持不变,保存退出
  2.修改nginx扩展模块的配置文件
  cd ../fastdfs-nginx-module/src
  cp mod_fastdfs.conf /etc/fdfs/
  vi /etc/fdfs/mod_fastdfs.conf
  base_path=/www/logs
  #存放log的路径
  tracker_server=127.0.0.1:22122
  #指定tracker服务器及端口
  url_have_group_name = true
  #这个很重要,在URL中包含group名称
  store_path0=/www/geebook_storage
  #存储文件的路径
  storage_server_port=23000
  #与storage的配置端口保持一致
  保存后退出
  3.做M00的链接
  ln -s /www/geebook_storage/data/www/geebook_storage/data/M00
  4.修改nginx的配置文件
  备注:如果nginx有其他服务器在用,在nginx.conf原有的基础上追加一个下面server的配置即可
  vi /usr/local/nginx/conf/nginx.conf
  server {
  listen 8888;
  location / {
  root /www/geebook_storage/data;
  index index.html index.htm;
  }
  location /group1/M00 {
  root /www/geebook_storage/data;
  ngx_fastdfs_module;
  }
  }
  5.重启相关服务,验证整合是否成功
  先重启storage服务:
  /etc/init.d/fdfs_storaged start
  然后再启动nginx,
  注意顺序,否则会报端口占用的错误
  /usr/local/nginx/sbin/nginx
  查看端口使用情况:
netstat -lnp --tcp
tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 1761/fdfs_storaged
  tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 1718/nginx
  tcp 0 0 0.0.0.0:8090 0.0.0.0:* LISTEN 1809/fdfs_trackerd
  tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 1809/fdfs_trackerd
  默认的8888端口本来是storage的,现在被nginx替代 完成了FastDFS和nginx的整合 用上面的fdfs_test程序测试上传和下载,能正常访问下载,说明nginx已经顺利替代 FastDFS的内置Web server。
  
页: [1]
查看完整版本: FastDFS和apache/nginx整合