Cluster基礎(五):配置tracker、配置storage、文件測試及web訪問

1、配置trackerhtml

目標:nginx

FastDFS是一個分佈式文件系統,主要的服務器角色有Tracker和Storage。本例安裝一臺Tracker,實現如下功能:web

  • 接受客戶端的訪問
  • 檢索存儲節點,爲客戶端提供一臺可用的storage

方案:vim

準備一臺虛擬機,安裝FastDFS Tracker。服務器

主機的主機名及對應的IP地址以下表所示。tcp

    

步驟:分佈式

1)配置yum源,並安裝所需的軟件包。工具

    [root@fdfs_tracker1 ~]# yum install -y gcc libevent make
    [root@fdfs_tracker1 ~]# yum install -y libevent-devel-*.rpm測試

2)解壓縮FastDFS安裝包,查看安裝說明文檔進行安裝。url

    [root@fdfs_tracker1 fdfs]# tar xzf FastDFS_v4.06.tar.gz
    [root@fdfs_tracker1 fdfs]# cd FastDFS
    [root@fdfs_tracker1 FastDFS]# vim INSTALL
    [root@fdfs_tracker1 fdfs]# ./make.sh
    [root@fdfs_tracker1 fdfs]# ./make.sh install
    [root@fdfs_tracker1 FastDFS]# vim INSTALL
    [root@fdfs_tracker1 FastDFS]# cp init.d/fdfs_trackerd /etc/init.d/

3)建立存儲目錄(存儲日誌等)。

  [root@fdfs_tracker1 FastDFS]# mkdir -pv /data/fastdfs

4)修改配置文件。

    [root@fdfs_tracker1 FastDFS]# vim /etc/fdfs/tracker.conf
    base_path=/data/fastdfs/     # 設置基礎目錄
    max_connections=4096         # 設置最大鏈接數
    store_group=group1           # 設置存儲組名
    use_storage_id = true        # 使用stroage_id代替ip地址

5)建立storage_id文件。

    [root@fdfs_tracker1 FastDFS]# cp conf/storage_ids.conf /etc/fdfs/

6)編輯storage id文件,加入存儲組聲明。

    [root@fdfs_tracker1 FastDFS]# vim /etc/fdfs/storage_ids.conf
    100001   group1  192.168.113.60

7)修改客戶端配置文件。

    [root@fdfs_tracker1 FastDFS]# vim /etc/fdfs/client.conf
    base_path=/data/fastdfs
    tracker_server=192.168.113.50:22122

8)控制tracker啓動。

    [root@fdfs_tracker1 FastDFS]# /etc/init.d/fdfs_trackerd
    用法:/etc/init.d/fdfs_trackerd {start|stop|status|restart|condrestart}

9)查看tracker運行狀態。

    [root@fdfs_tracker1 FastDFS]# /etc/init.d/fdfs_trackerd status
    fdfs_trackerd (pid 28928) 正在運行...
    [root@fdfs_tracker1 FastDFS]# netstat -tlnp | grep tracker
    tcp  0    0   0.0.0.0:22122      0.0.0.0:*    LISTEN      28928/fdfs_trackerd

2、配置storage

目標:

安裝FastDFS Storage存儲節點,存儲節點被劃分到相應的組裏。同一個組中的服務器保存徹底相同的內容, 不一樣分組存不一樣的內容。存儲節點具備如下功能:

  • 接受Tracker的調度
  • 響應客戶端請求
  • 將客戶端發來的文件存儲至相應存儲位置
  • 讀取請求的文件,發送給客戶端

方案:

準備一臺虛擬機,安裝FastDFS Tracker。

主機的主機名及對應的IP地址以下表所示。

    

步驟:

1)配置yum源,並安裝所需的軟件包。

    [root@fdfs_storage1 ~]# yum install -y gcc libevent make
    [root@fdfs_storage1 ~]# yum install -y libevent-devel-*.rpm

2)解壓縮、查看安裝指南進行安裝

    [root@fdfs_storage1 fdfs]# tar xzf FastDFS_v4.06.tar.gz
    [root@fdfs_storage1 fdfs]# cd FastDFS
    [root@fdfs_storage1 FastDFS]# vim INSTALL
    [root@fdfs_storage1 fdfs]# ./make.sh
    [root@fdfs_storage1 fdfs]# ./make.sh install
    [root@fdfs_storage1 FastDFS]# vim INSTALL
    [root@fdfs_storage1 FastDFS]# cp init.d/fdfs_storaged /etc/init.d/

3)建立數據存儲目錄(存儲日誌、數據文件等)

   [root@fdfs_storage1 FastDFS]# mkdir -pv /data/fastdfs

4)修改配置文件。

    [root@fdfs_storage1 FastDFS]# vim /etc/fdfs/storage.conf
    base_path=/data/fastdfs/      # 設置基礎工做目錄
    max_connections=4096           # 設置最大鏈接數
    store_path0=/data/fastdfs/    # 設置上傳文件目錄
    tracker_server=192.168.113.50:22122    # 設置鏈接的Tracker
    upload_priority=10              # 設置組內服務器優先級

