1.安裝libfastcommon
libfastcommon是從 FastDFS 和 FastDHT 中提取出來的公共 C 函數(shù)庫,基礎(chǔ)環(huán)境叨粘,安裝即可 。
① 下載libfastcommon
# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
② 解壓
# tar -zxvf V1.0.7.tar.gz
# cd libfastcommon-1.0.7
③ 編譯瘤睹、安裝
# ./make.sh
# ./make.sh install
④?libfastcommon.so 安裝到了/usr/lib64/libfastcommon.so升敲,但是FastDFS主程序設(shè)置的lib目錄是/usr/local/lib,所以需要?jiǎng)?chuàng)建軟鏈接轰传。
# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
# ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
# ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
# ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
2.安裝fastdfs
① 下載FastDFS
# wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
② 解壓
# tar -zxvf V5.05.tar.gz
# cd fastdfs-5.05
③ 編譯驴党、安裝
# ./make.sh
# ./make.sh install
④ 默認(rèn)安裝方式安裝后的相應(yīng)文件與目錄
A.啟動(dòng)命令:/etc/init.d/{fdfs_storaged,fdfs_trackerd}
B.默認(rèn)配置文件:/etc/fdfs/{client.conf.sample,storage.conf.sample,tracker.conf.sample}
c.命令工具在 /usr/bin/ 目錄中:
但是?FastDFS 服務(wù)啟動(dòng)腳本(/etc/init.d/{fdfs_storaged,fdfs_trackerd})設(shè)置的 bin 目錄是 /usr/local/bin, 但實(shí)際命令安裝在 /usr/bin/ 下获茬,需要添加軟鏈接:
?ln -s /usr/bin/fdfs_trackerd /usr/local/bin
?ln -s /usr/bin/fdfs_storaged? /usr/local/bin
?ln -s /usr/bin/stop.sh? ? ? ? /usr/local/bin
?ln -s /usr/bin/restart.sh? ? ? /usr/local/bin
3.添加tracker配置信息
①?cp? ??/etc/fdfs/client.conf.sample? ? ??/etc/fdfs/client.conf
修改配置文件:
disabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=60
base_path=/app/fastdfs/tracker
max_connections=256
accept_threads=1
work_threads=16
store_lookup=0
store_group=G1
store_server=1
store_path=0
download_server=0
reserved_storage_space = 10%
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
sync_log_buff_interval = 10
check_active_interval = 120
thread_stack_size = 64KB
storage_ip_changed_auto_adjust = true
storage_sync_file_max_delay = 86400
storage_sync_file_max_time = 300
use_trunk_file = false
slot_min_size = 256
slot_max_size = 16MB
trunk_file_size = 64MB
trunk_create_file_advance = false
trunk_create_file_time_base = 02:00
trunk_create_file_interval = 86400
trunk_create_file_space_threshold = 20G
trunk_init_check_occupying = false
trunk_init_reload_from_binlog = false
trunk_compress_binlog_min_interval = 0
use_storage_id = false
storage_ids_filename = storage_ids.conf
id_type_in_filename = ip
store_slave_file_use_link = false
rotate_error_log = false
error_log_rotate_time=00:00
rotate_error_log_size = 0
log_file_keep_days = 0
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.server_port=8080
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.html
②?創(chuàng)建tracker基礎(chǔ)數(shù)據(jù)目錄港庄,即base_path對(duì)應(yīng)的目錄:??
mkdir? -pv? ?/app/fastdfs/tracker
③ 啟動(dòng)tracker
/usr/bin/fdfs_trackerd? /etc/fdfs/tracker? ? ?start
④查看 FastDFS Tracker 是否已成功啟動(dòng) 倔既,22122端口正在被監(jiān)聽,則算是Tracker服務(wù)安裝成功鹏氧。
# netstat -unltp|grep? 22122
關(guān)閉Tracker命令:
/usr/bin/fdfs_trackerd? /etc/fdfs/tracker? ? ?stop
⑦tracker server?目錄及文件結(jié)構(gòu)
Tracker服務(wù)啟動(dòng)成功后叉存,會(huì)在base_path下創(chuàng)建data、logs兩個(gè)目錄度帮。
3.fastDHT安裝
由于FastDFS本身不能對(duì)重復(fù)上傳的文件進(jìn)行去重歼捏,而FastDHT可以做到去重。FastDHT是一個(gè)高性能的分布式哈希系統(tǒng)笨篷,它是基于鍵值對(duì)存儲(chǔ)的瞳秽,而且它需要依賴于Berkeley DB作為數(shù)據(jù)存儲(chǔ)的媒介,同時(shí)需要依賴于libfastcommon率翅。
2.安裝及配置:
1)下載FastDHT
FastDHT:FastDHT_v1.23.tar.gz
2).由于libfastcommon在安裝FastDFS時(shí)已經(jīng)安裝過练俐,不需再安裝。
3)下載Berkeley DB冕臭,最新版本下載地址:
http://www.oracle.com/technetwork/database/database-technologies/berkeleydb/downloads/index.html
Berkeley DB:db-6.1.19.tar.gz
4)安裝Berkeley DB腺晾,將db-6.1.19.tar.gz拷貝到/usr/local目錄下。
5)解壓:
tar -zxvf db-6.1.19.tar.gz
6)進(jìn)入build-unix目錄:
cd /usr/local/6.1.19/build_unix/
7)執(zhí)行命令:
../dist/configure --prefix=/usr/local/db-6.1.19
make
make install
8)DB安裝完畢辜贵,會(huì)在/usr/local目錄下生成目錄db-6.1.19
安裝過程可能報(bào)錯(cuò):
解決方法: yum? install? libevent*? -y? ? ? ? 重新編譯
9)安裝FastDHT悯蝉,將FastDHT_v1.23.tar.gz拷貝到/usr/local目錄下,解壓:
tar? xf? FastDHT_v1.23.tar.gz
10)進(jìn)入?FastDHT_v1.23目錄托慨,修改make.sh文件鼻由,修改:
CFLAGS=’-Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/usr/local/db-6.1.19/include/ -L/usr/local/db-6.1.19/lib/’
字體加黑部分為要加入的內(nèi)容。
11)進(jìn)入?FastDHT_v1.23目錄厚棵,編譯安裝:
cd /usr/local/?FastDHT_v1.23r/
./make.sh
./make.sh install
12).安裝成功后fastdht被安裝在/etc/fdht目錄下蕉世,生成3個(gè)配置文件??
fdht_client.conf?
?fdhtd.conf?
?fdht_servers.conf
13)配置FastDHT,創(chuàng)建fastdht目錄:
mkdir /opt/fastdht
14)修改/etc/fdht/目錄下的配置文件fdht_client.conf婆硬,依次修改如下內(nèi)容:
connect_timeout=3
network_timeout=60
keep_alive=1
base_path=/opt/fastdht
log_level=info
use_proxy=0
proxy_addr=127.0.0.1
proxy_port=12200
#include /etc/fdht/fdht_servers.conf
15)修改/etc/fdht/目錄下的配置文件fdht_servers.conf狠轻,依次修改如下內(nèi)容:
group_count = 1
group0 = 192.168.150.46:11411? ? ?#fdht安裝ip的地址
group0 = 192.168.150.47:11411? ? ?#fdht安裝ip的地址
16)修改/etc/fdht/目錄下的fdhtd.conf文件,依次修改如下內(nèi)容:
disabled=false
bind_addr=
port=11411
network_timeout=60
base_path=/opt/fastdht? ? ? #目錄需手動(dòng)創(chuàng)建
max_connections=256
max_threads=32
max_pkg_size=64KB
min_buff_size=64KB
store_type = BDB
cache_size = 64MB
db_prefix = db
page_size = 4096
db_type = btree
mpool_init_capacity = 10000
mpool_load_factor = 0.75
mpool_clear_min_interval = 30
log_level=debug
run_by_group=
run_by_user=
allow_hosts=*
sync_log_buff_interval=10
sync_db_time_base=00:00
sync_db_interval=86400
write_to_binlog=1
sync_binlog_buff_interval=60
clear_expired_time_base=04:00
clear_expired_interval=86400
db_dead_lock_detect_interval=1000
compress_binlog_time_base=02:00
compress_binlog_interval=86400
thread_stack_size=1MB
if_alias_prefix=
#include /etc/fdht/fdht_servers.conf? -> (本行前有#表示打開彬犯,如果想關(guān)閉此選項(xiàng)向楼,則應(yīng)該為##開頭)
17)配置/etc/fdfs/目錄下的storage.conf文件,依次修改如下內(nèi)容-----(后續(xù)安裝strage的時(shí)候需要修改):
#是否檢測上傳文件已經(jīng)存在躏嚎。如果已經(jīng)存在蜜自,則建立一個(gè)索引鏈接以節(jié)省磁盤空間
check_file_duplicate=1
#當(dāng)上個(gè)參數(shù)設(shè)定為1時(shí) , 在FastDHT中的命名空間
key_namespace=FastDFS
#長連接配置選項(xiàng)卢佣,如果為0則為短連接 1為長連接
keep_alive=1
#此處特別需要注意配置
#include /etc/fdht/fdht_servers.conf? ? ? ? 此處是strage配置文件配置信息
18).執(zhí)行如下命令:
cp /usr/local/db-6.1.19/lib/libdb-6.0.so /usr/lib/
cp /usr/local/db-6.1.19/lib/libdb-6.0.so /usr/lib64/
19.啟動(dòng)FastDHT:
fdhtd /etc/fdht/fdhtd.conf
驗(yàn)證時(shí)需要安裝完成strage才能配合測試重荠!
20.測試,通過客戶端命令測試上傳:
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /opt/test.png
21.上傳成功后返回路徑虚茶,查看storage存儲(chǔ)對(duì)應(yīng)存儲(chǔ)路徑戈鲁,發(fā)現(xiàn)返回的為一個(gè)軟鏈接仇参,之后每次重復(fù)上傳的haul都是返回一個(gè)指向第一次上傳的文件的軟鏈接。也就保證了文件只保存了一份婆殿。需要說明的是诈乒,F(xiàn)astDFS不會(huì)返回原始文件的索引,返回的全部都是軟鏈接婆芦,當(dāng)所有的軟鏈接都被刪除的時(shí)候怕磨,原始文件也會(huì)從FastDFS中被刪除。
目前位置安裝完成:tracker和fdhtd消约,下面需要安裝strage肠鲫!