隨筆-179  評論-666  文章-29  trackbacks-0

          最新的版本可以在這里獲取,目前下載的最新版本是5.08,更新于2016-02-03。在這里可以找到更多的說明。

            下載好后,server端分為兩個部分,一個是tracker,一個是storage。顧名思義,前者調度管理,負載均衡,后者則是實際的存儲節點。兩個都能做成集群,以防止單點故障。以前的4.x版本依賴libevent,現在不需要了,只需要libfastcommon。安裝方法如下:

          1. 下載安裝libfastcommon

          git clone https://github.com/happyfish100/libfastcommon.git
          cd libfastcommon/
          ./make.sh
          ./make.sh install

          確認make沒有錯誤后,執行安裝,64位系統默認會復制到/usr/lib64下。

          這時候需要設置環境變量或者創建軟鏈接

          export LD_LIBRARY_PATH=/usr/lib64/
          ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so

          2. 下載安裝fastdfs

          tar xzf FastDFS.tar.gz
          cd FastDFS/
          ./make.sh
          ./make.sh install

          確認make沒有錯誤后,執行安裝,默認會安裝到/usr/bin中,并在/etc/fdfs中添加三個配置文件。

          3. 修改配置文件
          首先將三個文件的名字去掉sample,暫時只修改以下幾點,先讓fastdfs跑起來,其余參數調優的時候再考慮。
          tracker.conf 中修改

          base_path=/home/fastdfs #用于存放日志。
          http.server_port=8090 

          storage.conf 中修改

          外網訪問 出現net.ConnectException: Connection refused: connect
          storage的tracker_server地址必須是外網地址,重啟FastDFS就好了。


          tracker_server=192.168.1.181:22122 #指定tracker服務器地址。
          base_path=/home/fastdfs #用于存放日志。
          store_path0=/home/fastdfs/storage #存放數據,若不設置默認為前面那個。

          http.server_port=80 
          group_name=group1 

          client.conf 中同樣要修改

          base_path=/home/fastdfs #用于存放日志。
          tracker_server=192.168.1.181:22122 #指定tracker服務器地址。
          http.tracker_server_port=80


          #include http.conf 

          其它保持默認,注意上面那個是1個#,默認是2個#,去掉1個就行

          4. 啟動tracker和storage

          /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
          /usr/bin/fdfs_storaged /etc/fdfs/storage.conf


          netstat –lnp –tcp 參看端口是否起來,默認如果顯示22122和8090,23000,80說明服務正常起來

          5. 檢查進程

          root@ubuntu:~# ps -ef |grep fdfs
          root       7819      1  0 15:24 ?        00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
          root       8046      1  0 15:36 ?        00:00:01 fdfs_storaged /etc/fdfs/storage.conf start

          表示啟動ok了,若有錯誤,可以在/home/fastdfs目錄下檢查日志。

          6. 上傳/刪除測試
          使用自帶的fdfs_test來測試,使用格式如下:

          root@ubuntu:~# fdfs_test /etc/fdfs/client.conf upload /home/steven/01.jpg
          ...
          group_name=group1, ip_addr=192.168.1.181, port=23000
          storage_upload_by_filename
          group_name=group1, remote_filename=M00/00/00/wKgdhFTV0ZmAP3AZAPk-Io7D4w8580.jpg
          ...
          example file url: http://192.168.1.181/group1/M00/00/00/wKgdhFTV0ZmAP3AZAPk-Io7D4w8580.jpg
          storage_upload_slave_by_filename
          group_name=group1, remote_filename=M00/00/00/wKgdhFTV0ZmAP3AZAPk-Io7D4w8580_big.jpg
          ...
          example file url: http://192.168.1.181/group1/M00/00/00/wKgdhFTV0ZmAP3AZAPk-Io7D4w8580_big.jpg

          使用fdfs_delete_file來刪除文件,格式如下:

          fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgdhFTV11uAXgKWAPk-Io7D4w8667.jpg

          可以看到,上傳ok了,這里會生成兩個文件,這是fastdfs的主/從文件特性,以后再介紹。example file url是不能在瀏覽器中直接打開的,除非配合nginx使用。刪除文件需要完整的group_name和remote_filename。

          因為FastDFS默認自帶的http服務器性能不好, 所以一般建議用外置的apache或者nginx 來解決http下載,以應付大并發的情況 注意nginx擴展模塊只支持GET和HEAD模式獲取文件,需要開發那邊配合修改程序
          獲取nginx和FastDFS的nginx擴展插件
          wget https://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/

          wget http://nginx.org/

          解壓并編譯安裝

            備注:如果之前機器上安裝了nginx,可以單獨安裝fastdfs-nginx-module模塊,具體方法請參考:如何單獨添加NGINX自定義模塊

          apt卸載nginx方法
          卸載方法
          # 刪除nginx,保留配置文件
          sudo apt-get remove nginx


          apt-get install libssl-dev zlib1g-dev libpcre3-dev 

          tar zvxf nginx-1.9.14.tar.gz

          tar zvxf fastdfs-nginx-module_v1.16.tar.gz

          cd nginx-1.9.14

          ./configure --prefix=/usr/local/nginx --with-http_gzip_static_module --add-module=/home/alpha/tools/fastdfs-nginx-module/src

                      make 

           

          sudo make install

          如果出現 fastdfs-nginx-module/src/common.c:21:25: fatal error: fdfs_define.h: 沒有那個文件或目錄

                     
                      添加鏈接
                      ln -sv /usr/include/fastcommon /usr/local/include/fastcommon 
                      ln -sv /usr/include/fastdfs /usr/local/include/fastdfs 
                      ln -sv /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so

                      可解決!


                             cd /home/alpha/tools/FastDFS/conf
                             cp http.conf /etc/fdfs/
                             cp mime.types /etc/fdfs/
                             cp storage_ids.conf /etc/fdfs


              修改nginx擴展模塊的配置文件
            cd ../fastdfs-nginx-module/src


          cp mod_fastdfs.conf /etc/fdfs/ 

          vi /etc/fdfs/mod_fastdfs.conf 

          base_path=/home/fastdfs/logs

          #存放log的路徑 

          tracker_server=127.0.0.1:22122 

          #指定tracker服務器及端口 

          url_have_group_name = true 

          #這個很重要,在URL中包含group名稱

          store_path0=/home/fastdfs/storage

          #存儲文件的路徑 

          storage_server_port=23000 

          #與storage的配置端口保持一致 

          保存后退出 

          做M00的鏈接

          ln -s /home/fastdfs/storage/data  /home/fastdfs/storage/data/M00 

          修改nginx的配置文件

          備注:如果nginx有其他服務器在用,在nginx.conf原有的基礎上追加一個下面server的配置即可

           vi /usr/local/nginx/conf/nginx.conf 

          server { 

            listen 80;
            location / { 

              root /home/fastdfs/storage/data; 

              index index.html index.htm;

             } 

            location /group1/M00 {

               root /home/fastdfs/storage/data; 

              ngx_fastdfs_module; 

            }

           }

          重啟相關服務,驗證整合是否成功

          先重啟storage服務:

           /etc/init.d/fdfs_storaged start 

          然后再啟動nginx,

          注意順序,否則會報端口占用的錯誤

           /usr/local/nginx/sbin/nginx 

          查看端口使用情況:
          netstat -lnp --tcp


          如何讓server進程退出運行?
          直接kill即可讓server進程正常退出,可以使用killall命令,例如:
          killall fdfs_trackerd
          killall fdfs_storaged
          也可以使用如下命令:
          /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop
          /usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop
          千萬不要使用-9參數強殺,否則可能會導致binlog數據丟失的問題。

          如何重啟server進程?
          直接使用:
          /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
          /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

          可以在任何storage機器上執行如下命令,查看fastdfs集群狀態,如果各個storage狀態都為ACTIVE,則搭建成功。

          /usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf

           

          關閉tracker(storage)

            /usr/local/bin/stop.sh /usr/local/bin/fdfs_trackered(fdfs_storaged) /etc/fdfs/tracker.conf(storage.conf)

            或者 killall fdfs_trackered(storaged)  -------注意,千萬不要使用-9強行殺死進程。否則可能會導致binlog數據丟失的問題。

           
          重啟tracker(storage)

          /usr/local/bin/restart.sh /usr/local/bin/fdfs_trackered(fdfs_storaged) /etc/fdfs/tracker.conf(storage.conf)


          刪除storage

           /usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf delete group2 20.12.1.73(刪除group2中ip為20.12.1.73的storage)

          注意:在配置過程,要注意防火墻的設置。關閉防火墻,或者設置對相關端口例外。

          http://wenku.baidu.com/view/78ca45c608a1284ac850431b.html?re=view

          posted on 2016-04-07 13:58 Alpha 閱讀(2855) 評論(2)  編輯  收藏

          評論:
          # re: Ubuntu14.04下部署FastDFS 5.08+Nginx 1.9.14 2016-04-15 12:30 | 司馬青衫
          可以可以可以  回復  更多評論
            
          # re: Ubuntu14.04下部署FastDFS 5.08+Nginx 1.9.14 2016-08-02 14:56 | reatang
          相當成功  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 常熟市| 哈尔滨市| 罗甸县| 福贡县| 剑川县| 荆州市| 齐齐哈尔市| 改则县| 芦溪县| 民权县| 石首市| 田阳县| 同心县| 昌黎县| 怀安县| 利辛县| 体育| 延津县| 中宁县| 玛纳斯县| 汶川县| 丘北县| 新泰市| 铅山县| 奉贤区| 中方县| 上高县| 波密县| 阳朔县| 东至县| 黎城县| 巴南区| 武义县| 邛崃市| 康乐县| 尼勒克县| 城步| 北宁市| 镇平县| 崇州市| 彭泽县|