- 准备linux虚拟机
- 下载软件
> mkdir -p /opt/tar
> cd /opt/tar
# github地址:https://github.com/happyfish100
> wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz -O /opt/tar/fastdfs5.11.tar.gz
> wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz -O /opt/tar/libfastcommon1.0.39.tar.gz
> wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz -O /opt/tar/fastdfs-nginx-module1.20.tar.gz
> wget http://nginx.org/download/nginx-1.20.2.tar.gz -O /opt/tar/nginx-1.20.2.tar.gz
# 安装编译工具
# FastDFS是C语言开发,安装FastDFS需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc
> yum install -y gcc gcc-c++
# FastDFS依赖libevent库, perl库,需要安装
> yum -y install libevent
> yum -y install perl
# libfastcommon是FastDFS官方提供的,libfastcommon包含了FastDFS运行所需要的一些基础库
- 安装FastDFS
# FastDFS依赖的jar包处理
# 编译
> cd /opt/tar
> tar -zxvf libfastcommon.1.0.39.tar.gz
> cd libfastcommon-1.0.39/
# 编译打包libfastcommon
> ./make.sh
# 安装
# 安装libfastcommon
> ./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 /usr/include/fastcommon
if [ ! -e /usr/lib/libfastcommon.so ]; then ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so; fi
# libfastcommon安装好后会在/usr/lib64 目录下生成 libfastcommon.so 库文件
> ll /usr/lib64 | grep "libfastcommon.so"
-rwxr-xr-x. 1 root root 957656 Nov 28 20:55 libfastcommon.so
# 由于FastDFS程序引用/usr/lib目录所以需要将/usr/lib64下的libfastcommon.so拷贝至/usr/lib下,若有的话则不用再操作了
# 或者创建一个超链接的形式:ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
> cp /usr/lib64/libfastcommon.so /usr/lib/
#安装FastDFS
> cd /opt/tar
> tar -zxvf FastDFS.5.11.tar.gz
> cd fastdfs-5.11/
# 编译
# 编译导报FastDFS,注意如果此时出现per之类的依赖没有安装,后来补安装yum -y install perl后重新执行编译./make.sh可能会导致编译报错
# 这个时候我们需要执行./make.sh clean ,清理以前的编译文件,然后再重新编译
> ./make.sh
# 安装
# 安装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
if [ ! -f /etc/fdfs/storage_ids.conf.sample ]; then cp -f ../conf/storage_ids.conf /etc/fdfs/storage_ids.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
mkdir -p /usr/lib
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
> cd /usr/bin
# 查看安装好的fastdfs相关文件
> ll fdfs*
# 配置文件初始化
# 查看配置文件,备份sample配置文件到smaple.bak文件夹中
> cd /etc/fdfs/
> mkdir sample.bak
> mv *.sample sample.bak
# 拷贝fastdfs配置文件到/etc/fdfs工作目录
> cp /opt/tar/fastdfs-5.11/conf/* /etc/fdfs/
# 创建目录,为服务器启动后日志数据前期准备
> mkdir -p /opt/fastdfs/tracker
> mkdir -p /opt/fastdfs/storage
> mkdir -p /opt/fastdfs/client
# 配置tracker服务
# 其中port=22122 在springboot配置中会应用这个服务的端口,即tracker server的服务端口
# 修改bash_path=/opt/fastdfs/tracker //存放日志数据的文件夹
> cd /etc/fdfs
> vi tracker.conf
# 启动tracker
> /usr/bin/./fdfs_trackerd /etc/fdfs/tracker.conf
# 如果修改了配置需要重新启动tracker server执行命令 /usr/bin/./fdfs_trackerd /etc/fdfs/tracker.conf restart
# 配置storage服务
# 进入配置文件目录,修改storage.conf配置
# base_path=/opt/fastdfs/storage, //存放日志数据的文件夹
# group_name=fxin(访问图片时,类似context root)
# store_path0=/opt/fastdfs/storage //存放图片的位置
# tracker_server=192.168.3.210:22122 //tracker server 的地址信息
> cd /etc/fdfs/
> vi storage.conf
# 启动storage server
> /usr/bin/./fdfs_storaged /etc/fdfs/storage.conf
# 如果修改了配置需要重新启动storage server执行命令: /usr/bin/./fdfs_storaged /etc/fdfs/storage.conf restart
# 配置client服务
# 进入配置文件目录,client.conf配置
# base_path=/opt/fastdfs/client //存放日志数据的文件夹
# tracker_server=192.168.3.210:22122 //tracker server 的地址信息
> cd /etc/fdfs/
> vi client.conf
# 使用FastDFS自带工具测试
# 测试通过client上传图片
# 上传文件的格式 Usage: /usr/bin/fdfs_test <config_file> upload <local_filename> [FILE | BUFF | CALLBACK]
> /usr/bin/./fdfs_test /etc/fdfs/client.conf upload /tmp/img/logo.png
This is FastDFS client test program v5.11
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.
[2021-12-01 01:01:23] DEBUG - base_path=/opt/fastdfs/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.3.210, port=23000
group_name=fxin, ip_addr=192.168.3.210, port=23000
storage_upload_by_filename
group_name=fxin, remote_filename=M00/00/00/wKgD0mGnD7OAUmLSAAAWH0Uu4hU808.png
source ip address: 192.168.3.210
file timestamp=2021-12-01 01:01:23
file size=5663
file crc32=1160700437
example file url: http://192.168.3.210/fxin/M00/00/00/wKgD0mGnD7OAUmLSAAAWH0Uu4hU808.png
storage_upload_slave_by_filename
group_name=fxin, remote_filename=M00/00/00/wKgD0mGnD7OAUmLSAAAWH0Uu4hU808_big.png
source ip address: 192.168.3.210
file timestamp=2021-12-01 01:01:23
file size=5663
file crc32=1160700437
example file url: http://192.168.3.210/fxin/M00/00/00/wKgD0mGnD7OAUmLSAAAWH0Uu4hU808_big.png
# 到此为止,fastdfs 服务器配置完成,但是这个file url现在无法访问,需要配置一个web服务器
- 安装Nginx
> cd /opt/tar
> tar -zxvf fastdfs-nginx-module-1.20.tar.gz
> cd /opt/tar/fastdfs-nginx-module-1.20/src
# 修改配置文件
# 把如下这两行的内容:
# ngx_module_incs="/usr/local/include"
# CORE_INCS="$CORE_INCS /usr/local/include"
# 换成:
# ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
# CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
> vi config
# 安装nginx
> cd /opt/tar
> tar -zxvf nginx-1.20.2.tar.gz
# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
# 增加gcc-c++支持
> yum -y install gcc-c++
# 增加正则表达式的支持
> yum -y install pcre pcre-devel
> yum -y install zlib zlib-devel
> yum -y install openssl openssl-devel
# 设置nginx配置文件
> cd /opt/tar/nginx-1.20.2
> ./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/ngxin/client \
--http-proxy-temp-path=/var/temp/ngxin/proxy \
--http-fastcgi-temp-path=/var/temp/ngxin/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/opt/tar/fastdfs-nginx-module-1.20/src
checking for OS
+ Linux 3.10.0-1160.45.1.el7.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
...
...
checking for getaddrinfo() ... found
configuring additional modules
adding module in /opt/tar/fastdfs-nginx-module-1.20/src
+ ngx_http_fastdfs_module was configured
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for zlib library ... found
creating objs/Makefile
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: "/var/run/nginx/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/var/temp/ngxin/client"
nginx http proxy temporary files: "/var/temp/ngxin/proxy"
nginx http fastcgi temporary files: "/var/temp/ngxin/fastcgi"
nginx http uwsgi temporary files: "/var/temp/nginx/uwsgi"
nginx http scgi temporary files: "/var/temp/nginx/scgi"
# 编译nginx
> make
...
...
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"' -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
-o objs/src/core/ngx_sha1.o \
...
...
objs/ngx_modules.o \
-ldl -lpthread -lcrypt -lfastcommon -lfdfsclient -lpcre -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
-e "s|%%PID_PATH%%|/var/run/nginx/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/var/log/nginx/error.log|" \
< man/nginx.8 > objs/nginx.8
# 安装nginx
> make install
"make -f objs/Makefile install
make[1]: Entering directory `/opt/tar/nginx-1.20.2'
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
|| mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' \
|| mv '/usr/local/nginx/sbin/nginx' \
'/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' \
|| mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
test -f '/usr/local/nginx/conf/mime.types' \
|| cp conf/mime.types '/usr/local/nginx/conf'
cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
test -f '/usr/local/nginx/conf/fastcgi_params' \
|| cp conf/fastcgi_params '/usr/local/nginx/conf'
cp conf/fastcgi_params \
'/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/fastcgi.conf' \
|| cp conf/fastcgi.conf '/usr/local/nginx/conf'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params' \
|| cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params \
'/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params' \
|| cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params \
'/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' \
|| cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/var/run/nginx' \
|| mkdir -p '/var/run/nginx'
test -d '/var/log/nginx' \
|| mkdir -p '/var/log/nginx'
test -d '/usr/local/nginx/html' \
|| cp -R html '/usr/local/nginx'
test -d '/var/log/nginx' \
|| mkdir -p '/var/log/nginx'
make[1]: Leaving directory `/opt/tar/nginx-1.20.2'"
# 检查nginx安装情况,在/usr/local下面出现nginx软件目录
> cd /usr/local
> ls | grep nginx
# 配置nginx与fastdfs的桥梁 mod_fastdfs.conf
> cd /opt/tar/fastdfs-nginx-module-1.20/src
> cp mod_fastdfs.conf /etc/fdfs/
> mkdir /opt/fastdfs/tmp
# 修改配置
# base_path=/opt/fastdfs/tmp
# tracker_server=192.168.3.210:22122
# group_name=fxin
# url_have_group_name = true //是否默认开启fxin
> vi /etc/fdfs/mod_fastdfs
# 配置nginx
> cd /usr/local/nginx/conf
# 增加一个本地服务反向代理
server {
listen 89;
server_name 192.168.3.210;
location /fxin/M00 {
# 增加nginx与fastdfs的模块
ngx_fastdfs_module;
}
}
#
> vi ngxin_config
# 检查nginx配置是否ok
> cd /usr/local/nginx/sbin
> ./nginx -t
# 检查出来各种文件没有目录,各种报错略,补目录
> mkdir -p /var/tmp/ngxin/client
> mkdir -p /var/temp/ngxin/client
> mkdir -p /var/temp/nginx/uwsgi
# 补充完目录以后,运行测试ngxin配置情况,成功
> ./nginx -t
ngx_http_fastdfs_set pid=12622
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# 启动ngxin
> ./nginx
访问图片
# 访问地址: http://192.168.3.210:89/fxin/M00/00/00/wKgD0mGnD7OAUmLSAAAWH0Uu4hU808_big.png
# 现在访问的是nginx地址,并不能访问到fastdfs存放图片的资源地址,这个时候需要配置fastdfs与nginx的桥梁模块
> cd /etc/fdfs
# 修改mod_fastdfs.conf 配置文件
# store_path0=/opt/fastdfs/storage
> vi mod_fastdfs.conf
# 重启各个服务
> /usr/bin/./fdfs_trackerd /etc/fdfs/tracker.conf restart
> /usr/bin/./fdfs_storaged /etc/fdfs/storage.conf restart
> /usr/local/nginx/sbin/nginx -s reload
Centos7开机启动FastDFS和Nginx
# 修改配置文件
#
# /usr/bin/./fdfs_trackerd /etc/fdfs/tracker.conf restart
# /usr/bin/./fdfs_storaged /etc/fdfs/storage.conf restart
# /usr/local/nginx/sbin/
> vi /etc/rc.d/rc.local
# 在centos7中, /etc/rc.d/rc.local 文件的权限被降低了,需要给rc.local 文件增加可执行的权限
> chmod +x /etc/rc.d/rc.local