centos6.5 搭建fastdfs分布式存储图片

什么是FastDFS?

FastDFS是一个开源的轻量级分布式文件系统。它解决了大数据量存储和负载均衡等问题。特别适合以中小文件(建议范围:4KB < file_size <500MB)为载体的在线服务,如相册网站、视频网站等等。在UC基于FastDFS开发向用户提供了:网盘,社区,广告和应用下载等业务的存储服务。

FastDFS架构:

FastDFS服务端有三个角色:跟踪服务器(tracker server)、存储服务器(storage server)和客户端(client)。

  • tracker server:跟踪服务器,主要做调度工作,起负载均衡的作用。在内存中记录集群中所有存储组和存储服务器的状态信息,是客户端和数据服务器交互的枢纽。相比GFS中的master更为精简,不记录文件索引信息,占用的内存量很少。
  • storage server:存储服务器(又称:存储节点或数据服务器),文件和文件属性(meta data)都保存到存储服务器上。Storageserver直接利用OS的文件系统调用管理文件。
  • client:客户端,作为业务请求的发起方,通过专有接口,使用TCP/IP协议与跟踪器服务器或存储节点进行数据交互。

Tracker Server:跟踪服务器,主要做调度工作,在访问上起负载均衡的作用。
Storage Server:存储服务器(又称数据服务器)。

存储节点采用了分组(group)的方式。存储系统由一个或多个group组成,group与group之间的文件是相互独立的,

所有group的文件容量累加就是整个存储系统中的文件容量。一个group可以由一台或多台存储服务器组成,一个group下的存储服务器中的文件都是相同的,group中的多台存储服务器起到了冗余备份和负载均衡的作用(一个组的存储容量为该组内存储服务器容量最小的那个,不同组的Storage server之间不会相互通信,同组内的Storage server之间会相互连
接进行文件同步)。

在group中增加服务器时,同步已有的文件由系统自动完成,同步完成后,系统自动将新增服务器切换到线上提供服务。

当存储空间不足或即将耗尽时,可以动态添加group。只需要增加一台或多台服务器,并将它们配置为一个新的group,
这样就扩大了存储系统的容量。

FastDFS两个角色:Tracker server和Storage server。Tracker server作为中心结点,其主要作用是负载均衡和调度。Tracker server在内存中记录分组和Storage server的状态等信息,不记录文件索引信息,占用的内存量很少。
另外,客户端(应用)和Storage server访问Tracker server时,Tracker server扫描内存中的分组和Storage server信息,然后给出应答。由此可以看出Tracker server非常轻量化,不会成为系统瓶颈。

FastDFS中的Storage server在其他文件系统中通常称作Trunk server或Data server。Storage server直接利用OS的文件系统存储文件。FastDFS不会对文件进行分块存储,客户端上传的文件和Storage server上的文件一一对应(FastDFS中的文件标识分为两个部分:组名和文件名,二者缺一不可)。

fastDFS下载地址:http://code.google.com/p/fastdfs/downloads/list
libevent官网: 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,则这里需要指定一个group
store_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的频率,默认10s
sync_log_buff_interval = 10

#检测storage服务器的间隔时间,storage定期主动向tracker发送心跳,如果在指定的时间没收到信号,tracker人为storage故障,默认120s
check_active_interval = 120

#线程栈的大小,最小64K
thread_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,默认256bytes
slot_min_size = 256

#最大的solt大小,如果上传的文件小于默认值,则上传文件被放入trunk文件中
slot_max_size = 16MB

#trunk文件的默认大小,应该大于4M
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
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必须返回200
http.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:

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服务器属于那个group
group_name=group1

#监听地址,不写,监听全部
bind_addr=

#连接其他服务器时是否绑定地址,bind_addr配置时本参数才有效
client_bind=true

#storage默认端口
port=23000

#storage在通过网络发送接收数据的超时时间
network_timeout=60

#主动向tracker发送心跳检测的时间间隔
heart_beat_interval=30

#主动向tracker发送磁盘使用率的时间间隔
stat_report_interval=60

#数据存储路径
base_path=/home/yuqing/fastdfs

#接收/发送数据的buff大小,必须大于8KB
buff_size = 256KB

#磁盘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 tracker
tracker_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
修改:
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:

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 ~]#cd FastDFS
编辑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中都进行如下配置:

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 2010fdfs_storaged
-rwxrwxr-x 1 500 500 1186 8月 15 2010fdfs_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文件,代码如下:

