建站不啰嗦,上手跟我做(二十一)FastDFS+FastDHT 安装

第一、复制安装文件到 tmp 目录下

挂载 windows 共享文件夹
[root@localhost /]# mount -t cifs -o username=linux,password=123456,vers=3.0  \\\\192.168.219.230\\linux /mnt
[root@localhost mnt]# cd Disk1/
[root@localhost Disk1]# pwd
/mnt/Disk1
[root@localhost Disk1]# ls
db-18.1.25.tar.gz  FastDFS_v5.08.tar.gz FastDHT_v2.01.tar.gz  libfastcommon_v1.01.tar.gz
[root@localhost Disk1]# cp ./db-18.1.25.tar.gz /tmp
[root@localhost Disk1]# cp ./FastDHT_v2.01.tar.gz /tmp
[root@localhost Disk1]# cp ./libfastcommon-master.zip  /tmp
[root@localhost Disk1]# cp ./FastDFS_v5.08.tar.gz /tmp
[root@localhost Disk1]# cd /tmp
[root@localhost tmp]# ls
db-18.1.25.tar.gz
FastDHT_v1.12.tar.gz
hsperfdata_root
ks-script-Yt2tvM
libfastcommon-master.zip 
systemd-private-860d6fe48efa4d34ba6571dfd6b65df8-cups.service-FL6dK7
FastDFS_v5.08.tar.gz
yum.log
[root@localhost tmp]# pwd
/tmp
配置 ip 映射
[root@localhost etc]# vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.102 fastdfsdht

修改后没有立即生效

[root@localhost conf]# service network restart
Restarting network (via systemctl):                        [  OK  ]

第二、安装对应软件

1、安装 gcc gcc-c++ 依赖

[root@localhost tmp]# yum install make cmake gcc gcc-c++
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.nju.edu.cn
 * extras: mirrors.shu.edu.cn
 * updates: mirrors.shu.edu.cn
base                                          | 3.6 kB     00:00   
extras                                        | 3.4 kB     00:00   
updates                                       | 3.4 kB     00:00   
(1/4): base/7/x86_64/group_gz                   | 166 kB   00:00   
(2/4): extras/7/x86_64/primary_db               | 156 kB   00:01   
(3/4): updates/7/x86_64/primary_db              | 1.3 MB   00:03   
(4/4): base/7/x86_64/primary_db                 | 6.0 MB   01:03   
Package 1:make-3.82-23.el7.x86_64 already installed and latest version
Package gcc-4.8.5-36.el7.x86_64 already installed and latest version
Package gcc-c++-4.8.5-36.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package cmake.x86_64 0:2.8.12.2-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================
 Package      Arch          Version                Repository   Size
=====================================================================
Installing:
 cmake        x86_64        2.8.12.2-2.el7         base        7.1 M

Transaction Summary
=====================================================================
Install  1 Package

Total download size: 7.1 M
Installed size: 27 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/cmake-2.8.12.2-2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for cmake-2.8.12.2-2.el7.x86_64.rpm is not installed
cmake-2.8.12.2-2.el7.x86_64.rpm                 | 7.1 MB   00:06   
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-6.1810.2.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : cmake-2.8.12.2-2.el7.x86_64                       1/1 
  Verifying  : cmake-2.8.12.2-2.el7.x86_64                       1/1 

Installed:
  cmake.x86_64 0:2.8.12.2-2.el7                                  

Complete!

2、安装 fastDFS

1)、安装 libfastcommon-master.zip
[root@localhost tmp]# unzip libfastcommon-master.zip 
Archive:  libfastcommon-master.zip
e9822aa8e3323cecb89fd5dc0059ad0786da5d9a
   creating: libfastcommon-master/
  inflating: libfastcommon-master/HISTORY  
  inflating: libfastcommon-master/INSTALL  
  inflating: libfastcommon-master/README  
   creating: libfastcommon-master/doc/
  inflating: libfastcommon-master/doc/id_generator-Chinese.md  
  inflating: libfastcommon-master/doc/ini_file_reader-Chinese.md  
  inflating: libfastcommon-master/doc/php_log_file_performance-Chinese.md  
  inflating: libfastcommon-master/libfastcommon.spec  
  inflating: libfastcommon-master/make.sh  

[root@localhost tmp]# cd libfastcommon-master/
[root@localhost libfastcommon-master]# ls
doc      INSTALL             make.sh         README
HISTORY  libfastcommon.spec  php-fastcommon  src
[root@localhost libfastcommon-master]# ./make.sh
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O3 -c -o hash.o hash.c  
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O3 -c -o chain.o chain.c  
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O3 -c -o shared_func.o shared_func.c  

