FastDFS是C语言开发,建议在linux上运行,学习中使用Centos7.4作为安装环境。
yum install gcc-c++ -y
yum -y install libevent
yum install perl*
命令安装一下yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget
上传压缩包文件libfastcommonV1.0.7.tar.gz 到 /opt目录下,并解压。
tar -zxvf libfastcommonV1.0.7.tar.gz
cd /opt/libfastcommon-1.0.7/
./make.sh
# yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget
cp /usr/lib64/libfastcommon.so /usr/lib/
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh
./make.sh install
cd conf
cp * /etc/fdfs/
vim /etc/fdfs/tracker.conf
# the tracker server port
port=22122
# connect timeout in seconds
# default value is 30s
connect_timeout=30
# network timeout in seconds
# default value is 30s
network_timeout=60
# the base path to store data and log files
# 软件基础目录修改成自己定义的
base_path=/opt/fastdfs
软件基础目录修改成自己定义的
base_path=/opt/fastdfs
mkdir /opt/fastdfs
创建一个启动服务文件夹
mkdir /usr/local/fdfs
拷贝安装目录下stop.sh 和restart.sh 到/usr/local/fdfs/
cp restart.sh /usr/local/fdfs/
cp stop.sh /usr/local/fdfs/
修改启动脚本
vim /etc/init.d/fdfs_trackerd
/usr/bin
目录是一个启动配置项/usr/local/fafs/
下的两个启动文件注册服务,把启动脚本放到开机服务里
chkconfig --add fdfs_trackerd
然后可以用service fdfs_trackerd start 启动测试 如下图
修改配置文件
vim /etc/fdfs/storage.conf
设置storage服务
/etc/fdfs/client.conf
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/winteriscoming.jpg
[root@atguigu ~]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/01.jpg
This is FastDFS client test program v5.05
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.
[2020-06-03 02:18:16] DEBUG - base_path=/opt/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.200.130, port=23000
group_name=group1, ip_addr=192.168.200.130, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKjIgl7Wl-iAJhhyAABiTR6BiQY165.jpg
source ip address: 192.168.200.130
file timestamp=2020-06-03 02:18:16
file size=25165
file crc32=511805702
example file url: http://192.168.200.130/group1/M00/00/00/wKjIgl7Wl-iAJhhyAABiTR6BiQY165.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKjIgl7Wl-iAJhhyAABiTR6BiQY165_big.jpg
source ip address: 192.168.200.130
file timestamp=2020-06-03 02:18:16
file size=25165
file crc32=511805702
example file url: http://192.168.200.130/group1/M00/00/00/wKjIgl7Wl-iAJhhyAABiTR6BiQY165_big.jpg
上传文件对应的上传路径:
/opt/fastdfs/fdfs_storage/data/00/00/wKjIgl7Wl-iAJhhyAABiTR6BiQY165_big.jpg
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
vim /opt/fastdfs-nginx-module/src/config
cp /opt/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf
cp /usr/lib64/libfdfsclient.so /usr/lib/
mkdir -p /var/temp/nginx/client
yum -y install pcre-devel
yum install -y zlib-devel
tar -zxvf nginx-1.12.2.tar.gz
cd /opt/nginx-1.12.2/
./configure \
--prefix=/usr/local/nginx \
--pid-path=/usr/local/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=/opt/fastdfs-nginx-module/src
最重要的是最后面的--add-module=/opt/fastdfs-nginx-module/src
添加之前设置好的fastdfs-nginx-module模块
编译
cd /opt/nginx-1.12.2/
make
安装
cd /opt/nginx-1.12.2/
make install
启动nginx
/usr/local/nginx/sbin/nginx
设置开机启动
vim /etc/rc.d/rc.local
需要关闭防火墙
service iptables stop
永久关闭 chkconfig iptables off
测试
This is FastDFS client test program v5.05
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.
[2020-06-03 08:16:22] DEBUG - base_path=/opt/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.200.130, port=23000
group_name=group1, ip_addr=192.168.200.130, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKjIgl7W69aASKziAABiTR6BiQY645.jpg
source ip address: 192.168.200.130
file timestamp=2020-06-03 08:16:22
file size=25165
file crc32=511805702
example file url: http://192.168.200.130/group1/M00/00/00/wKjIgl7W69aASKziAABiTR6BiQY645.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKjIgl7W69aASKziAABiTR6BiQY645_big.jpg
source ip address: 192.168.200.130
file timestamp=2020-06-03 08:16:22
file size=25165
file crc32=511805702
example file url: http://192.168.200.130/group1/M00/00/00/wKjIgl7W69aASKziAABiTR6BiQY645_big.jpg