歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

fastdfs_v4.06分布式文件系統的安裝及配置

fastdfs_v4.06分布式文件系統的安裝及配置   整體網絡配置   1 Tracker Server        192.168.127.11        /home/tracker 端口:22122 2 Storage1 Server       192.168.127.12 group1 /home/storage 端口:23000 3 Storage2 -Server1(源)  192.168.127.13 group2 /home/storage 端口:23000 4 Storage2 -Server2     192.168.127.14 group2 /home/storage 端口:23000 5 注意: 6 1.Storage2 同組的fastdfs服務的端口必須一致: port=23000 7 2.一台服務器可以裝多個組但不能裝同組的多個Storage,日志會報錯誤 8 3.Version 4.05之前fastdfs內部綁定了libevent作為http服務器.Version 4.05之後的版本刪除了內置的web http服務 01 #軟件安裝包存儲: 02 /usr/local/src 03 /usr/local/fastdfs  fastdfs安裝目錄 04   05 #基本目錄列表: 06 #創建fastdfs用戶 07 /usr/sbin/groupadd fastdfs 08 /usr/sbin/useradd -g fastdfs fastdfs 09 #創建存儲數據目錄 10 mkdir -p /home/fastdfs/tracker;#創建tracker目錄保存運行日志 11 mkdir -p /home/fastdfs/storage;#創建Storage目錄保存運行日志及其data數據 12   13 為方便查找目錄,設置變量 14 # vi .bashrc 15 alias  worksrc='cd /usr/local/src;ls' 16 alias  workfastdfs='cd /usr/local/fastdfs;ls' 17 alias  worktracker='cd /home/fastdfs/tracker;ls' 18 alias  workstorage='cd /home/fastdfs/storage;ls' 19 #track啟動 重啟 停止 20 alias  sertracker='service fdfs_trackerd' 21 #storage啟動 重啟 停止 22 alias  serstorage='service fdfs_storaged' 23 配置生效 24 # source .bashrc 安裝libevent 和 fastdfs 首先安裝libevent. fastdfs在編譯源程序時fastdfs內部調用libevent的處理機制,,需要用到libevent一些依賴文件,否則編譯fastdfs會出錯 01 ##卸載系統自帶libevent,自帶版本過低,安裝fastdfs會出錯 02 rpm -qa|grep libevent;yum remove libevent* 03 #下載安裝libevent 04 worksrc; 05 wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz; 06 tar -zxvf libevent-2.0.19-stable.tar.gz; 07 cd libevent-2.0.19-stable; 08 make clean; 09 ./configure --prefix=/usr/local/libevent 10 make && make install; 11 ##為libevent創建軟鏈接到/lib庫下,64位系統對應/lib64 12 ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5 13 ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5 14 # 15 命令匯總:worksrc;wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz;tar -zxvf libevent-2.0.19-stable.tar.gz;cd libevent-2.0.19-stable;make clean;./configure --prefix=/usr/local/libevent;make && make install;cd ../ 安裝fastdfs的步驟 1 wget http://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz 2 tar -zxvf FastDFS_v4.06.tar.gz 3 cd FastDFS 由於定義/usr/local/fastdfs為fastdfs安裝目錄,所以需要修改make.sh   1 vim make.sh 2 TARGET_PREFIX=/usr/local 修改為 /usr/local/fastdfs 3 TARGET_CONF_PATH=/etc/fdfs 修改為 /usr/local/fastdfs/conf 4 /etc/fdfs 全部替換為 /usr/local/fastdfs/conf 5 #安裝 6 ./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib 7 ./make.sh install 安裝Tracker Server -192.168.127.11 引用上例中安裝libevent 和 fastdfs步驟 配置及啟動Tracker Server,端口:22122 01 #修改tracker.conf配置 02 vim /usr/local/fastdfs/conf/tracker.conf 03 # the tracker server port 04 port=22122 05 # the base path to store data and log files 06 base_path=/home/yuqing/fastdfs -> base_path=/home/fastdfs/tracker #日志目錄 07 reserved_storage_space = 4GB -> reserved_storage_space = 1GB 08 #unix group name to run this program, 09 #not set (empty) means run by the group of current user 10 run_by_group= -> fastdfs 11 #unix username to run this program, 12 #not set (empty) means run by current user 13 run_by_user= -> fastdfs 14 #開啟自定義server ID取代ip形式,方便內部網絡服務器更換ip 15 use_storage_id = true #使用server ID作為storage server標識 16 storage_ids_filename = storage_ids.conf #<id> <group_name> <ip_or_hostname> 17 id_type_in_filename = id #文件名反解析中包含server ID,以前是ip 18 #PHP擴展支持連接池 19 use_connection_pool = true 20 connection_pool_max_idle_time = 3600 21 # 22 #移動storage_ids.conf文件 23 cp -r /usr/local/src/FastDFS/conf/storage_ids.conf /usr/local/fastdfs/conf/ 24 #編輯storage服務器ID與IP地址的對應關系 25 vim /usr/local/fastdfs/conf/storage_ids.conf 26 #<id> <group_name> <ip_or_hostname> 27  100001          group1           192.168.205.12 28  100002          group2           192.168.205.13 29  100003          group2           192.168.205.14 1 # base_path 附目錄說明: 2   tracker server目錄及文件結構: 3   ${base_path} 4     |__data 5     |     |__storage_groups.dat:存儲分組信息 6     |     |__storage_servers.dat:存儲服務器列表 7     |__logs 8           |__trackerd.log:tracker server日志文件 啟動Tracker Server 1 chown -R fastdfs:fastdfs /home/fastdfs 01 #啟動腳本 02 vim /etc/init.d/fdfs_trackerd 03 #增加下面的內容 04 #!/bin/bash 05 # 06 # fdfs_trackerd Starts fdfs_trackerd 07 # 08 # 09 # chkconfig: 2345 99 01 10 # description: FastDFS tracker server 11 ### BEGIN INIT INFO 12 # Provides: $fdfs_trackerd 13 ### END INIT INFO 14 # Source function library. 15 . /etc/init.d/functions 16 FastDfs='/usr/local/fastdfs' 17 CONF="$FastDfs/conf/tracker.conf" 18 if [ ! -f $CONF ]; then 19   echo "file $CONF does not exist!" 20   exit 2 21 fi 22 PRG="$FastDfs/bin/fdfs_trackerd" 23 if [ ! -f $PRG ]; then 24   echo "file $PRG does not exist!" 25   exit 2 26 fi 27 Stop="$FastDfs/bin/stop.sh" 28 if [ ! -f $Stop ]; then 29   echo "file $Stop does not exist!" 30   exit 2 31 fi 32 Restart="$FastDfs/bin/restart.sh" 33 if [ ! -f $Restart ]; then 34   echo "file $Restart does not exist!" 35   exit 2 36 fi 37 RETVAL=0 38 start() { 39     echo -n $"Starting FastDFS tracker server: " 40     $PRG $CONF & 41     RETVAL=$? 42     echo 43     return $RETVAL 44 } 45 stop() { 46     echo -n $"Stop FastDFS tracker server: " 47     $Stop $PRG $CONF 48     RETVAL=$? 49     return $RETVAL 50 } 51 rhstatus() { 52     status fdfs_trackerd 53 } 54 restart() { 55         $Restart $PRG $CONF & 56 } 57 case "$1" in 58   start) 59     start 60     ;; 61   stop) 62     stop 63     ;; 64   status) 65     rhstatus 66     ;; 67   restart|reload) 68     restart 69     ;; 70   condrestart) 71     restart 72     ;; 73   *) 74     echo $"Usage: $0 {start|stop|status|restart|condrestart}" 75     exit 1 76 esac 77 exit $? 78 # 79 #增加x權限 80 chmod a+x /etc/init.d/fdfs_trackerd 1 #啟動成功,加入開機啟動 2 # vim /etc/rc.d/rc.local 3 service fdfs_trackerd start 4 #啟動過程中出現的錯誤 5 #./fdfs_trackerd: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory 6 #解決辦法 7 ln -s /usr/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5 #檢查tracker是否啟動成功,可以查看如下文件 1 vim /home/fastdfs/tracker/logs/trackerd.log 2 #[2012-08-26 19:01:30] INFO - FastDFS v4.06, base_path=/home/fastdfs/tracker, run_by_group=fastdfs, run_by_user=fastdfs, 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=10.00%, 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, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, use_storage_id=1, id_type_in_filename=id, storage_id_count=1, rotate_error_log=0, error_log_rotate_time=00:00, rotate_error_log_size=0, store_slave_file_use_link=0, use_connection_pool=1, g_connection_pool_max_idle_time=3600s 安裝Storage Server -192.168.127.12 配置及啟動存儲服務(Storage Server)   引用上例中安裝libevent 和 fastdfs步驟 01 #修改storage.conf配置 02 vim /usr/local/fastdfs/conf/storage.conf 03 # the name of the group this storage server belongs to 04 group_name=group1 05 # the name of the group this storage server belongs to 06 # the storage server port #the storage server port 07 port=23000 08 # the base path to store data and log files #日志目錄 09 base_path=/home/yuqing/fastdfs -> /home/fastdfs/storage 10 # store_path#, based 0, if store_path0 not exists, it's value is base_path #data數據存儲目錄 11 # the paths must be exist 12 store_path0=/home/fastdfs/storage 13 #unix group name to run this program, 14 #not set (empty) means run by the group of current user 15 run_by_group= -> fastdfs 16 #unix username to run this program, 17 #not set (empty) means run by current user 18 run_by_user= -> fastdfs 19 # tracker_server can ocur more than once, and tracker_server format is 20 #  "host:port", host can be hostname or ip address 21 tracker_server=192.168.209.121:22122 -> tracker_server=192.168.127.11:22122 01 # base_path 附目錄說明: 02   tracker server目錄及文件結構: 03   ${base_path} 04     |__data 05     |     |__storage_stat.dat:本地存儲信息 06     |     |__sync 07     |           |__ binlog.000 08     |           |__ binlog.index 09     |__logs 10           |__storaged.log:storage server日志文件 01 #編輯啟動腳本 02 vim /etc/init.d/fdfs_storaged 03 #增加下面的內容 04 #!/bin/bash 05 # 06 # fdfs_storaged Starts fdfs_storaged 07 # 08 # 09 # chkconfig: 2345 99 01 10 # description: FastDFS storage server 11 ### BEGIN INIT INFO 12 # Provides: $fdfs_storaged 13 ### END INIT INFO 14 # Source function library. 15 . /etc/init.d/functions 16 FastDfs='/usr/local/fastdfs' 17 CONF="$FastDfs/conf/storage.conf" 18 if [ ! -f $CONF ]; then 19   echo "file $CONF does not exist!" 20   exit 2 21 fi 22 PRG="$FastDfs/bin/fdfs_storaged" 23 if [ ! -f $PRG ]; then 24   echo "file $PRG does not exist!" 25   exit 2 26 fi 27 Stop="$FastDfs/bin/stop.sh" 28 if [ ! -f $Stop ]; then 29   echo "file $Stop does not exist!" 30   exit 2 31 fi 32 Restart="$FastDfs/bin/restart.sh" 33 if [ ! -f $Restart ]; then 34   echo "file $Restart does not exist!" 35   exit 2 36 fi 37 RETVAL=0 38 start() { 39     echo -n $"Starting FastDFS storage server: " 40     $PRG $CONF & 41     RETVAL=$? 42     echo 43     return $RETVAL 44 } 45 stop() { 46     echo -n $"Stop FastDFS storage server: " 47     $Stop $PRG $CONF 48     RETVAL=$? 49     return $RETVAL 50 } 51 rhstatus() { 52     status fdfs_storaged 53 } 54 restart() { 55         $Restart $PRG $CONF & 56 } 57 case "$1" in 58   start) 59     start 60     ;; 61   stop) 62     stop 63     ;; 64   status) 65     rhstatus 66     ;; 67   restart|reload) 68     restart 69     ;; 70   condrestart) 71     restart 72     ;; 73   *) 74     echo $"Usage: $0 {start|stop|status|restart|condrestart}" 75     exit 1 76 esac 77 exit $? 78 # 79 #增加x權限 80 chmod a+x /etc/init.d/fdfs_storaged 01 #啟動storage 02 service fdfs_storaged restart 03 #接下來會出現很多mkdir data path,這是系統在創建數據目錄 04 data path: /home/fastdfs/storage/data, mkdir sub dir... 05 mkdir data path: 00 ... 06 mkdir data path: 01 ... 07 mkdir data path: 02 ... 08 mkdir data path: 03 ... 09 ....................... 10 data path: /home/fastdfs/storage/data, mkdir sub dir done. 1 #啟動成功,加入開機啟動 2 # vim /etc/rc.d/rc.local 3 service fdfs_storaged restart 安裝Storage Server -192.168.127.13 配置及啟動存儲服務(Storage Server)   引用上例中安裝libevent 和 fastdfs步驟 01 #修改storage.conf配置 02 vim /usr/local/fastdfs/conf/storage.conf 03 # the name of the group this storage server belongs to 04 group_name=group2 05 # the name of the group this storage server belongs to 06 # the storage server port #the storage server port 07 port=23000 08 # the base path to store data and log files #日志目錄 09 base_path=/home/yuqing/fastdfs -> /home/fastdfs/storage 10 # store_path#, based 0, if store_path0 not exists, it's value is base_path #data數據存儲目錄 11 # the paths must be exist 12 store_path0=/home/fastdfs/storage 13 #unix group name to run this program, 14 #not set (empty) means run by the group of current user 15 run_by_group= -> fastdfs 16 #unix username to run this program, 17 #not set (empty) means run by current user 18 run_by_user= -> fastdfs 19 # tracker_server can ocur more than once, and tracker_server format is 20 #  "host:port", host can be hostname or ip address 21 tracker_server=192.168.209.121:22122 -> tracker_server=192.168.127.11:22122 01 # base_path 附目錄說明: 02   tracker server目錄及文件結構: 03   ${base_path} 04     |__data 05     |     |__storage_stat.dat:本地存儲信息 06     |     |__sync 07     |           |__ binlog.000 08     |           |__ binlog.index 09     |__logs 10           |__storaged.log:storage server日志文件 01 #啟動storage 02 service fdfs_storaged restart 03 #接下來會出現很多mkdir data path,這是系統在創建數據目錄 04 data path: /home/fastdfs/storage/data, mkdir sub dir... 05 mkdir data path: 00 ... 06 mkdir data path: 01 ... 07 mkdir data path: 02 ... 08 mkdir data path: 03 ... 09 ....................... 10 data path: /home/fastdfs/storage/data, mkdir sub dir done. 1 #啟動成功,加入開機啟動 2 # vim /etc/rc.d/rc.local 3 service fdfs_storaged restart 安裝Storage Server -192.168.127.14 配置及啟動存儲服務(Storage Server)   引用上例中安裝libevent 和 fastdfs步驟 01 #修改storage.conf配置 02 vim /usr/local/fastdfs/conf/storage.conf 03 # the name of the group this storage server belongs to 04 group_name=group2 05 # the name of the group this storage server belongs to 06 # the storage server port #the storage server port 07 port=23000 08 # the base path to store data and log files #日志目錄 09 base_path=/home/yuqing/fastdfs -> /home/fastdfs/storage 10 # store_path#, based 0, if store_path0 not exists, it's value is base_path #data數據存儲目錄 11 # the paths must be exist 12 store_path0=/home/fastdfs/storage 13 #unix group name to run this program, 14 #not set (empty) means run by the group of current user 15 run_by_group= -> fastdfs 16 #unix username to run this program, 17 #not set (empty) means run by current user 18 run_by_user= -> fastdfs 19 # tracker_server can ocur more than once, and tracker_server format is 20 #  "host:port", host can be hostname or ip address 21 tracker_server=192.168.209.121:22122 -> tracker_server=192.168.127.11:22122 01 # base_path 附目錄說明: 02   tracker server目錄及文件結構: 03   ${base_path} 04     |__data 05     |     |__storage_stat.dat:本地存儲信息 06     |     |__sync 07     |           |__ binlog.000 08     |           |__ binlog.index 09     |__logs 10           |__storaged.log:storage server日志文件 01 #啟動storage 02 service fdfs_storaged restart 03 #接下來會出現很多mkdir data path,這是系統在創建數據目錄 04 data path: /home/fastdfs/storage/data, mkdir sub dir... 05 mkdir data path: 00 ... 06 mkdir data path: 01 ... 07 mkdir data path: 02 ... 08 mkdir data path: 03 ... 09 ....................... 10 data path: /home/fastdfs/storage/data, mkdir sub dir done. 1 #啟動成功,加入開機啟動 2 # vim /etc/rc.d/rc.local 3 service fdfs_storaged restart 測試及使用fastdfs-192.168.127.11 fastdfs之配置client 1 vim /usr/local/fastdfs/conf/client.conf 2 base_path=/home/yuqing/fastdfs-> base_path=/home/fastdfs/tracker 3 tracker_server=192.168.209.121:22122 -> tracker_server=192.168.127.11:22122 1 cd /usr/local/bin 2 vim aa.txt 增加內容:展示aa.txt文本數據   :wq 3 ./fdfs_test /usr/local/fastdfs/conf/client.conf upload aa.txt 執行成功後會出現如下提示:   01 # ./fdfs_test /usr/local/fastdfs/conf/client.conf upload aa.txt 02 [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 03 tracker_query_storage_store_list_without_group: 04         server 1. group_name=group2, ip_addr=192.168.127.13, port=23000 05 group_name=group2, ip_addr=192.168.127.6, port=23000 06 storage_upload_by_filename 07 group_name=group2, remote_filename=M00/00/00/wKh_BlA3wxql4hTXAAAAB8v-VvY710.txt 08 source ip address: 192.168.127.13 09 file timestamp=2012-08-25 02:08:26 10 file size=7 11 file crc32=3422443254 12 file url: 13 storage_upload_slave_by_filename 14 group_name=group2, remote_filename=M00/00/00/wKh_BlA3wxql4hTXAAAAB8v-VvY710_big.txt 15 source ip address: 192.168.127.6 16 file timestamp=2012-08-25 02:08:26 17 file size=7 18 file crc32=3422443254 19 file url: 1 執行過程中可能出現防火牆封口: 2 # ERROR - file: tracker_proto.c, line: 420, connect to 192.168.127.11:22122 fail, errno: 113, error info: No route to host 3 解決: 4 iptables -L;iptables -F;service iptables stop 測試下載文件 在浏覽器中,輸入上圖中的url地址, tracker server會自動重定向到存儲文件的storage server,文件下載成功。至此,已經成功搭建了fastdfs,編寫你自己的client來進行訪問吧: 1 展示aa.txt文本數據 常規命令范例: 01 #監控storage 02 /usr/local/fastdfs/bin/fdfs_monitor /usr/local/fastdfs/conf/storage.conf 03 #如果存在多個多個組,只需要監控其中一個組,就能調出所有組的狀態 04   05 #刪除組內服務器storage和查看各個組內服務器狀態 06 /usr/local/fastdfs/bin/fdfs_monitor /usr/local/fastdfs/conf/client.conf delete group2 192.168.127.13 07 /usr/local/fastdfs/bin/fdfs_monitor /usr/local/fastdfs/conf/client.conf 08 storage server有7個狀態,如下(數值從1~7): 09 # FDFS_STORAGE_STATUS:INIT      :初始化,尚未得到同步已有數據的源服務器 10 # FDFS_STORAGE_STATUS:WAIT_SYNC :等待同步,已得到同步已有數據的源服務器 11 # FDFS_STORAGE_STATUS:SYNCING   :同步中 12 # FDFS_STORAGE_STATUS:DELETED   :已刪除,該服務器從本組中摘除 13 # FDFS_STORAGE_STATUS:OFFLINE   :離線 14 # FDFS_STORAGE_STATUS:ONLINE    :在線,尚不能提供服務 15 # FDFS_STORAGE_STATUS:ACTIVE    :在線,可以提供服務    
Copyright © Linux教程網 All Rights Reserved