转载自: 搭建单机版的FastDFS服务器

* 为了便于理解,其中顺序有改变。

1、第八步创建软链接,可以等到第九步结束后进行。如果提前在第八步创建软链接,因为还没有安装 libfdfsclient.so文件,则创建软链接时会提示此文件不存在,但是不影响创建软链接。

  1. 为什么创建软链接: libfastcommon.so默认安装到了/usr/lib64/libfastcommon.so,而FastDFS主程序设置的lib目录是/usr/local/lib,所以设置软连接
  2. 先给被创建软链接的文件权限,然后进行软链接操作,否则会因为文件没有权限而出现闪烁现象(无法成功创建软链接的表现)。
  3. chmod 777 /usr/lib64/libfdfsclient.so
  4. chmod 777 /usr/lib64/libfastcommon.so

2、如果等到第九步完成 之后在进行创建,则不会有问题。如下如:

3、需要预先安装的软件

  vim-enhanced(关联安装了 perl perl-devel)、make 、cmake、gcc、gcc-c++、zip、unzip、zlib、zlib-devel、openssl、opssl-devel

==============================

由于FastDFS集群搭建非常复杂,对于初期学习FastDFS来说,搭建个单机版的作为入门更为实际一些。

第一步:搭建虚拟环境

FastDFS需要在Linux系统上安装,我们一般使用的都是Windows系统,这样就需要有虚拟环境,我这里使用Vmware12创建虚拟机,关于虚拟机最小化的安装大家可以参考:http://blog.csdn.net/u012453843/article/details/68947589这篇博客进行学习

第二步:配置静态IP而且要保证能上网

大家可以参考:http://blog.csdn.net/u012453843/article/details/52839105这篇博客进行学习,需要提醒的是,由于最小化安装默认是没有vim命令的,因此在配置静态IP时使用vi命令即可。

第三步:安装vim命令

之所以安装vim命令是因为在安装它的同时会自动帮我们安装perl,而perl在进行编译安装时是必须要有的。安装vim的命令是:yum install vim-enhanced

第四步:安装gcc

使用命令:yum install make cmake gcc gcc-c++进行安装即可

第五步:上传安装文件到Linux服务器

为了便于管理,我们在Linux服务器上新建一个/usr/local/software目录,专门用于存放安装包,如下所示

  1. [root@fastdfs ~]# mkdir /usr/local/software
  2. [root@fastdfs ~]#

下面我们把需要用到的安装包都上传到/usr/local/software目录下,我们可以使用XShell和Xftp5相结合来方便的进行上传下载操作,大家可以参考http://blog.csdn.net/u012453843/article/details/68951776这篇博客进行学习。也可以通过安装rzsz命令来进行上传下载操作,安装rzsz的命令是yum install lrzsz,安装完之后,rz表示上传,sz 文件表示下载。

大家可以到http://download.csdn.net/detail/u012453843/9802538这个地址下载需要的安装包,上传完之后,如下所示

  1. [root@fastdfs software]# ll
  2. 总用量 1248
  3. -rw-r--r--. 1 root root  17510 11月 28 00:19 fastdfs-nginx-module_v1.16.tar.gz
  4. -rw-r--r--. 1 root root 345400 11月 28 00:20 FastDFS_v5.05.tar.gz
  5. -rw-r--r--. 1 root root 102378 11月 28 00:19 libfastcommon-master.zip
  6. -rw-r--r--. 1 root root 804164 11月 28 01:11 nginx-1.6.2.tar.gz
  7. [root@fastdfs software]#

第六步:安装zip和unzip命令

由于解压.zip结尾的文件需要用到unzip命令,因此我们需要安装,安装命令是yum install zip unzip

第七步:安装libfastcommon

1、解压

  1. [root@fastdfs software]# unzip libfastcommon-master.zip -d /usr/local/fast/

