1. 程式人生 > >CentOS單機安裝FastDFS

CentOS單機安裝FastDFS


作業系統:CentOS 6.5 64位
libevent版本:libevent-2.0.21-stable.tar.gz
FastDFS版本:FastDFS_v4.06.tar.gz
GitHub下載地址:https://github.com/happyfish100
GoogleCode地址:https://code.google.com/archive/p/fastdfs/


一、安裝libevent
首先安裝libevent,因為 FastDFS 在編譯源程式時,需要用到libevent一些依賴檔案,否則編譯 FastDFS 會出錯


1.1  解除安裝掉舊版本
rpm -qa|grep libevent;yum remove libevent*
1.2 然後安裝新版本

tar -zxvpf libevent-2.0.21-stable.tar.gz

1.3  進入解壓目錄:
cd libevent-2.0.21-stable
1.4 指定安裝目錄:
./configure --prefix=/usr/local/libevent
1.5 安裝
make && make install
1.6 為libevent建立軟連結到/lib庫下,64位系統對應/lib64
ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5
ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5


二、安裝FastDFS的步驟
2.1 解壓tar
tar -zxvf FastDFS_v3.11.tar.gz
2.2 進入安裝包(解壓之後的檔案目錄)
cd FastDFS
2.3 修改make.sh
vi make.sh
TARGET_PREFIX=/usr/local/fdfs  ---安裝路徑  
TARGET_CONF_PATH=/etc/fdfs  ---配置檔案路徑  
WITH_LINUX_SERVICE=1   ---是否為linux服務
2.4 編譯,使用剛剛安裝過的libevent包
./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib
2.5 安裝
./make.sh install


三、安裝Tracker Server
TARGET_PREFIX=/usr/local/fdfs/tracker  ---安裝路徑  
TARGET_CONF_PATH=/etc/fdfs/tracker  ---配置檔案路徑
 
3.1 引用上例中安裝libevent 和 FastDFS步驟
3.2 配置及啟動Tracker Server,埠:22122
3.3 修改tracker.conf 配置
vim /etc/fdfs/tracker/tracker.conf

# the tracker server port
port=22122
# the base path to store data and log files
base_path=/home/yuqing/fastdfs -> base_path=/home/fastdfs/tracker #日誌目錄
reserved_storage_space = 4GB -> reserved_storage_space = 1GB

3.4 啟動Tracker Server
/usr/local/fdfs/tracker/bin/fdfs_trackerd /etc/fdfs/tracker/tracker.conf
3.5 檢查tracker是否啟動成功,可以檢視如下檔案
vim /home/fastdfs/tracker/logs/trackerd.log
#[2012-08-26 19:01:30] INFO - FastDFS v3.11, base_path=/home/fastdfs/tracker, run_by_group=, run_by_user=, connect_timeout=30s, 
network_timeout=60s, port=22122, bind_addr=, max_connections=256, work_threads=4, store_lookup=0, store_group=, store_server=0, store_path=0,
reserved_storage_space=1024MB, 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, use_trunk_file=0, slot_min_size=256, 
slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, 
trunk_create_file_space_threshold=20 GB

3.6 啟動成功,加入開機啟動
vim /etc/rc.d/rc.local
/usr/local/fdfs/tracker/bin/fdfs_trackerd /etc/fdfs/tracker/tracker.conf


四、安裝Storage Server

TARGET_PREFIX=/usr/local/fdfs/storage  ---安裝路徑  
TARGET_CONF_PATH=/etc/fdfs/storage  ---配置檔案路徑
4.1 引用上例中安裝libevent 和 FastDFS步驟
#修改storage.conf配置
vim /etc/fdfs/storage/storage.conf
# the name of the group this storage server belongs to
group_name=group1
# the name of the group this storage server belongs to
# the storage server port #the storage server port
port=23000
# the base path to store data and log files #日誌目錄
base_path=/home/yuqing/fastdfs -> /home/fastdfs/storage
# store_path#, based 0, if store_path0 not exists, it's value is base_path #data資料儲存目錄
# the paths must be exist
store_path0=/home/fastdfs/storage
# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address (tracker server伺服器IP 和埠)
tracker_server=192.168.209.121:22122 -> tracker_server=192.16.1.249:22122


4.2 啟動Storage Server
/usr/local/fdfs/bin/fdfs_storaged /etc/fdfs/storage/storage.conf

