Linux-搭建單機版的FastDFS服務器

 由於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目錄,專門用於存放安裝包,如下所示

[html] view plain copy
  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這個地址下載需要的安裝包,上傳完之後,如下所示

[html] view plain copy
  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、解壓

[html] view plain copy
  1. [root@fastdfs software]# unzip libfastcommon-master.zip -d /usr/local/fast/  
       2、進入目錄

[html] view plain copy
  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、編譯

[html] view plain copy
  1. [root@fastdfs libfastcommon-master]# ./make.sh  
      4、安裝

[html] view plain copy
  1. [root@fastdfs libfastcommon-master]# ./make.sh install  

 第八步:創建軟鏈接

       FastDFS主程序設置的目錄爲/usr/local/lib/,所以我們需要創建/ usr/lib64/下的一些核心執行程序的軟連接文件。如下所示。

[html] view plain copy
  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  
第九步:安裝FastDFS

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

[html] view plain copy
  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、編譯安裝

[html] view plain copy
  1. [root@fastdfs software]# cd /usr/local/fast/FastDFS/  
  2. [root@fastdfs FastDFS]# ./make.sh  
  3. [root@fastdfs FastDFS]# ./make.sh install  
      安裝完後,服務腳本位置如下

[html] view plain copy
  1. [root@fastdfs FastDFS]# cd /etc/init.d/ && ls | grep fdfs  
  2. fdfs_storaged  
  3. fdfs_trackerd  
  4. [root@fastdfs init.d]#  
       配置文件位置如下:

[html] view plain copy
  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一系列執行腳本如下,可以看到有上傳文件腳本、下載文件腳本等等。

[html] view plain copy
  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處。



第十步:配置跟蹤器

     1、進入到/etc/fdfs目錄並且複製一份tracker.conf.sample並命名爲tracker.conf,如下所示。

[html] view plain copy
  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目前是不存在的,因此我們需要創建一下該目錄

[html] view plain copy
  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、重啓防火牆

[html] view plain copy
  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目錄下是沒有任何文件的,如下所示
[html] view plain copy
  1. [root@fastdfs tracker]# cd /fastdfs/tracker/ && ll  
  2. 總用量 0  
  3. [root@fastdfs tracker]#   
       啓動tracker,啓動完之後,可以看到這個目錄下多了兩個目錄data和logs。如下所示。

[html] view plain copy
  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,如下所示。

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

     1、進入/etc/fdfs目錄,複製一份storage.conf.sample文件並命名爲storage.conf,如下所示。

[html] view plain copy
  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自行設置。

[html] view plain copy
  1. base_path=/fastdfs/storage  
  2. store_path0=/fastdfs/storage  
  3. tracker_server=192.168.156.13:22122  
  4. http.server_port=8888  
      3、創建存儲目錄,如下所示。

[html] view plain copy
  1. [root@fastdfs fdfs]# mkdir -p /fastdfs/storage  
  2. [root@fastdfs fdfs]#   
     4、配置防火牆,允許外界訪問storage的默認端口23000,如下所示。

[html] view plain copy
  1. [root@fastdfs fdfs]# vim /etc/sysconfig/iptables  
  2.   
  3. # Firewall configuration written by system-config-firewall  
  4. # Manual customization of this file is not recommended.  
  5. *filter  
  6. :INPUT ACCEPT [0:0]  
  7. :FORWARD ACCEPT [0:0]  
  8. :OUTPUT ACCEPT [0:0]  
  9. -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT  
  10. -A INPUT -p icmp -j ACCEPT  
  11. -A INPUT -i lo -j ACCEPT  
  12. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT  
  13. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT  
  14. -A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT  
  15. -A INPUT -j REJECT --reject-with icmp-host-prohibited  
  16. -A FORWARD -j REJECT --reject-with icmp-host-prohibited  
  17. COMMIT  
       添加完之後,重啓防火牆,如下所示。

[html] view plain copy
  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目錄下是沒有任何文件的

[html] view plain copy
  1. [root@fastdfs fdfs]# cd /fastdfs/storage/ && ll  
  2. 總用量 0  
  3. [root@fastdfs storage]#   
       啓動storage,啓動後再看/fastdfs/storage目錄,可以看到多了data和logs。

[html] view plain copy
  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 是否啓動成功,當看到如下所示信息時說明都啓動成功了。

[html] view plain copy
  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個目錄。

[html] view plain copy
  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,如下所示。

[html] view plain copy
  1. [root@fastdfs data]# vim /etc/rc.local   
  2.   
  3. #!/bin/sh  
  4. #  
  5. # This script will be executed *after* all the other init scripts.  
  6. # You can put your own initialization stuff in here if you don't  
  7. # want to do the full Sys V style init stuff.  
  8.   
  9. touch /var/lock/subsys/local  
  10. /etc/init.d/fdfs_trackerd start  
  11. /etc/init.d/fdfs_storaged start  
第十二步:測試圖片上傳

      1、進入到/etc/fdfs目錄下並複製一份client.conf.sample並更名爲client.conf,如下所示。

[html] view plain copy
  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進入編輯模式並修改如下兩項內容,如下所示。

[html] view plain copy
  1. base_path=/fastdfs/tracker  
  2. tracker_server=192.168.156.13:22122  
     3、我們找到命令的腳本位置,並且使用命令,進行文件的上傳。

[html] view plain copy
  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

[html] view plain copy
  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]#  
第十三步: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目錄並解壓,如下所示。

[html] view plain copy
  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文件。

[html] view plain copy
  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/目錄下並執行配置和編譯安裝,如下所示。

[html] view plain copy
  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目錄中,如下所示。

[html] view plain copy
  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方式訪問資源。

[html] view plain copy
  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目錄中,如下所示。

[html] view plain copy
  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文件存儲目錄下創建軟連接,將其鏈接到實際存放數據 的目錄,如下所示。

[html] view plain copy
  1. [root@fastdfs conf]# ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00  
  2. [root@fastdfs conf]#   
       進入到/usr/local/nginx/conf/目錄下,修改nginx.conf文件,如下圖所示。


        修改的內容如下圖示


        可以直接複製下面的內容。

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

       設置nginx開機自啓動,這樣下次重啓設備之後,tracker、storage、nginx都自動啓動了,直接就可以使用服務,如下所示。

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

       啓動nginx,如下所示。

[html] view plain copy
  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,如下圖所示。


      配置完防火牆後重啓防火牆

[html] view plain copy
  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便搭建完畢了!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章