FastDFS测试

上传测试

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf 100sh.jpg
1
上传成功后返回

group1/M00/00/00/rBBNW1sJCvCAHgH7AAVGh5jPYok707.jpg
1
返回的文件ID由group、存储目录、两级子目录、fileid、文件后缀名(由客户端指定,主要用于区分文件类型)拼接而成。

7、安装Nginx

安装Nginx作为服务器以支持Http方式访问文件

7.1、安装nginx所需环境

gcc 安装

yum install gcc-c++ -y
1
PCRE pcre-devel 安装

yum install -y pcre pcre-devel
1
zlib 安装

yum install -y zlib zlib-devel
1
OpenSSL 安装

yum install -y openssl openssl-devel
1
7.2、安装Nginx

下载nginx

wget https://nginx.org/download/nginx-1.9.8.tar.gz
1
解压

tar -zxvf nginx-1.9.8.tar.gz
cd nginx-1.9.8
1
2
使用默认配置

./configure
1
编译、安装

make
make install
1
2
防火墙中打开Nginx端口(默认的 80)

vim /etc/sysconfig/iptables

添加如下端口行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重启防火墙:
service iptables restart

7.3、访问文件

修改nginx.conf

vim /usr/local/nginx/conf/nginx.conf

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location /group1/M00 {
        alias /mnt/fastdfs/storage/data;
    }
}

添加nginx到启动文件

#!/bin/bash  
# nginx Startup script for the Nginx HTTP Server  
#  
# chkconfig: - 85 15  
# description: Nginx is a high-performance web and proxy server.  
# It has a lot of features, but it's not for everyone.  
# processname: nginx  
# pidfile: /var/run/nginx.pid  
# config: /usr/local/nginx/conf/nginx.conf  
nginxd=/usr/local/nginx/sbin/nginx  
nginx_config=/usr/local/nginx/conf/nginx.conf  
nginx_pid=/usr/local/nginx/nginx.pid  
 
RETVAL=0  
prog="nginx" 
 
# Source function library.  
. /etc/rc.d/init.d/functions  
 
# Source networking configuration.  
. /etc/sysconfig/network  
 
# Check that networking is up.  
[ ${NETWORKING} = "no" ] && exit 0  
 
[ -x $nginxd ] || exit 0  
 
 
# Start nginx daemons functions.  
start() {  
 
if [ -e $nginx_pid ];then 
   echo "nginx already running...." 
   exit 1  
fi  
 
   echo -n $"Starting $prog: " 
   daemon $nginxd -c ${nginx_config}  
   RETVAL=$?  
   echo  
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx  
   return $RETVAL  
 
}  
 
 
# Stop nginx daemons functions.  
stop() {  
        echo -n $"Stopping $prog: " 
        killproc $nginxd  
        RETVAL=$?  
        echo  
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid  
}  
 
 
# reload nginx service functions.  
reload() {  
 
    echo -n $"Reloading $prog: " 
 $nginxd -s reload  
    #if your nginx version is below 0.8, please use this command: "kill -HUP `cat ${nginx_pid}`" 
    RETVAL=$?  
    echo  
 
}  
 
# See how we were called.  
case "$1" in 
start)  
        start  
        ;;  
 
stop)  
        stop  
        ;;  
 
reload)  
        reload  
        ;;  
 
restart)  
        stop  
        start  
        ;;  
 
status)  
        status $prog  
        RETVAL=$?  
        ;;  
*)  
        echo $"Usage: $prog {start|stop|restart|reload|status|help}" 
        exit 1  
esac  
 
exit $RETVAL 

启动nginx

service nginx start
1
设置开机启动

chkconfig nginx on
1
访问:http://47.98.248.154/group1/M00/00/00/rBBNW1sJCvCAHgH7AAVGh5jPYok707.jpg 获取图片

8、FastDFS 配置 Nginx 模块

8.1、安装配置Nginx模块

下载 fastdfs-nginx-module、解压

wget https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
1
解压

unzip 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1 fastdfs-nginx-module
1
2
配置Nginx增加fastdfs-nginx-module模块

# 先停掉nginx服务
# /usr/local/nginx/sbin/ngix -s stop

进入解压包目录
# cd /softpackages/nginx-1.9.8/

# 添加模块
# ./configure --add-module=/opt/fastdfs-nginx-module/src

重新编译、安装
# make && make install

查看Nginx的模块

/usr/local/nginx/sbin/nginx -V
1
复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录

cd /opt/fastdfs-nginx-module/src
cp mod_fastdfs.conf /etc/fdfs/
1
2
修改配置文件

# 连接超时时间
connect_timeout=10

# Tracker Server
tracker_server=172.16.77.91:22122

# StorageServer 默认端口
storage_server_port=23000

# 如果文件ID的uri中包含/group**,则要设置为true
url_have_group_name = true

# Storage 配置的store_path0路径,必须和storage.conf中的一致
store_path0=/mnt/fastdfs/storage

复制 FastDFS 的部分配置文件到/etc/fdfs 目录

cd /opt/fastdfs-5.11/conf
cp anti-steal.jpg http.conf mime.types /etc/fdfs/
1
2
修改nginx.conf

vim /usr/local/nginx/conf/nginx.conf
location ~/group([0-9])/M00 {
    ngx_fastdfs_module;
}

启动nginx

service nginx start
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值