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
成功顯示: