文件服务器搭建(ubuntu16.0.04+fastdfs+nginx)

文件服务器搭建(ubuntu16.0.04+fastdfs+nginx)

1、环境

ubuntu 16.0.4(visualbox虚拟的ubuntu服务器)
fastdfs 5.11
nginx 1.12 实现文件服务器上文件的访问

2、资源准备

3、搭建

  • 编译安装 libfastcommon
> ./make.sh   #编译  
> ./make.sh install   # 安装   
> ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so   #创建符号链接
  • 编译安装 fastdfs
> ./make.sh  #编译 
> ./make.sh install #安装 
  • 配置tracker.conf
> cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
> vi /etc/fdfs/tracker.conf

 修改内容:
> base_path=/home/fastdfs
  • 配置storage.conf
> cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
> vi /etc/fdfs/storage.conf

修改内容:
> base_path=/home/fastdfs  
> tracker_server=10.0.2.15:22122
> store_path0=/home/fastdfs  
  • 配置 http.conf mime.types
> cp fastdfs-5.11/conf/http.conf /etc/fdfs/  
> cp fastdfs-5.11/conf/mime.types /etc/fdfs/
  • 配置client.conf
> cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf   
> vi /etc/fdfs/client.conf
修改内容
> base_path=/home/fastdfs
>  tracker_server=10.0.2.15:22122
>  include http.conf   #打开该行代码  默认是注释掉的
  • 启动tracker
> /etc/init.d/fdfs_trackerd start

其他命令
/etc/init.d/fdfs_trackerd stop #停止
/etc/init.d/fdfs_trackerd restart #重启
  • 启动storage
> /etc/init.d/fdfs_storaged start  

其他命令
/etc/init.d/fdfs_storaged stop #停止
/etc/init.d/fdfs_storaged restart #重启
  • 查看启动情况
> ps -aux|grep fdfs

显示内容如下 代表启动成功;如果失败,进入目录/home/fastdfs 查看错误日志信息

root      1543  0.0  0.2 145628  2260 ?        Sl   08:50   0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root      1596  0.0  6.4  82272 65800 ?        Sl   08:50   0:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
root      1699  0.0  0.0  14224   968 pts/0    S+   11:01   0:00 grep --color=auto fdfs

  • 测试fastdfs安装情况
>  fdfs_test /etc/fdfs/client.conf upload /home/test.png  
This is FastDFS client test program v5.11


Copyright (C) 2008, Happy Fish / YuQing


FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/ 
for more detail.


[2018-06-08 11:06:33] DEBUG - base_path=/home/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0


tracker_query_storage_store_list_without_group: 
    server 1. group_name=, ip_addr=10.0.2.15, port=23000


group_name=group1, ip_addr=10.0.2.15, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/CgACD1sZ8rmAU861AAAQAPSxqbc399.jpg
source ip address: 10.0.2.15
file timestamp=2018-06-08 11:06:33
file size=4096
file crc32=4105284023
example file url: http://10.0.2.15/group1/M00/00/00/CgACD1sZ8rmAU861AAAQAPSxqbc399.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/CgACD1sZ8rmAU861AAAQAPSxqbc399_big.jpg
source ip address: 10.0.2.15
file timestamp=2018-06-08 11:06:33
file size=4096
file crc32=4105284023
example file url: http://10.0.2.15/group1/M00/00/00/CgACD1sZ8rmAU861AAAQAPSxqbc399_big.jpg

  • 安装nginx
> apt-get install libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev 
> tar -zxvf /home/ubuntu/source/nginx-1.12.2.tar.gz
> cd /home/ubuntu/source/nginx
> ./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module/src/  # --prefix:安装目录;--add-module:fastdfs-nginx-module文件路径
> make  #编译 
> make install #安装 
> vi /usr/local/nginx/conf/nginx.conf #添加文件服务站点配置


添加内容如下
location /M00 {
    root /home/fastdfs/data;
    ngx_fastdfs_module;
}
  • 启动和检查
> /usr/local/nginx/sbin/nginx

其他命令
>/usr/local/nginx/sbin/nginx -s stop #停止
>/usr/local/nginx/sbin/nginx -s reload #重新加载配置文件

检查nginx启动情况

> ps -aux|grep nginx

正常情况下信息,如果启动失败,进入/usr/local/nginx/logs/ 目录查看错误信息

root      1607  0.0  0.0  32480   456 ?        Ss   08:50   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    1608  0.0  0.3  33060  3372 ?        S    08:50   0:00 nginx: worker process
root      1756  0.0  0.1  14224  1088 pts/0    S+   11:28   0:00 grep --color=auto nginx

访问刚测试上传的图片

http://10.0.2.15/M00/00/00/CgACD1sZ8rmAU861AAAQAPSxqbc399_big.jpg

4、归纳总结

整个安装过程比较简单,注意好安装的每一个细节.至此安装结束.
我安装是在本机的虚拟机安装。采用的链接模式:网络地址转换(NAT);
这种情况下需要添加端口转发,配置如下:

主机IP主机端口子系统IP子系统端口
本地IP2212210.0.2.1522122
本地IP2300010.0.2.1523000
本地IP800510.0.2.1580
22122:tracker服务端口
23000:文件上传服务storage端口
80:nginx 文件站点服务端口
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值