新聞中心
如何在Linux上快速啟動FastDFS?

FastDFS是一款開源的高性能分布式文件系統(tǒng)。它可以提供對海量小文件的存儲和訪問服務(wù)。FastDFS基于C語言編寫,支持Linux、Unix、MacOS等多種操作系統(tǒng),因此廣受開發(fā)者和企業(yè)用戶的歡迎。本文將介紹如何在Linux上快速啟動FastDFS,幫助用戶快速搭建高效的文件系統(tǒng)服務(wù)。
一、安裝FastDFS
在開始配置FastDFS之前,需要先進行安裝。FastDFS的安裝可以通過源碼編譯和二進制安裝包安裝兩種方式。其中,前者需要手動編譯源碼,比較麻煩。我們在這里介紹采用二進制安裝包的方式進行安裝。
1. 打開FastDFS官網(wǎng)(https://github.com/happyfish100/fastdfs),下載最新的fastdfs.tar.gz文件。
2. 解壓文件:tar zxvf fastdfs.tar.gz
3. 進入FastDFS安裝目錄:cd fastdfs
4. 運行安裝腳本:./make.sh
5. 運行安裝腳本:./make.sh install
6. 運行安裝腳本:./make.sh install-fastdfs
二、配置FastDFS
1. FastDFS提供了多種配置方式,包括INI格式配置文件和命令行參數(shù)。
2. 常用的INI格式配置文件為/etc/fdfs/storage.conf(存儲服務(wù)器配置文件)和/etc/fdfs/tracker.conf(跟蹤服務(wù)器配置文件)。
3. 配置文件的內(nèi)容包括服務(wù)器IP地址、端口號、存儲路徑、心跳時間等參數(shù)。
4. 配置好服務(wù)器的IP地址和端口號后,在命令行中啟動FastDFS即可。
三、啟動FastDFS
1. 在命令行中運行以下命令啟動FastDFS:
#啟動tracker服務(wù)器
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
#啟動storage服務(wù)器
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
2. 執(zhí)行以上命令后,F(xiàn)astDFS即可順利地啟動。
3. 查看FastDFS運行狀態(tài):/usr/bin/fdfs_monitor /etc/fdfs/client.conf
四、使用FastDFS
1. 客戶端上傳文件:/usr/bin/fdfs_upload_file /etc/fdfs/client.conf local_filename
2. 客戶端刪除文件:/usr/bin/fdfs_delete_file /etc/fdfs/client.conf group_name filename
3. 客戶端下載文件:/usr/bin/fdfs_download_file /etc/fdfs/client.conf group_name filename
4. 客戶端獲取文件URL:/usr/bin/fdfs_file_info /etc/fdfs/client.conf group_name filename
五、
通過以上步驟,我們可以快速地在Linux上啟動FastDFS服務(wù),并進行常規(guī)的操作。但是,F(xiàn)astDFS還有許多高級配置和優(yōu)化技巧,需要根據(jù)實際需求進行調(diào)整和優(yōu)化。希望本文能對需要使用FastDFS的用戶提供一定的幫助。
成都網(wǎng)站建設(shè)公司-創(chuàng)新互聯(lián)為您提供網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)頁設(shè)計及定制高端網(wǎng)站建設(shè)服務(wù)!
如何安裝FastDFS
目前FastDFS支持類Unix系統(tǒng) ,在Linux和FreeBSD下測試過,本文使用的是Ubuntu10.4,建議安裝之前先簡單了解一下FastDFS的原理 ,這對后繼的配置部分會有很好的理解。
一、準(zhǔn)備舉棚工作-安裝libevent
FastDFS 內(nèi)部鋒答蠢綁定了 libevent 作為 http 服務(wù)器 ,在V2.X版本必須安裝 libevent ,本文安裝的是V2.2版本,因此必須安裝libevent。(官方也推薦使用 http 方式下載 文件 )
如果已經(jīng)安裝了 libevent,請確認安裝路徑是 /usr , 因為 FastDFS 在編譯源程序時,需要到此目錄下查找一些依賴文件,否則編譯 FastDFS 會出錯 。如果不是,建議首先卸載 libevent ,然后安裝到 /usr 下。Ubuntu10.4默認是安裝了libevent,可以到軟件中心卸載掉然后按照下面介紹的方式安裝。
安裝步驟:
解壓 libevent ,然后進入解壓后的目錄分別執(zhí)行:
Shell代碼
./configure –prefix=/usr
make clean;
make
make install
安裝libevent完成。
二、安裝 FastDFS
1、下載 FastDFS 源程序
2、在 FastDFS_v4.05.tar.gz 所在文件夾下執(zhí)行:
Shell代碼
sudo tar vxzf FastDFS_v4.05.tar.gz /home/soar/FastDFS
注: /home/soar/FastDFS 也可以是其他目錄,記住這是解壓目錄,以后用 %FastDFS% 表示)
3、由于要使用內(nèi)置的 http 服務(wù),因此編輯 %FastDFS%/make.sh 文件,找到
#WITH_HTTPD=1
修改成
WITH_HTTPD=1
以支持 http
4、進入 %FastDFS% 目錄,執(zhí)行:
Shell代碼
sudo ./make.sh
5、在 %FastDFS% 目錄下,執(zhí)行:
Shell代碼
sudo ./make.sh install
如果運行如上命令后,在命令行信息最后看到類似
Shell代碼
#ln -fs /usr/local/lib/libfastcommon.so.1 /usr/local/lib/libfastcommon.so
#ln -fs /usr/local/lib/libfdfsclient.so.1 /usr/local/lib/libfdfsclient.so
sh ./fdfs_link_library.sh
恭喜你,已經(jīng)安裝成功了!
FastDFS的配置文件在%FastDFS%/conf目錄下,其中包括
Client.conf 客戶端上傳配置文件
Storage.conf 文件存儲服務(wù)器配置文件
Tracker.conf 負責(zé)均衡調(diào)度服務(wù)器配置文件
http.confhttp服務(wù)器配置文件
配置文件需要根據(jù)服務(wù)器環(huán)境的不同,進行不同的配置,具體可以參考FastDFS官方的安裝配置文檔
,以及FastDFS原理介紹文檔
在本例中,Tracker Server,Storage Server都安裝在一臺服務(wù)器上,IP:10.0.2.15
1、配置及啟動Tracker Server
A、修改%FastDFS%/conf/tracker.conf文件,修改如下
#可以自己指定目錄位置,銀陪但目錄必須存在,用于存儲日志及storage server等信息,否則tracker server無法啟動
Txt代碼
base_path=/home/yuqing/fastdfs -> base_path=/home/soar/fastdfs_tracker
#改成你想要的http端口,將來http下載文件的端口就是他了
Txt代碼
http.server_port=8080 -> http.server_port=
#http支持
Txt代碼
##include http.conf -> #include http.conf
#默認4GB,如果空間不足,建議調(diào)小,否則會報no free space的異常,無法正常啟動
Txt代碼
reserved_storage_space = 4GB -> reserved_storage_space = 1GB
#tracker server對storage server供服務(wù)的端口,使用默認的即可,也可以自定義
Txt代碼
port=
B、將http.conf文件拷貝到/etc/fdfs目錄下,執(zhí)行
Shell代碼
sudo cp %FastDFS%/conf/http.conf /etc/fdfs/
注:為了支持http,必須將這個文件拷貝到此目錄,否則無法啟動,報param http.XXX not exist or is empty類似的錯誤
C、進入/usr/local/bin/目錄,啟動tracker服務(wù)器,執(zhí)行
Shell代碼
sudo fdfs_trackerd %FastDFS%/conf/tracker.conf
D、進入/home/soar/fastdfs_tracker/logs/trackerd.log查看tracker的啟動日志,如果看到類似
Shell代碼
INFO – FastDFS v2.02, base_path=/home/soar/fastdfs_tracker, connect_timeout=30s, network_timeout=60s, port=22122, bind_addr=, max_connections=256, work_threads=4, store_lookup=2, store_group=, store_server=0, store_path=0, reserved_storage_space=4MB, download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s, check_active_interval=120s, thread_stack_size=64 KB, storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s, storage_sync_file_max_time=300s
INFO – HTTP supported: server_port=8090, default_content_type=application/octet-stream, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0, check_active_interval=30, check_active_type=tcp, check_active_uri=/status.html
恭喜你,tracker server已經(jīng)啟動成功!
2、配置及啟動Storage Server
A、修改%FastDFS%/conf/storage.conf文件,修改如下:
#可以自定義,但必須存在此目錄,用于存儲storage相關(guān)的log、group內(nèi)的相關(guān)信息
Txt代碼
base_path=/home/yuqing/fastdfs -> /home/soar/fastdfs_storge
#文件的存儲位置,在一臺storage server上可以指定多個存儲位置
Txt代碼
store_path0=/home/yuqing/fastdfs -> store_path0=/home/soar/fastdfs_storge
#必須指定
Txt代碼
group_name=group1
#修改成tracker server的IP和端口信息
Txt代碼
tracker_server=192.168.209.121:> tracker_server=10.0.2.15:
#http支持
Txt代碼
##include http.conf ->#include http.conf
B、進入/usr/local/bin/目錄,啟動storage服務(wù)器,執(zhí)行
Shell代碼
sudo fdfs_storaged %FastDFS%/conf/storage.conf
C、進入/home/soar/fastdfs_tracker/logs/storage.log查看storage服務(wù)器啟動日志,如果看到類似
Shell代碼
INFO – FastDFS v2.02, base_path=/home/soar/fastdfs_storge, store_path_count=1, subdir_count_per_path=256, group_name=group1, connect_timeout=30s, network_timeout=60s, port=23000, bind_addr=, client_bind=1, max_connections=256, work_threads=4, disk_rw_separated=1, disk_reader_threads=1, disk_writer_threads=1, buff_size=256KB, heart_beat_interval=30s, stat_report_interval=60s, tracker_server_count=1, sync_wait_msec=200ms, sync_interval=0ms, sync_start_time=00:00, sync_end_time=23:59, write_mark_file_freq=500, allow_ip_count=-1, file_distribute_path_mode=0, file_distribute_rotate_count=100, fsync_after_written_bytes=0, sync_log_buff_interval=10s, sync_binlog_buff_interval=60s, sync_stat_file_interval=300s, thread_stack_size=512 KB, upload_priority=10, if_alias_prefix=, check_file_duplicate=0, FDHT group count=0, FDHT server count=0, FDHT key_namespace=, FDHT keep_alive=0, HTTP server port=8888, domain name=
INFO – HTTP supported: server_port=8888, http_trunk_size=262144, default_content_type=application/octet-stream, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0
INFO – file: storage_param_getter.c, line: 48, storage_ip_changed_auto_adjust=1
INFO – file: tracker_client_thread.c, line: 274, successfully connect to tracker server 10.0.2.15:22122, as a tracker client, my ip is 10.0.2.15
恭喜你,storage server已經(jīng)啟動成功!
經(jīng)過前面的安裝、配置、啟動,馬上就可以看到FastDFS的效果了,我們先上傳一個文件,然后再通過http下載。
一、上傳文件
FastDFS安裝包中,自帶了客戶端程序,通過程序可以進行文件上傳。在使用這個客戶端程序之前,首先需要配置client.conf,然后再進行文件上傳及下載。
1、修改%FastDFS%/conf/client.conf文件,修改如下:
#可自定義,但此目錄必須存在,用于存放文件上傳log
Txt代碼
base_path=/home/yuqing/fastdfs-> base_path=/home/soar/fastdfs_tracker
Txt代碼
tracker_server=192.168.209.121:> tracker_server=10.0.2.15:
Txt代碼
http.tracker_server_port=8080 ->http.tracker_server_port=8090
#支持http
Txt代碼
##include http.conf ->#include http.conf
2、進入/usr/local/bin/目錄,上傳文件,執(zhí)行
Txt代碼
sudo fdfs_test %FastDFS%/conf/client.conf upload a.txt
注:a.txt可以在/usr/local/bin/目錄下自己創(chuàng)建一個
如果命令行反饋類似如下:
則說明上傳文件成功。
關(guān)于fastdfs集群和備份配置
1、修改tracker.conf文件中store_lookup=2 平衡負載
2、修改tracker.conf文件中store_server=0 采用輪詢方式。
如果希望只使用一臺文件存儲服務(wù)器,其他二臺做備份,則修改文件tracker_server為某臺主機的IP,只啟動文件存儲服務(wù)器的tracker,其他二臺備份服務(wù)器不需要啟動tracker。
如果希望三臺服務(wù)器集群使用,互相備份,比如:使用A機器存儲文件,這時候A機器會將文件同步到B機器和C機器,同理使用B機器存儲文件,則會同時將文件同步到A機器和C機器。這時候需要將所有的機器IP和端口號
都配置在storage.conf中,如下所示:
tracker_server=10.207.16.127:22122
關(guān)于linux開啟fastdfs的介紹到此就結(jié)束了,不知道你從中找到你需要的信息了嗎 ?如果你還想了解更多這方面的信息,記得收藏關(guān)注本站。
香港服務(wù)器選創(chuàng)新互聯(lián),香港虛擬主機被稱為香港虛擬空間/香港網(wǎng)站空間,或者簡稱香港主機/香港空間。香港虛擬主機特點是免備案空間開通就用, 創(chuàng)新互聯(lián)香港主機精選cn2+bgp線路訪問快、穩(wěn)定!
本文名稱:如何在linux上快速啟動fastdfs?(linux開啟fastdfs)
網(wǎng)頁路徑:http://www.fisionsoft.com.cn/article/cdhoeps.html


咨詢
建站咨詢
