FastDFS及Nginx的部署

来源:互联网 发布:图片归类整理软件 编辑:程序博客网 时间:2024/06/15 23:27
确保系统已经安装gcc和Perl  安装命令如下
  安装gcc环境
  [root@localhost ~]# yum install gcc-c++
    
  安装pcre库。
  [root@localhost ~]# yum install -y pcre pcre-devel

  安装FastDFS之前,先安装libevent工具包。
  [root@localhost ~]# yum -y install libevent

将软件放到一个目录中(这里用"/usr/soft")
将FastDFS相关压缩包上传到liunx
  libfastcommon-master.tar.gz            下载地址:https://github.com/happyfish100/libfastcommon
  fastdfs-nginx-module_v1.16.tar.gz        下载地址:http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
  FastDFS_v5.08.tar.gz                    下载地址:https://github.com/happyfish100/fastdfs
 
linux直接下载源码命令(libfastcommon从Windows下载)https://github.com/happyfish100/libfastcommon
  wget https://github.com/happyfish100/fastdfs/archive/V5.08.tar.gz
  wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
  wget http://nginx.org/download/nginx-1.10.1.tar.gz

解压    libfastcommon
  [root@localhost soft]# tar -zxvf libfastcommon-master.tar.gz
  [root@localhost soft]# cd libfastcommon

编译/安装
  [root@localhost libfastcommon]# ./make.sh
  [root@localhost libfastcommon]# ./make.sh install
 
将/usr/lib64/libfastcommon.so文件向/usr/lib/下复制一份
  [root@localhost libfastcommon]# cp /usr/lib64/libfastcommon.so /usr/lib
 
解压    FastDFS_v5.08
  [root@localhost soft]# tar -zxvf FastDFS_v5.08.tar.gz
  [root@localhost soft]# cd FastDFS
 
编译/安装
  [root@localhost FastDFS]# ./make.sh
  [root@localhost FastDFS]# ./make.sh install
  安装后在/usr/bin/目录下有以fdfs开头的文件都是编译出来的
  [root@images-001 bin]# ll /usr/bin/fdfs_*
  -rwxr-xr-x. 1 root root 260472 Aug  4 03:08 /usr/bin/fdfs_appender_test
  -rwxr-xr-x. 1 root root 260169 Aug  4 03:08 /usr/bin/fdfs_appender_test1
  -rwxr-xr-x. 1 root root 250513 Aug  4 03:08 /usr/bin/fdfs_append_file
  -rwxr-xr-x. 1 root root 249941 Aug  4 03:08 /usr/bin/fdfs_crc32
  -rwxr-xr-x. 1 root root 250596 Aug  4 03:08 /usr/bin/fdfs_delete_file
  -rwxr-xr-x. 1 root root 251403 Aug  4 03:08 /usr/bin/fdfs_download_file
  -rwxr-xr-x. 1 root root 251161 Aug  4 03:08 /usr/bin/fdfs_file_info
  -rwxr-xr-x. 1 root root 266297 Aug  4 03:08 /usr/bin/fdfs_monitor
  -rwxr-xr-x. 1 root root 873313 Aug  4 03:08 /usr/bin/fdfs_storaged
  -rwxr-xr-x. 1 root root 266840 Aug  4 03:08 /usr/bin/fdfs_test
  -rwxr-xr-x. 1 root root 266041 Aug  4 03:08 /usr/bin/fdfs_test1
  -rwxr-xr-x. 1 root root 371432 Aug  4 03:08 /usr/bin/fdfs_trackerd
  -rwxr-xr-x. 1 root root 251539 Aug  4 03:08 /usr/bin/fdfs_upload_appender
  -rwxr-xr-x. 1 root root 252669 Aug  4 03:08 /usr/bin/fdfs_upload_file
 
配置文件都放到/etc/fdfs文件夹
把FastDFS/conf目录下的所有的配置文件都复制到/etc/fdfs下
  [root@localhost FastDFS]# cp /usr/soft/FastDFS_v5.08/conf/* /etc/fdfs
  [root@localhost FastDFS]# ll /etc/fdfs
  total 108
  -rw-r--r--. 1 root root 23981 Aug  4 03:13 anti-steal.jpg
  -rw-r--r--. 1 root root  1462 Aug  3 19:54 client.conf
  -rw-r--r--. 1 root root  1461 Aug  4 03:08 client.conf.sample
  -rw-r--r--. 1 root root   858 Aug  4 03:13 http.conf
  -rw-r--r--. 1 root root 31172 Aug  4 03:13 mime.types
  -rw-r--r--. 1 root root  3686 Aug  3 20:28 mod_fastdfs.conf
  -rw-r--r--. 1 root root  7928 Aug  3 19:48 storage.conf
  -rw-r--r--. 1 root root  7927 Aug  4 03:08 storage.conf.sample
  -rw-r--r--. 1 root root   105 Aug  4 03:13 storage_ids.conf
  -rw-r--r--. 1 root root  7273 Aug  4 07:35 tracker.conf
  -rw-r--r--. 1 root root  7200 Aug  4 03:08 tracker.conf.sample

修改所有配置之前在/home下创建repository
再在repository下面创建fastdfs存放图片, 下面配置要用
 
修改tracker.conf文件
  [root@localhost FastDFS]# cd /etc/fdfs
  [root@localhost fdfs]# vim tracker.conf
 
  修改以下几项
  ┌─────────────────────────────────────────────────────────────────────────────────┐
  │# bind an address of this host                                                    │
  │# empty for bind all addresses of this host                                        │
  │bind_addr=192.168.58.150                                                            │
  │                                                                                    │
  │# the base path to store data and log files                                        │
  │base_path=/home/repository/fastdfs    (图片上传目录, 可以自定义)                    │
  │                                                                                    │
  │tracker_server=192.168.58.150:22122            【自己的IP】                        │
  └─────────────────────────────────────────────────────────────────────────────────┘
 
