1.下载服务包及依赖包
fastdfs-5.11.tar.gz
下载址址:https://github.com/happyfish100/fastdfs/releases
libfastcommon-1.0.39.tar.gz
下载址址:https://github.com/happyfish100/libfastcommon/releases
fastdfs-nginx-module-1.20.tar.gz
下载址址: https://github.com/happyfish100/fastdfs-nginx-module/releases
nginx-1.14.2.tar.gz
下载址址:http://nginx.org/download/nginx-1.14.2.tar.gz
2.安装相关依赖
yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
3.新建用户
[root@localhost ~]# useradd fastdfs
##设置密码并确认即可
[root@localhost ~]# passwd fastdfs
Changing password for user fastdfs.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# su - fastdfs
[fastdfs@localhost ~]$
4.创建安装目录
[fastdfs@localhost ~]$ mkdir -p /home/fastdfs/opt/fastdfs
####存放软件安装包
[fastdfs@localhost ~]$ mkdir -p /home/fastdfs/soft
[fastdfs@localhost ~]$ pwd
/home/fastdfs
[fastdfs@localhost ~]$ ll
总用量 0
drwxrwxr-x. 3 fastdfs fastdfs 21 8月 14 14:54 opt
drwxrwxr-x. 2 fastdfs fastdfs 6 8月 14 14:54 soft
[fastdfs@localhost ~]$ cd soft
[fastdfs@localhost soft]$ ll
总用量 1496
-rwxr-xr-x. 1 fastdfs fastdfs 336939 8月 14 14:57 fastdfs-5.11.tar.gz
-rwxr-xr-x. 1 fastdfs fastdfs 19825 8月 14 14:57 fastdfs-nginx-module-1.20.tar.gz
-rwxr-xr-x. 1 fastdfs fastdfs 153951 8月 14 14:57 libfastcommon-1.0.39.tar.gz
-rwxr-xr-x. 1 fastdfs fastdfs 1015384 8月 14 14:58 nginx-1.14.2.tar.gz
5.编译安装libfastcommon
##设置安装路径
[fastdfs@localhost soft]$ export DESTDIR=/home/fastdfs/opt/fastdfs
[fastdfs@localhost soft]# tar -zxvf libfastcommon-1.0.39.tar.gz
[fastdfs@localhost soft]# cd libfastcommon-1.0.39/
[fastdfs@localhost libfastcommon-1.0.39]# ./make.sh
[fastdfs@localhost libfastcommon-1.0.39]# ./make.sh install
mkdir -p /home/fastdfs/opt/fastdfs/usr/lib64
mkdir -p /home/fastdfs/opt/fastdfs/usr/lib
mkdir -p /home/fastdfs/opt/fastdfs/usr/include/fastcommon
install -m 755 libfastcommon.so /home/fastdfs/opt/fastdfs/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 /home/fastdfs/opt/fastdfs/usr/include/fastcommon
if [ ! -e /home/fastdfs/opt/fastdfs/usr/lib/libfastcommon.so ]; then ln -s /home/fastdfs/opt/fastdfs/usr/lib64/libfastcommon.so /home/fastdfs/opt/fastdfs/usr/lib/libfastcommon.so; fi
#### libfastcommon.so 默认安装到了/usr/lib64/libfastcommon.so,但是FastDFS主程序设置的lib目录是/home/fastdfs/opt/fastdfs/usr/lib,所以此处需要重新设置软链接
[fastdfs@localhost libfastcommon-1.0.39]$ ln -s /home/fastdfs/opt/fastdfs/usr/lib64/libfastcommon.so /home/fastdfs/opt/fastdfs/usr/lib/libfastcommon.so
6.编译安装fastdfs
6.1. 编译安装fastdfs
[fastdfs@localhost soft]$ tar -zxvf fastdfs-5.11.tar.gz
[fastdfs@localhost soft]$ cd fastdfs-5.11/
6.2. 修改make.sh文件
LIBS="-Wl,-rpath=/home/fastdfs/opt/fastdfs/usr/lib64"
$TARGET_CONF_PATH
6.3. 修改Makefile.in文件,文件不同修改方法相同
vi /home/fastdfs/soft/fastdfs-5.11/tracker/Makefile.in
vi /home/fastdfs/soft/fastdfs-5.11/storage/Makefile.in
vi /home/fastdfs/soft/fastdfs-5.11/client/Makefile.in
${DESTDIR}
-L${DESTDIR}/usr/lib64
6.4. 编译并安装
cd /home/fastdfs/soft/fastdfs-5.11/
./make.sh
./make.sh install
6.5. 检查是否安装程序正常加载所有依赖
ldd /home/fastdfs/opt/fastdfs/usr/bin/fdfs_trackerd
ldd /home/fastdfs/opt/fastdfs/usr/bin/fdfs_storaged
ldd /home/fastdfs/opt/fastdfs/usr/bin/fdfs_monitor
7.安装nginx和fastdfs-nginx-module
7.1. 到相应目录下解压安装包
cd /home/fastdfs/soft/
tar zxvf nginx-1.14.2.tar.gz
tar zxvf fastdfs-nginx-module-1.20.tar.gz
7.2. 修改fastdfs-nginx-module编译配置
vi fastdfs-nginx-module-1.20/src/config
${DESTDIR}/usr/include
${DESTDIR}/usr/include/fastcommon
7.3. 复制fastdfs-nginx-module配置文件到fastdfs存放配置文件的目录
cp /home/fastdfs/soft/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /home/fastdfs/opt/fastdfs/etc/fdfs
7.4.修改配置
修改ip为本机地址
[fastdfs@localhost src]$ cd /home/fastdfs/soft/fastdfs-nginx-module-1.20/src
[fastdfs@localhost src]$ vim mod_fastdfs.conf
##找到tracker_server修改成本机IP
tracker_server=172.16.87.165:22122
[fastdfs@localhost src]$ cd /home/fastdfs/soft/fastdfs-5.11/conf/
[fastdfs@localhost conf]$ vim storage.conf
##找到tracker_server修改成本机IP
tracker_server=172.16.87.165:22122
[fastdfs@localhost conf]$ vim client.conf
##找到tracker_server修改成本机IP
tracker_server=172.16.87.165:22122
7.5.编译Nginx
[fastdfs@localhost nginx-1.14.2]$ cd /home/fastdfs/soft/nginx-1.14.2
[fastdfs@localhost nginx-1.14.2]$ export DESTDIR=/home/fastdfs/opt/fastdfs
[fastdfs@localhost nginx-1.14.2]$ export DESTDIR=/home/fastdfs/opt/fastdfs
[fastdfs@localhost nginx-1.14.2]$ ./configure --prefix=/home/fastdfs/opt/nginx-fdfs --add-module=/home/fastdfs/soft/fastdfs-nginx-module-1.20/src --with-http_ssl_module --with-ld-opt="-L /home/fastdfs/opt/fastdfs/usr/lib -Wl,-rpath=/home/fastdfs/opt/fastdfs/usr/lib64"
[fastdfs@localhost nginx-1.14.2]$ make
[fastdfs@localhost nginx-1.14.2]$ export DESTDIR=""
[fastdfs@localhost nginx-1.14.2]$ make install
[fastdfs@localhost nginx-1.14.2]$ cp /home/fastdfs/soft/fastdfs-5.11/conf/mime.types /home/fastdfs/opt/fastdfs/etc/fdfs
7.6.检查nginx是否正常加载所有依赖
ldd /home/fastdfs/opt/nginx-fdfs/sbin/nginx
7.7.复制fastdfs源码中给的参考配置文件到fastdfs安装目录
[fastdfs@localhost nginx-1.14.2]$ cd /home/fastdfs/soft/fastdfs-5.11/conf
[fastdfs@localhost conf]$ cp ./*.conf /home/fastdfs/opt/fastdfs/etc/fdfs/
8.启动脚本
8.1. 创建启动脚本目录
[fastdfs@localhost conf]$ cd /home/fastdfs/
[fastdfs@localhost ~]$ mkdir -p /home/fastdfs/data/storage
[fastdfs@localhost ~]$ mkdir -p /home/fastdfs/data/fastdfs
[fastdfs@localhost ~]$ mkdir -p /home/fastdfs/bin
[fastdfs@localhost ~]$ cp /home/fastdfs/opt/fastdfs/etc/init.d/* /home/fastdfs/bin
8.2. 修改启动脚本
vim /home/fastdfs/bin/fdfs_trackerd
PRG=/home/fastdfs/opt/fastdfs/usr/bin/fdfs_trackerd
CONF=/home/fastdfs/opt/fastdfs/etc/fdfs/tracker.conf
vim /home/fastdfs/bin/fdfs_storaged
PRG=/home/fastdfs/opt/fastdfs/usr/bin/fdfs_storaged
CONF=/home/fastdfs/opt/fastdfs/etc/fdfs/storage.conf
8.3. 启停命令
cd /home/fastdfs/bin
./fdfs_trackerd start|stop|restart
./fdfs_storaged start|stop|restart
9.配置并启动Nginx
9.1.修改nginx.conf
vi /home/fastdfs/opt/nginx-fdfs/conf/nginx.conf
include /home/fastdfs/opt/nginx-fdfs/conf/fastdfs.conf;
9.2.新增fastdfs.conf文件
[fastdfs@localhost soft]$ cd /home/fastdfs/opt/nginx-fdfs/conf/
[fastdfs@localhost conf]$ touch fastdfs.conf
[fastdfs@localhost conf]$ vim fastdfs.conf
###添加以下内容#####
upstream fdfs_group1 {
server 172.16.26.80:6666;
}
server {
listen 8888;
server_name fastdfs;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~/group[1-3]/M00 {
root /home/fastdfs/data/storage;
ngx_fastdfs_module;
}
location /group1/M00 {
proxy_pass http://fdfs_group1;
}
}
9.3.启动nginx
./home/fastdfs/opt/nginx-fdfs/sbin/nginx
10.测试执行
1)上传图片
2)执行/home/fastdfs/opt/fastdfs/usr/bin/fdfs_upload_file /home/fastdfs/opt/fastdfs/etc/fdfs/client.conf ./1.png
成功显示: