首页 > linux > 测试nginx的FastDFS分布式存储模块

测试nginx的FastDFS分布式存储模块

2010年12月2日 eric 发表评论 阅读评论

很长时间没有关注FastDFS了,第一次使用FastDFS 是在 08年的时候11月的时候,那个时候是为了解决公司的数据存储~那时候可能是对Fastdfs了解不深,功能还不算太健全,最后选择了lustre。再回过头来看FastDFS更新很快,还看到fastdfs-nginx-module_v1.01.tar.gz nginx模块,所以今天在一台测试机上测试了·测试几天看稳定不稳定,在考虑换掉浪费资源的 lustre !

环境:

storage1:192.168.6.100
storage2:192.168.6.101
tracker:192.168.6.102

1. 在每个机器上,下载安装 FastDFS

nginx $>  wget http://fastdfs.googlecode.com/files/FastDFS_v2.04.tar.gz
# 解压
nginx $> tar zxvf FastDFS_v2.04.tar.gz
nginx $> cd FastDFS
# 因为我是给nginx添加fastdfs模块,所以不需要fastdfs支持 http 所以我就不需要去掉  #WITH_HTTPD=1 前的注释了,直接编译
nginx $> ./make.sh
nginx $> ./make.sh install

2.修改tracker 和 storage 的配置文件
# tracker 的修改

tracker $> vim /etc/fdfs/tracker.conf
disabled=false
#配置是否生效
bind_addr=192.168.6.102
#绑定IP
port=22122
#服务端口
connect_timeout=30
#连接超时时间
network_timeout=60
#  tracker server的网络超时,单位为秒。
base_path=/home/yangzi
#目录地址,里面会创建data(存放存储服务器信息)、logs,日志文件
max_connections=256
#系统提供服务最大连接数
work_threads=4
#线程数,通常设置CPU数
store_lookup=2
上传组(卷) 的方式 0:轮询方式 1: 指定组 2: 平衡负载(选择最大剩余空间的组(卷)上传)
这里如果在应用层指定了上传到一个固定组,那么这个参数被绕过
store_group=group1
当上一个参数设定为1 时 (store_lookup=1,即指定组名时),必须设置本参数为系统中存在的一个组名。如果选择其他的上传方式,这个参数就没有效了
store_server=0
选择哪个storage server 进行上传操作(一个文件被上传后,这个storage server就相当于这个文件的storage server源,会对同组的storage server推送这个文件达到同步效果)
# 0: 轮询方式
# 1: 根据ip 地址进行排序选择第一个服务器(IP地址最小者)
# 2: 根据优先级进行排序(上传优先级由storage server来设置,参数名为upload_priority)
store_path=0
选择storage server 中的哪个目录进行上传。storage server可以有多个存放文件的base path(可以理解为多个磁盘)。
# 0: 轮流方式,多个目录依次存放文件
# 2: 选择剩余空间最大的目录存放文件(注意:剩余磁盘空间是动态的,因此存储到的目录或磁盘可能也是变化的)
download_server=0
 选择哪个 storage server 作为下载服务器