2、进入目录

  1. [root@fastdfs software]# cd /usr/local/fast/libfastcommon-master/
  2. [root@fastdfs libfastcommon-master]# ll
  3. 总用量 28
  4. -rw-r--r--. 1 root root 2913 2月  27 2015 HISTORY
  5. -rw-r--r--. 1 root root  582 2月  27 2015 INSTALL
  6. -rw-r--r--. 1 root root 1342 2月  27 2015 libfastcommon.spec
  7. -rwxr-xr-x. 1 root root 2151 2月  27 2015 make.sh
  8. drwxr-xr-x. 2 root root 4096 2月  27 2015 php-fastcommon
  9. -rw-r--r--. 1 root root  617 2月  27 2015 README
  10. drwxr-xr-x. 2 root root 4096 2月  27 2015 src
  11. [root@fastdfs libfastcommon-master]#

3、编译

  1. [root@fastdfs libfastcommon-master]# ./make.sh

4、安装

  1. [root@fastdfs libfastcommon-master]# ./make.sh install

第八步移动至第九步之后

第九步:安装FastDFS

1、进入到cd /usr/local/software下,解压FastDFS_v5.05.tar.gz文件

  1. [root@fastdfs fast]# cd /usr/local/software/
  2. [root@fastdfs software]# ll
  3. 总用量 1248
  4. -rw-r--r--. 1 root root  17510 4月  11 03:28 fastdfs-nginx-module_v1.16.tar.gz
  5. -rw-r--r--. 1 root root 345400 4月  11 03:28 FastDFS_v5.05.tar.gz
  6. -rw-r--r--. 1 root root 102378 4月  11 03:28 libfastcommon-master.zip
  7. -rw-r--r--. 1 root root 804164 4月  11 03:29 nginx-1.6.2.tar.gz
  8. [root@fastdfs software]# tar -zxvf FastDFS_v5.05.tar.gz -C /usr/local/fast/

2、编译安装

  1. [root@fastdfs software]# cd /usr/local/fast/FastDFS/
  2. [root@fastdfs FastDFS]# ./make.sh
  3. [root@fastdfs FastDFS]# ./make.sh install

安装完后,服务脚本位置如下

  1. [root@fastdfs FastDFS]# cd /etc/init.d/ && ls | grep fdfs
  2. fdfs_storaged
  3. fdfs_trackerd
  4. [root@fastdfs init.d]#

配置文件位置如下:

  1. [root@fastdfs init.d]# cd /etc/fdfs/
  2. [root@fastdfs fdfs]# ll
  3. 总用量 20
  4. -rw-r--r--. 1 root root 1461 4月  11 04:10 client.conf.sample
  5. -rw-r--r--. 1 root root 7829 4月  11 04:10 storage.conf.sample
  6. -rw-r--r--. 1 root root 7102 4月  11 04:10 tracker.conf.sample
  7. [root@fastdfs fdfs]#

FastDFS一系列执行脚本如下,可以看到有上传文件脚本、下载文件脚本等等。

  1. [root@fastdfs fdfs]# cd /usr/bin/ && ls | grep fdfs
  2. fdfs_appender_test
  3. fdfs_appender_test1
  4. fdfs_append_file
  5. fdfs_crc32
  6. fdfs_delete_file
  7. fdfs_download_file
  8. fdfs_file_info
  9. fdfs_monitor
  10. fdfs_storaged
  11. fdfs_test
  12. fdfs_test1
  13. fdfs_trackerd
  14. fdfs_upload_appender
  15. fdfs_upload_file
  16. [root@fastdfs bin]#

3、因为FastDFS服务脚本设置的bin目录为/usr/local/bin/下,但是实际我们安装在了/u sr/bin/下面。所以我们需要修改FastDFS配置文件中的路径,也就是需要修改两个配置文件

使用命令vim /etc/init.d/fdfs_storaged进入编辑模式,然后直接输入":",光标会定位到最后一行,在":"后输入"%s+/usr/local/bin+/usr/bin",如下图所示。输入完之后回车,会提示修改了7处。为了确保所有的/usr/local/bin都被替换了,我们可以再打开文件确认一下。

       接着修改第二个配置文件,我们使用命令vim /etc/init.d/fdfs_trackerd进入编辑模式,接着按照上面那样输入":%s+/usr/local/bin+/usr/bin "并按回车,同样会提醒我们修改了7处。