5)控制storage啓動

    [root@fdfs_storage1 FastDFS]# /etc/init.d/fdfs_storaged
    用法:/etc/init.d/fdfs_storaged {start|stop|status|restart|condrestart}

6)查看storage工做狀態

    [root@fdfs_storage1 FastDFS]# /etc/init.d/fdfs_storaged status
    fdfs_storaged (pid 28916) 正在運行...
    [root@fdfs_storage1 FastDFS]# netstat -tlnp | grep storage
    tcp        0      0 0.0.0.0:23000               0.0.0.0:*                   LISTEN      28916/fdfs_storaged

3、文件測試及web訪問

目標:

爲實現文件的上傳、下載和刪除等功能,FastDFS提供相應的命令行工具。測試這些工具的使用。

爲了方便用戶訪問,能夠在storage上配置web訪問功能,使得文件通夠經過web頁面進行訪問。

步驟:

步驟一:經過fdfs_test

1)上傳文件

測試程序會對一個文件上傳兩次。返回的文件id也是兩個並上傳文件附加屬性。storage上生成4個文件

  [root@fdfs_tracker ~]# /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload install.log

查看上傳到storage的文件

    [root@fdfs_storage1 FastDFS]# ls /data/fastdfs/data/00/00/
    wKhxPFc3oD6ARewxAAC6OPZ7hp8271_big.log    wKhxPFc3oD6ARewxAAC6OPZ7hp8271.log
    wKhxPFc3oD6ARewxAAC6OPZ7hp8271_big.log-m  wKhxPFc3oD6ARewxAAC6OPZ7hp8271.log-m

2)刪除文件

    [root@fdfs_tracker1 fastdfs]# /usr/local/bin/fdfs_test /etc/fdfs/client.conf\
     delete group1 M00/00/00/wKhxPFc3oD6ARewxAAC6OPZ7hp8271_big.log

步驟二:經過其餘相關命令

1)經過fdfs_upload_file上傳文件

    [root@fdfs_tracker1 fastdfs]# /usr/local/bin/fdfs_upload_file\
     /etc/fdfs/client.conf /etc/passwd
    group1/M00/00/00/wKhxPFc3pEyAFrHBAAAGKI1fx1k5058918

2)經過fdfs_download_file下載文件

    [root@fdfs_tracker1 ~]# /usr/local/bin/fdfs_download_file /etc/fdfs/client.conf\
     group1/M00/00/00/wKhxPFc3pEyAFrHBAAAGKI1fx1k5058918

3)經過fdfs_delete_file刪除文件

    [root@fdfs_tracker1 ~]# /usr/local/bin/fdfs_delete_file /etc/fdfs/client.conf\
     group1/M00/00/00/wKhxPFc3pEyAFrHBAAAGKI1fx1k5058918

步驟三:配置web訪問

1)在storage上安裝nginx

    [root@fdfs_storage1 ~]# yum install -y pcre pcre-devel zlib zlib-devel
    [root@fdfs_storage1 fdfs]# tar xzf fastdfs-nginx-module_v1.16.tar.gz
    [root@fdfs_storage1 fdfs]# tar xzf nginx-1.7.10.tar.gz
    [root@fdfs_storage1 fdfs]# cd nginx-1.7.10
    [root@fdfs_storage1 nginx-1.7.10]# useradd -s /sbin/nologin nginx
    [root@fdfs_storage1 nginx-1.7.10]# ./configure --prefix=/usr/local/nginx \
    --user=nginx --group=nginx --add-module=../fastdfs-nginx-module/src/
    [root@fdfs_storage1 nginx-1.7.10]# make && make install

2)爲nginx修改fastdfs模塊配置

    [root@fdfs_storage1 fdfs]# cp fastdfs-nginx-module/src/mod_fastdfs.conf \
    /etc/fdfs
    [root@fdfs_storage1 fdfs]# vim /etc/fdfs/mod_fastdfs.conf
    tracker_server=192.168.113.50:22122
    group_name=group1
    url_have_group_name = true
    store_path0=/data/fastdfs/

3)修改ngin配置文件並啓動

    [root@fdfs_storage1 fdfs]# vim /usr/local/nginx/conf/nginx.conf
    # location / {
    #    root   html;
    #    index  index.html index.htm;
    # }                                      將這段說明註釋掉,增長如下說明
     location / {
                ngx_fastdfs_module;
            }
    [root@fdfs_storage1 fdfs]# /usr/local/nginx/sbin/nginx

4)測試web訪問

    [root@fdfs_tracker1 ~]# /usr/local/bin/fdfs_upload_file \
    /etc/fdfs/client.conf tedu.jpg
    group1/M00/00/00/wKhxPFc4f2yAVLH7AACwEV-ILDc194.jpg
    [root@fdfs_tracker1 ~]# firefox\
     http://192.168.113.60/group1/M00/00/00/wKhxPFc4f2yAVLH7AACwEV-ILDc194.jpg &

結果以下圖所示

     

相關文章
相關標籤/搜索