FastDFS安裝
1.1 準備機器
根據實際情況準備多臺Linux機器
1.2 FastDFS--tracker安裝
分別在多個節點上安裝tracker,
注:這里只演示安裝一臺tracker,
1.2.1 下載
tracker和storage使用相同的安裝包,下載地址:https://github.com/happyfish100/FastDFS

1.2.2 FastDFS安裝環境
FastDFS是C語言開發,建議在linux上運行,本教程使用Centos7作為安裝環境,
安裝FastDFS需要先將官網下載的原始碼進行編譯,編譯依賴gcc環境,如果沒有gcc環境,需要安裝gcc:
yum install gcc-c++
1.2.3 安裝libevent
FastDFS依賴libevent庫,需要安裝:
yum -y install libevent
1.2.4 安裝libfastcommon
libfastcommon是FastDFS官方提供的,libfastcommon包含了FastDFS運行所需要的一些基礎庫,
libfastcommon下載地址:https://github.com/happyfish100/libfastcommon

下載后將libfastcommon檔案夾(里邊包含以上檔案)拷貝至/usr/local/下
cd /usr/local/libfastcommon ./make.sh ./make.sh install
注意:libfastcommon安裝好后會自動將庫檔案拷貝至/usr/lib64下,由于FastDFS程式參考usr/lib目錄所以需要將/usr/lib64下的庫檔案拷貝至/usr/lib下,若/usr/lib下已存在所需檔案就不需要拷貝了,
要拷貝的檔案如下:

1.2.5 tracker編譯安裝
將下載好的FastDFS拷貝至/usr/local/下
cd fastdfs
./make.sh 編譯
./make.sh install 安裝
安裝成功將安裝目錄下的conf下的檔案拷貝到/etc/fdfs/下,

1.2.6 配置
安裝成功后進入/etc/fdfs目錄:

拷貝一份新的tracker組態檔:
cp tracker.conf.sample tracker.conf
修改tracker.conf
vi tracker.conf
base_path=/home/yuqing/FastDFS
改為:
base_path=/home/FastDFS
配置http埠:
http.server_port=80
1.2.7 啟動
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
啟動的日志顯示先停止5619行程(實際環境不是5619)再啟動,如下圖:

注意:如果沒有顯示上圖要注意是否正常停止原有行程,
1.3 FastDFS--storage安裝
分別在多臺上安裝storage,
注:這里演示只安裝一臺storage,
1.3.1 安裝libevent
同tracker安裝
1.3.2 安裝libfastcommon
同tracker安裝,
1.3.3 storage編譯安裝
同tracker編譯安裝,
1.3.4 配置
安裝成功后進入/etc/fdfs目錄:
拷貝一份新的storage組態檔:
cp storage.conf.sample storage.conf
修改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
#配置http埠
http.server_port=80
1.3.5 啟動
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
啟動的日志顯示先停止8931行程(實際環境不是8931)再啟動,如下圖:

