linux環境配置單機FastDFS文件存儲服務器

搭建linux環境下的FDFS文件服務器,用於圖片文件、視頻文件、音頻文件的存儲管理。html

測試環境:

tracker server 和 storage server 在同一臺機器121.42.25.134
nginx 與 storage server 對接linux

所需主要軟件包:
nginx

 pcre-8.36安裝服務器

tar -zxvf pcre-8.36.tar.gztcp

cd pcre-8.36測試

./configureui

make url

make installspa

 

zlib-1.2.8安裝.net

1> tar -xvf zlib-1.2.8.tar.gz
2> ./configure --prefix=/usr/local/zlib-1.2.8 
3> make
4> make install

 libevent-2.0.21-stable.tar.gz 安裝
1> tar -xvf libevent-2.0.21-stable.tar.gz
2> ./configure --prefix=/usr/local/libevent-2.0.21 (指定安裝目錄)
3> make
4> make install

FastDFS_v4.06.tar.gz 安裝
1> tar -xvf FastDFS_v4.06.tar.gz
2> cd FastDFS

3>vi make.sh

#指定fastdfs安裝路徑
TARGET_PREFIX=/usr/local/FastDFS

#指定fastdfs配置文件路徑
TARGET_CONF_PATH=/etc/fdfs
WITH_LINUX_SERVICE=1
4> ./make.sh C_INCLUDE_PATH=(libevent指定的安裝目錄)/usr/local/libevent-2.0.21/include LIBRARY_PATH=(libevent指定的安裝目錄)/usr/local/libevent-2.0.21/lib


5> ./make.sh install
6> 設置軟鏈接(不然編譯nginx時會出錯)
ln -sv /usr/local/FastDFS/include/fastcommon /usr/local/include/fastcommon
ln -sv /usr/local/FastDFS/include/fastdfs /usr/local/include/fastdfs
ln -sv /usr/local/FastDFS/lib/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -sv /usr/local/FastDFS/lib/libfastcommon.so.1 /usr/local/lib/libfastcommon.so.1
ln -sv /usr/local/FastDFS/lib/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -sv /usr/local/FastDFS/lib/libfdfsclient.so.1 /usr/local/lib/libfdfsclient.so.1

nginx-1.7.7.tar.gz + fastdfs-nginx-module_v1.15.tar.gz 安裝
1> tar -xvf nginx-1.7.7.tar.gz
2> tar -xvf fastdfs-nginx-module_v1.15.tar.gz
3> cd nginx-1.7.7
4> ./configure --prefix=/usr/local/nginx  --add-module=/fastdfs-nginx-module所在路徑/fastdfs-nginx-module/src

若是安裝nginx出錯時可指定安裝模塊和不安裝的模塊,確保安裝nginx不出錯(./configure --prefix=/usr/local/nginx --add-module=/usr/local/software/fastdfs-nginx-module/src/ --with-pcre=/usr/local/software/pcre-8.36 --with-openssl=/usr/local/software/openssl-1.0.2h --with-zlib=/usr/local/software/zlib-1.2.8)
5> make

6> make install

注意:安裝nginx 確保系統有 gcc、 openssl-devel、 pcre-devel和zlib-devel軟件庫

(安裝:yum install gcc 

 yum install openssl-devel

 yum install pcre-devel

 yum install zlib-devel)


5. tracker server
1> vi /etc/fdfs/tracker.conf
#bind_addr=
base_path=/home/tracker/fastdfs
2> 啓動 tracker
/usr/local/FastDFS/bin/fdfs_trackerd /etc/fdfs/tracker.conf 
3> netstat -ntpl | grep fdfs
tcp 00121.42.25.134:221220.0.0.0:* LISTEN /fdfs_trackerd

6. storage server
1> vi /etc/fdfs/storage.conf
group_name=group1
#bind_addr=
base_path=/home/storage1/fastdfs
store_path0=/home/storage1/fastdfs
tracker_server=121.42.25.134:22122