# 0: 轮询方式,可以下载当前文件的任一storage server
# 1: 哪个为源storage server 就用哪一个 (前面说过了这个storage server源 是怎样产生的) 就是之前上传到哪个storage server服务器就是哪个了
reserved_storage_space = 4GB
storage server 上保留的空间,保证系统或其他应用需求空间(指出 如果同组的服务器的硬盘大小一样,以最小的为准,也就是只要同组中有一台服务器达到这个标准了,这个标准就生效,原因就是因为他们进行备份)
log_level=info
#选择日志级别
run_by_group=
#操作系统运行FastDFS的用户组
run_by_user=
#操作系统运行FastDFS的用户
allow_hosts=*
#可以连接到此 tracker server 的ip范围(对所有类型的连接都有影响,包括客户端,storage server)
sync_log_buff_interval = 10
# 同步或刷新日志信息到硬盘的时间间隔,单位为秒
# 注意:tracker server 的日志不是时时写硬盘的,而是先写内存。
check_active_interval = 120
# 检测 storage server 存活的时间隔,单位为秒。
# storage server定期向tracker server 发心跳,如果tracker server在一个check_active_interval内还没有收到storage server的一次心跳,那边将认为该storage server已经下线。所以本参数值必须大于storage server配置的心跳时间间隔。通常配置为storage server心跳时间间隔的2倍或3倍。
thread_stack_size = 64KB
# 线程栈的大小。FastDFS server端采用了线程方式。更正一下,tracker server线程栈不应小于64KB,不是512KB。
# 线程栈越大,一个线程占用的系统资源就越多。如果要启动更多的线程(V1.x对应的参数为max_connections,
V2.0为work_threads),可以适当降低本参数值。
storage_ip_changed_auto_adjust = true
# 这个参数控制当storage server IP地址改变时,集群是否自动调整。注:只有在storage server进程重启时才完成自动调整。
storage_sync_file_max_delay = 86400
# V2.0引入的参数。存储服务器之间同步文件的最大延迟时间,缺省为1天。根据实际情况进行调整
storage_sync_file_max_time = 300
# V2.0引入的参数。存储服务器同步一个文件需要消耗的最大时间,缺省为300s,即5分钟。
http.disabled=true
# HTTP服务是否不生效 当然编译的时候我已经把 with_httpd宏去掉了,
http.server_port=80
# HTTP服务端口
# 下列参数只有 开启http服务才有用
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.html
http.need_find_content_type=true

#两台 storage.conf的修改

storage $> vim /etc/fdfs/storage.conf
disabled=false
#配置是否生效
group_name=group1
#storage所在组(卷)
bind_addr=192.168.6.100
# 绑定IP,另一太 storage IP为 192.168.6.101
client_bind=true
#bind_addr通常是针对server的。当指定bind_addr时,本参数才有效。
port=23000
# 是storage 服务端口
connect_timeout=30
# 连接超时时间,针对socket套接字函数connect
network_timeout=60
# storage server 网络超时时间,单位为秒。
heart_beat_interval=30
# 心跳间隔时间,单位为秒
stat_report_interval=60
# storage server向tracker server报告磁盘剩余空间的时间间隔,单位为秒。
base_path=/home/eric
# base_path 目录地址,根目录必须存在  子目录会自动生成
# 会产生data(数据存储地方)、 logs日志文件
max_connections=256
# 最大连接数
buff_size = 256KB
# 设置队列结点的buffer大小。
work_threads=4
# 工作线程数
disk_rw_separated = true
# 磁盘IO读写是否分离,缺省是分离的。
disk_reader_threads = 1
# 针对单个存储路径的读线程数,缺省值为1
disk_writer_threads = 1
# 针对单个存储路径的写线程数,缺省值为1
sync_wait_msec=200
# 同步文件时,如果从binlog中没有读到要同步的文件,休眠N毫秒后重新读取,0表示不休眠,立即再次尝试读取。
sync_interval=0
#  同步上一个文件后,再同步下一个文件的时间间隔,单位为毫秒,0表示不休眠,直接同步下一个文件。
sync_start_time=00:00
sync_end_time=23:59
# 允许系统同步的时间段 (默认是全天) 。一般用于避免高峰同步产生一些问题而设定,相信sa都会明白。
write_mark_file_freq=500
# 把storage的mark文件定期同步到磁盘的时间间隔,单位为秒
store_path_count=1
# 存放文件时storage server支持多个路径(例如磁盘)。这里配置存放文件的基路径数目,通常只配一个目录。
store_path0=/home/eric
#  逐一配置store_path个路径,索引号基于0。注意配置方法后面有0,1,2 ......,需要配置0到store_path - 1。
# 如果不配置base_path0,那边它就和base_path对应的路径一样。
subdir_count_per_path=32
# FastDFS存储文件时,采用了两级目录。这里配置存放文件的目录个数
tracker_server=192.168.6.188:22122
# tracker_server 的列表 要写端口的哦
log_level=info
# 日志级别
run_by_group=
# 运行storage 用户组
run_by_user=
# 运行storage 用户
allow_hosts=*
# 允许连接IP列表
file_distribute_path_mode=0
# 文件在data目录下分散存储策略。
# 0: 轮流存放
# 1: 随机存储
file_distribute_rotate_count=100
# 当上面的参数file_distribute_path_mode配置为0(轮流存放方式)时,本参数有效。
#当一个目录下的文件存放的文件数达到本参数值时,后续上传的文件存储到下一个目录中
fsync_after_written_bytes=0
# 当写入大文件时,每写入N个字节,调用一次系统函数fsync将内容强行同步到硬盘。0表示从不调用fsync
sync_log_buff_interval=10
# 同步或刷新日志信息到硬盘的时间间隔,单位为秒
sync_binlog_buff_interval=60
# 同步binglog(更新操作日志)到硬盘的时间间隔,单位为秒
sync_stat_file_interval=300
# 把storage的stat文件同步到磁盘的时间间隔,单位为秒。
thread_stack_size=512KB
# 线程栈的大小。FastDFS server端采用了线程方式。
# 线程栈越大,一个线程占用的系统资源就越多。
upload_priority=10
本storage server作为源服务器,上传文件的优先级,可以为负数。值越小,优先级越高。这里就和 tracker.conf 中store_server= 2时的配置相对应了
if_alias_prefix=
check_file_duplicate=0
# 是否检测上传文件已经存在。如果已经存在,则不存在文件内容,建立一个符号链接以节省磁盘空间。 结合 fastdfh使用的。 1是检测,0是不检测,我们不使用fastdfh 当然 0 
key_namespace=FastDFS
# 当上个参数设定为1 或 yes时 (true/on也是可以的) , 在FastDHT中的命名空间
keep_alive=0
# 与FastDHT servers 的连接方式 (是否为持久连接) 

