FastDFS是分布式高可用叹洲、自動(dòng)負(fù)載均衡的文件系統(tǒng),特別適合小文件的在線服務(wù)工禾,比如圖片服務(wù)等运提。本文介紹一下,如何快速部署FastDFS服務(wù)器
FastDFS系列
說(shuō)明
說(shuō)明 | 位置 |
---|---|
數(shù)據(jù)存儲(chǔ)目錄 | /home/dfs |
安裝包 | /usr/local/src |
安裝依賴
- 創(chuàng)建數(shù)據(jù)存儲(chǔ)目錄
mkdir /home/dfs
- 安裝依賴的第三方庫(kù)
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
- 安裝
libfastcommon
cd /usr/local/src
git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
./make.sh && ./make.sh install #編譯安裝
安裝FastDFS
cd /usr/local/src
git clone https://github.com/happyfish100/fastdfs.git --depth 1
cd fastdfs/
./make.sh && ./make.sh install #編譯安裝
#配置文件準(zhǔn)備
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客戶端文件闻葵,測(cè)試用
cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/ #供nginx訪問(wèn)使用
cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ #供nginx訪問(wèn)使用
單機(jī)部署
tracker配置
vim /etc/fdfs/tracker.conf
#需要修改的內(nèi)容如下
port=22122 # tracker服務(wù)器端口(默認(rèn)22122,一般不修改)
base_path=/home/dfs # 存儲(chǔ)日志和數(shù)據(jù)的根目錄
storage配置
vim /etc/fdfs/storage.conf
#需要修改的內(nèi)容如下
port=23000 # storage服務(wù)端口(默認(rèn)23000,一般不修改)
base_path=/home/dfs # 數(shù)據(jù)和日志文件存儲(chǔ)根目錄
store_path0=/home/dfs # 第一個(gè)存儲(chǔ)目錄
tracker_server=192.168.58.101:22122 # tracker服務(wù)器IP和端口
http.server_port=8888 # http訪問(wèn)文件的端口(默認(rèn)8888,看情況修改,和nginx中保持一致)
服務(wù)啟動(dòng)
- 關(guān)閉防火墻
#不關(guān)閉防火墻的話無(wú)法使用
systemctl stop firewalld.service #關(guān)閉
systemctl restart firewalld.service #重啟
- 啟動(dòng)tracker
/etc/init.d/fdfs_trackerd start #啟動(dòng)tracker服務(wù)
chkconfig fdfs_trackerd on #自啟動(dòng)tracker服務(wù)
- 啟動(dòng)storage
/etc/init.d/fdfs_storaged start #啟動(dòng)storage服務(wù)
chkconfig fdfs_storaged on #自啟動(dòng)storage服務(wù)
Client測(cè)試
vim /etc/fdfs/client.conf
#需要修改的內(nèi)容如下
base_path=/home/dfs
tracker_server=192.168.58.101:22122 #tracker服務(wù)器IP和端口
#保存后測(cè)試,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz
fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz
Nginx直接訪問(wèn)
FastDFS支持Nginx直接訪問(wèn)糙捺,不需要經(jīng)過(guò)Client中轉(zhuǎn),效率更高
安裝fastdfs-nginx-module
cd ../ #返回上一級(jí)目錄
git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
安裝nginx
wget http://nginx.org/download/nginx-1.15.4.tar.gz #下載nginx壓縮包
tar -zxvf nginx-1.15.4.tar.gz #解壓
cd nginx-1.15.4/
#添加fastdfs-nginx-module模塊
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/
make && make install #編譯安裝
/etc/fdfs/mod_fastdfs.conf
tracker_server=192.168.58.101:22122 #tracker服務(wù)器IP和端口
url_have_group_name=true
store_path0=/home/dfs
/usr/local/nginx/conf/nginx.conf
server {
listen 8888; ## 該端口為storage.conf中的http.server_port相同
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
- 瀏覽器訪問(wèn)
http://192.168.58.101:8888/group1/M00/00/00/wKgAQ1pysxmAaqhAAA76tz-dVgg.tar.gz
分布式部署
- 增加部署
按照單機(jī)部署模式在192.168.58.201
上部署FastDFS(數(shù)據(jù)目錄/home/dfs
笙隙,tracker.conf
配置)
- 修改
/etc/fdfs/storage.conf
port=23000 # storage服務(wù)端口(默認(rèn)23000,一般不修改)
base_path=/home/dfs # 數(shù)據(jù)和日志文件存儲(chǔ)根目錄
store_path0=/home/dfs # 第一個(gè)存儲(chǔ)目錄
tracker_server=192.168.58.101:22122 # 服務(wù)器1
tracker_server=192.168.58.201:22122 # 服務(wù)器2
http.server_port=8888 # http訪問(wèn)文件的端口(默認(rèn)8888,看情況修改,和nginx中保持一致)
- 修改
/etc/fdfs/client.conf
base_path=/home/dfs
tracker_server=192.168.58.101:22122 # 服務(wù)器1
tracker_server=192.168.58.201:22122 # 服務(wù)器2
- 修改
/etc/fdfs/mod_fastdfs.conf
tracker_server=192.168.58.101:22122 # 服務(wù)器1
tracker_server=192.168.58.201:22122 # 服務(wù)器2
url_have_group_name=true
store_path0=/home/dfs
重要信息
- 日志目錄:
/home/dfs/logs
如果遇到問(wèn)題可以查看日志/home/dfs/logs
常見(jiàn)問(wèn)題
-
tracker_query_storage fail, error no: 2, error info: No such file or directory
:檢查配置文件/etc/fdfs/tracker.conf
,storage.conf
洪灯,client.conf
是否正確。還可以查看日志/home/dfs/logs/