第 在此处执行 第八步:创建软链接

  libfastcommon.so默认安装到了/usr/lib64/libfastcommon.so,而FastDFS主程序设置的lib目录是/usr/local/lib,所以设置软连接

 如下所示。

  1. [root@fastdfs libfastcommon-master]# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
  2. [root@fastdfs libfastcommon-master]# ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
  3. [root@fastdfs libfastcommon-master]# ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
  4. [root@fastdfs libfastcommon-master]# ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

第十步:配置跟踪器

1、进入到/etc/fdfs目录并且复制一份tracker.conf.sample并命名为tracker.conf,如下所示。

  1. [root@fastdfs bin]# cd /etc/fdfs/
  2. [root@fastdfs fdfs]# ll
  3. 总用量 20
  4. -rw-r--r--. 1 root root 1461 4月  11 04:10 client.conf.sample
  5. -rw-r--r--. 1 root root 7829 4月  11 04:10 storage.conf.sample
  6. -rw-r--r--. 1 root root 7102 4月  11 04:10 tracker.conf.sample
  7. [root@fastdfs fdfs]# cp tracker.conf.sample tracker.conf
  8. [root@fastdfs fdfs]#

2、使用命令vim /etc/fdfs/tracker.conf进入编辑模式,然后修改base_path的值为/fastdfs/tracker,如下图所示。

/
      3、我们在上图配置文件中配置的/fastdfs/tracker目前是不存在的,因此我们需要创建一下该目录

  1. [root@fastdfs fdfs]# mkdir -p /fastdfs/tracker
  2. [root@fastdfs fdfs]#

4、配置防火墙,放开tracker使用的端口22122,使用命令vim
/etc/sysconfig/iptables进入编辑模式,添加一行内容-A INPUT -m state --state NEW -m tcp
-p tcp --dport 22122 -j ACCEPT,如下图所示。

5、重启防火墙

  1. [root@fastdfs fdfs]# service iptables restart
  2. iptables:将链设置为政策 ACCEPT:filter                    [确定]
  3. iptables:清除防火墙规则:                                 [确定]
  4. iptables:正在卸载模块:                                   [确定]
  5. iptables:应用防火墙规则:                                 [确定]
  6. [root@fastdfs fdfs]#

6、在启动tracker之前,/fastdfs/tracker目录下是没有任何文件的,如下所示

  1. [root@fastdfs tracker]# cd /fastdfs/tracker/ && ll
  2. 总用量 0
  3. [root@fastdfs tracker]#

启动tracker,启动完之后,可以看到这个目录下多了两个目录data和logs。如下所示。

  1. [root@fastdfs tracker]# /etc/init.d/fdfs_trackerd start
  2. Starting FastDFS tracker server:
  3. [root@fastdfs tracker]# cd /fastdfs/tracker/ && ll
  4. 总用量 8
  5. drwxr-xr-x. 2 root root 4096 4月  11 05:01 data
  6. drwxr-xr-x. 2 root root 4096 4月  11 05:01 logs
  7. [root@fastdfs tracker]#

7、设置开机自启动,在rc.local文件中添加/etc/init.d/fdfs_trackerd start,如下所示。

  1. [root@fastdfs tracker]# vim /etc/rc.d/rc.local
  2. #!/bin/sh
  3. #
  4. # This script will be executed *after* all the other init scripts.
  5. # You can put your own initialization stuff in here if you don't
  6. # want to do the full Sys V style init stuff.
  7. touch /var/lock/subsys/local
  8. /etc/init.d/fdfs_trackerd start

第十一步:配置FastDFS存储

