開一臺新的 centos 虛擬機.
- 安裝 jdk1.8
yum install java-1.8.0-openjdk*
自己配置環(huán)境變量也可以,個人選擇.
- 安裝Nginx所需要的環(huán)境.(此案例自己下載nginx,自己編譯.)
安裝環(huán)境可參考【http://www.itdecent.cn/p/780a0530ed8f】
- 安裝libevent
yum -y install libevent

準備好安裝包,并解壓(沒有包自己去官網(wǎng)下載)=-=.
- 安裝libfastcommon
將libfastcommonV1.0.7.tar.gz拷貝至/usr/local/下
cd /usr/local
tar -zxvf libfastcommonV1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh
./make.sh install
注意:libfastcommon安裝好后會自動將庫文件拷貝至/usr/lib64下,由于FastDFS程序引用usr/lib目錄所以需要將/usr/lib64下的庫文件拷貝至/usr/lib下。
要拷貝的文件【libfastcommon.so】
[root@192 lib64]# cp libfastcommon.so ../lib

- tracker編譯安裝
將FastDFS_v5.05.tar.gz拷貝至/usr/local/下
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh
./make.sh install
安裝成功將安裝目錄下的conf下的文件拷貝到/etc/fdfs/下。

- 配置
6.1進入/etc/fdfs目錄
拷貝一份新的tracker配置文件:
cp tracker.conf.sample tracker.conf
修改tracker.conf
vim tracker.conf
base_path=/home/yuqing/fastdfs
改為:
base_path=/home/fastdfs
6.2啟動
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

error 意思就是沒有 '/home/fastdfs' 這個目錄,那就 mkdir -p 創(chuàng)建一下=。=.
然后在 啟動.

6.3設置開機自動啟動
vim /etc/rc.d/rc.loca
將命令添加到文件:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
然后 wq 保存=。=.
- FastDFS--storage安裝(和 5.tracker編譯安裝)一模一樣,不做解釋.
7.1 配置
進入/etc/fdfs目錄:
拷貝一份新的storage配置文件:
cp storage.conf.sample storage.conf
修改storage.conf
vim storage.conf
group_name=group1
base_path=/home/yuqing/fastdfs改為:base_path=/home/fastdfs
store_path0=/home/yuqing/fastdfs改為:store_path0=/home/fastdfs/fdfs_storage
#如果有多個掛載磁盤則定義多個store_path,如下
#store_path1=.....
#store_path2=......
tracker_server=192.168.101.3:22122 #配置tracker服務器:IP
#如果有多個則配置多個tracker
tracker_server=192.168.101.4:22122
7.2 啟動
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
一樣的 寫到 【/etc/rc.d/rc.local】里面
vim /etc/rc.d/rc.local
將命令添加到文件:/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
- 修改/etc/fdfs/client.conf
vim /etc/fdfs/client.conf
base_path=/home/fastdfs
tracker_server=192.168.101.3:22122

- FastDFS安裝成功可通過/usr/bin/fdfs_test測試上傳、下載等操作。
使用格式:
/usr/bin/fdfs_test 客戶端配置文件地址 upload 上傳文件
比如將/root下的圖片上傳到FastDFS中:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/1.png

-
FastDFS 和nginx整合
一開始Nginx的環(huán)境已經(jīng)安裝好了,直接開始編譯.
8.png
一個Nginx 一個 Fast模塊
10.1 先處理下 fast-nginx-module

將FastDFS-nginx-module_v1.16.tar.gz傳至/usr/local/下
cd /usr/local
tar -zxvf FastDFS-nginx-module_v1.16.tar.gz
cd FastDFS-nginx-module/src
修改config文件將/usr/local/路徑改為/usr/

將FastDFS-nginx-module/src下的mod_fastdfs.conf拷貝至/etc/fdfs/下
cp mod_fastdfs.conf /etc/fdfs/
并修改mod_fastdfs.conf的內(nèi)容:
vi /etc/fdfs/mod_fastdfs.conf
base_path=/home/fastdfs
tracker_server=192.168.101.3:22122
#tracker_server=192.168.101.4:22122(多個tracker配置多行)
url_have_group_name=true #url中包含group名稱
store_path0=/home/fastdfs #指定文件存儲路徑
將libfdfsclient.so拷貝至/usr/lib下
cp /usr/lib64/libfdfsclient.so /usr/lib/
創(chuàng)建nginx/client目錄
mkdir -p /var/temp/nginx/client

10.2 開始編譯Nginx
進入 Nginx目錄

./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
然后 make
然后 make install
切換目錄配置 nginx.conf
cd /usr/local/nginx
vim nginx.conf

最后啟動Nginx

再執(zhí)行一下
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/1.png
[root@192 conf]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /root/1.png
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.
[2018-10-20 15:04:41] DEBUG - base_path=/home/fastdfs, connect_timeout=30, network_timeout=30, 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.0.103, port=23000
group_name=group1, ip_addr=192.168.0.103, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgAZ1vLpnmAL9sKAACS3YKjgyI364.png
source ip address: 192.168.0.103
file timestamp=2018-10-20 15:04:41
file size=37597
file crc32=2191754018
example file url: http://192.168.0.103/group1/M00/00/00/wKgAZ1vLpnmAL9sKAACS3YKjgyI364.png
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgAZ1vLpnmAL9sKAACS3YKjgyI364_big.png
source ip address: 192.168.0.103
file timestamp=2018-10-20 15:04:41
file size=37597
file crc32=2191754018
example file url: http://192.168.0.103/group1/M00/00/00/wKgAZ1vLpnmAL9sKAACS3YKjgyI364_big.png
[root@192 conf]#
訪問:http://192.168.0.103/group1/M00/00/00/wKgAZ1vLpnmAL9sKAACS3YKjgyI364_big.png

