參見 INSTALL 文件php
cd libfastcommon ./make.sh ./make.sh install #生成的文件 mkdir -p /usr/lib64 mkdir -p /usr/lib install -m 755 libfastcommon.so /usr/lib64 install -m 755 libfastcommon.so /usr/lib mkdir -p /usr/include/fastcommon install -m 644 common_define.h hash.h chain.h logger.h base64.h shared_func.h pthread_func.h ini_file_reader.h _os_define.h sockopt.h sched_thread.h http_func.h md5.h local_ip_func.h avl_tree.h ioevent.h ioevent_loop.h fast_task_queue.h fast_timer.h process_ctrl.h fast_mblock.h connection_pool.h fast_mpool.h fast_allocator.h fast_buffer.h skiplist.h multi_skiplist.h flat_skiplist.h skiplist_common.h system_info.h fast_blocked_queue.h php7_ext_wrapper.h id_generator.h char_converter.h char_convert_loader.h /usr/include/fastcommon
直接運行 make.sh
,sh make.sh install
直接安裝html
也能夠修改 make.sh
, 指定安裝位置,第51行添加nginx
DESTDIR=/Users/sky/all/web/fastdfs
這樣全部文件都在指定目錄中,方便管理.git
若是指定了安裝位置,安裝 fastdfs-nginx-module
會找不到文件.能夠只留下 bin
文件的內容,將其餘文件複製到系統對應的位置.github
修改配置文件web
vi /etc/fdfs/tracker.conf # the base path to store data and log files # modify base_path=/Users/sky/all/web/fastdfs/base/trackerd
啓動shell
/Users/sky/all/web/fastdfs/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
修改 storage.conf瀏覽器
#拷貝一份新的storage配置文件: cp storage.conf.sample storage.conf #修改storage.conf vi storage.conf group_name=group1 base_path=base_path=/Users/sky/all/web/fastdfs/base/storaged store_path0=/Users/sky/all/web/fastdfs/store #若是有多個掛載磁盤則定義多個store_path,以下 #store_path1=..... #store_path2=...... tracker_server=192.168.1.103:22122 #配置tracker服務器:IP #若是有多個則配置多個tracker #tracker_server=192.168.101.4:22122 #配置http端口 http.server_port=80
啓動bash
/Users/sky/all/web/fastdfs/bin/fdfs_storaged /etc/fdfs/storage.conf restart
fdfs_monitor /etc/fdfs/storage.conf服務器
/Users/sky/all/web/fastdfs/bin/fdfs_monitor /etc/fdfs/storage.conf /Users/sky/all/web/fastdfs/bin/fdfs_monitor /etc/fdfs/client.conf
test
/Users/sky/all/web/fastdfs/bin/fdfs_test /etc/fdfs/client.conf upload /Users/sky/Pictures/pretty.jpg
測試結果
$ /Users/sky/all/web/fastdfs/bin/fdfs_test /etc/fdfs/client.conf upload /Users/sky/Pictures/pretty.jpg This is FastDFS client test program v5.12 Copyright (C) 2008, Happy Fish / YuQing FastDFS may be copied only under the terms of the GNU General Public License V3, which may be found in the FastDFS source kit. Please visit the FastDFS Home Page http://www.csource.org/ for more detail. [2018-04-27 15:16:09] DEBUG - base_path=/Users/sky/all/web/fastdfs/base/client, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0 tracker_query_storage_store_list_without_group: server 1. group_name=, ip_addr=192.168.1.103, port=23000 group_name=group1, ip_addr=192.168.1.103, port=23000 storage_upload_by_filename group_name=group1, remote_filename=M00/00/00/wKgBZ1rizjmAIoMoAAAiJgI2OLI651.jpg source ip address: 192.168.1.103 file timestamp=2018-04-27 15:16:09 file size=8742 file crc32=37107890 example file url: http://192.168.1.103:8080/group1/M00/00/00/wKgBZ1rizjmAIoMoAAAiJgI2OLI651.jpg storage_upload_slave_by_filename group_name=group1, remote_filename=M00/00/00/wKgBZ1rizjmAIoMoAAAiJgI2OLI651_big.jpg source ip address: 192.168.1.103 file timestamp=2018-04-27 15:16:09 file size=8742 file crc32=37107890 example file url: http://192.168.1.103:8080/group1/M00/00/00/wKgBZ1rizjmAIoMoAAAiJgI2OLI651_big.jpg
配置
./configure \ --prefix=/Users/sky/all/web/nginx \ --with-http_ssl_module \ --with-pcre \ --sbin-path=/Users/sky/all/web/nginx/bin/nginx \ --with-cc-opt='-I/usr/local/opt/pcre/include -I/usr/local/opt/openssl/include' \ --with-ld-opt='-L/usr/local/opt/pcre/lib -L/usr/local/opt/openssl/lib' \ --conf-path=/Users/sky/all/web/nginx/nginx.conf \ --pid-path=/Users/sky/all/web/nginx/run/nginx.pid \ --lock-path=/Users/sky/all/web/nginx/run/nginx.lock \ --http-client-body-temp-path=/Users/sky/all/web/nginx/run/nginx/client_body_temp \ --http-proxy-temp-path=/Users/sky/all/web/nginx/run/nginx/proxy_temp \ --http-fastcgi-temp-path=/Users/sky/all/web/nginx/run/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/Users/sky/all/web/nginx/run/nginx/uwsgi_temp \ --http-scgi-temp-path=/Users/sky/all/web/nginx/run/nginx/scgi_temp \ --http-log-path=/Users/sky/all/web/nginx/log/access.log \ --error-log-path=/Users/sky/all/web/nginx/log/error.log \ --with-http_gzip_static_module \ --with-http_v2_module \ --with-http_addition_module \ --add-module=/Users/sky/all/source/nginx/ngx-fancyindex \ --add-module=/Users/sky/all/source/nginx/fastdfs-nginx-module/src
說明:
--prefix=/Users/sky/all/web/nginx
: nginx 主目錄--sbin-path=/Users/sky/all/web/nginx/bin/nginx
: nginx 的可執行文件--conf-path=/Users/sky/all/web/nginx/nginx.conf
:nginx 的配置文件--http-log-path=/Users/sky/all/web/nginx/log/access.log
:訪問日誌--error-log-path=/Users/sky/all/web/nginx/log/error.log
:錯誤日誌--add-module=/Users/sky/all/source/nginx/ngx-fancyindex
:一個 nginx 目錄美化插件,教程地址:nginx目錄列表及美化--add-module=/Users/sky/all/source/nginx/fastdfs-nginx-module/src
: fastdfs-nginx-module
,插件目錄安裝
make & make install
修改 nginx 的配置文件
subl /Users/sky/all/web/nginx/nginx.conf server { listen 8080; server_name localhost; location / { root html; index index.html index.htm; } location /download{ # 目錄美化配置 include /Users/sky/all/web/nginx/html/Nginx-Fancyindex-Theme/fancyindex.conf; alias /Users/sky/Downloads; #指定目錄所在路徑 autoindex on; #開啓目錄瀏覽 autoindex_format html; #以html風格將目錄展現在瀏覽器中 autoindex_exact_size off; #切換爲 off 後,以可讀的方式顯示文件大小,單位爲 KB、MB 或者 GB autoindex_localtime on; #以服務器的文件時間做爲顯示的時間 charset utf-8,gbk; #展現中文文件名 } location /group1/M00 { alias /Users/sky/all/web/fastdfs/store/data; 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; }
修改/etc/fdfs/mod_fastdfs.conf
#存放 mod_fastdfs 日誌的位置,不重要 base_path=/Users/sky/all/web/fastdfs/base/fastdfs-nginx-module #設置 tracker_server 的地址 tracker_server=localhost:22122 #設置該 storage 所屬組 group_name=group1 #url 訪問路徑. false 爲: /M00/00/xxx. true 爲/group1/M00/00/XXX url_have_group_name = true #必須與 storage.conf 中的配置相同 store_path0=/Users/sky/all/web/fastdfs/store
建立符號連接
ln -s /Users/sky/all/web/fastdfs/store/data /Users/sky/all/web/fastdfs/store/data/M00
用上面的測試結果測試:
下載fastdht
git clone https://github.com/happyfish100/fastdht.git
下載berkeley-db
wget http://download.oracle.com/berkeley-db/db-4.7.25.tar.gz
該版本比較舊了,不過fastdht
中的文檔使用的是這個版本,能用就行.
安裝berkeley-db
tar xzf db-4.7.25.tar.gz cd db-4.7.25/build_unix ../dist/configure --prefix=/Users/sky/all/db/berkeley-4.7.25 make; make install
我指定了berkeley-db
安裝到其餘位置.
編譯安裝fastdht
TARGET_PREFIX=/Users/sky/all/web/fdht TARGET_CONF_PATH=/Users/sky/all/web/fdht/conf CFLAGS='-Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/Users/sky/all/db/berkeley-4.7.25/include/ -L/Users/sky/all/db/berkeley-4.7.25/lib/'
cd FastDHT ./make.sh; sudo ./make.sh install
說明:
TARGET_PREFIX=/Users/sky/all/web/fdht
安裝位置TARGET_CONF_PATH=/Users/sky/all/web/fdht/conf
配置文件位置CFLAGS='-Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/Users/sky/all/db/berkeley-4.7.25/include/ -L/Users/sky/all/db/berkeley-4.7.25/lib/'
berkeley
的安裝目錄位置,注意寫法./make.sh install
時,會有文件到連接到/usr
目錄中去,須要root
權限.因此使用sudo
圓形
配置
修改fdfhd.conf
# the base path to store data and log files # 日誌和數據文件位置 base_path=/Users/sky/all/web/fdht/fastdht #引用fdht_servers.conf,注意 : include 語法,不適用的話要加兩個 ## #include /Users/sky/all/web/fdht/conf/fdht_servers.conf
修改fdht_servers.conf
group_count = 1 group0 = 192.168.1.103:11411
修改fdht-client.conf
#modify keep_alive=1 #modify base_path=/Users/sky/all/web/fdht/fastdht-client #include /Users/sky/all/web/fdht/conf/fdht_servers.conf
啓動
/Users/sky/all/web/fdht/bin/fdhtd /Users/sky/all/web/fdht/conf/fdhtd.conf restart
測試
/Users/sky/all/web/fdht/bin/fdht_test /Users/sky/all/web/fdht/conf/fdht_client.conf
mac 下用這個命令測試會有錯.直接使用上傳測試
上傳一個文件
/Users/sky/all/web/fastdfs/bin/fdfs_upload_file /etc/fdfs/client.conf /Users/sky/Pictures/pretty.jpg
返回結果:
group1/M00/00/00/wKgBZ1rjRm2ANoTIAAAiJjMA_kk080.jpg
這時在/Users/sky/all/web/fastdfs/store/data/00
目錄發現有兩個文件. 分別是:wKgBZ1rjRm2AYrHAAAAiJgI2OLI775.jpg
和wKgBZ1rjRm2ANoTIAAAiJjMA_kk080.jpg
其中wKgBZ1rjRm2ANoTIAAAiJjMA_kk080.jpg
時指向wKgBZ1rjRm2AYrHAAAAiJgI2OLI775.jpg
的連接.能夠多上傳幾回嘗試.
刪除剛纔上傳的文件.
/Users/sky/all/web/fastdfs/bin/fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgBZ1rjRm2ANoTIAAAiJjMA_kk080.jpg
結束是wKgBZ1rjRm2AYrHAAAAiJgI2OLI775.jpg
和wKgBZ1rjRm2ANoTIAAAiJjMA_kk080.jpg
都被刪除了.
總結: fastdht
確實起到了文件去重的效果.文件只保留一份,繼續上傳相同的文件會建立文件的連接.若是最後一個連接被刪除的時候,原文件也會被刪除.