1、进入/etc/fdfs目录,复制一份storage.conf.sample文件并命名为storage.conf,如下所示。

  1. [root@fastdfs tracker]# cd /etc/fdfs/
  2. [root@fastdfs fdfs]# ll
  3. 总用量 28
  4. -rw-r--r--. 1 root root 1461 4月  11 04:10 client.conf.sample
  5. -rw-r--r--. 1 root root 7829 4月  11 04:10 storage.conf.sample
  6. -rw-r--r--. 1 root root 7098 4月  11 04:45 tracker.conf
  7. -rw-r--r--. 1 root root 7102 4月  11 04:10 tracker.conf.sample
  8. [root@fastdfs fdfs]# cp storage.conf.sample storage.conf
  9. [root@fastdfs fdfs]# ll
  10. 总用量 36
  11. -rw-r--r--. 1 root root 1461 4月  11 04:10 client.conf.sample
  12. -rw-r--r--. 1 root root 7829 4月  11 05:07 storage.conf
  13. -rw-r--r--. 1 root root 7829 4月  11 04:10 storage.conf.sample
  14. -rw-r--r--. 1 root root 7098 4月  11 04:45 tracker.conf
  15. -rw-r--r--. 1 root root 7102 4月  11 04:10 tracker.conf.sample
  16. [root@fastdfs fdfs]#

2、修改storage.conf文件 ,我们使用命令vim /etc/fdfs/storage.conf进入编辑模式,对以下四项进行修改,192.168.156.13是我的虚拟机的IP,大家根据自己虚拟机的IP自行设置。

  1. base_path=/fastdfs/storage
  2. store_path0=/fastdfs/storage
  3. tracker_server=192.168.156.13:22122
  4. http.server_port=8888

3、创建存储目录,如下所示。

  1. [root@fastdfs fdfs]# mkdir -p /fastdfs/storage
  2. [root@fastdfs fdfs]#

4、配置防火墙,允许外界访问storage的默认端口23000,如下所示。

  1. [root@fastdfs fdfs]# vim /etc/sysconfig/iptables
  2. # Firewall configuration written by system-config-firewall
  3. # Manual customization of this file is not recommended.
  4. *filter
  5. :INPUT ACCEPT [0:0]
  6. :FORWARD ACCEPT [0:0]
  7. :OUTPUT ACCEPT [0:0]
  8. -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  9. -A INPUT -p icmp -j ACCEPT
  10. -A INPUT -i lo -j ACCEPT
  11. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
  12. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT
  13. -A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT
  14. -A INPUT -j REJECT --reject-with icmp-host-prohibited
  15. -A FORWARD -j REJECT --reject-with icmp-host-prohibited
  16. COMMIT

添加完之后,重启防火墙,如下所示。

  1. [root@fastdfs fdfs]# service iptables restart
  2. iptables:将链设置为政策 ACCEPT:filter                    [确定]
  3. iptables:清除防火墙规则:                                 [确定]
  4. iptables:正在卸载模块:                                   [确定]
  5. iptables:应用防火墙规则:                                 [确定]
  6. [root@fastdfs fdfs]#

5、在启动storage之前,/fastdbf/storage目录下是没有任何文件的

  1. [root@fastdfs fdfs]# cd /fastdfs/storage/ && ll
  2. 总用量 0
  3. [root@fastdfs storage]#

启动storage,启动后再看/fastdfs/storage目录,可以看到多了data和logs。

  1. [root@fastdfs storage]# /etc/init.d/fdfs_storaged start
  2. Starting FastDFS storage server:
  3. [root@fastdfs storage]# cd /fastdfs/storage/ && ll
  4. 总用量 8
  5. drwxr-xr-x. 68 root root 4096 4月  11 05:21 data
  6. drwxr-xr-x.  2 root root 4096 4月  11 05:20 logs
  7. [root@fastdfs storage]#

6、查看FastDFS tracker和storage 是否启动成功,当看到如下所示信息时说明都启动成功了。

  1. [root@fastdfs storage]# ps -ef | grep fdfs
  2. root       2124      1  0 05:01 ?        00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
  3. root       2228      1  0 05:21 ?        00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
  4. root       2238   1360  0 05:22 pts/0    00:00:00 grep fdfs
  5. [root@fastdfs storage]#

7、我们进入到 /fastdfs/storage/data/目录下,可以看到两级共256*256个目录,每级都是从00到FF,如下只是列出了第一级的目录,点进去每个目录都还有00到FF共256个目录。

  1. [root@fastdfs storage]# cd /fastdfs/storage/data/ && ls
  2. 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
  3. 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
  4. 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  fdfs_storaged.pid
  5. 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  FE
  6. 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  FF
  7. 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  storage_stat.dat
  8. 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  sync
  9. 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
  10. 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
  11. [root@fastdfs data]#

