| 
	fastDFS下载地址:http://code.google.com/p/fastdfs/downloads/listlibevent官网: http://libevent.org/
 
	目前最新版:https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz目前最新版:http://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz
 
	系统环境:fastdfs_tracker       centos6.5_64 ip:192.168.1.50
 fastdfs_storage_s1 centos6.5_64 ip:192.168.1.51
 fastdfs_storage_s2 centos6.5_64 ip:192.168.1.52
 fastdfs_client           centos6.5_64 ip:192.168.1.54
 
	selinux关闭,iptables关闭。 
	配置tracker:先装libevent,后fastdfs
 
	
		
			
				
					| 
							1 
							2 
							3 
							4 
							5 
							6 
							7 
							8 | 
							
								[root@centos-6.5-x64 ~]#yum install -y gcc gcc-c++ 
								[root@centos-6.5-x64 ~]#tar zxvf libevent-2.0.21-stable 
								[root@centos-6.5-x64 ~]#tar zxvf FastDFS_v4.06.tar.gz 
								[root@centos-6.5-x64 ~]#cd libevent-2.0.21-stable 
								[root@centos-6.5-x64 libevent-2.0.21-stable]#./configure && make && make install 
								[root@centos-6.5-x64 libevent-2.0.21-stable]# cd 
								[root@centos-6.5-x64 ~]#cd FastDFS 
								[root@centos-6.5-x64 FastDFS]#sh make.sh && sh make.sh install |  
	fastdfs的配置文件路径默认在 /etc/fdfs/[root@centos-6.5-x64 ~]#cd /etc/fdfs/
 [root@centos-6.5-x64 fdfs]#ll
 总用量 56
 -rw-r–r– 1 root root 1463 4月 23 04:10 client.conf
 -rw-r–r– 1 root root 858 4月 23 04:10 http.conf
 -rw-r–r– 1 root root 31172 4月 23 04:10 mime.types
 -rw-r–r– 1 root root 7460 4月 23 04:10 storage.conf
 -rw-r–r– 1 root root 6621 4月 23 04:10 tracker.conf
 
	client.conf 客户端上传配置文件storage.conf 文件存储服务器配置文件
 tracker.conf 负责均衡调度服务器配置文件
 http.conf http服务器配置文件(可忽略不用)
 
	跟fastdfs相关的命令都在 /usr/local/bin/ 下 
	编辑tracker配置文件:[root@centos-6.5-x64 fdfs]#grep -v “#” tracker.conf | grep -v “^$”
 
	#tracker.conf 配置文件是否生效,false是生效,true是屏蔽。disabled=false
 
	#程序的监听地址,如果不设定则监听所有地址bind_addr=
 
	#tracker监听的端口port=22122
 
	#连接超时时间connect_timeout=30
 
	#tracker在通过网络发送接收数据的超时时间network_timeout=60
 
	#数据和日志的存放地点base_path=/home/yuqing/fastdfs
 
	#最大连接数max_connections=256
 
	#工作线程数一般为cpu个数work_threads=4
 
	#在存储文件时选择group的策略,0:轮训策略 1:指定某一个组 2:负载均衡,选择空闲空间最大的group.store_lookup=2
 
	#如果上面的store_lookup选择了1,则这里需要指定一个groupstore_group=group2
 
	#在group中的哪台storage做主storage,当一个文件上传到主storage后,就由这台机器同步文件到group内的其他storage上,0:轮训策略 1:根据ip地址排序,第一个 2:根据优先级排序,第一个store_server=0
 
	#选择文件上传到storage中的哪个(目录/挂载点),storage可以有多个存放文件的base path 0:轮训策略 2:负载均衡,选择空闲空间最大的store_path=0
 
	#选择那个storage作为主下载服务器,0:轮训策略 1:主上传storage作为主下载服务器download_server=0
 
	#系统预留空间,当一个group中的任何storage的剩余空间小于定义的值,整个group就不能上传文件了reserved_storage_space = 10%
 
	#日志信息级别log_level=info
 
	#进程以那个用户/用户组运行,不指定默认是当前用户run_by_group=
 run_by_user=
 
	#允许那些机器连接tracker默认是所有机器allow_hosts=*
 
	#设置日志信息刷新到disk的频率,默认10ssync_log_buff_interval = 10
 
	#检测storage服务器的间隔时间,storage定期主动向tracker发送心跳,如果在指定的时间没收到信号,tracker人为storage故障,默认120scheck_active_interval = 120
 
	#线程栈的大小,最小64Kthread_stack_size = 64KB
 
	#storage的ip改变后服务端是否自动调整,storage进程重启时才自动调整storage_ip_changed_auto_adjust = true
 
	#storage之间同步文件的最大延迟,默认1天storage_sync_file_max_delay = 86400
 
	#同步一个文件所花费的最大时间storage_sync_file_max_time = 300
 
	#是否用一个trunk文件存储多个小文件use_trunk_file = false
 
	#最小的solt大小,应该小于4KB,默认256bytesslot_min_size = 256
 
	#最大的solt大小,如果上传的文件小于默认值,则上传文件被放入trunk文件中slot_max_size = 16MB
 
	#trunk文件的默认大小,应该大于4Mtrunk_file_size = 64MB
 
	trunk_create_file_advance = falsetrunk_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
 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
 use_connection_pool = false
 connection_pool_max_idle_time = 3600
 
	#http服务是否生效,默认不生效,此项可能在4.0版本后剔除。不起作用且没有此行。http.disabled=false
 
	#http服务端口http.server_port=8080
 
	#检测storage上http服务的时间间隔,<=0表示不检测http.check_alive_interval=30
 
	#检测storage上http服务时所用请求的类型,tcp只检测是否可以连接,http必须返回200http.check_alive_type=tcp
 
	#通过url检测storage http服务状态http.check_alive_uri=/status.html
 
	#用include包含进http的其他设置,此项可能在4.0版本后剔除。不起作用。##include http.conf
 
	需要修改的地方是 base_path 改为自己的路径,这里改为:base_path=/mnt/fastdfs_tracker
 
	[root@centos-6.5-x64 fdfs]#mkdir /mnt/fastdfs_tracker启动tracker:
 [root@centos-6.5-x64 fdfs]#/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
 /usr/local/bin/fdfs_trackerd: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
 [root@centos-6.5-x64 ~]#find / -name libevent-2.0.so.5
 /root/libevent-2.0.21-stable/.libs/libevent-2.0.so.5
 /usr/local/lib/libevent-2.0.so.5
 [root@centos-6.5-x64 ~]#ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5 #找不到库文件,搜索一下软链接过去即可。
 [root@centos-6.5-x64 ~]#/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
 [root@centos-6.5-x64 ~]#
 [root@centos-6.5-x64 ~]#lsof -i:22122 #端口启动
 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
 fdfs_trac 8287 root 5u IPv4 40633 0t0 TCP *:22122 (LISTEN)
 
	配置storage_s1: 
	
		
			
				
					| 
							1 
							2 
							3 
							4 
							5 
							6 
							7 
							8 
							9 
							10 
							11 
							12 
							13 
							14 
							15 | 
							
								[root@centos-6.5-x64 ~]#tar zxvf libevent-2.0.21-stable 
								[root@centos-6.5-x64 ~]#tar zxvf FastDFS_v4.06.tar.gz 
								[root@centos-6.5-x64 ~]#cd libevent-2.0.21-stable 
								[root@centos-6.5-x64 libevent-2.0.21-stable]#./configure && make && make install 
								[root@centos-6.5-x64 libevent-2.0.21-stable]#cd 
								[root@centos-6.5-x64 ~]#cd FastDFS 
								[root@centos-6.5-x64 FastDFS]#sh make.sh && sh make.sh install 
								[root@centos-6.5-x64 FastDFS]#cd /etc/fdfs/ 
								[root@centos-6.5-x64 fdfs]#ll 
								总用量 56 
								-rw-r--r-- 1 root root 1463 4月 23 04:52 client.conf 
								-rw-r--r-- 1 root root 858 4月 23 04:52 http.conf 
								-rw-r--r-- 1 root root 31172 4月 23 04:52 mime.types 
								-rw-r--r-- 1 root root 7460 4月 23 04:52 storage.conf 
								-rw-r--r-- 1 root root 6621 4月 23 04:52 tracker.conf |  
	[root@centos-6.5-x64 fdfs]#grep -v “#” storage.conf | grep -v “^$”#是否启用配置文件
 disabled=false
 
	#这个storage服务器属于那个groupgroup_name=group1
 
	#监听地址,不写,监听全部bind_addr=
 
	#连接其他服务器时是否绑定地址,bind_addr配置时本参数才有效client_bind=true
 
	#storage默认端口port=23000
 
	#连接超时时间connect_timeout=30
 
	#storage在通过网络发送接收数据的超时时间network_timeout=60
 
	#主动向tracker发送心跳检测的时间间隔heart_beat_interval=30
 
	#主动向tracker发送磁盘使用率的时间间隔stat_report_interval=60
 
	#数据存储路径base_path=/home/yuqing/fastdfs
 
	#最大连接数max_connections=256
 
	#接收/发送数据的buff大小,必须大于8KBbuff_size = 256KB
 
	#工作线程数一般为cpu个数work_threads=4
 
	#磁盘IO是否读写分离disk_rw_separated = true
 
	#混合读写时的读写线程数disk_reader_threads = 1
 disk_writer_threads = 1
 
	#同步文件时如果binlog没有要同步的文件,则延迟多少毫秒后重新读取,0表示不延迟sync_wait_msec=50
 
	#同步完一个文件后间隔多少毫秒同步下一个文件,0表示不休息直接同步sync_interval=0
 
	#表示这段时间内同步文件sync_start_time=00:00
 sync_end_time=23:59
 
	#同步完多少文件后写mark标记write_mark_file_freq=500
 
	#storage在存储文件时支持多路径,默认只设置一个store_path_count=1
 
	#配置多个store_path路径,从0开始,如果store_path0不存在,则base_path必须存在store_path0=/home/yuqing/fastdfs
 
	#subdir_count * subdir_count个目录会在store_path下创建,采用两级存储subdir_count_per_path=256
 
	#设置fastdfs trackertracker_server=192.168.209.121:22122
 
	#日志级别log_level=info
 
	#运行时的用户和组,为空,为当前用户run_by_group=
 run_by_user=
 
	#允许访问网段allow_hosts=*
 
	#文件在数据目录下的存放策略,0:轮训 1:随机file_distribute_path_mode=0
 
	#当问及是轮训存放时,一个目录下可存放的文件数目file_distribute_rotate_count=100
 
	#写入多少字节后就开始同步,0表示不同步fsync_after_written_bytes=0
 
	#刷新日志信息到disk的间隔sync_log_buff_interval=10
 
	sync_binlog_buff_interval=10 
	#同步storage的状态信息到disk的间隔sync_stat_file_interval=300
 
	#线程栈大小thread_stack_size=512KB
 
	#设置文件上传服务器的优先级,值越小越高upload_priority=10
 
	if_alias_prefix= 
	#是否检测文件重复存在,1:检测 0:不检测check_file_duplicate=0
 file_signature_method=hash
 
	#当check_file_duplicate设置为1时,次值必须设置key_namespace=FastDFS
 
	#与FastDHT建立连接的方式 0:短连接 1:长连接keep_alive=0
 use_access_log = false
 rotate_access_log = false
 access_log_rotate_time=00:00
 rotate_error_log = false
 error_log_rotate_time=00:00
 rotate_access_log_size = 0
 rotate_error_log_size = 0
 file_sync_skip_invalid_record=false
 use_connection_pool = false
 connection_pool_max_idle_time = 3600
 http.domain_name=
 http.server_port=8888
 
	其中主要修改的地方为 base_path (用于存储storage相关的log、group内的相关信息) 和 store_path0 (文件的存储位置)这里改为:
 base_path=/mnt/fastdfs_storage_info
 store_path0=/mnt/fastdfs_storage_data
 tracker_server=192.168.1.50:22122 #tracker服务器地址
 
	[root@centos-6.5-x64 fdfs]#mkdir /mnt/fastdfs_storage_info #创建文件夹[root@centos-6.5-x64 fdfs]#mkdir /mnt/fastdfs_storage_data
 启动服务:
 [root@centos-6.5-x64 ~]#/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
 /usr/local/bin/fdfs_storaged: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
 [root@centos-6.5-x64 ~]#ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
 [root@centos-6.5-x64 ~]#/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
 
	会看到好多提示:mkdir data path: FA …
 mkdir data path: FB …
 mkdir data path: FC …
 mkdir data path: FD …
 mkdir data path: FE …
 mkdir data path: FF …
 data path: /mnt/fastdfs_storage_data/data, mkdir sub dir done.
 [root@centos-6.5-x64 ~]#lsof -i:23000 #默认占用23000端口
 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
 fdfs_stor 10922 root 5u IPv4 86805 0t0 TCP *:inovaport1 (LISTEN)
 
	配置storage_s2:[root@centos-6.5-x64 ~]#tar zxvf libevent-2.0.21-stable
 [root@centos-6.5-x64 ~]#tar zxvf FastDFS_v4.06.tar.gz
 [root@centos-6.5-x64 ~]#cd libevent-2.0.21-stable
 [root@centos-6.5-x64 libevent-2.0.21-stable]#./configure && make && make install
 [root@centos-6.5-x64 libevent-2.0.21-stable]#cd
 [root@centos-6.5-x64 ~]#cd FastDFS
 [root@centos-6.5-x64 FastDFS]#sh make.sh && sh make.sh install
 [root@centos-6.5-x64 FastDFS]#cd /etc/fdfs/
 [root@centos-6.5-x64 fdfs]#mkdir /mnt/fastdfs_storage_info
 [root@centos-6.5-x64 fdfs]#mkdir /mnt/fastdfs_storage_data
 [root@centos-6.5-x64 fdfs]#vi storage.conf
 修改:
 base_path=/mnt/fastdfs_storage_info
 store_path0=/mnt/fastdfs_storage_data
 tracker_server=192.168.1.50:22122
 [root@centos-6.5-x64 fdfs]#ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
 [root@centos-6.5-x64 fdfs]#/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
 [root@centos-6.5-x64 fdfs]#lsof -i:23000
 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
 fdfs_stor 8277 root 5u IPv4 83248 0t0 TCP *:inovaport1 (LISTEN)
 
	服务已经启动。[root@centos-6.5-x64 fdfs]#netstat -anlp | grep ESTABLISHED
 tcp 0 0 192.168.1.52:37220 192.168.1.50:22122 ESTABLISHED 8277/fdfs_storaged
 tcp 0 0 192.168.1.52:23000 192.168.1.51:40161 ESTABLISHED 8277/fdfs_storaged
 可以看到storage服务器和tracker服务器(端口22122,管理)建立了会话,与另一台storage(端口23000,数据同步)建立了会话。
 
	安装fastdfs_client: 
	
		
			
				
					| 
							1 
							2 
							3 
							4 
							5 | 
							
								[root@centos-6.5-x64 ~]#tar zxvf libevent-2.0.21-stable.tar.gz 
								[root@centos-6.5-x64 libevent-2.0.21-stable]#./configure --prefix=/usr && make && make install 
								[root@centos-6.5-x64 ~]#tar zxvf FastDFS_v4.06.tar.gz 
								[root@centos-6.5-x64 ~]#cd FastDFS 
								[root@centos-6.5-x64 FastDFS]#sh make.sh && sh make.sh install |  
	编辑fastdfs_client的配置文件:[root@centos-6.5-x64 ~]#vi /etc/fdfs/client.conf
 修改:
 base_path=/mnt/fastdfs_client
 tracker_server=192.168.1.50:22122
 
	[root@centos-6.5-x64 ~]#mkdir /mnt/fastdfs_client 
	在fastdfs_client上上传文件测试:[root@centos-6.5-x64 ~]#echo “that’s fastdfs_client” > index.html
 [[root@centos-6.5-x64 ~]#/usr/local/bin/fdfs_upload_file /etc/fdfs/client.conf index.html
 group1/M00/00/00/wKgBM1NW5JmAO_BCAAAAFhSwOfU49.html
 这个是在storage服务器下的物理路径。
 
	在storage_s1服务器查看:[root@centos-6.5-x64 ~]#cd /mnt/fastdfs_storage_data/data/00/00
 [root@centos-6.5-x64 00]#ll
 总用量 20
 -rw-r–r– 1 root root 22 4月 23 05:52 wKgBM1NW5JmAO_BCAAAAFhSwOfU49.html
 在storage_s2服务器此目录下也会有这个文件,表明上传文件没问题。
 
	现在我们需要通过web方式去访问这个文件。 
	在每台storage server上部署web server,直接对外提供HTTP服务,tracker server上不需要部署web server。如果请求文件在当前storage上不存在,通过文件ID反解出源storage,直接请求源storage。
 
	我这里用apache来实现访问fastdfs的文件,并且apache为yum安装。想达到访问目的需要在apache中加载fastdfs-apache-module模块。fastdfs-apache-module模块默认不在apache中,需要自己手动编译,加载。
 
	在storage_s1和storage_s2中都进行如下配置: 
	
		
			
				
					| 
							1 
							2 
							3 
							4 
							5 
							6 
							7 
							8 
							9 
							10 
							11 
							12 
							13 
							14 
							15 
							16 
							17 
							18 
							19 | 
							
								[root@centos-6.5-x64 ~]#wget -c http://fastdfs.googlecode.com/files/fastdfs-apache-module_v1.15.tar.gz 
								在编译fastdfs-apache-module时需要apache的某些源文件,需要安装httpd-devel开发工具包。 
								[root@centos-6.5-x64 ~]#yum install -y httpd-devel 
								[root@centos-6.5-x64 ~]#tar zxvf fastdfs-apache-module_v1.15.tar.gz 
								[root@centos-6.5-x64 ~]#cd fastdfs-apache-module 
								[root@centos-6.5-x64 fastdfs-apache-module]#ll 
								总用量 12 
								-rw-rw-r-- 1 root root 1726 1月 13 2013 HISTORY 
								-rw-rw-r-- 1 root root 1725 5月 22 2011 INSTALL 
								drwxrwxr-x 2 root root 4096 2月 19 2013 src 
								[root@centos-6.5-x64 fastdfs-apache-module]#cd src/ 
								[root@centos-6.5-x64 src]#ll 
								总用量 56 
								-rw-rw-r-- 1 root root 32266 1月 13 2013 common.c 
								-rw-rw-r-- 1 root root 3479 1月 3 2012 common.h 
								-rw-rw-r-- 1 root root 1350 11月 4 2010 Makefile 
								-rw-rw-r-- 1 root root 5039 1月 3 2012 mod_fastdfs.c 
								-rw-rw-r-- 1 root root 3869 1月 13 2013 mod_fastdfs.conf 
								-rw-rw-r-- 1 root root 160 9月 5 2010 modules.mk |  
	这里需要修改Makefile文件:APACHE_BASE_PATH=/usr/local/apache2
 include $(APACHE_BASE_PATH)/build/special.mk
 APXS=$(APACHE_BASE_PATH)/bin/apxs
 APACHECTL=$(APACHE_BASE_PATH)/bin/apachectl
 
	改为:APACHE_BASE_PATH=/etc/httpd #apache安装根目录,根据实际情况修改
 include /usr/lib64/httpd/build/special.mk
 APXS=/usr/sbin/apxs
 APACHECTL=/usr/sbin/apachectl
 
	special.mk文件路径可以通过find查找,apxs和apachectl可通过whereis查找。 
	[root@centos-6.5-x64 src]#make/usr/lib64/httpd/build/special.mk:27: /etc/httpd/build/rules.mk: 没有那个文件或目录
 make: *** 没有规则可以创建目标“/etc/httpd/build/rules.mk”。 停止。
 [root@centos-6.5-x64 src]#
 
	报错解决方法: 
	[root@centos-6.5-x64 src]#mkdir /etc/httpd/build[root@centos-6.5-x64 src]#cp /usr/lib64/httpd/build/*.mk /etc/httpd/build/
 [root@centos-6.5-x64 src]#make
 /usr/lib64/apr-1/build/libtool –silent –mode=compile gcc -pthread -Wall -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE=’256*1024′ -DFDFS_MOD_CONF_FILENAME=’”/etc/fdfs/mod_fastdfs.conf”‘ -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -I/usr/local/include/fastdfs -I/usr/local/include/fastcommon/ -I/usr/include/httpd -I. -I/usr/include/apr-1 -prefer-pic -c mod_fastdfs.c && touch mod_fastdfs.slo
 /usr/lib64/apr-1/build/libtool –silent –mode=link gcc -pthread -Wall -Wl,-z,relro -lfastcommon -lfdfsclient -o mod_fastdfs.la -rpath /usr/lib64/httpd/modules -module -avoid-version mod_fastdfs.lo
 make通过,然后make install
 
	[root@centos-6.5-x64 src]#make install/bin/sh: line 1: /etc/httpd/build/instdso.sh: 没有那个文件或目录
 make: *** [install-modules-yes] 错误 127
 [root@centos-6.5-x64 src]#
 
	报错解决方法: 
	[root@centos-6.5-x64 src]#cp /usr/lib64/httpd/build/instdso.sh /etc/httpd/build/[root@centos-6.5-x64 src]#make install
 
	通过。 
	[root@centos-6.5-x64 src]#cd /etc/httpd/modules/[root@centos-6.5-x64 modules]#ll mod_fastdfs.so
 -rwxr-xr-x 1 root root 37564 4月 22 21:34 mod_fastdfs.so
 
	mod_fastdfs.so模块编译完成。 
	编辑mod_fastdfs模块的配置文件:[root@centos-6.5-x64 ~]#vi /etc/fdfs/mod_fastdfs.conf
 tracker_server=192.168.1.50:22122 #修改为tracker server信息
 url_have_group_name = true #改为true
 store_path0=/mnt/fastdfs_storage_data #改为数据存储路径,和storage.conf一样。
 
	编辑apache主配置文件:[root@centos-6.5-x64 ~]#vi /etc/httpd/conf/httpd.conf
 添加两行:
 LoadModule fastdfs_module modules/mod_fastdfs.so #加载模块
 alias /group1/M00 /mnt/fastdfs_storage_data/data #虚拟目录映射
 
	<Location /group1/M00>    #访问/group1/M00时交给fastdfs模块处理sethandler fastdfs
 </Location>
 
	重启httpd服务加到开机启动。现在通过浏览器去访问storage服务器:
 
	http://192.168.1.51/group1/M00/00/00/wKgBM1NW5JmAO_BCAAAAFhSwOfU49.html 
	会看到通过echo重定向的内容。 
	再去配置storage_s2,过程跟s1一样,完成后把ip改为192.168.1.52,后面内容不变,一样可以访问到文件。 
	现在我们停掉storage_s2的storaged服务,删掉此文件 再去访问http://192.168.1.52/group1/M00/00/00/wKgBM1NW5JmAO_BCAAAAFhSwOfU49.html发现依旧可以访问到文件,这就是fastdfs模块起到了作用。这个功能就是防止因为数据同步延迟导致无法访问。而去源storage服务器查找文件。
 
	到这里配置接近尾声,now,我把fastdfs的tracker和storage管理脚本加到系统中,方便用service管理。进入fastdfs源码包:
 [root@centos-6.5-x64 ~]#cd FastDFS/init.d/
 [root@centos-6.5-x64 init.d]#ll
 总用量 8
 -rwxrwxr-x 1 500 500 1186 8月 15 2010 fdfs_storaged
 -rwxrwxr-x 1 500 500 1186 8月 15 2010 fdfs_trackerd
 不用说也能看明白。一个storaged脚本一个trackerd脚本。无需修改即可使用。
 把各自脚本拷贝到/etc/init.d/下即可。然后就可以通过service fdfs_storaged/fdfs_trackerd start/stop/status管理了。
 
	再回到我们的fastdfs_client客户端,为php添加模块:因为fastdfs是基于应用的分布式存储,不像moosefs可以挂载为本地磁盘。fastdfs提供一个api接口实现文件操作。
 所以要安装php扩展让Fastdfs支持php,在FastDFS的源码包解压后里面有个php_client目录,进入此目录,参照README进行安装:
 安装此模块需要phpize命令,此命令由php-devel包提供,没有的话安装即可。
 [root@centos-6.5-x64 php_client]#phpize
 Configuring for:
 PHP Api Version: 20090626
 Zend Module Api No: 20090626
 Zend Extension Api No: 220090626
 [root@centos-6.5-x64 php_client]#./configure && make && make install
 Installing shared extensions: /usr/lib64/php/modules/ #提示模块安装到的路径。
 重定向配置文件到/etc/php.ini:
 [root@centos-6.5-x64 php_client]#cat fastdfs_client.ini >> /etc/php.ini
 重启apache。
 [root@centos-6.5-x64 ~]#php -m | grep fast
 fastdfs_client
 看到php加载模块成功。
 
	测试:创建一个php文件,代码如下:
 
	
		
			
				
					| 
							1 
							2 
							3 
							4 
							5 | 
							
								[root@centos-6.5-x64 html]#cat test.php 
								<?php 
								$file_info=fastdfs_get_file_info1('group1/M00/00/00/wKgBM1NW5JmAO_BCAAAAFhSwOfU49.html'); 
								var_dump($file_info); 
								?> |  
	然后执行: 
	
		
			
				
					| 
							1 
							2 
							3 
							4 
							5 
							6 
							7 
							8 
							9 
							10 
							11 
							12 
							13 | 
							
								[root@centos-6.5-x64 html]#php test.php 
								array(5) { 
								 ["source_id"]=> 
								 int(0) 
								 ["create_timestamp"]=> 
								 int(1398203545) 
								 ["file_size"]=> 
								 int(22) 
								 ["source_ip_addr"]=> 
								 string(12) "192.168.1.51" 
								 ["crc32"]=> 
								 int(347093493) 
								} |  
	得到文件信息。完成! 
	ps:上面重定向fastdfs_client.ini信息到php.ini,作者说需要将其拷贝到跟php.ini同一个目录,并在php.ini配置模块目录路径(extension_dir = ),结果重启apache发现模块没有加载。
 所以就直接将fastdfs_client.ini内容信息全部追加到php.ini中,模块才被加载。
 
	有关fastdfs的原理:http://os.51cto.com/art/201210/359380.htm(责任编辑:IT) |