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; } }