8、设置storage开机自启动,添加一行/etc/init.d/fdfs_storaged start,如下所示。

  1. [root@fastdfs data]# vim /etc/rc.local
  2. #!/bin/sh
  3. #
  4. # This script will be executed *after* all the other init scripts.
  5. # You can put your own initialization stuff in here if you don't
  6. # want to do the full Sys V style init stuff.
  7. touch /var/lock/subsys/local
  8. /etc/init.d/fdfs_trackerd start
  9. /etc/init.d/fdfs_storaged start

第十二步:测试图片上传

1、进入到/etc/fdfs目录下并复制一份client.conf.sample并更名为client.conf,如下所示。

  1. [root@fastdfs data]# cd /etc/fdfs
  2. [root@fastdfs fdfs]# ll
  3. 总用量 36
  4. -rw-r--r--. 1 root root 1461 4月  11 04:10 client.conf.sample
  5. -rw-r--r--. 1 root root 7820 4月  11 05:12 storage.conf
  6. -rw-r--r--. 1 root root 7829 4月  11 04:10 storage.conf.sample
  7. -rw-r--r--. 1 root root 7098 4月  11 04:45 tracker.conf
  8. -rw-r--r--. 1 root root 7102 4月  11 04:10 tracker.conf.sample
  9. [root@fastdfs fdfs]# cp client.conf.sample client.conf
  10. [root@fastdfs fdfs]# ll
  11. 总用量 40
  12. -rw-r--r--. 1 root root 1461 4月  11 05:40 client.conf
  13. -rw-r--r--. 1 root root 1461 4月  11 04:10 client.conf.sample
  14. -rw-r--r--. 1 root root 7820 4月  11 05:12 storage.conf
  15. -rw-r--r--. 1 root root 7829 4月  11 04:10 storage.conf.sample
  16. -rw-r--r--. 1 root root 7098 4月  11 04:45 tracker.conf
  17. -rw-r--r--. 1 root root 7102 4月  11 04:10 tracker.conf.sample
  18. [root@fastdfs fdfs]#

2、使用命令vim /etc/fdfs/client.conf进入编辑模式并修改如下两项内容,如下所示。

  1. base_path=/fastdfs/tracker
  2. tracker_server=192.168.156.13:22122

3、我们找到命令的脚本位置,并且使用命令,进行文件的上传。

  1. [root@fastdfs bin]# cd /usr/bin/ && ls | grep fdfs
  2. fdfs_appender_test
  3. fdfs_appender_test1
  4. fdfs_append_file
  5. fdfs_crc32
  6. fdfs_delete_file
  7. fdfs_download_file
  8. fdfs_file_info
  9. fdfs_monitor
  10. fdfs_storaged
  11. fdfs_test
  12. fdfs_test1
  13. fdfs_trackerd
  14. fdfs_upload_appender
  15. fdfs_upload_file
  16. [root@fastdfs bin]#

下面使用fdfs_upload_file脚本进行文件上传操作,如下所示。可以看到已经上传成功了,返回的是图片的保存位置:group1/M00/00/00/wKicDVjr_ayAE4VVAAHk-VzqZ6w020.jpg

  1. [root@fastdfs bin]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/software/3.jpg
  2. group1/M00/00/00/wKicDVjr_ayAE4VVAAHk-VzqZ6w020.jpg
  3. [root@fastdfs bin]#

 小结:

1、至此,我们就完成了FastDFS的安装, 可以通过 程序自带的上传工具进行上传文件,也可以通过程序进行上传。详细可参见:http://blog.csdn.net/u012453843/article/details/69946109

2、虽然我们已经可以将文件上传至服务器,但是无法通过浏览器连接直接访问到(也可以通过程序下载文件),我们将FastDFS程序与nginx结合,可以通过链接进行访问,详细功能可以参考上面的链接。