[root@localhost libfastcommon-master]# ./make.sh install
mkdir -p /usr/lib64
mkdir -p /usr/lib
mkdir -p /usr/include/fastcommon
install -m 755 libfastcommon.so /usr/lib64
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 common_blocked_queue.h multi_socket_client.h skiplist_set.h fc_list.h json_parser.h /usr/include/fastcommon
if [ ! -e /usr/lib/libfastcommon.so ]; then ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so; fi
2)、安装 FastDFS
[root@localhost tmp]# tar -zxvf FastDFS_v5.08.tar.gz 
FastDFS/
FastDFS/tracker/
FastDFS/tracker/tracker_global.c
FastDFS/tracker/tracker_http_check.c
FastDFS/tracker/tracker_http_check.h
FastDFS/tracker/tracker_types.h
FastDFS/tracker/tracker_service.h

[root@localhost tmp]# cd FastDFS/
[root@localhost FastDFS]# ls
client  COPYING-3_0.txt  init.d   php_client  stop.sh  tracker
common  fastdfs.spec     INSTALL  README.md   storage
conf    HISTORY          make.sh  restart.sh  test
[root@localhost FastDFS]# ./make.sh
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -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 -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 -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 -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]
[root@localhost FastDFS]# ./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; cp -f libfdfsclient.a /usr/lib;fi
if [ 1 -eq 1 ]; then cp -f libfdfsclient.so /usr/lib64; cp -f libfdfsclient.so /usr/lib;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
3)、配置 tracker.conf
[root@localhost FastDFS]# cd /etc/fdfs
[root@localhost fdfs]# ls
client.conf.sample  storage.conf.sample  tracker.conf.sample
拷贝一份新的tracker配置文件
[root@localhost fdfs]# cp tracker.conf.sample tracker.conf
[root@localhost fdfs]# vim tracker.conf
base_path=/home/yuqing/fastdfs  改为:  base_path=/home/fastdfs
http.server_port  改为: 80
base_path=/home/fastdfs
http.server_port=80  #配置http端口
创建 /home/fastdfs 目录
[root@localhost fdfs]# mkdir /home/fastdfs
4)、启动 tracker
[root@localhost bin]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
5)、配置 storage
[root@localhost logs]# cd /etc/fdfs
[root@localhost fdfs]# ls
client.conf.sample  storage.conf.sample  tracker.conf  tracker.conf.sample
[root@localhost fdfs]# cp storage.conf.sample storage.conf
[root@localhost fdfs]# ls
client.conf.sample  storage.conf  storage.conf.sample  tracker.conf  tracker.conf.sample
[root@localhost fdfs]# vim storage.conf
group_name=group1 #配置组名
base_path=/home/yuqing/fastdfs    改为:  base_path=/home/fastdfs

#store存放文件的位置(store_path)
store_path0=/home/yuqing/fastdfs  改为: store_path0=/home/fdfs_storage1 
#如果有多个挂载磁盘则定义多个store_path,如下
#store_path1=.....
#store_path2=......

#配置tracker服务器:IP
tracker_server=fastdfsdht:22122
#如果有多个则配置多个tracker
#tracker_server=192.168.101.4:22122

#配置http端口
http.server_port=88
[root@localhost fdfs]# mkdir /home/fdfs_storage1
6)、启动 storage
[root@localhost fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

3、测试 fastDFS

[root@localhost fdfs]# cp client.conf.sample client.conf
[root@localhost fdfs]# vim client.conf
# the base path to store log files
base_path=/home/fastdfs

# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=fastdfsdht:22122
[root@localhost tmp]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /tmp/test.jpg
This is FastDFS client test program v5.08

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-12-29 16:22:30] DEBUG - base_path=/home/fastdfs, 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.219.39, port=23000