接下來會出現很多mkdir data path,這是系統在建立資料目錄

data path: /home/fastdfs/storage/data, mkdir sub dir...
mkdir data path: 00 ...
mkdir data path: 01 ...
mkdir data path: 02 ...
mkdir data path: 03 ...
.......................
data path: /home/fdfs/storage/data, mkdir sub dir done.

4.3 啟動成功,加入開機啟動

# vim /etc/rc.d/rc.local
/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf

五、測試及使用FastDFS

5.1 FastDFS之配置client
vim /etc/fdfs/client.conf
base_path=/home/yuqing/fastdfs-> base_path=/home/fastdfs/tracker
tracker_server=192.168.209.121:22122 -> tracker_server=192.16.1.249:22122(本機IP地址)
view source
cd /usr/local/bin

vim aa.txt 增加內容:展示aa.txt文字資料   :wq

5.2 測試上傳

/usr/local/fdfs/tracker/bin/fdfs_test  /etc/fdfs/tracker/client.conf upload aa.txt


執行成功後會出現如下提示:
[2012-08-25 02:08:26] INFO - base_path=/home/fastdfs/tracker, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0
tracker_query_storage_store_list_without_group:
        server 1. group_name=group2, ip_addr=192.16.1.249, port=23000
group_name=group2, ip_addr=192.168.127.6, port=23000
storage_upload_by_filename
group_name=group2, remote_filename=M00/00/00/wKh_BlA3wxql4hTXAAAAB8v-VvY710.txt
source ip address: 192.16.1.249
file timestamp=2012-08-25 02:08:26
file size=7
file crc32=3422443254
file url:
storage_upload_slave_by_filename
group_name=group2, remote_filename=M00/00/00/wKh_BlA3wxql4hTXAAAAB8v-VvY710_big.txt
source ip address: 192.16.1.249
file timestamp=2012-08-25 02:08:26
file size=7
file crc32=3422443254
file url:
view source
執行過程中可能出現防火牆封口:
# ERROR - file: tracker_proto.c, line: 420, connect to 192.16.1.249:22122 fail, errno: 113, error info: No route to host
解決:

iptables -L;iptables -F;service iptables stop


六、常規命令範例


#啟動tracker、storaged
/usr/local/fdfs/tracker/bin/trackerd   /etc/fdfs/tracker/tracker.conf
/usr/local/fdfs/storage/bin/storaged /etc/fdfs/storage/storage.conf

#重啟tracker、storaged
/usr/local/fdfs/tracker/bin/restart.sh    /usr/local/fdfs/tracker/bin/trackerd    /etc/fdfs/tracker/tracker.conf
 /usr/local/fdfs/storage/bin/restart.sh  /usr/local/fdfs/storage/bin/storaged /etc/fdfs/storage/storage.conf


#停止tracker、storaged
/usr/local/fdfs/tracker/bin/stop.sh      /usr/local/fdfs/tracker/bin/trackerd    /etc/fdfs/tracker/tracker.conf
 /usr/local/fdfs/storage/bin/stop.sh   /usr/local/fdfs/storage/bin/storaged /etc/fdfs/storage/storage.conf

#監控storage
 /usr/local/fdfs/storage/bin/fdfs_monitor  /etc/fdfs/storage/storage.conf

#如果存在多個多個組,只需要監控其中一個組,就能調出所有組的狀態
#刪除組內伺服器storage和檢視各個組內伺服器狀態
 /usr/local/fdfs/storage/bin/fdfs_monitor /etc/fdfs/tracker/client.conf  delete group2 192.168.127.13
 /usr/local/fdfs/storage/bin/fdfs_monitor /etc/fdfs/tracker/client.conf

storage server有7個狀態,如下(數值從1~7):
# FDFS_STORAGE_STATUS:INIT      :初始化,尚未得到同步已有資料的源伺服器
# FDFS_STORAGE_STATUS:WAIT_SYNC :等待同步,已得到同步已有資料的源伺服器
# FDFS_STORAGE_STATUS:SYNCING   :同步中
# FDFS_STORAGE_STATUS:DELETED   :已刪除,該伺服器從本組中摘除
# FDFS_STORAGE_STATUS:OFFLINE   :離線
# FDFS_STORAGE_STATUS:ONLINE    :線上,尚不能提供服務
# FDFS_STORAGE_STATUS:ACTIVE    :線上,可以提供服務