Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux管理 >> Linux 設定

FastDFS 雙節點部署:Tracker 與 Storage 整合 Nginx 上傳測試

環境:CentOS x86_64,0.205 與 0.206 兩台同時擔任 tracker 與 storage。

192.168.0.205  storage  tracker
192.168.0.206  storage  tracker

兩台的安裝配置幾乎一致,以下以單台為例,另一台照做並把 IP 換掉即可。

1. 安裝依賴並建立執行帳號

yum install -y zlib zlib-devel pcre pcre-devel gcc gcc-c++ \
  openssl openssl-devel libevent libevent-devel perl unzip
useradd -s /sbin/nologin fastdfs

2. 建立資料目錄

mkdir -p /export/fastdfs/{storage,tracker}

# storage 目錄存放運行日誌與 data 資料
# tracker 目錄存放運行日誌

3. 安裝 libfastcommon

wget https://github.com/happyfish100/libfastcommon/archive/master.zip
unzip master.zip
cd libfastcommon-master/
./make.sh
./make.sh install

4. 安裝 FastDFS

tar zxf FastDFS_v5.05.tar.gz && cd FastDFS
./make.sh
./make.sh install

cp conf/*.conf /etc/fdfs/
cd /etc/fdfs/ && rm -rf *.sample
chown -R fastdfs: /export/fastdfs

5. 修改配置文件

# storage.conf
group_name=group1
base_path=/export/fastdfs/storage
store_path0=/export/fastdfs/storage
tracker_server=192.168.0.205:22122
tracker_server=192.168.0.206:22122
http.server_port=80

# tracker.conf
base_path=/export/fastdfs/tracker

# mod_fastdfs.conf
group_name=group1
base_path=/export/fastdfs/storage
store_path0=/export/fastdfs/storage
tracker_server=192.168.0.205:22122
tracker_server=192.168.0.206:22122
url_have_group_name = true

# client.conf
tracker_server=192.168.0.205:22122
tracker_server=192.168.0.206:22122

6. 編譯 Nginx 與 fastdfs-nginx-module

tar zxf fastdfs-nginx-module_v1.16.tar.gz
tar zxf nginx-1.8.0.tar.gz

# 64 位元系統要改 module 中的函式庫路徑,否則無法正確載入
cd fastdfs-nginx-module/src
vi config
# 去掉 local,並指定 lib64
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib64 -lfastcommon -lfdfsclient"

ulimit -SHn 102400
useradd -s /sbin/nologin www

cd ../../nginx-1.8.0
./configure --user=www --group=www \
  --add-module=../fastdfs-nginx-module/src/ \
  --prefix=/usr/local/nginx \
  --with-http_stub_status_module \
  --with-http_ssl_module \
  --with-http_realip_module
make && make install

7. 配置 Nginx

server {
    listen 80;
    server_name 192.168.0.205;
    root /webdata/fastdfs.com;
    index index.html index.htm;

    location / {
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.html last;
        }

        location /group1/M00 {
            root /export/fastdfs/storage/data/;
            ngx_fastdfs_module;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js)$ {
            fastcgi_cache_valid 200 10m;
            fastcgi_cache_valid 304 3m;
            fastcgi_cache_valid 301 302 1h;
            fastcgi_cache_valid any 1m;
            fastcgi_cache_min_uses 1;
            fastcgi_cache_use_stale error timeout invalid_header http_500;
            fastcgi_cache_key $host$request_uri;
            access_log off;
        }
    }

    access_log off;
}

若要啟用 fastcgi_cache,記得先在 nginx.conf 的 http 段定義對應的 cache 區域,否則啟動會報錯。

8. 啟動並確認

206 的配置相同,Nginx 的 server_name 換成 206 即可。

/etc/init.d/fdfs_storaged start
/etc/init.d/fdfs_trackerd start

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload

netstat -npl | grep -E "nginx|fdfs"
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 8972/fdfs_trackerd
tcp 0 0 0.0.0.0:80    0.0.0.0:* LISTEN 7561/nginx
tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 8679/fdfs_storaged

9. 上傳測試

fdfs_test /etc/fdfs/client.conf upload test.html

輸出中會列出 tracker 查詢到的 storage 節點、最終落點的 group 與 remote_filename,並給出可直接存取的 URL:

group_name=group1, ip_addr=192.168.0.206, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgAzlV8em6Af8qBAAAADxtaRO466.html
example file url: https://192.168.0.206/group1/M00/00/00/wKgAzlV8em6Af8qBAAAADxtaRO466.html

看到這行網址能正常回傳檔案內容,整個集群就通了。

Copyright © Linux教程網 All Rights Reserved