group_name=group1, ip_addr=192.168.219.39, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKjbJ1wnLsaAXEtEAAAMNijkPP8291.jpg
source ip address: 192.168.219.39
file timestamp=2018-12-29 16:22:30
file size=3126
file crc32=686046463
example file url: http://192.168.219.39/group1/M00/00/00/wKjbJ1wnLsaAXEtEAAAMNijkPP8291.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKjbJ1wnLsaAXEtEAAAMNijkPP8291_big.jpg
source ip address: 192.168.219.39
file timestamp=2018-12-29 16:22:30
file size=3126
file crc32=686046463
example file url: http://192.168.219.39/group1/M00/00/00/wKjbJ1wnLsaAXEtEAAAMNijkPP8291_big.jpg
[root@localhost 00]# ls
wKjbJ1wnLsaAXEtEAAAMNijkPP8291_big.jpg    wKjbJ1wnLsaAXEtEAAAMNijkPP8291.jpg
wKjbJ1wnLsaAXEtEAAAMNijkPP8291_big.jpg-m  wKjbJ1wnLsaAXEtEAAAMNijkPP8291.jpg-m
[root@localhost 00]# pwd
/home/fdfs_storage1/data/00/00

4、安装 db-18.1.25.tar.gz

[root@localhost tmp]# tar -zxvf db-18.1.25.tar.gz
[root@localhost tmp]# cd db-18.1.25/
[root@localhost db-18.1.25]# ls
build_android  build_vxworks  dist  examples          lang     README
build_unix     build_windows  docs  EXAMPLES-LICENSE  LICENSE  src   
[root@localhost db-18.1.25]# cd build_unix
[root@localhost build_unix]# chmod 777 ../dist/configure
[root@localhost build_unix]# ../dist/configure --prefix=/usr/local/db-18.1.25
[root@localhost build_unix]# make && make install
[root@localhost build_unix]# cd /usr/local
[root@localhost local]# ls
bin         etc    include  lib64    sbin   src
db-18.1.25  games  lib      libexec  share

5、安装 fastDHT

[root@localhost local]# cd /tmp
[root@localhost tmp]# ls
db-18.1.25
db-18.1.25.tar.gz
FastDFS
FastDFS_v5.08.tar.gz
FastDHT_v2.01.tar.gz
hsperfdata_root
ks-script-Yt2tvM
libfastcommon-master
libfastcommon-master.zip
libfastcommon_v1.01.tar.gz
libfastcommon_v1.04.tar.gz
systemd-private-860d6fe48efa4d34ba6571dfd6b65df8-cups.service-FL6dK7
test.jpg
yum.log
[root@localhost tmp]# tar -zxvf FastDHT_v2.01.tar.gz
[root@localhost tmp]# cd /tmp/FastDHT/
[root@localhost FastDHT]# ls
client  common  conf  HISTORY  init.d  INSTALL  make.sh  php_client  README  restart.sh  server  stop.sh  tool
[root@localhost FastDHT]# vim make.sh
编译之前需要先修改make.sh文件。在大约27修改CFLAGS为:

#CFLAGS='-O3 -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE'
CFLAGS='-Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/usr/local/db-18.1.25/include/ -L/usr/local/db-18.1.25/lib/'
[root@localhost FastDHT]# ./make.sh && ./make.sh install 
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/usr/local/db-18.1.25/include/ -L/usr/local/db-18.1.25/lib/ -DOS_LINUX -c -o global.o global.c  -I../common -I/usr/local/include
In file included from global.c:15:0:
global.h:18:19: fatal error: event.h: No such file or directory
 #include <event.h>
                   ^
compilation terminated.
make: *** [global.o] Error 1
[root@localhost FastDHT]# cd ..
[root@localhost tmp]# wget -O libevent-2.0.21-stable.tar.gz https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
--2018-12-29 17:15:55--  https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
Resolving github.com (github.com)... 52.74.223.119, 13.250.177.223, 13.229.188.59
Connecting to github.com (github.com)|52.74.223.119|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github.s3.amazonaws.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20181229%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20181229T091558Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=dffd852b27f88ccd9c5adc18a4aed6e6007b223b6039ae3c26eefeb3380d7a0c [following]
--2018-12-29 17:15:58--  https://github.s3.amazonaws.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20181229%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20181229T091558Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=dffd852b27f88ccd9c5adc18a4aed6e6007b223b6039ae3c26eefeb3380d7a0c
Resolving github.s3.amazonaws.com (github.s3.amazonaws.com)... 52.216.105.171
Connecting to github.s3.amazonaws.com (github.s3.amazonaws.com)|52.216.105.171|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 850772 (831K) [application/gzip]
Saving to: ‘libevent-2.0.21-stable.tar.gz’

100%[===================================================================================================================================================>] 850,772      244KB/s   in 3.4s   

2018-12-29 17:16:03 (244 KB/s) - ‘libevent-2.0.21-stable.tar.gz’ saved [850772/850772]
[root@localhost tmp]# tar -zxvf libevent-2.0.21-stable.tar.gz
[root@localhost tmp]# cd libevent-2.0.21-stable/
[root@localhost libevent-2.0.21-stable]# ls
aclocal.m4              bufferevent_ratelim.c  configure            evdns.h           evport.c             evutil.h         libevent_openssl.pc.in   Makefile.am         select.c
arc4random.c            bufferevent_sock.c     configure.in         event.c           evrpc.c              evutil_rand.c    libevent.pc.in           Makefile.in         signal.c
autogen.sh              buffer_iocp.c          defer-internal.h     event.h           evrpc.h              ht-internal.h    libevent_pthreads.pc.in  Makefile.nmake      strlcpy.c
buffer.c                changelist-internal.h  depcomp              event-internal.h  evrpc-internal.h     http.c           LICENSE                  minheap-internal.h  strlcpy-internal.h
bufferevent_async.c     ChangeLog              devpoll.c            event_iocp.c      evsignal-internal.h  http-internal.h  listener.c               missing             test
bufferevent.c           compat                 Doxyfile             event_rpcgen.py   evthread.c           include          log.c                    mm-internal.h       util-internal.h
bufferevent_filter.c    compile                epoll.c              event_tagging.c   evthread-internal.h  install-sh       log-internal.h           poll.c              whatsnew-2.0.txt
bufferevent-internal.h  config.guess           epoll_sub.c          evhttp.h          evthread_pthread.c   iocp-internal.h  ltmain.sh                ratelim-internal.h  WIN32-Code
bufferevent_openssl.c   config.h.in            evbuffer-internal.h  evmap.c           evthread_win32.c     ipv6-internal.h  m4                       README              win32select.c
bufferevent_pair.c      config.sub             evdns.c              evmap-internal.h  evutil.c             kqueue.c         make-event-config.sed    sample
[root@localhost libevent-2.0.21-stable]# ./configure -prefix=/usr
[root@localhost libevent-2.0.21-stable]# make
[root@localhost libevent-2.0.21-stable]# make install
[root@localhost libevent-2.0.21-stable]#  ls -al /usr/lib | grep libevent
lrwxrwxrwx.  1 root root      21 Dec 29 17:20 libevent-2.0.so.5 -> libevent-2.0.so.5.1.9
-rwxr-xr-x.  1 root root 1139800 Dec 29 17:20 libevent-2.0.so.5.1.9
-rw-r--r--.  1 root root 2219954 Dec 29 17:20 libevent.a
lrwxrwxrwx.  1 root root      26 Dec 29 17:20 libevent_core-2.0.so.5 -> libevent_core-2.0.so.5.1.9
-rwxr-xr-x.  1 root root  690088 Dec 29 17:20 libevent_core-2.0.so.5.1.9
-rw-r--r--.  1 root root 1392922 Dec 29 17:20 libevent_core.a
-rwxr-xr-x.  1 root root     974 Dec 29 17:20 libevent_core.la
lrwxrwxrwx.  1 root root      26 Dec 29 17:20 libevent_core.so -> libevent_core-2.0.so.5.1.9
lrwxrwxrwx.  1 root root      27 Dec 29 17:20 libevent_extra-2.0.so.5 -> libevent_extra-2.0.so.5.1.9
-rwxr-xr-x.  1 root root  471848 Dec 29 17:20 libevent_extra-2.0.so.5.1.9
-rw-r--r--.  1 root root  827104 Dec 29 17:20 libevent_extra.a
-rwxr-xr-x.  1 root root     981 Dec 29 17:20 libevent_extra.la
lrwxrwxrwx.  1 root root      27 Dec 29 17:20 libevent_extra.so -> libevent_extra-2.0.so.5.1.9
-rwxr-xr-x.  1 root root     939 Dec 29 17:20 libevent.la
lrwxrwxrwx.  1 root root      30 Dec 29 17:20 libevent_pthreads-2.0.so.5 -> libevent_pthreads-2.0.so.5.1.9
-rwxr-xr-x.  1 root root   24072 Dec 29 17:20 libevent_pthreads-2.0.so.5.1.9
-rw-r--r--.  1 root root   21974 Dec 29 17:20 libevent_pthreads.a
-rwxr-xr-x.  1 root root    1002 Dec 29 17:20 libevent_pthreads.la
lrwxrwxrwx.  1 root root      30 Dec 29 17:20 libevent_pthreads.so -> libevent_pthreads-2.0.so.5.1.9
lrwxrwxrwx.  1 root root      21 Dec 29 17:20 libevent.so -> libevent-2.0.so.5.1.9
[root@localhost FastDHT]# yum -y install libevent libevent-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.nju.edu.cn
 * extras: mirrors.shu.edu.cn
 * updates: mirrors.shu.edu.cn