修改storage.conf文件
  [root@localhost FastDFS]# cd /etc/fdfs
  [root@localhost fdfs]# vim storage.conf
 
  修改以下几项
  ┌─────────────────────────────────────────────────────────────────────────────────┐
  │group_name=group1    (文件存放的分组名, 可自定义)                                │
  │                                                                                    │
  │# empty for bind all addresses of this host                                        │
  │bind_addr=192.168.58.150                                                            │
  │                                                                                    │
  │# the base path to store data and log files                                        │
  │base_path=/home/repository/fastdfs    (图片上传目录, 可以自定义)                    │
  │                                                                                    │
  │# store_path#, based 0, if store_path0 not exists, it's value is base_path        │
  │# the paths must be exist                                                        │
  │store_path0=/home/repository/fastdfs                                                │
  │                                                                                    │
  │tracker_server=192.168.58.150:22122                【自己的IP】                    │
  └─────────────────────────────────────────────────────────────────────────────────┘
 
启动tracker。
  [root@localhost fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
 
启动storage。
  [root@localhost fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
 

 
测试服务 修改配置文件client.conf
  [root@localhost fdfs]# vim client.conf
  ┌─────────────────────────────────────────────────────────────────────────────────┐
  │# the base path to store log files                                                │
  │base_path=/home/repository/client                                                │
  │                                                                                    │
  │# tracker_server can ocur more than once, and tracker_server format is            │
  │#  "host:port", host can be hostname or ip address                                │
  │tracker_server=192.168.58.150:22122            【自己的IP】                        │
  └─────────────────────────────────────────────────────────────────────────────────┘

测试上传
  [root@localhost fdfs]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/anti-steal.jpg
  最后一句出现返回地址证明上传成功
  example file url:http://192.168.58.150/group1/M00/00/00/wKg6llmWudGAc3fYAABdrZgsqUU812_big.jpg
 
查看文件
  [root@localhost fdfs]# ll /home/repository/fastdfs/data/00/00
  看见jpg结尾的证明服务器测试成功

 
 
搭建nginx提供http服务。
可以使用官方提供的nginx插件

解压    fastdfs-nginx-module_v1.16.tar.gz
  [root@localhost fdfs]# cd /usr/soft
  [root@localhost soft]# tar -zxvf libfastcommon-master.tar.gz

将config文件其中的local去掉  这里用【】标注
  [root@localhost soft]# cd fastdfs-nginx-module/src
  [root@localhost src]# vim config
  ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ngx_addon_name=ngx_http_fastdfs_module                                                                                                    │
  │HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"                                                                                        │
  │NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"                                                                │
  │CORE_INCS="$CORE_INCS /usr/【local】/include/fastdfs /usr/【local】/include/fastcommon/"                                                                        │
  │CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient"                                                                                │
  │CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"    │
  └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

安装nginx对nginx进行configure带上以下参数
  [root@localhost nginx]# ./configure \
  --prefix=/usr/local/nginx \                            【nginx安装位置】
  --add-module=/usr/soft/fastdfs-nginx-module/src        【往nginx中添加FastDFS模块】

编译/安装
  [root@localhost nginx]# make && make install

 
将/usr/soft/fastdfs-nginx-module/src/mod_fastdfs.conf文件复制到/etc/fdfs目录下
  [root@localhost nginx]# cp /usr/soft/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
 
编辑mod_fastdfs.conf文件
  [root@localhost nginx]# cd /etc/fdfs
  [root@localhost fdfs]# vim mod_fastdfs.conf
  ┌─────────────────────────────────────────────────────────────────────────────────┐
  │# the base path to store log files                                                │
  │base_path=/tmp        【日志存放路径】                                            │
  │                                                                                    │
  │# FastDFS tracker_server can ocur more than once, and tracker_server format is    │
  │#  "host:port", host can be hostname or ip address                                │
  │# valid only when load_fdfs_parameters_from_tracker is true                        │
  │tracker_server=192.168.58.150:22122                                                │
  │                                                                                    │
  │# the group name of the local storage server                                        │
  │group_name=group1    【文件存放分组名, 可自定义】                                │
  │                                                                                    │
  │# if the url / uri including the group name                                        │
  │# set to false when uri like /M00/00/00/xxx                                        │
  │# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx    │
  │# default value is false                                                            │
  │url_have_group_name = true                                                        │
  │                                                                                  │
  │# store_path#, based 0, if store_path0 not exists, it's value is base_path        │
  │# the paths must be exist                                                        │
  │# must same as storage.conf                                                        │
  │store_path0=/home/repository/fastdfs                                                │
  └─────────────────────────────────────────────────────────────────────────────────┘
 
 
nginx配置
  [root@localhost fdfs]# cd /usr/local/nginx/conf
  [root@localhost conf]# vim nginx.conf
  ┌─────────────────────────────────────────────────────────────────────────────────┐
  │server {                                                                            │
  │     listen       80;                                                            │
  │     server_name  192.168.58.150;                                                │
  │                                                                                    │
  │     #charset koi8-r;                                                            │
  │                                                                                    │
  │     #access_log  logs/host.access.log  main;                                    │
  │                                                                                    │
  │     location /group1/M00/ {                        【正则匹配】                    │
  │         root /home/repository/fastdfs/data;                                        │
  │         ngx_fastdfs_module;                                                        │
  │     }                                                                            │
  │}                                                                                │
  └─────────────────────────────────────────────────────────────────────────────────┘
原创粉丝点击