http://github.com/happyfish100
Ô´ÂëÎļþ
ËùÓеݲװ¶¼ÊÇÒ»¸ö°²×°°ü£¬Ö»ÊÇÆô¶¯µÄ·þÎñ²»Í¬¶øÒÑ
·þÎñ¶Ë°²×°ÅäÖãº
´ÓgithubÉÏÏÂÔØlib¿â°²×°£º
https://github.com/happyfish100/libfastcommon.git
°²×°ÒÀÀµ°ü£º
cd /usr/local/src/fastdfs
# unzip libfastcommon-master.zip
#./make.sh
#./make.sh install
´ÓgibhubÉÏÏÂÔØ °²×°°ü:£¨Ã¿Ì¨°²×°¶¼Ò»Ñù£©
[root@node120 fastdfs]# ls
fastdfs-5.05 fastdfs-5.05.tar.gz libfastcommon-master
[root@node120 fastdfs]# cd fastdfs-5.05
[root@node120 fastdfs-5.05]# ls
COPYING-3_0.txt INSTALL client conf init.d php_client stop.sh test
HISTORY README.md common fastdfs.spec make.sh restart.sh storage tracker
[root@node120 fastdfs-5.05]# ./make.sh
[root@node120 fastdfs-5.05]# ./make.sh install
ÅäÖÃÎļþ£º
[root@node120 fastdfs-5.05]# cd /etc/fdfs/
[root@node120 fdfs]# ls
client.conf.sample storage.conf.sample tracker.conf.sample
ÃüÁ
[root@node120 fdfs]# ls /usr/bin/fdfs_
fdfs_append_file fdfs_crc32 fdfs_file_info fdfs_test fdfs_upload_appender
fdfs_appender_test fdfs_delete_file fdfs_monitor fdfs_test1 fdfs_upload_file
fdfs_appender_test1 fdfs_download_file fdfs_storaged fdfs_trackerd
Æô¶¯½Å±¾ÎļþλÖãº
[root@node120 fdfs]# ls /etc/init.d/fdfs_
fdfs_storaged fdfs_trackerd
ÐÞ¸ÄÆô¶¯½Å±¾Â·¾¶:
[root@node120 fdfs]# sed -i's#/usr/local/bin/#/usr/bin/#g' /etc/init.d/fdfs_storaged
[root@node120 fdfs]# sed -i's#/usr/local/bin/#/usr/bin/#g' /etc/init.d/fdfs_trackerd
´´½¨´æ´¢ºÍÈÕ־Ŀ¼£º
[root@node120 data]# mkdir -p /data/fdfs_tracker
[root@node120 data]# mkdir -p /data/fdfs_storage
[root@node120 data]#mkdir -p /data/fdfs_storage/base
[root@node120 fdfs]# mkdir -p /data/fdfs_storage/store
[root@node120 fdfs]# mkdir /data/fdfs_client_log
ÐÞ¸ÄÅäÖÃÎļþ£º
[root@node120 fdfs]# cd /etc/fdfs/
[root@node120 fdfs]# ls
client.conf.sample storage.conf.sample tracker.conf.sample
[root@node120 fdfs]# cp tracker.conf.sampletracker.conf
vim tracker.conf
21 # the base path to store data and log files
22base_path=/data/fdfs_tracker
Æô¶¯tracker·þÎñ£º
[root@node120 fdfs]# /etc/init.d/fdfs_trackerd start
Starting FastDFS tracker server:
²é¿´¶Ë¿Ú£º
[root@node120 fdfs]# lsof -i:22122
COMMAND PIDUSER FD TYPE DEVICE SIZE/OFF NODE NAME
fdfs_trac 2701 root 5u IPv4 21510 0t0 TCP *:22122 (LISTEN)
Æô¶¯´æ´¢·þÎñ£º
[root@node120 fdfs]# /etc/init.d/fdfs_storaged start
[root@node120 fdfs]# lsof -i:23000
COMMAND PIDUSER FD TYPE DEVICE SIZE/OFF NODE NAME
fdfs_stor 3403 root 5u IPv4 92413 0t0 TCP *:inovaport1 (LISTEN)
¿Í»§¶Ë°²×°ÅäÖÃ(Èí¼þ×Ô´øC¿Í»§¶Ë)£º
ÐÞ¸ÄÅäÖÃÎļþ£º
[root@node120 fdfs]# ls
client.conf.sample storage.conf storage.conf.sample tracker.conf tracker.conf.sample
[root@node120 fdfs]# cp client.conf.sampleclient.conf
vim client.conf
9 # the basepath to store log files
10base_path=/data/fdfs_client_log
11
12 #tracker_server can ocur more than once, and tracker_server format is
13 # "host:port", host can be hostnameor ip address
14tracker_server=192.168.2.120:22122
15tracker_server=192.168.2.121:22122
ÉÏ´«Îļþ£º
[root@node120 fdfs]# fdfs_upload_file
Usage: fdfs_upload_file <config_file><local_filename> [storage_ip:port] [store_path_index]
[root@node120 fdfs]# fdfs_upload_file/etc/fdfs/client.conf /etc/passwd
group1/M00/00/00/wKgCeFhu8haAF4HhAAAG0Jjs4Jk9559117 #ÎļþID
group1:×éÃû
[root@node120 00]# pwd
/data/fdfs_storage/store/data/00/00
[root@node120 00]# ls
wKgCeFhu8haAF4HhAAAG0Jjs4Jk9559117
²é¿´´æ´¢µÄÎļþµÄλÖãº
[root@node120 fdfs]# cd /data/fdfs_storage/store/
[root@node120 store]# ls
data
[root@node120 store]# cd data
[root@node120 data]# ls
00 09 12 1B 24 2D 36 3F 48 51 5A 63 6C 75 7E 87 90 99 A2 AB B4 BD C6 CF D8 E1 EA F3 FC
01 0A 13 1C 25 2E 37 40 49 52 5B 64 6D 76 7F 88 91 9A A3 AC B5 BE C7 D0 D9 E2 EB F4 FD
02 0B 14 1D 26 2F 38 41 4A 53 5C 65 6E 77 80 89 92 9B A4 AD B6 BF C8 D1 DA E3 EC F5 FE
03 0C 15 1E 27 30 39 42 4B 54 5D 66 6F 78 81 8A 93 9C A5 AE B7 C0 C9 D2 DB E4 ED F6 FF
04 0D 16 1F 28 31 3A 43 4C 55 5E 67 70 79 82 8B 94 9D A6 AF B8 C1 CA D3 DC E5 EE F7
05 0E 17 20 29 32 3B 44 4D 56 5F 68 71 7A 83 8C 95 9E A7 B0 B9 C2 CB D4 DD E6 EF F8
06 0F 18 21 2A 33 3C 45 4E 57 60 69 72 7B 84 8D 96 9F A8 B1 BA C3 CC D5 DE E7 F0 F9
07 10 19 22 2B 34 3D 46 4F 58 61 6A 73 7C 85 8E 97 A0 A9 B2 BB C4 CD D6 DF E8 F1 FA
08 11 1A 23 2C 35 3E 47 50 59 62 6B 74 7D 86 8F 98 A1 AA B3 BC C5 CE D7 E0 E9 F2 FB
[root@node120 data]# pwd
/data/fdfs_storage/store/data
²é¿´Îļþ£º£¨ÉÏ´«µÄÎļþ²»»á¸Ä±äÎļþÄÚÈÝ£¬Ö»ÐÞ¸ÄÁËÎļþÃû£©
[root@node120 00]# catwKgCeFhu8haAF4HhAAAG0Jjs4Jk9559117
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
ÏÂÔØÎļþ£º
[root@node120 ~]# fdfs_download_file/etc/fdfs/client.conf group1/M00/00/00/wKgCeFhu8haAF4HhAAAG0Jjs4Jk9559117
[root@node120 ~]# catwKgCeFhu8haAF4HhAAAG0Jjs4Jk9559117 # ÏÂÔصÄÎļþÃû
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
¾md5sum¼ìÑ飬ÎļþûÓÐÐ޸ģº
´æ´¢ÔÚfdfsÖеÄMD5:
[root@node121 00]# md5sumwKgCeFhu8haAF4HhAAAG0Jjs4Jk9559117
452cd1ad6be44513daaa6c887ceb7bfa wKgCeFhu8haAF4HhAAAG0Jjs4Jk9559117
ÏÂÔغóµÄmd5Öµ£º
[root@node120 ~]# md5sumwKgCeFhu8haAF4HhAAAG0Jjs4Jk9559117
452cd1ad6be44513daaa6c887ceb7bfa wKgCeFhu8haAF4HhAAAG0Jjs4Jk9559117
²é¿´ÎļþµÄÊôÐÔ£º
[root@node120 ~]# fdfs_file_info /etc/fdfs/client.confgroup1/M00/00/00/wKgCeFhu8haAF4HhAAAG0Jjs4Jk9559117
source storage id: 0
source ip address: 192.168.2.120
file create timestamp: 2017-01-06 09:25:42
file size: 1744
file crc32: 2565660825 (0x98ECE099)
ÎļþµÄɾ³ý£º
[root@node120 ~]# fdfs_delete_file/etc/fdfs/client.conf group1/M00/00/00/wKgCeFhu8haAF4HhAAAG0Jjs4Jk9559117
µ½¶ÔӦĿ¼Ï²鿴£¬ÎļþÒÑɾ³ý£º
[root@node120 00]# pwd
/data/fdfs_storage/store/data/00/00
[root@node120 00]# ls
Îļþ×·¼Ó£º
[root@node120 ~]# echo "hello">append.txt
[root@node120 ~]# echo "world">append2.txt
ÒÔ×·¼ÓµÄ·½Ê½ÉÏ´«Îļþ£º
[root@node120 ~]# fdfs_upload_appender/etc/fdfs/client.conf append.txt
group1/M00/00/00/wKgCeVhu9myEZY9zAAAAAHcc3SA000.txt
[root@node120 ~]# fdfs_download_file/etc/fdfs/client.conf group1/M00/00/00/wKgCeVhu9myEZY9zAAAAAHcc3SA000.txt
hello
×·¼ÓÎļþÄÚÈÝ£º
[root@node120 ~]# fdfs_append_file/etc/fdfs/client.conf group1/M00/00/00/wKgCeVhu9myEZY9zAAAAAHcc3SA000.txtappend2.txt
ÏÂÔØ×·¼ÓºóµÄÎļþ£º
[root@node120 ~]# fdfs_download_file/etc/fdfs/client.conf group1/M00/00/00/wKgCeVhu9myEZY9zAAAAAHcc3SA000.txt
[root@node120 ~]# ls
anaconda-ks.cfg db.sql.gz install.log.syslog test-position.sql tests.sql
append.txt grep.log q.sh test.sh wKgCeFhu8haAF4HhAAAG0Jjs4Jk9559117
append2.txt hello.go rsc.sh test.sql wKgCeVhu9myEZY9zAAAAAHcc3SA000.txt
db.sql image.baidu.com seqnum.sh test_2596.txt
²é¿´×·¼ÓºóµÄÎļþÄÚÈÝ£º
[root@node120 ~]# catwKgCeVhu9myEZY9zAAAAAHcc3SA000.txt
hello
world
Òª¿´ÎļþµÄÊôÐÔ£º
[root@node120 ~]# fdfs_file_info /etc/fdfs/client.confgroup1/M00/00/00/wKgCeVhu9myEZY9zAAAAAHcc3SA000.txt
source storage id: 0
source ip address: 192.168.2.121
file create timestamp: 2017-01-06 09:47:15
file size: 12
file crc32: 1998380320 (0x771CDD20)
²é¿´ËùÓнڵãµÄ״̬£º
[root@node120 ~]# fdfs_monitor /etc/fdfs/client.conf
[2017-01-06 09:54:01] DEBUG -base_path=/data/fdfs_client_log, connect_timeout=30, network_timeout=60,tracker_server_count=2, 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
server_count=2, server_index=0
tracker server is 192.168.2.120:22122
group count: 1
Group 1:
group name = group1
disk total space = 50268 MB
disk free space = 36047 MB
trunk free space = 0 MB
storage server count = 2
active server count = 2
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0
Storage1:
¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£¡£
ɾ³ýÒ»¸ö´æ´¢½Úµã£º
1.ÏÈÍ£Ö¹½ÚµãµÄ·þÎñ£º
[root@node121 00]# /etc/init.d/fdfs_storaged stop
stopping fdfs_storaged ...
.
2.ÔÙÔÚɾ³ý½Úµã£º
[root@node120 ~]# fdfs_monitor /etc/fdfs/client.confdelete group1 192.168.2.121
[2017-01-06 10:01:03] DEBUG -base_path=/data/fdfs_client_log, connect_timeout=30, network_timeout=60,tracker_server_count=2, 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
server_count=2, server_index=1
tracker server is 192.168.2.121:22122
delete storage server group1::192.168.2.121 success
²é¿´½ÚµãÊÇ·ñɾ³ý£º
[root@node120 ~]# fdfs_monitor /etc/fdfs/client.conf
Storage2:
id= 192.168.2.121
ip_addr= 192.168.2.121 DELETED
httpdomain =
version= 5.05
ÖØÐÂÆô¶¯½Úµã£º
[root@node121 00]# /etc/init.d/fdfs_storaged start
Starting FastDFS storage server:
ÔÙ´ÎÔÙ¿´½Úµã״̬£º
[root@node120 ~]# fdfs_monitor /etc/fdfs/client.conf
[root@node121 00]# /etc/init.d/fdfs_storaged start
Starting FastDFS storage server:
Storage2:
id= 192.168.2.121
ip_addr= 192.168.2.121 ACTIVE
httpdomain =
version= 5.05
PHP¿Í»§¶ËʹÓ÷½·¨(Ìí¼ÓPHPÄ£¿é)£º
[root@node120 fastdfs-5.05]# cd php_client/
[root@node120 php_client]# ls
README fastdfs_appender_test1.php fastdfs_client.h fastdfs_test.php
config.m4 fastdfs_callback_test.php fastdfs_client.ini fastdfs_test1.php
fastdfs_appender_test.php fastdfs_client.c fastdfs_client.spec.in fastdfs_test_slave.php
[root@node120 php_client]#/usr/local/php-5.6.15/bin/phpize #±àÒëPHPÄ£¿é
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[root@node120 php_client]# ./configure--with-php-config=/usr/local/php-5.6.15/bin/php-config
[root@node120 php_client]# make && makeinstall
Installing shared extensions: /usr/local/php-5.6.15/lib/php/extensions/no-debug-zts-20131226/
[root@node120 ~]# cd/usr/local/php-5.6.15/lib/php/extensions/no-debug-zts-20131226/
[root@node120 no-debug-zts-20131226]# ls
fastdfs_client.so opcache.so
ÔÚÔ´Âë°üÖеÄPHPÅäÖÃÎļþ£º
[root@node120 php_client]# pwd
/usr/local/src/fastdfs/fastdfs-5.05/php_client
[root@node120 php_client]# cat fastdfs_client.ini
½«fastdfs_client.ini×·¼Óµ½php.iniÎļþÖУº
[root@node120 php_client]# cat fastdfs_client.ini>>/etc/php.ini
²âÊÔphpÓëfastdfsÊÇ·ñÕý³£µÄPHPÎļþ£º
[root@node120 php_client]# ll fastdfs_test.php
-rw-rw-r-- 1 root root 15907 Nov 22 2014 fastdfs_test.php
[root@node120 php_client]#/usr/local/php-5.6.15/bin/php fastdfs_test.php
²é¿´PHPÊÇ·ñ¼ÓÔØÁËfastdfsÄ£¿é£º
[root@node120 php_client]# /usr/local/php-5.6.15/bin/php-i |grep dfs
fastdfs_client
fastdfs_client v5.05 support => enabled
OLDPWD => /usr/local/src/fastdfs/fastdfs-5.05
PWD =>/usr/local/src/fastdfs/fastdfs-5.05/php_client
_SERVER["OLDPWD"] =>/usr/local/src/fastdfs/fastdfs-5.05
_SERVER["PWD"] => /usr/local/src/fastdfs/fastdfs-5.05/php_client
fastdfsÔÚphpÖеÄÓ÷¨¿ÉÒԲ鿴fastdfs_test.phpÎļþµÄÄÚÈÝ£º
[root@node120 php_client]# ll fastdfs_test.php
-rw-rw-r-- 1 root root 15907 Nov 22 2014 fastdfs_test.php
[root@node120 php_client]# pwd
/usr/local/src/fastdfs/fastdfs-5.05/php_client
JAVA¿Í»§¶ËʹÓ÷½·¨(Ìí¼ÓJAVAÄ£¿é)£º
½âѹ£º
[root@node120 fastdfs-client-java-master]# unzipfastdfs-client-java-master.zip
[root@node120 fastdfs-client-java-master]# pwd
/usr/local/src/fastdfs/fastdfs-client-java-master
[root@node120 fastdfs-client-java-master]# ls
README.md pom.xml src
[root@node120 fastdfs-client-java-master]#cd src
Ç°ÌâÊÇÒª°²×°ant
yum install ant
[root@node120 src]# ant
Buildfile: build.xml
init:
compile:
[mkdir]Created dir: /usr/local/src/fastdfs/fastdfs-client-java-master/src/build/classes
[javac]Compiling 32 source files to/usr/local/src/fastdfs/fastdfs-client-java-master/src/build/classes
[javac] Thisversion of java does not support the classic compiler; upgrading to modern
[javac]Note: Some input files use unchecked or unsafe operations.
[javac]Note: Recompile with -Xlint:unchecked for details.
jar:
[jar]Building jar:/usr/local/src/fastdfs/fastdfs-client-java-master/src/build/fastdfs_client.jar
BUILD SUCCESSFUL
Total time: 10 seconds
°²×°Íê³ÉºóÉú³Éjar°ü:
²âÊÔÊÇ·ñ¿ÉÓãº
[root@node120 src]# java -cp/usr/local/src/fastdfs/fastdfs-client-java-master/src/build/fastdfs_client.jar
ʹÓ÷½·¨£º
https://github.com/happyfish100/fastdfs-client-java/tree/master/src
Copyright (C) 2008 Happy Fish / YuQing
FastDFS Java Client API may be copied only under theterms of
the BSD license.
Please visit the FastDFS Home Page for more detail.
English language: http://english.csource.org/
Chinese language: http://www.csource.org/
The jar file is compiled by JDK1.5, you can downloadthe last version
from google code: http://code.google.com/p/fastdfs/downloads/list
run the FastDFS Java Client test:
java -cp <fastdfs_client_jar_filename>org.csource.fastdfs.test.TestClient <config_filename><upload_filename>
eg.:
java -cp fastdfs_client_v1.22.jarorg.csource.fastdfs.test.TestClient fdfs_client.confc:\windows\system32\notepad.exe
or:
java -cp fastdfs_client_v1.22.jarorg.csource.fastdfs.test.TestClient fdfs_client.conf /usr/include/stdlib.h
run the FastDFS monitor:#¼à¿Ø
java -cp <fastdfs_client_jar_filename>org.csource.fastdfs.test.Monitor <config_filename>
eg.:
java -cp fastdfs_client_v1.22.jarorg.csource.fastdfs.test.Monitor fdfs_client.conf