Package libevent-2.0.21-4.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package libevent-devel.x86_64 0:2.0.21-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================
 Package             Arch        Version            Repository
                                                               Size
====================================================================
Installing:
 libevent-devel      x86_64      2.0.21-4.el7       base       85 k

Transaction Summary
====================================================================
Install  1 Package

Total download size: 85 k
Installed size: 357 k
Downloading packages:
libevent-devel-2.0.21-4.el7.x86_64.rpm         |  85 kB   00:00   
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libevent-devel-2.0.21-4.el7.x86_64               1/1 
  Verifying  : libevent-devel-2.0.21-4.el7.x86_64               1/1 

Installed:
  libevent-devel.x86_64 0:2.0.21-4.el7                          

Complete!
#include 这个地方是引入文件,不可忽略。
[root@localhost libevent-2.0.21-stable]# cd /tmp/FastDHT/
[root@localhost FastDHT]# ./make.sh && ./make.sh install 
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/usr/local/db-18.1.25/include/ -L/usr/local/db-18.1.25/lib/ -DOS_LINUX -c -o global.o global.c  -I../common -I/usr/local/include
[root@localhost fastdfs]# mkdir -p /home/fastdfs/fastdht
[root@localhost FastDHT]# cd /etc/fdht
[root@localhost fdht]# ls
fdht_client.conf  fdhtd.conf  fdht_servers.conf
[root@localhost fdht]# vim fdht_client.conf
# set keep_alive to 1 to enable persistent connection
# default value is 0 (short connection)
keep_alive=1

base_path=/home/fastdfs/fastdht

#include /etc/fdht/fdht_servers.conf

[root@localhost fdht]# vim /etc/fdht/fdhtd.conf
# the base path to store data and log files
base_path=/home/fastdfs/fastdht

#include /etc/fdht/fdht_servers.conf
[root@localhost fdht]# vim /etc/fdht/fdht_servers.conf
group_count = 1
group0 = fastdfsdht:11411
[root@localhost fdht]# vim /etc/fdfs/storage.conf
check_file_duplicate=1
keep_alive=1
#include  /etc/fdht/fdht_servers.conf

[root@localhost lib]# cp /usr/local/db-18.1.25/lib/libdb-18.so /usr/lib/
[root@localhost lib]# cp /usr/local/db-18.1.25/lib/libdb-18.so /usr/lib64/
[root@localhost lib]# cp /usr/local/db-18.1.25/lib/libdb-18.1.so /usr/lib64/
[root@localhost lib]# cp /usr/local/db-18.1.25/lib/libdb-18.1.so /usr/lib/

[root@localhost lib]# fdhtd /etc/fdht/fdhtd.conf restart

fdhtd 命令找不到

[root@localhost app]# fdhtd /etc/fdht/fdhtd.conf restart
bash: fdhtd: command not found
[root@localhost app]# vim /etc/profile

export PATH=$PATH:/usr/local/bin
[root@localhost app]# source /etc/profile
[root@localhost app]# fdhtd /etc/fdht/fdhtd.conf restart
waiting for pid [112362] exit ...
starting ...

6、去重上传

使用 /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /tmp/test.jpg 去重上传
注:/usr/bin/fdfs_test /etc/fdfs/client.conf upload /tmp/test.jpg #这条命令是不会去重的。

[root@localhost lib]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf  /tmp/test.jpg
group1/M00/00/00/wKgBZlwoYHqANUiIAAAMNh8kP7g258.jpg
[root@localhost lib]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf  /tmp/test.jpg
group1/M00/00/00/wKgBZlwoYJOACZApAAAMNk5wcTY682.jpg
[root@localhost lib]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /tmp/test.jpg
This is FastDFS client test program v5.08

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-12-30 14:09:28] DEBUG - base_path=/home/fastdfs, 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.102, port=23000