================================

第十三步:FastDFS与nginx相结合

1、先安装nginx,大家可以参考http://blog.csdn.net/u012453843/article/details/69396434这篇博客的第四步Nginx安装(我们已经安装过的vim、gcc等就不需要重复安装了)。

2、安装fastdfs-nginxmodule_v1.16.tar.gz(fast与nginx相结合的模块安装包), 进入 /usr/local/software目录并解压,如下所示。

  1. [root@fastdfs nginx-1.6.2]# cd /usr/local/software/
  2. [root@fastdfs software]# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/fast/
  3. fastdfs-nginx-module/
  4. fastdfs-nginx-module/src/
  5. fastdfs-nginx-module/src/ngx_http_fastdfs_module.c
  6. fastdfs-nginx-module/src/mod_fastdfs.conf
  7. fastdfs-nginx-module/src/config
  8. fastdfs-nginx-module/src/common.h
  9. fastdfs-nginx-module/src/common.c
  10. fastdfs-nginx-module/INSTALL
  11. fastdfs-nginx-module/HISTORY
  12. [root@fastdfs software]#

3、进入到/usr/local/fast目录下可以看到解压的fastdfs-nginx-module目录,然后进入到fastdfs-nginx-module/src/目录下,可以看到config文件。

  1. [root@fastdfs software]# cd /usr/local/fast/
  2. [root@fastdfs fast]# ll
  3. 总用量 12
  4. drwxr-xr-x. 10 8980 users 4096 4月  11 04:10 FastDFS
  5. drwxrwxr-x.  3  500   500 4096 5月   4 2014 fastdfs-nginx-module
  6. drwxr-xr-x.  4 root root  4096 4月  11 03:30 libfastcommon-master
  7. [root@fastdfs fast]# cd fastdfs-nginx-module/src/
  8. [root@fastdfs src]# ll
  9. 总用量 76
  10. -rw-rw-r--. 1 500 500 33207 8月  30 2013 common.c
  11. -rw-rw-r--. 1 500 500  3479 1月   3 2012 common.h
  12. -rw-rw-r--. 1 500 500   447 11月  4 2010 config
  13. -rw-rw-r--. 1 500 500  3679 3月  30 2013 mod_fastdfs.conf
  14. -rw-rw-r--. 1 500 500 28542 5月   4 2014 ngx_http_fastdfs_module.c
  15. [root@fastdfs src]#

修改该conf文件,我们把文件的第四行配置中的/usr/local/include都改为/usr/include,共两处。


      4、fastdfs与nginx进行结合,由于我们刚才安装过nginx了,因此在/usr/local目录下已经生成了一个nginx目录了,如下图所示。

为了将nginx与fastdfs相结合,我们先把这个nginx目录删除掉,如下图所示,可以看到已经没有nginx目录了。

进入到nginx-1.6.2/目录下并执行配置和编译安装,如下所示。

  1. [root@fastdfs local]# cd nginx-1.6.2/
  2. [root@fastdfs nginx-1.6.2]# ./configure --add-module=/usr/local/fast/fastdfs-nginx-module/src/
  3. [root@fastdfs nginx-1.6.2]# make && make install

复制fastdfs-nginx-module中的配置文件,到/etc/fdfs目录中,如下所示。

  1. [root@fastdfs fdfs]# cd /usr/local/fast/fastdfs-nginx-module/src/
  2. [root@fastdfs src]# ll
  3. 总用量 76
  4. -rw-rw-r--. 1 500 500 33207 8月  30 2013 common.c
  5. -rw-rw-r--. 1 500 500  3479 1月   3 2012 common.h
  6. -rw-rw-r--. 1 500 500   435 4月  11 06:09 config
  7. -rw-rw-r--. 1 500 500  3679 3月  30 2013 mod_fastdfs.conf
  8. -rw-rw-r--. 1 500 500 28542 5月   4 2014 ngx_http_fastdfs_module.c
  9. [root@fastdfs src]# cp /usr/local/fast/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
  10. [root@fastdfs src]#