注意:如果沒有顯示上圖要注意是否正常停止原有行程,
1.4 上傳圖片測驗
1.4.1 通過fdfs_test程式
FastDFS安裝成功可通過/usr/bin/fdfs_test程式來測驗上傳、下載等操作,
修改/etc/fdfs/client.conf
tracker_server根據自己部署虛擬機的情況配置
base_path=/home/fastdfs
tracker_server=192.168.101.3:22122
tracker_server=192.168.101.4:22122
使用格式:
/usr/bin/fdfs_test 客戶端組態檔地址 upload 上傳檔案
比如將/home下的圖片上傳到FastDFS中:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/tomcat.png
列印如下日志:
This is FastDFS client test program v6.02
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.
[2019-11-11 20:03:02] DEBUG - base_path=/home/fastdfs, connect_timeout=10, 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=192.168.9.131, port=23000
group_name=group1, ip_addr=192.168.9.131, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgJg13KLvaAXn65AABdreSfEnY403.jpg
source ip address: 192.168.9.131
file timestamp=2019-11-11 20:03:02
file size=23981
file crc32=3835630198
example file url: http://192.168.9.131/group1/M00/00/00/wKgJg13KLvaAXn65AABdreSfEnY403.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgJg13KLvaAXn65AABdreSfEnY403_big.jpg
source ip address: 192.168.9.131
file timestamp=2019-11-11 20:03:02
file size=23981
file crc32=3835630198
example file url: http://192.168.9.131/group1/M00/00/00/wKgJg13KLvaAXn65AABdreSfEnY403_big.jpg
http://192.168.9.131/group1/M00/00/00/wKgJg13KLvaAXn65AABdreSfEnY403_big.jpg就是檔案的下載路徑,
對應storage服務器上的
/home/fastdfs/fdfs_storage/data/00/00/wKgJg13KLvaAXn65AABdreSfEnY403_big.png檔案,
由于現在還沒有和nginx整合無法使用http下載,
1.5 FastDFS 和nginx整合
1.5.1 在Storage上安裝nginx
在storage server上安裝nginx的目的是對外通過http訪問storage server上的檔案,使用nginx的模塊FastDFS-nginx-module的作用是通過http方式訪問storage中的檔案,當storage本機沒有要找的檔案時向源storage主機代理請求檔案,
1.5.1.1 FastDFS-nginx-module
下載地址:https://github.com/happyfish100/fastdfs-nginx-module
將下載的fastdfs-nginx-module檔案包傳至fastDFS的storage服務器的/usr/local/下,然后
cd /usr/local/fastdfs-nginx-module/src
修改config檔案將/usr/local/路徑改為/usr/
將FastDFS-nginx-module/src下的mod_FastDFS.conf拷貝至/etc/fdfs/下
cp mod_FastDFS.conf /etc/fdfs/
并修改mod_FastDFS.conf的內容:
vi /etc/fdfs/mod_FastDFS.conf
base_path=/home/fastdfs
tracker_server=192.168.101.3:22122
tracker_server=192.168.101.4:22122
url_have_group_name=true #url中包含group名稱
store_path0=/home/fastdfs/fdfs_storage #指定檔案存盤路徑
#如果有多個
將libfdfsclient.so拷貝至/usr/lib下
cp /usr/lib64/libfdfsclient.so /usr/lib/
創建nginx/client目錄
mkdir -p /var/temp/nginx/client
1.5.2.2 nginx安裝
將nginx-1.8.0.tar.gz拷貝到/usr/local下
解壓nginx-1.8.0.tar.gz
進入nginx-1.8.0目錄,執行如下配置命令:
下邊紅色部分表示添加fastdfs-nginx-module模塊
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/usr/local/fastdfs-nginx-module/src
執行以上命令程序可能會由于缺少zlib庫或pcre庫產生錯誤,可按以下方式安裝相應的庫解決
yum -y install pcre-devel
yum install zlib-devel
然后
make
make install
1.5.2.3 nginx組態檔
新建一個nginx組態檔nginx-fdfs.conf.
添加虛擬主機:
server {
listen 80;
server_name 192.168.101.65;
location /group1/M00/{
root /home/fastdfs/fdfs_storage/data;
ngx_fastdfs_module;
}
}
說明:
server_name指定本機ip
location /group1/M00/:group1為nginx 服務FastDFS的分組名稱,M00是FastDFS自動生成編號,對應store_path0=/home/FastDFS/fdfs_storage,如果FastDFS定義store_path1,這里就是M01
1.5.3 測驗
啟動nginx
nginx -c /usr/local/nginx/conf/nginx.conf
通過java客戶端上傳檔案,使用瀏覽器http訪問檔案,這里訪問上傳圖片測驗的檔案:
訪問storage:
http://192.168.101.5/group1/M00/00/00/wKhlBVVY2M-AM_9DAAAT7-0xdqM485_big.png
ip地址改為192.168.101.6也可以訪問到檔案,因為同一個分組的storage檔案互相同步,
訪問tracker:
http://192.168.101.3/group1/M00/00/00/wKhlBVVY2M-AM_9DAAAT7-0xdqM485_big.png
ip地址改為192.168.101.4也可以訪問到檔案,
使用域名訪問 (推薦):
nginx對外由vip提供服務,使用域名訪問如下:
比如vip對應的域名為img.test.com:
http://img.test.com/group1/M00/00/00/wKhlBVVY2M-AM_9DAAAT7-0xdqM485_big.png
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/107573.html
標籤:其他
下一篇:心率傳感器 SC7R30資料尋求