[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);
?>

然后执行:

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

参考:http://www.rootop.org/pages/2431.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


linux下开机自启: 在/etc/init.d目录下新建文件elasticsearch 并敲入shell脚本: 注意, 前两行必须填写,且要注释掉。 第一行为shell前行代码,目的告诉系统使用shell。 第二行分别代表运行级别、启动优先权、关闭优先权,且后面添加开机服务会用到。 shell脚本
1、因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以需要赋予其可执行权 chmod +x /etc/rc.d/rc.local 2、赋予脚本可执行权限假设/usr/local/script/autostart.sh是你的脚本路径,给予执行权限 chmod +x /usr
最简单的查看方法可以使用ls -ll、ls-lh命令进行查看,当使用ls -ll,会显示成字节大小,而ls- lh会以KB、MB等为单位进行显示,这样比较直观一些。 通过命令du -h –max-depth=1 *,可以查看当前目录下各文件、文件夹的大小,这个比较实用。 查询当前目录总大小可以使用d
ASP.NET Core应用程序发布linux在shell中运行是正常的。可一但shell关闭网站也就关闭了,所以要配置守护进程, 用的是Supervisor,本文主要记录配置的过程和过程遇到的问题 安装Supervisor&#160;1 yum install python-setuptools
设置时区(CentOS 7) 先执行命令timedatectl status|grep &#39;Time zone&#39;查看当前时区,如果不是时区(Asia/Shanghai),则需要先设置为中国时区,否则时区不同会存在时差。 #已经是Asia/Shanghai,则无需设置 [root@xia
vim&#160;/etc/sysconfig/network-scripts/ifcfg-eth0 BOOTPROTO=&quot;static&quot; ONBOOT=yes IPADDR=192.168.8.106 NETMASK=255.255.252.0 GATEWAY=192.168.
一、安装gcc依赖 由于 redis 是用 C 语言开发,安装之前必先确认是否安装 gcc 环境(gcc -v),如果没有安装,执行以下命令进行安装 [root@localhost local]# yum install -y gcc 二、下载并解压安装包 [root@localhost local
第一步 On CentOS/RHEL 6.*: $ sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm On CentOS/RHEL 7: $
/// &lt;summary&gt; /// 取小写文件名后缀 /// &lt;/summary&gt; /// &lt;param name=&quot;name&quot;&gt;文件名&lt;/param&gt; /// &lt;returns&gt;返回小写后缀,不带“.”&lt;/ret
which nohup .bash_profile中并source加载 如果没有就安装吧 yum provides */nohup nohup npm run start &amp; nohup ./kibana &amp;
1.1 MySQL安装 1.1.1 下载wget命令 yum -y install wget 1.1.2 在线下载mysql安装包 wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 1.1.3 安装My
重启 reboot shutdown -r now init 6 关闭 init 0 shutdown -h now shutdown -h 20:25 #8点25关机查看内存 free CPU利用率 top 日期 date 设置时间 date 033017002015 #月日时间年 日历 cal
1、firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status firewalld 开机禁用 : systemctl disable firewalld 开机启用 :
1 下载并安装MySQL官方的&#160;Yum Repository wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm 使用上面的命令就直接下载了安装用的Yum Repository,大概
CentOS6.x CentOS6中转用Upstrat代替以前的init.d/rcX.d的线性启动方式。 一、相关命令 通过initctl help可以查看相关命令 [root@localhost ~]# initctl help Job commands: start Start job. sto
1、使用命令:df -lk 找到已满磁盘 2、使用命令:du --max-depth=1 -h 查找大文件,删除
ifconfig:查看网卡信息 网卡配置文件位置: /etc/sysconfig/network-scripts/文件夹 nmtui:配置网卡 netstat -tlunp:查看端口信息 端口信息存储位置: /etc/services文件 route:查看路由信息 wget:下载网路文件,例如 wg
ps -ef:查看所有进程,&#160;ps -ef |grap firewalld 查看与firewalld相关的进程 which :查看进程:which firewalld kill 进程id:杀掉进程 kill 640,强制杀:kill -9 640 man:查看帮助,例如 man ps 查看
useradd:添加用户 useradd abc,默认添加一个abc组 vipw:查看系统中用户 groupadd:添加组groupadd ccna vigr:查看系统中的组 gpasswd:将用户abc添加到ccna组 gpasswd -a abc ccna groups abc:查看用户abc属