我们到 /etc/fdfs/ 目录下,修改我们刚copy过来的mod_fastdfs.conf 文件,需要修改的项如下,其中第一项是超时时长,第三项是允许外界通过http方式访问资源。

  1. connect_timeout=10
  2. tracker_server=192.168.156.13:22122
  3. url_have_group_name = true
  4. store_path0=/fastdfs/storage

复制FastDFS里的2个文件,到/etc/fdfs目录中,如下所示。

  1. [root@fastdfs fdfs]# cd /usr/local/fast/FastDFS/conf/
  2. [root@fastdfs conf]# ll
  3. 总用量 84
  4. -rw-r--r--. 1 8980 users 23981 12月  2 2014 anti-steal.jpg
  5. -rw-r--r--. 1 8980 users  1461 12月  2 2014 client.conf
  6. -rw-r--r--. 1 8980 users   858 12月  2 2014 http.conf
  7. -rw-r--r--. 1 8980 users 31172 12月  2 2014 mime.types
  8. -rw-r--r--. 1 8980 users  7829 12月  2 2014 storage.conf
  9. -rw-r--r--. 1 8980 users   105 12月  2 2014 storage_ids.conf
  10. -rw-r--r--. 1 8980 users  7102 12月  2 2014 tracker.conf
  11. [root@fastdfs conf]# cp http.conf mime.types /etc/fdfs/
  12. [root@fastdfs conf]#

创建一个软连接,在/fastdfs/storage文件存储目录下创建软连接,将其链接到实际存放数据 的目录,如下所示。

  * 看情况也可以不创建。

  1. [root@fastdfs conf]# ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
  2. [root@fastdfs conf]#

进入到/usr/local/nginx/conf/目录下,修改nginx.conf文件,如下图所示。


        修改的内容如下图示


        可以直接复制下面的内容。

  1. listen       8888;
  2. location ~/group([0-9])/M00 {
  3. ngx_fastdfs_module;
  4. }

设置nginx开机自启动,这样下次重启设备之后,tracker、storage、nginx都自动启动了,直接就可以使用服务,如下所示。

  1. [root@fastdfs ~]# vim /etc/rc.d/rc.local
  2. #!/bin/sh
  3. #
  4. # This script will be executed *after* all the other init scripts.
  5. # You can put your own initialization stuff in here if you don't
  6. # want to do the full Sys V style init stuff.
  7. touch /var/lock/subsys/local
  8. /etc/init.d/fdfs_trackerd start
  9. /etc/init.d/fdfs_storaged start
  10. /usr/local/nginx/sbin/nginx

启动nginx,如下所示。

  1. [root@fastdfs conf]# /usr/local/nginx/sbin/nginx
  2. ngx_http_fastdfs_set pid=6809
  3. [root@fastdfs conf]#

5、在通过8888端口访问图片之前先配置下防火墙,允许外界访问8888端口,添加的一行是-A INPUT -m state --state NEW -m tcp -p tcp --dport 8888 -j ACCEPT,如下图所示。

配置完防火墙后重启防火墙

  1. [root@fastdfs conf]# service iptables restart
  2. iptables:将链设置为政策 ACCEPT:filter                    [确定]
  3. iptables:清除防火墙规则:                                 [确定]
  4. iptables:正在卸载模块:                                   [确定]
  5. iptables:应用防火墙规则:                                 [确定]
  6. [root@fastdfs conf]#

6、现在我们便可以通过http的方式访问我们刚才上传的图片了(我们刚才上传图片返回的地址是group1/M00/00/00/wKicDVjr_ayAE4VVAAHk-VzqZ6w020.jpg),如下图所示。

至此,一个单机版的FastDFS便搭建完毕了!!