group_name=group1, ip_addr=192.168.1.102, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBZlwoYReACEjUAAAMNh6HzqY877.jpg
source ip address: 192.168.1.102
file timestamp=2018-12-30 14:09:27
file size=3126
file crc32=512216742
example file url: http://192.168.1.102/group1/M00/00/00/wKgBZlwoYReACEjUAAAMNh6HzqY877.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBZlwoYReACEjUAAAMNh6HzqY877_big.jpg
source ip address: 192.168.1.102
file timestamp=2018-12-30 14:09:28
file size=3126
file crc32=512216742
example file url: http://192.168.1.102/group1/M00/00/00/wKgBZlwoYReACEjUAAAMNh6HzqY877_big.jpg
[root@localhost home]# cd /home/fdfs_storage1/data/00/00
[root@localhost 00]# ll
total 48
-rw-r--r--. 1 root root 3126 Dec 30 11:44 wKgBZlwoPzOAGJyxAAAMNijkPP8246_big.jpg
-rw-r--r--. 1 root root   49 Dec 30 11:44 wKgBZlwoPzOAGJyxAAAMNijkPP8246_big.jpg-m
-rw-r--r--. 1 root root 3126 Dec 30 11:44 wKgBZlwoPzOAGJyxAAAMNijkPP8246.jpg
-rw-r--r--. 1 root root   49 Dec 30 11:44 wKgBZlwoPzOAGJyxAAAMNijkPP8246.jpg-m
lrwxrwxrwx. 1 root root   65 Dec 30 14:06 wKgBZlwoYHqANUiIAAAMNh8kP7g258.jpg -> /home/fdfs_storage1/data/00/00/wKgBZlwoYHqAUDFJAAAMNijkPP8399.jpg
-rw-r--r--. 1 root root 3126 Dec 30 14:06 wKgBZlwoYHqAUDFJAAAMNijkPP8399.jpg
lrwxrwxrwx. 1 root root   65 Dec 30 14:07 wKgBZlwoYJOACZApAAAMNk5wcTY682.jpg -> /home/fdfs_storage1/data/00/00/wKgBZlwoYHqAUDFJAAAMNijkPP8399.jpg
-rw-r--r--. 1 root root 3126 Dec 30 14:09 wKgBZlwoYReACEjUAAAMNh6HzqY877_big.jpg
-rw-r--r--. 1 root root   49 Dec 30 14:09 wKgBZlwoYReACEjUAAAMNh6HzqY877_big.jpg-m
lrwxrwxrwx. 1 root root   65 Dec 30 14:09 wKgBZlwoYReACEjUAAAMNh6HzqY877.jpg -> /home/fdfs_storage1/data/00/00/wKgBZlwoYHqAUDFJAAAMNijkPP8399.jpg
-rw-r--r--. 1 root root   49 Dec 30 14:09 wKgBZlwoYReACEjUAAAMNh6HzqY877.jpg-m
lrwxrwxrwx. 1 root root   65 Dec 30 14:10 wKgBZlwoYV6ANr71AAAMNhTdym8558.jpg -> /home/fdfs_storage1/data/00/00/wKgBZlwoYHqAUDFJAAAMNijkPP8399.jpg
lrwxrwxrwx. 1 root root   65 Dec 30 14:10 wKgBZlwoYWeAPhVcAAAMNhzqW_4350.jpg -> /home/fdfs_storage1/data/00/00/wKgBZlwoYHqAUDFJAAAMNijkPP8399.jpg
lrwxrwxrwx. 1 root root   65 Dec 30 14:10 wKgBZlwoYWuAcwRlAAAMNkSa8ts525.jpg -> /home/fdfs_storage1/data/00/00/wKgBZlwoYHqAUDFJAAAMNijkPP8399.jpg
-rw-r--r--. 1 root root 3126 Dec 29 16:22 wKjbJ1wnLsaAXEtEAAAMNijkPP8291_big.jpg
-rw-r--r--. 1 root root   49 Dec 29 16:22 wKjbJ1wnLsaAXEtEAAAMNijkPP8291_big.jpg-m
-rw-r--r--. 1 root root 3126 Dec 29 16:22 wKjbJ1wnLsaAXEtEAAAMNijkPP8291.jpg
-rw-r--r--. 1 root root   49 Dec 29 16:22 wKjbJ1wnLsaAXEtEAAAMNijkPP8291.jpg-m

去重上传创建的是软连接,非去重上传创建的是文件

7、安装 fastdfs-nginx-module_v1.16.tar.gz

github 下载安装包