# 下面是http的配置了就不多说了
http.disabled=true
http.domain_name=
http.server_port=80
http.trunk_size=256KB
http.need_find_content_type=true

3.建立tracker 和 storage 的根目录

# tracker
tracker $> mkdir -p /home/eric
# storage
storage $> mkdir -p /home/yangzi

4.在 一台storage上下载,比如我在 192.168.6.100上下载 nginx 和 fastdfs-nginx-module 模块

storage $> wget http://www.nginx.org/download/nginx-0.8.53.tar.gz
storage $> svn export http://fastdfs-nginx-module.googlecode.com/svn/trunk/ fastdfs-nginx-module-read-only

5.编译安装 nginx 附带 fastdfs-nginx-module 模块

storage $> tar zxvf nginx-0.8.53.tar.gz
storage $> cd nginx-0.8.53
storage $> ./configure --prefix=/usr/local/nginx --add-module=/root/fastdfs-nginx-module-read-only/src
storage $> make
storage $> make install
# 拷贝mod_fastdfs.conf 到/etc/fdfs/
storage $> cp /root/fastdfs-nginx-module-read-only/src/mod_fastdfs.conf  /etc/fdfs/

6.修改 nginx 配置文件增加

storage $> vim /usr/local/nginx/conf/nginx.conf

# 增加一下
location /M00 {
alias /home/eric/data;
ngx_fastdfs_module;
}

7. 给 storage 的存储目录做一个软连接

storage $> ln -s /home/yangzi/data  /home/yangzi/data/M00

8. 启动两台 storage 和tracker nginx

#  启动 tracker
tracker $> /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
# 启动 storage
storage $>  /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
# 启动 storage2
storage2 $>  /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
#在 storage启动  nginx
storage $> /usr/local/nginx/sbin/nginx

9、上传文件测试。
# 修改客户端配置文件

storage $> vim /etc/fdfs/client.conf
connect_timeout=30
network_timeout=60
base_path=/home/yangzi
tracker_server=192.168.6.102:22122
log_level=info
#下面参数无所谓了反正没有用到http 服务
http.tracker_server_port=80
storage $>  vim  a.html
test FastDFS!
storage $>  /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload a.html
This is FastDFS client test program v2.04

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.

