FastDFS是一个开源的分布式文件系统,她对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等。nginx
FastDFS有两个角色:跟踪服务(tracker)和存储服务(storage),跟踪服务控制,调度文件以负载均衡的方式访问;存储服务包括:文件存储,文件同步,提供文件访问接口,同时以key value的方式管理文件的元数据。c++
相关软件centos
后面遇到了坑,fastdfs须要使用5.10 也便是最新版本的,否则fastdfs-nginx-module-master编译不成功bash
首先须要安装编译环境,命令以下(centos环境)服务器
yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget
yum install -y libevent架构
将相关软件上传到/opt/softs目录下负载均衡
libfastcommon 中封装了一些fastdfs的公共函数等,因此在安装fastdfs前须要先安装 libfastcommon 包。tcp
[root@localhost ~]# cd /opt/softs/ [root@localhost softs]# ls fastdfs-5.05.tar.gz fastdfs-nginx-module-master libfastcommon-1.0.7.tar.gz [root@localhost softs]# tar -zxvf libfastcommon-1.0.7.tar.gz
[root@localhost softs]# cd libfastcommon-1.0.7 [root@localhost libfastcommon-1.0.7]# chmod 777 make.sh [root@localhost libfastcommon-1.0.7]# ./make.sh [root@localhost libfastcommon-1.0.7]# ./make.sh install
若是报错分布式
./make.sh:行99: perl: 未找到命令
./make.sh:行100: perl: 未找到命令
那执行:函数
yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget
手动设置libfastcommon的软链接
[root@localhost libfastcommon-1.0.7]# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so [root@localhost libfastcommon-1.0.7]# ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
[root@localhost softs]# tar -zxvf fastdfs-5.10.tar.gz [root@localhost fastdfs-5.05]# chmod 777 make.sh [root@localhost fastdfs-5.05]# ./make.sh [root@localhost fastdfs-5.05]# ./make.sh install [root@localhost fastdfs-5.05]# ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so [root@localhost fastdfs-5.05]# ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
[root@localhost ~]# cd /etc/fdfs/ [root@localhost fdfs]# ls client.conf.sample storage.conf.sample tracker.conf.sample [root@localhost fdfs]# cp tracker.conf.sample tracker.conf [root@localhost fdfs]# vi tracker.conf
disabled=false #启用配置文件
port=22122 #设置tracker的端口号,通常采用22122这个默认端口
base_path=/opt/softs/fastdfs-5.10/logs/tracker
bind_addr=192.168.22.135
[root@localhost fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
查看运行状态 netstat -unltp|grep fdfs
[root@localhost fdfs]# netstat -unltp|grep fdfs tcp 0 0 192.168.22.135:22122 0.0.0.0:* LISTEN 10451/fdfs_trackerd [root@localhost fdfs]#
此时已经完成了tracker的部署工做。
chkconfig fdfs_trackerd on
解压安装
[root@localhost softs]# tar -zxvf nginx-1.11.13.tar.gz [root@localhost nginx-1.11.13]# pwd /opt/softs/nginx-1.11.13 [root@localhost nginx-1.11.13]# ./configure [root@localhost nginx-1.11.13]# make [root@localhost nginx-1.11.13]# make install
启动nginx
[root@localhost nginx-1.11.13]# /usr/local/nginx/sbin/nginx [root@localhost nginx-1.11.13]# ps aux|grep nginx root 16357 0.0 0.0 20480 604 ? Ss 17:19 0:00 nginx: master process /usr/local/nginx/sbin/nginx nobody 16358 0.0 0.1 20924 1068 ? S 17:19 0:00 nginx: worker process root 16360 0.0 0.0 112664 976 pts/0 R+ 17:19 0:00 grep --color=auto nginx [root@localhost nginx-1.11.13]#
关闭nginx
[root@localhost nginx-1.11.13]# ps aux|grep nginx -s stop
编辑/usr/local/nginx/conf配置文件目录下的nginx.conf
[root@localhost nginx-1.11.13]# cd /usr/local/nginx/conf/ [root@localhost conf]# vi nginx.conf
#设置group1的服务器 upstream fdfs_group1 { server 192.168.22.139:8888 weight=1 max_fails=2 fail_timeout=30s; server 192.168.7.140:8888 weight=1 max_fails=2 fail_timeout=30s; } # 在自带的server里添加 server{ location /group1/M00 { proxy_pass http://fdfs_group1; } }