2> cp /路徑/fastdfs-nginx-module/src/mod_fastdfs.conf 至 /etc/fdfs/
3> vi /etc/fdfs/mod_fastdfs.conf
base_path=/home/storage1/fastdfs
group_name=group1
url_have_group_name=true

store_path0=/home/stroage1/fastdfs

tracker_server=121.42.25.134:22122

#HTTP settings
http.tracker_server_port=80

 

4>配置訪問路徑和nginx-fastdfs模塊: vi /usr/local/nginx/conf/nginx.conf    
   location /group1/M00 {
            root /home/storage1/fastdfs/data;
            ngx_fastdfs_module;
}
5> 啓動 storage  
/usr/local/FastDFS/bin/fdfs_storaged /etc/fdfs/storage.conf
6>  ln -s /home/storage1/fastdfs/data /home/storage1/fastdfs/data/M00
7> 啓動 nginx 
/usr/local/nginx/sbin/nginx

8> netstat -ntl

此時應該有3個監聽端口,分別是:
80 -> nginx
22122 -> tracker server
23000 -> storage server

7. 測試
1> vi /etc/fdfs/client.conf
base_path=/home/storage1/fastdfs
tracker_server=121.42.25.134:22122
2> /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload header.png


遊覽器輸入:
http://121.42.25.134/group1/M00/00/00/eSoZhlaSHkKAfOaDAAFWJ__s_HE465_big.png
 

正常來講按上面配置下來是能夠正常訪問,如圖

若是不能正常訪問,請檢查:

  1. 以上每步沒有出錯

  2. 檢查nginx路徑配置是否正確,nginx模塊是否有加載

  3. 服務器的防火牆是否已關閉

  4. 文件訪問權限

     

========================經常使用命令============================

啓動storage:   ./fdfs_storaged /etc/fdfs/storage.conf

啓動stracker:  ./fdfs_trackerd /etc/fdfs/tracker.conf

關閉storage:  ./stop.sh /etc/fdfs/storage.conf

關閉tracker:  ./stop.sh /etc/fdfs/tracker.conf

查看tracker和storage進程: netstat -unltp|grep fdfs

查看nginx進程: ps -ef|grep nginx

測試上傳:   ./fdfs_test /etc/fdfs/client.conf upload /usr/local/head.png 

查看存儲節點: ./fdfs_monitor /etc/fdfs/storage.conf

       ./fdfs_monitor /etc/fdfs/client.conf

移除某一集羣分組節點:

fdfs_monitor /etc/fdfs/client.conf delete group1 192.168.1.106

啓動順序:tracker-->storage-->nginx

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

一、tracker
A、啓動命令 :/usr/local/bin/fdfs_trackerd  /etc/fdfs/tracker.conf(tracker的配置文件路徑)
B、重啓命令:/usr/local/bin/restart.sh  /usr/local/bin/fdfs_trackerd /usr/local/config/tracker.conf (tracker的配置文件路徑)

二、storage
A、啓動命令:/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf (storage配置文件路徑)
B、重啓命令:/usr/local/bin/restart.sh :/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf (storage配置文件路徑)

三、重啓nginx: /usr/local/nginx/sbin/nginx -s reload

四、參考:

http://www.cnblogs.com/zhoulf/archive/2013/02/09/2909653.html

http://blog.csdn.net/yl_wh/article/details/8784569

http://blog.chinaunix.net/uid-20196318-id-4058561.html

http://baike.sogou.com/h60583131.htm?sp=l60583132

查看文件依賴關係:

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

遇到問題:

./fdfs_trackerd: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory解決辦法:

1 >whereis libevent-2.0.so.5

/usr/local/lib/libevent-2.0.so.5

2>ln -s /usr/local/lib/libevent-2.0.so.5 /lib64

參考:http://blog.sina.com.cn/s/blog_6d09b5750100vqow.html

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

雙storage,單tracker時,以下圖:大部分場景下,單tracker+多storage足夠知足大部分需求了

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

多tracker+多storage集羣參考:http://my.oschina.net/xiejunbo/blog/726192

相關文章
相關標籤/搜索