一、跟蹤服務器(Tracker Server)php
tracker1:192.168.2.134html
tracker2:192.168.2.135
二、存儲服務器(Storage Server)linux
storage1:192.168.2.136nginx
storage2:192.168.2.137c++
storage3:192.168.2.138git
storage4:192.168.2.139
三、操做系統:CentOS7
用戶:root
數據存儲目錄:/home/fastdfsgithub
我把全部的安裝包下載到/usr/local/softpackages/下,解壓到當前目錄vim
[root@tracker1 ~]# ls /usr/local/softpackages/ 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip fastdfs-5.05 fastdfs-nginx-module-master libfastcommon-1.0.7 nginx-1.12.1 nginx-1.12.1.tar.gz V1.0.7.tar.gz V5.05.tar.gz
libfastcommon是從 FastDFS 和 FastDHT 中提取出來的公共 C 函數庫,基礎環境,安裝便可 。瀏覽器
① 下載libfastcommonbash
# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
② 解壓
# tar -zxvf V1.0.7.tar.gz
# cd libfastcommon-1.0.7
絕對路徑
# cd /usr/local/softpackages/libfastcommon-1.0.7
受權
# chmod 755 *
③ 編譯、安裝
# ./make.sh
# ./make.sh install
能夠一條語句:
# ./make.sh && ./make.sh install
[root@tracker1 libfastcommon-1.0.7]# pwd /usr/local/softpackages/libfastcommon-1.0.7 [root@tracker1 libfastcommon-1.0.7]# [root@tracker1 libfastcommon-1.0.7]# ll total 24 -rw-r--r--. 1 root root 2170 Jun 3 23:47 HISTORY -rw-r--r--. 1 root root 582 Jun 3 23:47 INSTALL -rw-r--r--. 1 root root 1341 Jun 3 23:47 libfastcommon.spec -rw-r--r--. 1 root root 2151 Jun 3 23:47 make.sh -rw-r--r--. 1 root root 617 Jun 3 23:47 README drwxr-xr-x. 2 root root 4096 Jun 3 23:47 src [root@tracker1 libfastcommon-1.0.7]# [root@tracker1 libfastcommon-1.0.7]# chmod 755 * [root@tracker1 libfastcommon-1.0.7]# [root@tracker1 libfastcommon-1.0.7]# ll total 24 -rwxr-xr-x. 1 root root 2170 Jun 3 23:47 HISTORY -rwxr-xr-x. 1 root root 582 Jun 3 23:47 INSTALL -rwxr-xr-x. 1 root root 1341 Jun 3 23:47 libfastcommon.spec -rwxr-xr-x. 1 root root 2151 Jun 3 23:47 make.sh -rwxr-xr-x. 1 root root 617 Jun 3 23:47 README drwxr-xr-x. 2 root root 4096 Jun 3 23:47 src [root@tracker1 libfastcommon-1.0.7]# [root@tracker1 libfastcommon-1.0.7]# ./make.sh cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o hash.lo hash.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o chain.lo chain.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o shared_func.lo shared_func.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o ini_file_reader.lo ini_file_reader.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o logger.lo logger.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o sockopt.lo sockopt.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o base64.lo base64.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o sched_thread.lo sched_thread.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o http_func.lo http_func.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o md5.lo md5.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o pthread_func.lo pthread_func.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o local_ip_func.lo local_ip_func.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o avl_tree.lo avl_tree.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o ioevent.lo ioevent.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o ioevent_loop.lo ioevent_loop.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o fast_task_queue.lo fast_task_queue.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o fast_timer.lo fast_timer.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o process_ctrl.lo process_ctrl.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o fast_mblock.lo fast_mblock.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -fPIC -o connection_pool.lo connection_pool.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o hash.o hash.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o chain.o chain.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o shared_func.o shared_func.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o ini_file_reader.o ini_file_reader.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o logger.o logger.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o sockopt.o sockopt.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o base64.o base64.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o sched_thread.o sched_thread.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o http_func.o http_func.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o md5.o md5.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o pthread_func.o pthread_func.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o local_ip_func.o local_ip_func.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o avl_tree.o avl_tree.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o ioevent.o ioevent.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o ioevent_loop.o ioevent_loop.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o fast_task_queue.o fast_task_queue.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o fast_timer.o fast_timer.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o process_ctrl.o process_ctrl.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o fast_mblock.o fast_mblock.c cc -Wall -D_FILE_OFFSET_BITS=64 -g -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o connection_pool.o connection_pool.c ar rcs libfastcommon.a hash.o [root@tracker1 libfastcommon-1.0.7]# [root@tracker1 libfastcommon-1.0.7]# ./make.sh install mkdir -p /usr/lib64 install -m 755 libfastcommon.so /usr/lib64 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_bits.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 /usr/include/fastcommon [root@tracker1 libfastcommon-1.0.7]#
④ libfastcommon.so 安裝到了/usr/lib64/libfastcommon.so,可是FastDFS主程序設置的lib目錄是/usr/local/lib,因此須要建立軟連接。
# 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
① 下載FastDFS
# wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
② 解壓
# tar -zxvf V5.05.tar.gz
# cd fastdfs-5.05
絕對路徑
# cd /usr/local/softpackages/fastdfs-5.05
受權
# chmod 755 *
③ 編譯、安裝
# ./make.sh
# ./make.sh install
[root@tracker1 softpackages]# cd fastdfs-5.05 [root@tracker1 fastdfs-5.05]# [root@tracker1 fastdfs-5.05]# pwd /usr/local/softpackages/fastdfs-5.05 [root@tracker1 fastdfs-5.05]# [root@tracker1 fastdfs-5.05]# ll total 128 drwxr-xr-x. 3 root root 4096 Jun 3 23:47 client drwxr-xr-x. 2 root root 4096 Jun 3 23:47 common drwxr-xr-x. 2 root root 4096 Jun 3 23:47 conf -rw-r--r--. 1 root root 35067 Jun 3 23:47 COPYING-3_0.txt -rw-r--r--. 1 root root 2802 Jun 3 23:47 fastdfs.spec -rw-r--r--. 1 root root 31386 Jun 3 23:47 HISTORY drwxr-xr-x. 2 root root 46 Jun 3 23:47 init.d -rw-r--r--. 1 root root 7755 Jun 3 23:47 INSTALL -rw-r--r--. 1 root root 5813 Jun 3 23:47 make.sh drwxr-xr-x. 2 root root 4096 Jun 3 23:47 php_client -rw-r--r--. 1 root root 2380 Jun 3 23:47 README.md -rw-r--r--. 1 root root 1768 Jun 3 23:47 restart.sh -rw-r--r--. 1 root root 1680 Jun 3 23:47 stop.sh drwxr-xr-x. 4 root root 4096 Jun 3 23:47 storage drwxr-xr-x. 2 root root 4096 Jun 3 23:47 test drwxr-xr-x. 2 root root 4096 Jun 3 23:47 tracker [root@tracker1 fastdfs-5.05]# [root@tracker1 fastdfs-5.05]# chmod 755 * [root@tracker1 fastdfs-5.05]# [root@tracker1 fastdfs-5.05]# ll total 128 drwxr-xr-x. 3 root root 4096 Jun 3 23:47 client drwxr-xr-x. 2 root root 4096 Jun 3 23:47 common drwxr-xr-x. 2 root root 4096 Jun 3 23:47 conf -rwxr-xr-x. 1 root root 35067 Jun 3 23:47 COPYING-3_0.txt -rwxr-xr-x. 1 root root 2802 Jun 3 23:47 fastdfs.spec -rwxr-xr-x. 1 root root 31386 Jun 3 23:47 HISTORY drwxr-xr-x. 2 root root 46 Jun 3 23:47 init.d -rwxr-xr-x. 1 root root 7755 Jun 3 23:47 INSTALL -rwxr-xr-x. 1 root root 5813 Jun 3 23:47 make.sh drwxr-xr-x. 2 root root 4096 Jun 3 23:47 php_client -rwxr-xr-x. 1 root root 2380 Jun 3 23:47 README.md -rwxr-xr-x. 1 root root 1768 Jun 3 23:47 restart.sh -rwxr-xr-x. 1 root root 1680 Jun 3 23:47 stop.sh drwxr-xr-x. 4 root root 4096 Jun 3 23:47 storage drwxr-xr-x. 2 root root 4096 Jun 3 23:47 test drwxr-xr-x. 2 root root 4096 Jun 3 23:47 tracker [root@tracker1 fastdfs-5.05]# [root@tracker1 fastdfs-5.05]# ./make.sh cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o ../common/fdfs_global.o ../common/fdfs_global.c -I../common -I/usr/include/fastcommon cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o tracker_proto.o tracker_proto.c -I../common -I/usr/include/fastcommon cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o tracker_mem.o tracker_mem.c -I../common -I/usr/include/fastcommon cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o tracker_service.o tracker_service.c -I../common -I/usr/include/fastcommon tracker_service.c: In function ‘tracker_deal_reselect_leader’: tracker_service.c:1743:21: warning: variable ‘pClientInfo’ set but not used [-Wunused-but-set-variable] TrackerClientInfo *pClientInfo; ……………………………… ……………………………… ……………………………… [root@tracker1 fastdfs-5.05]# ./make.sh install mkdir -p /usr/bin mkdir -p /etc/fdfs cp -f fdfs_trackerd /usr/bin if [ ! -f /etc/fdfs/tracker.conf.sample ]; then cp -f ../conf/tracker.conf /etc/fdfs/tracker.conf.sample; fi mkdir -p /usr/bin mkdir -p /etc/fdfs cp -f fdfs_storaged /usr/bin if [ ! -f /etc/fdfs/storage.conf.sample ]; then cp -f ../conf/storage.conf /etc/fdfs/storage.conf.sample; fi mkdir -p /usr/bin mkdir -p /etc/fdfs mkdir -p /usr/lib64 cp -f fdfs_monitor fdfs_test fdfs_test1 fdfs_crc32 fdfs_upload_file fdfs_download_file fdfs_delete_file fdfs_file_info fdfs_appender_test fdfs_appender_test1 fdfs_append_file fdfs_upload_appender /usr/bin if [ 0 -eq 1 ]; then cp -f libfdfsclient.a /usr/lib64; fi if [ 1 -eq 1 ]; then cp -f libfdfsclient.so /usr/lib64; fi mkdir -p /usr/include/fastdfs cp -f ../common/fdfs_define.h ../common/fdfs_global.h ../common/mime_file_parser.h ../common/fdfs_http_shared.h ../tracker/tracker_types.h ../tracker/tracker_proto.h ../tracker/fdfs_shared_func.h ../storage/trunk_mgr/trunk_shared.h tracker_client.h storage_client.h storage_client1.h client_func.h client_global.h fdfs_client.h /usr/include/fastdfs if [ ! -f /etc/fdfs/client.conf.sample ]; then cp -f ../conf/client.conf /etc/fdfs/client.conf.sample; fi
④ 默認安裝方式安裝後的相應文件與目錄
A、服務腳本:
/etc/init.d/fdfs_storaged
/etc/init.d/fdfs_tracker
B、配置文件(這三個是做者給的樣例配置文件) :
/etc/fdfs/client.conf.sample /etc/fdfs/storage.conf.sample /etc/fdfs/tracker.conf.sample
C、命令工具在 /usr/bin/ 目錄下:
fdfs_appender_test fdfs_appender_test1 fdfs_append_file fdfs_crc32 fdfs_delete_file fdfs_download_file fdfs_file_info fdfs_monitor fdfs_storaged fdfs_test fdfs_test1 fdfs_trackerd fdfs_upload_appender fdfs_upload_file stop.sh restart.sh
⑤ FastDFS 服務腳本設置的 bin 目錄是 /usr/local/bin, 但實際命令安裝在 /usr/bin/ 下
兩種方式:
》 一是修改FastDFS 服務腳本中相應的命令路徑,也就是把 /etc/init.d/fdfs_storaged 和 /etc/init.d/fdfs_tracker 兩個腳本中的 /usr/local/bin 修改爲 /usr/bin。
# vim fdfs_trackerd
使用查找替換命令進統一修改:%s+/usr/local/bin+/usr/bin
# vim fdfs_storaged
使用查找替換命令進統一修改:%s+/usr/local/bin+/usr/bin
# vi /etc/init.d/fdfs_storaged
》 二是創建 /usr/bin 到 /usr/local/bin 的軟連接,我是用這種方式。
# ln -s /usr/bin/fdfs_trackerd /usr/local/bin # ln -s /usr/bin/fdfs_storaged /usr/local/bin # ln -s /usr/bin/stop.sh /usr/local/bin # ln -s /usr/bin/restart.sh /usr/local/bin
配置文件詳細說明參考:FastDFS 配置文件詳解
① 進入 /etc/fdfs,複製 FastDFS 跟蹤器樣例配置文件 tracker.conf.sample,並重命名爲 tracker.conf。
# cd /etc/fdfs
# cp tracker.conf.sample tracker.conf
# vim tracker.conf
[root@tracker1 ~]# cd /etc/fdfs [root@tracker1 fdfs]# [root@tracker1 fdfs]# ls client.conf.sample storage.conf.sample tracker.conf.sample [root@tracker1 fdfs]# [root@tracker1 fdfs]# cp tracker.conf.sample tracker.conf [root@tracker1 fdfs]#
② 編輯tracker.conf ,標紅的須要修改下,其它的默認便可。
# vi tracker.conf
# 配置文件是否不生效,false 爲生效 disabled=false # 提供服務的端口 port=22122 # Tracker 數據和日誌目錄地址(根目錄必須存在,子目錄會自動建立) base_path=/home/fastdfs/tracker # HTTP 服務端口 http.server_port=80
③ 建立tracker基礎數據目錄,即base_path對應的目錄
# mkdir -p /home/fastdfs/tracker
④ 防火牆中打開跟蹤端口(默認的22122)
# vim /etc/sysconfig/iptables 添加以下端口行: -A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT 重啓防火牆: # service iptables restart
⑤ 啓動Tracker
初次成功啓動,會在 /home/fdfsdfs/tracker/ (配置的base_path)下建立 data、logs 兩個目錄。
注意:
啓動前先受權
# chmod 755 /etc/init.d/fdfs_trackerd
# chmod 755 -R /usr/local/bin/fdfs_trackerd
[root@tracker2 fdfs]# /etc/init.d/fdfs_trackerd start -bash: /etc/init.d/fdfs_trackerd: Permission denied [root@tracker2 fdfs]# [root@tracker2 fdfs]# chmod 755 /etc/init.d/fdfs_trackerd [root@tracker2 fdfs]# [root@tracker2 fdfs]# /etc/init.d/fdfs_trackerd start Reloading systemd: [ OK ] Starting fdfs_trackerd (via systemctl): [ OK ] [root@tracker2 fdfs]# [root@tracker2 fdfs]# service fdfs_trackerd status ● fdfs_trackerd.service - LSB: FastDFS tracker server Loaded: loaded (/etc/rc.d/init.d/fdfs_trackerd) Active: active (exited) since Tue 2019-06-04 18:47:32 CST; 14s ago Docs: man:systemd-sysv-generator(8) Process: 3083 ExecStart=/etc/rc.d/init.d/fdfs_trackerd start (code=exited, status=0/SUCCESS) Jun 04 18:47:32 tracker2 systemd[1]: Starting LSB: FastDFS tracker server... Jun 04 18:47:32 tracker2 fdfs_trackerd[3083]: Starting FastDFS tracker server: Jun 04 18:47:32 tracker2 systemd[1]: Started LSB: FastDFS tracker server. Jun 04 18:47:32 tracker2 fdfs_trackerd[3083]: /etc/rc.d/init.d/fdfs_trackerd: line 43: /usr/local/bin/fdfs_trackerd: Permission denied [root@tracker2 fdfs]# [root@tracker2 fdfs]# chmod 755 -R /usr/local/bin/fdfs_trackerd [root@tracker2 fdfs]# [root@tracker2 fdfs]# service fdfs_trackerd restart Restarting fdfs_trackerd (via systemctl): [ OK ] [root@tracker2 fdfs]# [root@tracker2 fdfs]# service fdfs_trackerd status ● fdfs_trackerd.service - LSB: FastDFS tracker server Loaded: loaded (/etc/rc.d/init.d/fdfs_trackerd) Active: active (running) since Tue 2019-06-04 18:48:08 CST; 3s ago Docs: man:systemd-sysv-generator(8) Process: 3127 ExecStop=/etc/rc.d/init.d/fdfs_trackerd stop (code=exited, status=0/SUCCESS) Process: 3150 ExecStart=/etc/rc.d/init.d/fdfs_trackerd start (code=exited, status=0/SUCCESS) CGroup: /system.slice/fdfs_trackerd.service └─3154 /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf Jun 04 18:48:08 tracker2 systemd[1]: Starting LSB: FastDFS tracker server... Jun 04 18:48:08 tracker2 fdfs_trackerd[3150]: Starting FastDFS tracker server: Jun 04 18:48:08 tracker2 systemd[1]: Started LSB: FastDFS tracker server. [root@tracker2 fdfs]#
能夠用這種方式啓動
# /etc/init.d/fdfs_trackerd start
也能夠用這種方式啓動,前提是上面建立了軟連接,後面都用這種方式
# service fdfs_trackerd start
查看 FastDFS Tracker 是否已成功啓動 ,22122端口正在被監聽,則算是Tracker服務安裝成功。
# netstat -tunlp | grep fdfs
[root@tracker1 ~]# service fdfs_trackerd start Starting fdfs_trackerd (via systemctl): [ OK ] [root@tracker1 ~]# [root@tracker1 ~]# [root@tracker1 ~]# service fdfs_trackerd status ● fdfs_trackerd.service - LSB: FastDFS tracker server Loaded: loaded (/etc/rc.d/init.d/fdfs_trackerd) Active: active (running) since Tue 2019-06-04 00:45:46 CST; 4s ago Docs: man:systemd-sysv-generator(8) Process: 2822 ExecStart=/etc/rc.d/init.d/fdfs_trackerd start (code=exited, status=0/SUCCESS) CGroup: /system.slice/fdfs_trackerd.service └─2825 /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf Jun 04 00:45:46 tracker1 systemd[1]: Starting LSB: FastDFS tracker server... Jun 04 00:45:46 tracker1 fdfs_trackerd[2822]: Starting FastDFS tracker server: Jun 04 00:45:46 tracker1 systemd[1]: Started LSB: FastDFS tracker server. [root@tracker1 ~]# [root@tracker1 ~]# [root@tracker1 ~]# netstat -tunlp | grep fdfs tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 2825/fdfs_trackerd [root@tracker1 ~]# [root@tracker1 ~]# ls /home/fastdfs/tracker/ data logs
關閉Tracker命令:
# service fdfs_trackerd stop
⑥ 設置Tracker開機啓動
# chkconfig fdfs_trackerd on 或者: # vim /etc/rc.d/rc.local 加入配置: /etc/init.d/fdfs_trackerd start
⑦ tracker server 目錄及文件結構
Tracker服務啓動成功後,會在base_path下建立data、logs兩個目錄。目錄結構以下:
${base_path} |__data | |__storage_groups.dat:存儲分組信息 | |__storage_servers.dat:存儲服務器列表 |__logs | |__trackerd.log: tracker server 日誌文件
① 進入 /etc/fdfs 目錄,複製 FastDFS 存儲器樣例配置文件 storage.conf.sample,並重命名爲 storage.conf
# cd /etc/fdfs # cp storage.conf.sample storage.conf
② 編輯storage.conf
標紅的須要修改,其它的默認便可。
# vi storage.conf
# 配置文件是否不生效,false 爲生效 disabled=false # 指定此 storage server 所在 組(卷) group_name=group1 # storage server 服務端口 port=23000 # 心跳間隔時間,單位爲秒 (這裏是指主動向 tracker server 發送心跳) heart_beat_interval=30 # Storage 數據和日誌目錄地址(根目錄必須存在,子目錄會自動生成) base_path=/home/fastdfs/storage # 存放文件時 storage server 支持多個路徑。這裏配置存放文件的基路徑數目,一般只配一個目錄。 store_path_count=1 # 逐一配置 store_path_count 個路徑,索引號基於 0。 # 若是不配置 store_path0,那它就和 base_path 對應的路徑同樣。 store_path0=/home/fastdfs/file # FastDFS 存儲文件時,採用了兩級目錄。這裏配置存放文件的目錄個數。 # 若是本參數只爲 N(如: 256),那麼 storage server 在初次運行時,會在 store_path 下自動建立 N * N 個存放文件的子目錄。 subdir_count_per_path=256 # tracker_server 的列表 ,會主動鏈接 tracker_server # 有多個 tracker server 時,每一個 tracker server 寫一行 tracker_server=192.168.2.134:22122
tracker_server=192.168.2.135:22122
# 容許系統同步的時間段 (默認是全天) 。通常用於避免高峯同步產生一些問題而設定。 sync_start_time=00:00 sync_end_time=23:59 # 訪問端口 http.server_port=80
③ 建立Storage基礎數據目錄,對應base_path目錄
# mkdir -p /home/fastdfs/storage
這是配置的store_path0路徑
# mkdir -p /home/fastdfs/file
④ 防火牆中打開存儲器端口(默認的 23000)
# vim /etc/sysconfig/iptables 添加以下端口行: -A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT 重啓防火牆: # service iptables restart
⑤ 啓動 Storage
啓動Storage前確保Tracker是啓動的。初次啓動成功,會在 /home/fastdfs/storage 目錄下建立 data、 logs 兩個目錄。
注意:
啓動前先受權
# chmod 755 /etc/init.d/fdfs_storaged
# chmod 755 /usr/local/bin/fdfs_storaged
能夠用這種方式啓動
# /etc/init.d/fdfs_storaged start
也能夠用這種方式,後面都用這種
# service fdfs_storaged start
[root@storage1 ~]# service fdfs_storaged start env: /etc/init.d/fdfs_storaged: Permission denied [root@storage1 ~]# [root@storage1 ~]# chmod 755 /etc/init.d/fdfs_storaged [root@storage1 ~]# [root@storage1 ~]# service fdfs_storaged start Starting fdfs_storaged (via systemctl): [ OK ] [root@storage1 ~]# [root@storage1 ~]# service fdfs_storaged status ● fdfs_storaged.service - LSB: FastDFS storage server Loaded: loaded (/etc/rc.d/init.d/fdfs_storaged) Active: active (exited) since Tue 2019-06-04 02:28:10 CST; 50s ago Docs: man:systemd-sysv-generator(8) Process: 16929 ExecStart=/etc/rc.d/init.d/fdfs_storaged start (code=exited, status=0/SUCCESS) Jun 04 02:28:10 storage1 systemd[1]: Starting LSB: FastDFS storage server... Jun 04 02:28:10 storage1 fdfs_storaged[16929]: Starting FastDFS storage server: Jun 04 02:28:10 storage1 systemd[1]: Started LSB: FastDFS storage server. Jun 04 02:28:10 storage1 fdfs_storaged[16929]: /etc/rc.d/init.d/fdfs_storaged: line 43: /usr/local/bin/fdfs_storaged: Permission denied [root@storage1 ~]# [root@storage1 ~]# chmod 755 /usr/local/bin/fdfs_storaged [root@storage1 ~]# [root@storage1 ~]# service fdfs_storaged restart Restarting fdfs_storaged (via systemctl): [ OK ] [root@storage1 ~]# [root@storage1 ~]# service fdfs_storaged status ● fdfs_storaged.service - LSB: FastDFS storage server Loaded: loaded (/etc/rc.d/init.d/fdfs_storaged) Active: active (running) since Tue 2019-06-04 02:29:30 CST; 4s ago Docs: man:systemd-sysv-generator(8) Process: 16973 ExecStop=/etc/rc.d/init.d/fdfs_storaged stop (code=exited, status=0/SUCCESS) Process: 16996 ExecStart=/etc/rc.d/init.d/fdfs_storaged start (code=exited, status=0/SUCCESS) CGroup: /system.slice/fdfs_storaged.service └─17001 /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf Jun 04 02:29:30 storage1 systemd[1]: Starting LSB: FastDFS storage server... Jun 04 02:29:30 storage1 fdfs_storaged[16996]: Starting FastDFS storage server: Jun 04 02:29:30 storage1 systemd[1]: Started LSB: FastDFS storage server. [root@storage1 ~]# netstat -tunlp | grep fdfs tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 17001/fdfs_storaged
關閉Storage命令:
# service fdfs_storaged stop
查看Storage和Tracker是否在通訊:
# chmod 755 /usr/bin/fdfs_monitor
# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[root@storage1 ~]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf bash: /usr/bin/fdfs_monitor: Permission denied [root@storage1 ~]# [root@storage1 ~]# chmod 755 /usr/bin/fdfs_monitor [root@storage1 ~]# [root@storage1 ~]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf [2019-06-04 02:36:19] DEBUG - base_path=/home/fastdfs/storage, 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 server_count=1, server_index=0 tracker server is 192.168.2.134:22122 group count: 1 Group 1: group name = group1 disk total space = 79833 MB disk free space = 78514 MB trunk free space = 0 MB storage server count = 1 active server count = 1 storage server port = 23000 storage HTTP port = 80 store path count = 1 subdir count per path = 256 current write server index = 0 current trunk file id = 0 Storage 1: id = 192.168.2.136 ip_addr = 192.168.2.136 ACTIVE http domain = version = 5.05 join time = 2019-06-04 02:29:30 up time = 2019-06-04 02:29:30 total storage = 79833 MB free storage = 78514 MB upload priority = 10 store_path_count = 1 subdir_count_per_path = 256 storage_port = 23000 storage_http_port = 80 current_write_path = 0 source storage id = if_trunk_server = 0 connection.alloc_count = 256 connection.current_count = 0 connection.max_count = 0 total_upload_count = 0 success_upload_count = 0 total_append_count = 0 success_append_count = 0 total_modify_count = 0 success_modify_count = 0 total_truncate_count = 0 success_truncate_count = 0 total_set_meta_count = 0 success_set_meta_count = 0 total_delete_count = 0 success_delete_count = 0 total_download_count = 0 success_download_count = 0 total_get_meta_count = 0 success_get_meta_count = 0 total_create_link_count = 0 success_create_link_count = 0 total_delete_link_count = 0 success_delete_link_count = 0 total_upload_bytes = 0 success_upload_bytes = 0 total_append_bytes = 0 success_append_bytes = 0 total_modify_bytes = 0 success_modify_bytes = 0 stotal_download_bytes = 0 success_download_bytes = 0 total_sync_in_bytes = 0 success_sync_in_bytes = 0 total_sync_out_bytes = 0 success_sync_out_bytes = 0 total_file_open_count = 0 success_file_open_count = 0 total_file_read_count = 0 success_file_read_count = 0 total_file_write_count = 0 success_file_write_count = 0 last_heart_beat_time = 2019-06-04 02:36:02 last_source_update = 1970-01-01 08:00:00 last_sync_update = 1970-01-01 08:00:00 last_synced_timestamp = 1970-01-01 08:00:00 [root@storage1 ~]#
⑥ 設置 Storage 開機啓動
# chkconfig fdfs_storaged on 或者: # vim /etc/rc.d/rc.local 加入配置: /etc/init.d/fdfs_storaged start
⑦ Storage 目錄
同 Tracker,Storage 啓動成功後,在base_path 下建立了data、logs目錄,記錄着 Storage Server 的信息。
在 store_path0 目錄下,建立了N*N個子目錄:
# ls /home/fastdfs/file/data/
① 修改 Tracker 服務器中的客戶端配置文件
# cd /etc/fdfs # cp client.conf.sample client.conf
修改以下配置便可,其它默認。
# Client 的數據和日誌目錄 base_path=/home/fastdfs/client # Tracker端口 tracker_server=192.168.2.134:22122
建立client基礎數據目錄,對應base_path目錄
# mkdir -p /home/fastdfs/client
② 上傳測試
在linux內部執行以下命令上傳test.jpg 圖片
# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf test.jpg
[root@tracker1 ~]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf test.jpg -bash: /usr/bin/fdfs_upload_file: Permission denied [root@tracker1 ~]# [root@tracker1 ~]# chmod 755 /usr/bin/fdfs_upload_file [root@tracker1 ~]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf test.jpg group1/M00/00/00/wKgCiFz1bm-ATQNlAACLwhA7j18254.jpg
上傳成功後返回文件ID號:group1/M00/00/00/wKgCiFz1bm-ATQNlAACLwhA7j18254.jpg
返回的文件ID由group、存儲目錄、兩級子目錄、fileid、文件後綴名(由客戶端指定,主要用於區分文件類型)拼接而成。
上面將文件上傳成功了,但咱們沒法下載。所以安裝Nginx做爲服務器以支持Http方式訪問文件。同時,後面安裝FastDFS的Nginx模塊也須要Nginx環境。
Nginx只須要安裝到StorageServer所在的服務器便可,用於訪問文件。
① gcc 安裝
# yum install gcc-c++ -y
② PCRE pcre-devel 安裝
# yum install -y pcre pcre-devel
③ zlib 安裝
# yum install -y zlib zlib-devel
④ OpenSSL 安裝
# yum install -y openssl openssl-devel
① 下載nginx
# wget -c https://nginx.org/download/nginx-1.12.1.tar.gz
② 解壓
# tar -zxvf nginx-1.12.1.tar.gz # cd nginx-1.12.1
③ 使用默認配置
# ./configure
實例操做以下:
[root@storage1 softpackages]# chmod 755 -R nginx-1.12.1 [root@storage1 softpackages]# [root@storage1 softpackages]# cd nginx-1.12.1 [root@storage1 nginx-1.12.1]# [root@storage1 nginx-1.12.1]# pwd /usr/local/softpackages/nginx-1.12.1 [root@storage1 nginx-1.12.1]# [root@storage1 nginx-1.12.1]# ll total 716 drwxr-xr-x. 6 root root 4096 Jun 3 23:48 auto -rwxr-xr-x. 1 root root 277349 Jun 3 23:48 CHANGES -rwxr-xr-x. 1 root root 422542 Jun 3 23:48 CHANGES.ru drwxr-xr-x. 2 root root 4096 Jun 3 23:48 conf -rwxr-xr-x. 1 root root 2481 Jun 3 23:48 configure drwxr-xr-x. 4 root root 68 Jun 3 23:48 contrib drwxr-xr-x. 2 root root 38 Jun 3 23:48 html -rwxr-xr-x. 1 root root 1397 Jun 3 23:48 LICENSE -rwxr-xr-x. 1 root root 376 Jun 3 23:48 Makefile drwxr-xr-x. 2 root root 20 Jun 3 23:48 man drwxr-xr-x. 4 root root 4096 Jun 3 23:48 objs -rwxr-xr-x. 1 root root 49 Jun 3 23:48 README drwxr-xr-x. 9 root root 84 Jun 3 23:48 src [root@storage1 nginx-1.12.1]# [root@storage1 nginx-1.12.1]# ./configure Configuration summary + using system PCRE library + OpenSSL library is not used + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp" [root@storage1 nginx-1.12.1]#
④ 編譯、安裝
# make # make install
⑤ 啓動nginx
# cd /usr/local/nginx/sbin/ # ./nginx 其它命令 # ./nginx -s stop # ./nginx -s quit # ./nginx -s reload
⑥ 設置開機啓動
# vim /etc/rc.local 添加一行: /usr/local/nginx/sbin/nginx # 設置執行權限 # chmod 755 rc.local
⑦ 查看nginx的版本及模塊
# /usr/local/nginx/sbin/nginx -V
[root@storage1 ~]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.12.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) configure arguments:
⑧ 防火牆中打開Nginx端口(默認的 80)
添加後就能在本機使用80端口訪問了。
# vim /etc/sysconfig/iptables 添加以下端口行: -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 重啓防火牆: # service iptables restart
簡單的測試訪問文件
① 修改nginx.conf
# vim /usr/local/nginx/conf/nginx.conf 添加以下行,將 /group1/M00 映射到 /home/fastdfs/file/data location /group1/M00 { alias /home/fastdfs/file/data; } # 重啓nginx # /usr/local/nginx/sbin/nginx -s reload
查看80端口是否監聽
# netstat -tunlp | grep 80
[root@storage1 sbin]# netstat -tunlp | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 31104/nginx: master
② 在瀏覽器訪問以前上傳的圖片、成功。
http://192.168.2.136/group1/M00/00/00/wKgCiFz1bm-ATQNlAACLwhA7j18254.jpg
① fastdfs-nginx-module 模塊說明
FastDFS 經過 Tracker 服務器,將文件放在 Storage 服務器存儲, 可是同組存儲服務器之間須要進行文件複製, 有同步延遲的問題。
假設 Tracker 服務器將文件上傳到了 192.168.2.136,上傳成功後文件 ID已經返回給客戶端。
此時 FastDFS 存儲集羣機制會將這個文件同步到同組存儲 192.168.2.138,在文件尚未複製完成的狀況下,客戶端若是用這個文件 ID 在 192.168.2.138 上取文件,就會出現文件沒法訪問的錯誤。
而 fastdfs-nginx-module 能夠重定向文件連接到源服務器取文件,避免客戶端因爲複製延遲致使的文件沒法訪問錯誤。
② 下載 fastdfs-nginx-module、解壓
# 這裏爲啥這麼長一串呢,由於最新版的master與當前nginx有些版本問題。 # wget https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip # 解壓 # unzip 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip # 重命名 # mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1 fastdfs-nginx-module-master
③ 配置Nginx
在nginx中添加模塊
# 先停掉nginx服務 # /usr/local/nginx/sbin/nginx -s stop 進入解壓包目錄 # cd /usr/local/softpackages/nginx-1.12.1 # 添加模塊 # ./configure --add-module=../fastdfs-nginx-module-master/src 從新編譯、安裝 # make && make install
④ 查看Nginx的模塊
# /usr/local/nginx/sbin/nginx -V
有下面這個就說明添加模塊成功
[root@storage1 nginx-1.12.1]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.12.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) configure arguments: --add-module=../fastdfs-nginx-module-master/src [root@storage1 nginx-1.12.1]#
⑤ 複製 fastdfs-nginx-module 源碼中的配置文件到/etc/fdfs 目錄, 並修改
[root@storage1 ~]# cd /usr/local/softpackages/fastdfs-nginx-module-master/src/ [root@storage1 src]# [root@storage1 src]# cp mod_fastdfs.conf /etc/fdfs/
修改以下配置,其它默認
# vi /etc/fdfs/mod_fastdfs.conf
# 鏈接超時時間 connect_timeout=10 # Tracker Server tracker_server=192.168.2.134:22122 # StorageServer 默認端口 storage_server_port=23000 # 若是文件ID的uri中包含/group**,則要設置爲true url_have_group_name = true # Storage 配置的store_path0路徑,必須和storage.conf中的一致 store_path0=/home/fastdfs/file
⑥ 複製 FastDFS 的部分配置文件到/etc/fdfs 目錄
[root@storage1 softpackages]# cd fastdfs-5.05/conf/ [root@storage1 conf]# [root@storage1 conf]# pwd /usr/local/softpackages/fastdfs-5.05/conf [root@storage1 conf]# [root@storage1 conf]# cp anti-steal.jpg http.conf mime.types /etc/fdfs/
⑦ 配置nginx,修改nginx.conf
# vim /usr/local/nginx/conf/nginx.conf
修改配置,其它的默認
在80端口下添加fastdfs-nginx模塊
location ~/group([0-9])/M00 { ngx_fastdfs_module; }
注意:
listen 80 端口值是要與 /etc/fdfs/storage.conf 中的 http.server_port=80 (前面改爲80了)相對應。若是改爲其它端口,則須要統一,同時在防火牆中打開該端口。
location 的配置,若是有多個group則配置location ~/group([0-9])/M00 ,沒有則不用配group。
⑧ 在/home/fastdfs/file 文件存儲目錄下建立軟鏈接,將其連接到實際存放數據的目錄,這一步能夠省略
# ln -s /home/fastdfs/file/data/ /home/fastdfs/file/data/M00
⑨ 啓動nginx
# /usr/local/nginx/sbin/nginx
打印處以下就算配置成功
[root@storage1 ~]# /usr/local/nginx/sbin/nginx ngx_http_fastdfs_set pid=34082 [root@storage1 ~]#
⑩ 在地址欄訪問。
能下載文件就算安裝成功。注意和第三點中直接使用nginx路由訪問不一樣的是,這裏配置 fastdfs-nginx-module 模塊,能夠重定向文件連接到源服務器取文件。
http://192.168.2.136/group1/M00/00/00/wKgCiFz1bm-ATQNlAACLwhA7j18254.jpg
https://www.cnblogs.com/chiangchou/p/fastdfs.html
https://blog.csdn.net/yin_zh0522/article/details/81232041