CentOS安装FastDFS+Nginx

来源:互联网 发布:网络黑名单 编辑:程序博客网 时间:2024/06/06 13:34
1,安装libfastcommon
安装FastDFS,版本5以上,依赖libfastcommon 
1-1 下载libfastcommon-master.zip
1-2 unzip libfastcommon-master.zip -d /usr/local
    cd /usr/local/libfastcommon-master
    ./make.sh
    ./make.sh install
    libfastcommon.so默认安装到了/usr/lib64/libfastcommon.so,而FastDFS主程序设置的lib目录是/usr/local/lib,所以设置软连接
    ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
2,安装FastDFS
tar -zxvf FastDFS_v5.04.tar.gz -C /usr/local
cd /usr/local/FastDFS
./make.sh
./make.sh install

3,建立文件夹供使用
   根目录下
   -data  
     -fdfs  
        -tracker  
        -storage  
        -client
4,修改配置文件  
cd /etc/fdfs

mv tracker.conf.sample tracker.conf  
    vi tracker.conf  
    base_path=/data/fdfs/tracker 
    
    mv storage.conf.sample storage.conf  
    vi storage.conf  
//...  
base_path=/data/fdfs/storage #指定日志位置  
store_path0=/data/fdfs/storage #指定数据位置  
tracker_server=192.168.146.131:22122  #指定tracker服务器地址 

mv client.conf.sample client.conf  
vi client.conf  
//...  
base_path=/data/fdfs/client  
tracker_server=192.168.146.131:22122   
5,启动
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf   
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf   
通过日志查看是否启动成功
tail -f /data/fdfs/storage/logs/storaged.log   
  tail -f /data/fdfs/tracker/logs/trackerd.log   


6,测试
#上传  
/usr/bin/fdfs_test /etc/fdfs/client.conf  upload 1.txt  
 
#下载  
/usr/bin/fdfs_download_file  /etc/fdfs/client.conf group1/M00/00/00/wKiZglauvkmANC2wAAAAPpWmuhI171.txt  
 
#删除  
/usr/bin/fdfs_delete_file  /etc/fdfs/client.conf group1/M00/00/00/wKiZglauvkmANC2wAAAAPpWmuhI171.txt  

7,安装nginx
  find -name nginx  
  yum remove nginx  
  
  安装依赖 yum -y install gcc gcc-c++ autoconf automake
           yum -y install pcre-devel openssl openssl-devel
           yum install zlib zlib-devel
           
  增加组:groupadd -r nginx
         useradd -s /sbin/nologin -g nginx -r nginx 
         
  下载fastdfs-nginx-module-master.zip  (https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip)
  下载nginx,http://nginx.org/download/nginx-1.9.5.tar.gz
  unzip fastdfs-nginx-module-master.zip
  tar -zxvf nginx-1.9.5.tar.gz -C /usr/local
  cd /usr/local/nginx-1.9.5


  ./configure --prefix=/usr/local/nginx --add-module=/app/fastdfs-nginx-module-master/src/  --with-pcre --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module 
 --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module
   make
   make install
8,配置mod_fastdfs.conf
  cp /app/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/    将解压后的插件中src中的配置文件,复制到/etc/fdfs路径
  mkdir /data/ngx  设置日志路径 the base path to store log files
  修改参数,vim /etc/fdfs/mod_fastdfs.conf
  # the base path to store log files
base_path=/data/ngx
# FastDFS tracker_server 
tracker_server=192.168.146.131:22122
# 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=/data/fdfs/storage
# if the url / uri including the group name
url_have_group_name = true
9,添加http.conf,mime.types到/etc/fdfs
  cd /usr/local/FastDFS/conf
  cp http.conf mime.types  /etc/fdfs
10,修改nginx配置文件
  vim /usr/local/nginx/conf/nginx.conf
  增加:
  location /group1/M00 {
            #root指向数据根目录,即storage的store_path
            root /data/fdfs/storage/data;
            ngx_fastdfs_module;
  }
11,启动nginx
   /usr/local/nginx/sbin/nginx
   验证:curl http://localhost
   查看错误信息:tail -f /usr/local/nginx/logs/error.log
12,验证访问FDFS
   重启 /usr/local/nginx/sbin/nginx -s reload
   测试 wget http://192.168.146.131/group1/M00/00/00/wKiSg1fiIhaAb5CgAAAAyGsBrBI989_big.log  下载成功
1 0
原创粉丝点击