[root@localhost 00]# cd /tmp
[root@localhost tmp]# ls
db-18.1.25
db-18.1.25.tar.gz
FastDFS
fastdfs-nginx-module_v1.16.tar.gz
FastDFS_v5.08.tar.gz
FastDHT
FastDHT_v2.01.tar.gz
hsperfdata_root
ks-script-Yt2tvM
libevent-2.0.21-stable
libevent-2.0.21-stable.tar.gz
libfastcommon-master
libfastcommon-master.zip
libfastcommon_v1.01.tar.gz
libfastcommon_v1.04.tar.gz
systemd-private-860d6fe48efa4d34ba6571dfd6b65df8-cups.service-FL6dK7
systemd-private-f7a7566fa896429fa1053fef71a20285-cups.service-K6eMzX
test.jpg
yum.log
[root@localhost tmp]# tar -xzf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/
[root@localhost local]# cd /usr/local/fastdfs-nginx-module/
[root@localhost fastdfs-nginx-module]# ls
HISTORY  INSTALL  src
[root@localhost fastdfs-nginx-module]# cd src
[root@localhost src]# ls
common.c  config            ngx_http_fastdfs_module.c
common.h  mod_fastdfs.conf
[root@localhost src]# cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
[root@localhost src]# vim /etc/fdfs/mod_fastdfs.conf 
base_path=/home/fastdfs/fdfs_nginx
tracker_server=fastdfsdht:22122
url_have_group_name = true
store_path_count=1
store_path0=/home/fdfs_storage1

修改 config 文件,将文件中的所有 /usr/local/ 路径改为 /usr/

[root@localhost src]# vim /usr/local/fastdfs-nginx-module/src/config

ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

[root@localhost /]# mkdir -p /var/temp/nginx/client
[root@localhost /]# mkdir -p /home/fastdfs/fdfs_nginx

8、安装 nginx

[root@localhost tmp]# ls
db-18.1.25
db-18.1.25.tar.gz
FastDFS
fastdfs-nginx-module_v1.16.tar.gz
FastDFS_v5.08.tar.gz
FastDHT
FastDHT_v2.01.tar.gz
hsperfdata_root
ks-script-Yt2tvM
libevent-2.0.21-stable
libevent-2.0.21-stable.tar.gz
libfastcommon-master
libfastcommon-master.zip
libfastcommon_v1.01.tar.gz
libfastcommon_v1.04.tar.gz
nginx-1.15.8.tar.gz
systemd-private-860d6fe48efa4d34ba6571dfd6b65df8-cups.service-FL6dK7
systemd-private-f7a7566fa896429fa1053fef71a20285-cups.service-K6eMzX
test.jpg
yum.log
[root@localhost tmp]# tar -zxvf nginx-1.15.8.tar.gz  -C /usr/local
安装 nginx 的依赖库
[root@localhost tmp]#  yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
[root@localhost nginx-1.15.8]# cd /usr/local/nginx-1.15.8/
[root@localhost nginx-1.15.8]# ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README
[root@localhost nginx-1.15.8]# ./configure \
> --prefix=/usr/local/nginx \
> --pid-path=/var/run/nginx/nginx.pid \
> --lock-path=/var/lock/nginx.lock \
> --error-log-path=/var/log/nginx/error.log \
> --http-log-path=/var/log/nginx/access.log \
> --with-http_gzip_static_module \
> --http-client-body-temp-path=/var/temp/nginx/client \
> --http-proxy-temp-path=/var/temp/nginx/proxy \
> --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
> --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
> --http-scgi-temp-path=/var/temp/nginx/scgi \
> --add-module=/usr/local/fastdfs-nginx-module/src
[root@localhost nginx-1.15.8]# make && make install
[root@localhost local]# rm -rf nginx-1.15.8/
[root@localhost conf]# cd /tmp/FastDFS/conf
[root@localhost conf]# ls
anti-steal.jpg  http.conf   storage.conf      tracker.conf
client.conf     mime.types  storage_ids.conf
[root@localhost conf]# cp http.conf mime.types /etc/fdfs
[root@localhost conf]# mkdir -p /usr/local/nginx/logs
[root@localhost conf]# cd /usr/local/nginx/conf
[root@localhost conf]# ls
fastcgi.conf            koi-win             scgi_params
fastcgi.conf.default    mime.types          scgi_params.default
fastcgi_params          mime.types.default  uwsgi_params
fastcgi_params.default  nginx.conf          uwsgi_params.default
koi-utf                 nginx.conf.default  win-utf
[root@localhost conf]# vim nginx.conf


user  root;
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        /var/run/nginx/nginx.pid;


