FastDFS是一款開源的輕量級分佈式文件系統,純C實現,支持Linux、FreeBSD等Unix系統。
類google FS,不是通用的文件系統,只能通過專有API訪問。
FastDFS服務端有兩種角色:跟蹤器(tracker)和存儲節點(storage)。
tracker主要做調度工作,在訪問上起負載均衡的作用,在內存中記錄集羣中group和storage的狀態信息,是連接client和storage的樞紐。
storage存儲服務器,文件和文件屬性都保存到存儲服務器上。
FastDFS是C語言開發,建議在linux上運行,本教程使用Centos6.4作爲安裝環境。
安裝FastDFS需要先將官網下載的源碼進行編譯,編譯依賴gcc環境,
如果沒有gcc環境,需要安裝gcc:
yum install -y gcc gcc-c++
如果沒有make命令
yum -y install gcc automake autoconf libtool make
安裝libevent
FastDFS依賴libevent庫,需要安裝:
yum -y install libevent
安裝libfastcommon包
最新下載地址
https://github.com/happyfish100/libfastcommon/releases
tar -zxvf libfastcommon-1.0.38.tar.gz -C /usr/local/
cd /usr/local/libfastcommon-1.0.38/
./make.sh #編譯
./make.sh install #安裝
libfastcommon安裝好後會在/usr/lib64 目錄下生成 libfastcommon.so 庫文件;
注意:由於FastDFS程序引用usr/lib目錄所以需要將/usr/lib64下的庫文件拷貝至/usr/lib下。cp libfastcommon.so /usr/lib
不過最新的libfastcommon-1.0.38.tar安裝後已經不需要往 /usr/lib拷貝了
安裝fastdfs
https://github.com/happyfish100/fastdfs/releases
tar -zxvf fastdfs-5.11.tar.gz
cd fastdfs-5.11
./make.sh && ./make.sh install
安裝成功將安裝目錄下的conf下的文件拷貝到/etc/fdfs/下;
cp /usr/local/FastDFS/conf/* /etc/fdfs/
安裝成功後進入/etc/fdfs目錄:
修改tracker.conf
vi tracker.conf
base_path=/home/yuqing/FastDFS
改爲:
base_path=/home/server/fastdfs
啓動tracker,運行如下命令:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
設置開機自動啓動。
vim /etc/rc.d/rc.local
將運行命令行添加進文件:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
配置和啓動storage
由於上面已經安裝過FastDFS,這裏只需要配置storage就好了;
切換目錄到: /etc/fdfs/ 目錄下;
修改storage.conf
vi storage.conf
group_name=group1
base_path=/home/yuqing/FastDFS改爲:base_path=/home/FastDFS
store_path0=/home/yuqing/FastDFS改爲:store_path0=/home/FastDFS/fdfs_storage
#如果有多個掛載磁盤則定義多個store_path,如下
#store_path1=.....
#store_path2=......
tracker_server=192.168.101.3:22122 #配置tracker服務器:IP
#如果有多個則配置多個tracker
tracker_server=192.168.101.4:22122
啓動storage,配置開機啓動同trackerserver
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
FastDFS 和nginx整合
配置fastdfs-nginx-module
將FastDFS-nginx-module_v1.16.tar.gz傳至/usr/local/下
cd /usr/local
tar -zxvf FastDFS-nginx-module_v1.16.tar.gz
cd FastDFS-nginx-module/src
修改config文件
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
將fastdfs-nginx-module/src下的mod_fastdfs.conf拷貝至/etc/fdfs/下
cp mod_fastdfs.conf /etc/fdfs/
並修改 /etc/fdfs/mod_fastdfs.conf 的內容;
vi /etc/fdfs/mod_fastdfs.conf
base_path=/tmp 修改爲 base_path=/home/fastdfs
base_path=/home/fastdfs
tracker_server=192.168.172.20:22122
#tracker_server=192.168.172.20:22122 #(多個tracker配置多行)
url_have_group_name=true #url中包含group名稱
store_path0=/home/fdfs_storage #指定文件存儲路徑(上面配置的store路徑)
安裝nginx
上傳 nginx-1.14.0.tar.gz 到Centos服務器上;
解壓 tar -zxvf nginx-1.14.0.tar.gz
./configure \
--prefix=/home/server/nginx \
--conf-path=/home/server/nginx/conf/nginx.conf \
--pid-path=/home/server/nginx/conf/nginx.pid \
--lock-path=/home/server/nginx/lock/nginx.lock \
--error-log-path=/home/server/nginx/logs/error.log \
--http-log-path=/home/server/nginx/logs/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/home/server/nginx/temp/client \
--http-proxy-temp-path=/home/server/nginx/temp/proxy \
--http-fastcgi-temp-path=/home/server/nginx/temp/fastcgi \
--http-uwsgi-temp-path=/home/server/nginx/temp/uwsgi \
--http-scgi-temp-path=/home/server/nginx/temp/scgi \
--add-module=/home/server/fastdfs/fastdfs-nginx-module/src
make && make install
修改配置文件ningx.config
user root;
worker_processes 1;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 7777;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ~ /group([0-9])/M00/{
root /home/amm/server/fastdfs/fdfs_storage/data;
ngx_fastdfs_module;
}
}
}
創建nginx/client目錄
mkdir -p /var/temp/nginx/client
啓動nginx
/home/server/nginx/sbin/nginx -c /home/server/nginx/conf/nginx.conf -s reload
查詢端口是否有進程守護用如下命令grep對應端口,如80爲端口號
例:netstat -nalp|grep 7777
查看某個程序用到的端口
例: netstat -unltp|grep nginx
查看開放端口
例:/sbin/iptables -L -n
參考資料: