FastDFS+Nginx單機部署


一、環境

    Ubuntu 18.04.1 LTS

二、資源準備

1.  nginx-1.14.0

2.  FastDFS-5.11

3.  fastdfs-nginx-module

4.  libfastcommon

三、安裝

    1.安裝libfastcommon

       1>解壓libfastcommon

       2>make命令編譯

       3>make install命令安裝

       4>設置軟鏈接

       ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
       ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
       ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
       ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

    2.安裝FastDFS

       1>解壓

       2>make命令編譯,make install命令安裝

       3>將安裝到/etc/fdfs/下的三個示例配置文件複製一份,去掉.sample後綴

    3.配置Tracker

       1>在/opt/下建立f_tracker目錄

       2>修改2.3>中的tracker.conf文件

           disabled=false#啓用配置文件(false爲啓用)
           port=22122#設置tracker的端口號,通常採用22122這個默認端口
           base_path=/opt/f_tracker#設置tracker的數據文件和日誌目錄
           http.server_port=6666#設置http端口號,默認爲8080

3>爲啓動腳本創建軟引用,因爲fdfs_trackerd等命令在/usr/local/bin中並沒有,而是在/usr/bin路徑下

           ln -s /usr/bin/fdfs_trackerd /usr/local/bin
           ln -s /usr/bin/stop.sh /usr/local/bin
           ln -s /usr/bin/restart.sh /usr/local/bin

4>service fdfs_trackerd start 啓動Tracker服務器(通過netstat -unltp|grep fdfs 命令查看tracker服務的監聽情況)

    4.配置Storage

       1>在/opt/下建立f_storage和f_storage_data目錄

       2>修改2.3>中的storage.conf文件

       disabled=false#啓用配置文件(false爲啓用)
       group_name=group1#組名,根據實際情況修改
       port=23000 #設置storage的端口號,默認是23000,同一個組的storage端口號必須  一致
       base_path=/opt/f_storage#設置storage數據文件和日誌目錄
       store_path_count=1 #存儲路徑個數,需要和store_path個數匹配
       store_path0=/opt/f_storage_data #實際文件存儲路徑
       tracker_server=192.168.43.45:22122 #tracker 服務器的 IP地址和端口號,因爲本次是單機搭建,所以此處爲本機ip,集羣搭建的話即填寫tracker服務器所在的ip
       http.server_port=8888#設置 http 端口號

       3>爲Storage服務器的啓動腳本設置軟引用

         ln -s /usr/bin/fdfs_storaged /usr/local/bin

       4>service fdfs_storaged start 命令啓動Storage服務器,文件存儲路徑下會生成多級存儲目錄即爲成功

       5>查看storage是否登記在tracker上。命令/usr/bin/fdfs_monitor /etc/fdfs/storage.conf 有圖中Active字樣爲成功

1111.png


    5.配置client.conf

       1>修改2.3>中的storage.conf文件

         base_path=/opt/fastdfs_tracker#tracker服務器文件路徑
         tracker_server=192.168.43.45:22122#tracker服務器IP地址和端口號
       http.tracker_server_port=6666# tracker 服務器的 http 端口號,必須和tracker的設置對應起來

       2>通過命令上傳1.txt

         /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/2.jpg

       3>成功則返回id爲group1/M00/00/00/wKgrLVu5nQ6ADqBpAAB92gKP0_o908.jpg

    6.安裝Nginx

       1>解壓nginx-1.14.0和fastdfs-nginx-module

       2>爲nginx添加fastdfs-nginx-module模塊。在nginx-1.14.0目錄下輸入命令./configure --prefix=/usr/share/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module --add-module=/home/jobs/fastdfs/moudle1/src

--prefix爲安裝目錄,/home/jobs/fastdfs/moudle1/src爲模塊所在目錄

       3>make命令編譯

       4>make install命令安裝

       5>我安裝時編譯一直不通過,弄了大半天也沒通過,最後我是先通過apt-get install nginx安裝nginx,然後nognx -V命令查看安裝信息,得知--prefix=/usr/share/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module,然後在nginx-1.14.0目錄下輸入命令./configure加以上信息加--add-module=/home/jobs/fastdfs/moudle1/src  最終編譯成功。

    7.配置fastdfs-nginx-module模塊和nginx

       1>修改/usr/share/nginx/nginx.conf

           server {

        listen       8888;

        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   html;

            index  index.html index.htm;

        }

    location ~/group1/M00 {

           ngx_fastdfs_module;

    }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #    root           html;

        #    fastcgi_pass   127.0.0.1:9000;

        #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #    include        fastcgi_params;

        #}

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

       2>進入FastDFS安裝包的目錄下的conf目錄,將http.conf和mime.types拷貝到/etc/fdfs目錄下,接下來還需要把fastdfs-nginx-module安裝目錄中src目錄下的mod_fastdfs.conf也拷貝到/etc/fdfs目錄下:

       3>mod_fastdfs.conf修改如下配置,其它默認

# 連接超時時間

connect_timeout=10

# Tracker Server

tracker_server=file.ljzsg.com:22122

# StorageServer 默認端口

storage_server_port=23000

# 如果文件ID的uri中包含/group**,則要設置爲true

url_have_group_name = true

# Storage 配置的store_path0路徑,必須和storage.conf中的一致

store_path0=/opt/f_storage_data

       4>啓動Nginx 命令service nginx start,打印出pid信息爲成功

       5>瀏覽器訪問http://192.168.43.45:8888/group1/M00/00/00/wKgrLVu5nQ6ADqBpAAB92gKP0_o908.jpg

 2222.png

 

四、集羣安裝

    集羣安裝只需要在每臺機器上安裝fastdfs和nginx,如果是一臺tracker,多臺storage,只要在一臺機器上配置tracker,其他機器上配置storage和nginx即可。Fastdfs也可以有多臺tracker組成,每臺tracker地位相同,輪查使用,storage可以按組劃分,每個group內的storage的內容相同。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章