events {
    worker_connections  65535;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;
    error_log  /var/log/nginx/error.log  error;
    server_names_hash_bucket_size 128;

    client_header_buffer_size 32k;

    large_client_header_buffers 4 32k;

    client_max_body_size 8m;


    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay     on;

    keepalive_timeout  65;
    fastcgi_connect_timeout 300;

    fastcgi_send_timeout 300;

    fastcgi_read_timeout 300;

    fastcgi_buffer_size 64k;

    fastcgi_buffers 4 64k;

    fastcgi_busy_buffers_size 128k;

    fastcgi_temp_file_write_size 128k;

    gzip  on;
    gzip_min_length 1k;

    gzip_buffers 4 16k;

    gzip_http_version 1.0;

    gzip_comp_level 2;

    gzip_types text/plain application/x-javascript text/css application/xml;

    gzip_vary on;


    server {
        listen       80;
        #server_name  fastdfsdht;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

	location ~/group[0-9]/ {
           #root   /home/fdfs_storage1;
            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;
        #}
        #
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
[root@localhost conf]# cd /etc/security
[root@localhost security]# ls
access.conf   console.handlers  group.conf   namespace.conf  opasswd         sepermit.conf
chroot.conf   console.perms     limits.conf  namespace.d     pam_env.conf    time.conf
console.apps  console.perms.d   limits.d     namespace.init  pwquality.conf
[root@localhost security]# vim limits.conf

# End of file
*               soft    nofile          100000

*               hard    nofile          100000

*               soft    nproc           100000

*               hard    nproc           100000

[root@localhost security]# ulimit -n 100000
[root@localhost security]# cd /usr/local/nginx/sbin
[root@localhost sbin]# ls
nginx
[root@localhost sbin]# ./nginx
[root@localhost sbin]# systemctl stop firewalld
访问上传文件

http://192.168.1.102/group1/M00/00/00/wKgBZlwoYReACEjUAAAMNh6HzqY877_big.jpg
BA43DDF790F34366BBB29D1BA4AD717E.jpg

禁用防火墙
[root@localhost sbin]# systemctl disable firewalld

Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.

Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
开机启动
[root@fastdfsdht ~]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

[root@fastdfsdht ~]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

[root@fastdfsdht tmp]# fdhtd /etc/fdht/fdhtd.conf restart

[root@fastdfsdht tmp]# mkdir -p /var/run/nginx/

[root@fastdfsdht tmp]# /usr/local/nginx/sbin/nginx

[root@fastdfsdht ~]# chmod +x /etc/rc.local

[root@fastdfsdht tmp]# vim /etc/rc.local

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

fdhtd /etc/fdht/fdhtd.conf restart

mkdir -p /var/run/nginx/

/usr/local/nginx/sbin/nginx

exit 0

防盗连

[root@fastdfsdht conf]# vim /etc/fdfs/http.conf
# if use token to anti-steal
# default value is false (0)
http.anti_steal.check_token=true
# secret key to generate anti-steal token
# this parameter must be set when http.anti_steal.check_token set to true
# the length of the secret key should not exceed 128 bytes
http.anti_steal.secret_key=FastDFS1234567890
# return the content of the file when check token fail
# default value is empty (no file sepecified)
http.anti_steal.token_check_fail=/home/fastdfs/conf/anti-steal.jpg

配置 /home/fastdfs/conf/anti-steal.jpg 访问失败显示

[root@localhost sbin]# cd /home/fastdfs
[root@localhost fastdfs]# ls
data  fastdht  fdfs_nginx  logs
[root@localhost fastdfs]# cd conf
-bash: cd: conf: No such file or directory
[root@localhost fastdfs]# mkdir conf
[root@localhost fastdfs]# ls
conf  data  fastdht  fdfs_nginx  logs
[root@localhost fastdfs]# cd conf
[root@localhost conf]# ls
[root@localhost conf]# ls
anti-steal.jpg

测试防盗链是否配置成功,token 生成,ts 失效时间,格式满足即可

http://192.168.1.102/group1/M00/00/0B/wKjcAl9Z2USAfkpPCXW1EEIydL0892.jpg?token=6d3fe0e48771bab6c19c1b048ea2afa7&ts=1603096371

访问 fastDFS 失败,需要开放端口
涉及到的端口有

80
88
22122
11411
23000

文件服务器访问时序图
FastDFS、NFS、TFS 优劣对比
FastDFS+FastDHT 外网访问视频
FastDFS 文件服务器访问
上一篇 建站不啰嗦,上手跟我做(二十)mysql8.0 安装
目录
下一篇 建站不啰嗦,上手跟我做(二十二)Docker 使用