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

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

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

          1. 下載安裝libfastcommon

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

          確認(rèn)make沒有錯誤后,執(zhí)行安裝,64位系統(tǒng)默認(rèn)會復(fù)制到/usr/lib64下。

          這時候需要設(shè)置環(huán)境變量或者創(chuàng)建軟鏈接

          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

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

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

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

          storage.conf 中修改

          外網(wǎng)訪問 出現(xiàn)net.ConnectException: Connection refused: connect
          storage的tracker_server地址必須是外網(wǎng)地址,重啟FastDFS就好了。


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

          http.server_port=80 
          group_name=group1 

          client.conf 中同樣要修改

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


          #include http.conf 

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

          4. 啟動tracker和storage

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


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

          5. 檢查進(jìn)程

          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默認(rèn)自帶的http服務(wù)器性能不好, 所以一般建議用外置的apache或者nginx 來解決http下載,以應(yīng)付大并發(fā)的情況 注意nginx擴展模塊只支持GET和HEAD模式獲取文件,需要開發(fā)那邊配合修改程序
          獲取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

          如果出現(xiàn) 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服務(wù)器及端口 

          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有其他服務(wù)器在用,在nginx.conf原有的基礎(chǔ)上追加一個下面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; 

            }

           }

          重啟相關(guān)服務(wù),驗證整合是否成功

          先重啟storage服務(wù):

           /etc/init.d/fdfs_storaged start 

          然后再啟動nginx,

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

           /usr/local/nginx/sbin/nginx 

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


          如何讓server進(jìn)程退出運行?
          直接kill即可讓server進(jìn)程正常退出,可以使用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參數(shù)強殺,否則可能會導(dǎo)致binlog數(shù)據(jù)丟失的問題。

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

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

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

           

          關(guān)閉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強行殺死進(jìn)程。否則可能會導(dǎo)致binlog數(shù)據(jù)丟失的問題。

           
          重啟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)

          注意:在配置過程,要注意防火墻的設(shè)置。關(guān)閉防火墻,或者設(shè)置對相關(guān)端口例外。

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

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

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

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 海南省| 双柏县| 滦平县| 抚州市| 久治县| 石河子市| 始兴县| 吴江市| 高陵县| 会宁县| 景洪市| 乌海市| 孝昌县| 尚志市| 韶关市| 绥宁县| 通河县| 吉木萨尔县| 十堰市| 呼和浩特市| 普洱| 天镇县| 唐山市| 安康市| 图木舒克市| 太康县| 中方县| 襄樊市| 肥城市| 汤阴县| 雷州市| 花莲市| 监利县| 江口县| 黄浦区| 吉木乃县| 社旗县| 高尔夫| 阜宁县| 陆河县| 泽库县|