base_path=/home/yangzi, 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=group1, ip_addr=192.168.6.100, port=23000

group_name=group1, ip_addr=192.168.6.100, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgGvEz3Y9MAAAAAAAAADigvbpc73.html
source ip address: 192.168.6.100
file timestamp=2010-12-02 17:16:03
file size=14
file crc32=674197143
file url: http://192.168.6.100/group1/M00/00/00/wKgGvEz3Y9MAAAAAAAAADigvbpc73.html
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgGvEz3Y9MAAAAAAAAADigvbpc73_big.html
source ip address: 192.168.6.100
file timestamp=2010-12-02 17:16:03
file size=14
file crc32=674197143
file url: http://192.168.6.100/group1/M00/00/00/wKgGvEz3Y9MAAAAAAAAADigvbpc73_big.html

打开IE浏览器访问:

转载请注明:文章转载自:Eric's linux and nginx! (http://www.nginxs.com)
本文地址:http://www.nginxs.com/linux/350.html

分类: linux 标签: , ,
  1. 2018年9月20日20:54 | #1

    erectile medication over counter
    erectile dysfunction injections
    erectile tissue

  2. 2018年10月1日21:06 | #2

    Wonderful stuff. With thanks!
    erectile dysfunction when trying to conceive

  3. 2018年10月4日01:29 | #3

    Great actors proceed the learning course of.

  4. 2018年10月4日16:29 | #4

    Hello i am kavin, its my first occasion to commenting anywhere, when i read this post i thought i could also create comment due to this
    good paragraph.

  5. 2018年10月5日00:39 | #5

    Great article! This is the type of info that should be shared across the internet.
    Disgrace on the seek engines for not positioning this put up upper!
    Come on over and visit my site . Thank you =)

  6. 2018年10月6日03:36 | #6

    I’m not that much of a online reader to be honest but your blogs really nice,
    keep it up! I’ll go ahead and bookmark your website to
    come back in the future. All the best

  7. 2018年10月6日09:19 | #7

    I am sure this piece of writing has touched all the internet visitors, its really really fastidious piece of writing
    on building up new weblog.

  8. 2018年10月7日04:05 | #8

    slot game
    online casino real money
    play casino games online
    online gambling casino
    kasino

  9. 2018年10月7日17:39 | #9

    Hello to all, the contents present at this web site are truly awesome
    for people experience, well, keep up the nice work fellows.

  10. 2018年10月8日01:27 | #10

    Link exchange is nothing else but it is simply placing the other person’s website link on your page at appropriate
    place and other person will also do same in favor of
    you.

  11. 2018年10月8日02:40 | #11

    online casino slots
    slot game
    online casino
    online casino
    casino online

  12. 2018年10月8日22:06 | #12

    Hi there, You’ve done an incredible job. I will certainly digg it and personally suggest to my friends.
    I’m confident they will be benefited from this website.

  13. 2018年10月9日00:47 | #13

    What’s up everyone, it’s my first pay a quick visit at this website, and article is
    in fact fruitful in favor of me, keep up posting such articles or reviews.

  14. 2018年10月9日01:46 | #14

    Good info. Lucky me I recently found your site by chance (stumbleupon).

    I have book marked it for later!

  15. 2018年10月9日08:15 | #15

    Hey! Do you know if they make any plugins to protect against
    hackers? I’m kinda paranoid about losing everything I’ve worked hard on.
    Any recommendations?

  16. 2018年10月10日17:50 | #16

    Hi there! Do you use Twitter? I’d like to follow you if that would be ok.
    I’m definitely enjoying your blog and look forward to new posts.

  17. 2018年10月11日21:30 | #17

    This is my first time go to see at here and i am genuinely impressed to read all at alone place.

  18. 2018年10月18日21:41 | #18

    Spot on with this write-up, I really believe this amazing site needs
    a lot more attention. I’ll probably be back again to read
    more, thanks for the advice!

  19. 2018年10月19日18:01 | #19

    I could not refrain from commenting. Very well written!

  20. 2018年10月20日05:25 | #20

    Awesome post.

  21. 2018年11月6日22:46 | #21

    Thanks for finally writing about >Eric’s linux and nginx!

    > 测试nginx的FastDFS分布式存储模块 <Liked it!

  22. 2018年11月7日13:15 | #22

    I’m amazed, I must say. Seldom do I come across a blog that’s equally educative and engaging, and without a
    doubt, you’ve hit the nail on the head. The issue is
    something too few folks are speaking intelligently about.
    I’m very happy I came across this in my hunt for something relating to this.

  23. 2018年11月9日20:16 | #23

    Its such as you read my thoughts! You seem to know a lot
    about this, like you wrote the e book in it or something.
    I believe that you can do with some % to drive
    the message house a bit, however instead of that, that is great
    blog. A fantastic read. I’ll definitely be back.

  24. 2018年11月10日13:33 | #24

    Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my
    newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your
    blog and I look forward to your new updates.

  25. 2018年11月11日02:17 | #25

    Hi I am so thrilled I found your website, I really found you
    by error, while I was researching on Aol for something else, Anyways I
    am here now and would just like to say thanks a lot for a remarkable post and a all
    round entertaining blog (I also love the theme/design), I don’t
    have time to read it all at the moment but I have bookmarked it and also included your RSS feeds, so when I have time I will be back to read a
    great deal more, Please do keep up the fantastic work.

  26. 2018年11月11日13:30 | #26

    Hi there excellent blog! Does running a blog like
    this take a large amount of work? I have virtually no expertise in computer programming
    however I was hoping to start my own blog in the near future.
    Anyway, if you have any ideas or techniques for new blog owners please
    share. I know this is off topic nevertheless I just needed
    to ask. Many thanks!

  27. 2018年11月11日14:01 | #27

    buy viagra no prescription viagra cheap alternative to viagra [url=http://viagraeq.com/]online viagra[/url]

  28. 2018年11月13日01:05 | #28

    With havin so much content and articles do you ever run into any problems
    of plagorism or copyright infringement? My blog has a lot of exclusive content I’ve either authored myself or outsourced but it looks like
    a lot of it is popping it up all over the web without my authorization. Do you know any techniques to help stop
    content from being ripped off? I’d genuinely appreciate it.

  29. 2018年11月14日15:49 | #29

    of course like your website but you need to test the spelling
    on several of your posts. Several of them are rife with spelling problems and I to find it very bothersome to tell the
    reality however I’ll certainly come back again.

  30. 2018年11月17日20:14 | #30

    We stumbled over here coming from a different website and thought I might as well check things out.
    I like what I see so now i’m following you.

    Look forward to exploring your web page yet again.

  31. 2018年11月18日00:34 | #31

    Sling tv coupons and promo codes for november 2018
    Everything published was very reasonable. However,
    what about this? suppose you added a little content?
    I ain’t saying your information isn’t good, however suppose
    you added something to maybe grab folk’s attention? I mean Eric's linux
    and nginx! » 测试nginx的FastDFS分布式存储模块 is a little vanilla.
    You ought to peek at Yahoo’s home page and see how they create article titles to get viewers to open the links.
    You might add a video or a related pic or two to get people excited about everything’ve got to say.

    Just my opinion, it would bring your posts a little bit
    more interesting. Sling tv coupons and promo
    codes for november 2018

  32. 2018年11月19日00:24 | #32

    You have made some really good points there.
    I looked on the web for more info about the issue and found most individuals will go along with
    your views on this website.

  33. 2018年11月19日09:47 | #33

    casino online
    casinos online
    online casino real money
    casino games slots
    slot game

  34. 2018年11月20日00:14 | #34

    Everyone loves it whenever people come together and share opinions.
    Great website, stick with it!

  35. 2018年12月1日13:14 | #35

    onlinefr

    6c7d click now how to obtain online

  36. 2018年12月5日00:02 | #36

    comprar online en man

    4e42 only today 5mg online online

评论分页
1 ... 3 4 5 350
订阅评论
5+7= (必填)