FastDFS-单机版安装的更多相关文章

  1. FastDFS单机版安装

    FastDFS 分布式文件系统 1 目标 了解项目中使用FastDFS的原因和意义. 掌握FastDFS的架构组成部分,能说出tracker和storage的作用. 了解FastDFS+nginx上传 ...

  2. docker安装fastdfs单机版

    docker search fastdfs INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/season/fas ...

  3. CentOS7 安装FastDFS单机版

    1. 下载 FastDFS https://github.com/happyfish100/fastdfs/releases libfastcommon https://github.com/happ ...

  4. Fastdfs 单机安装 教程

    分布式存储 CentOS6.5虚拟机环境搭建FastDFS-5.0.5集群 详细的最新版fastdfs单机版搭建 分布式文件系统 - FastDFS 在64位CentOS 下配置安装部署

  5. FastDfs单机版搭建

    详细的最新版fastdfs单机版搭建 前言 目前项目是tomcat单机部署的,图片.视频也是上传到tomcat目录下,关键是此项目的主要内容还就是针对图片.视频的,这让我非常担忧:文件服务器的应用是必 ...

  6. 01.FastDFS的安装部署

    1.FastDFS简介 (1)FastDFS的功能介绍 FastDFS是一个开源的分布式文件系统,它对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负 ...

  7. FASTDFS 5X安装

    FASTDFS 5X安装 http://www.wingdevops.com/?p=603 流行的开源分布式文件系统有很多,FastDFS 是国人在mogileFS的基础上进行改进的key-value ...

  8. Oracle Primavera P6 R84单机版安装教程

    本教程用于指导Oracle Primavera P6 R84版本的单机版安装过程.P6 R84版本于2014年9月30日发布.其功能较之前版本有较大提升.单机版的安装方式也发生了很大的变化.P6 R8 ...

  9. SQL Server 2008 (R2) 单机版安装的先决条件

    原文:SQL Server 2008 (R2) 单机版安装的先决条件 出自:http://blogs.msdn.com/b/apgcdsd/archive/2012/03/07/sql-server- ...

  10. hadoop单机版安装及基本功能演示

    本文所使用的Linux发行版本为:CentOS Linux release 7.4.1708 (Core) hadoop单机版安装 准备工作 创建用户 useradd -m hadoop passwd ...

随机推荐

  1. Android开发学习之SQLite数据存取浅析

    一.SQLite的介绍 1.SQLite简介 SQLite是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入 式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低 ...

  2. iOS “[App] if we're in the real pre-commit handler we can't actually add any new fences due

    最近运行APP,发现了这个问题,本着宁可错看,不可放过的原则,上stackoverFlow学习了一下: 链接:http://stackoverflow.com/questions/38458170/i ...

  3. 【jQuery】将form表单通过ajax实现无刷新提交

    //将form转换为AJAX提交 function ajaxSubmit(url,frm,fn){ var dataPara=getFormJson(frm); $.ajax({ url:url, t ...

  4. Android 中发送短信

    import android.net.Uri; //调用Android系统API发送短信 Uri uri = Uri.parse("smsto:" + strSmsPhone_va ...

  5. PO_员工主管审批模式详解(设定)

    2014-06-03 Created By BaoXinjian

  6. android检测网络连接状态示例讲解

    网络的时候,并不是每次都能连接到网络,因此在程序启动中需要对网络的状态进行判断,如果没有网络则提醒用户进行设置   Android连接首先,要判断网络状态,需要有相应的权限,下面为权限代码(Andro ...

  7. rpm安装PostgreSQL

    一.首先去官网下载相关的安装包 https://yum.postgresql.org/rpmchart.php 二.下载安装包 1. 最小的数据库服务器安装包: postgresql96--1PGDG ...

  8. 两种方式— 在hive SQL中传入参数

    第一种: sql = sql.format(dt=dt) 第二种: item_third_cate_cd_list = " 发发发 " ...... ""&qu ...

  9. 使用PM2管理Node.js集群

    介绍 众所周知,Node.js运行在Chrome的JavaScript运行时平台上,我们把该平台优雅地称之为V8引擎.不论是V8引擎,还是之后的Node.js,都是以单线程的方式运行的,因此,在多核心 ...

  10. leetcode第一刷_Jump Game II

    要求最小的步数,是不是非常easy想到用dp啊? 我一開始的做法是,当找到了一个可以从它延伸到更远的位置,就把这个位置和最远位置的步数都更新一下,结果超时了. 事实上这样不仅是超时的,并且是错误的.由 ...