1. 程式人生 > >FastDFS配置及測試

FastDFS配置及測試

伺服器端指令碼語言: java php python asp
客戶端指令碼語言: js(javascript)

web: 程式程式碼檔案
儲存伺服器:靜態檔案
資料庫:動態檔案

靜態檔案:模板檔案、js程式碼、圖片、CSS樣式表
動態檔案:有變化的資料

配置fastDFS tracker
1、安裝信賴包
[[email protected] fdfs_soft]# yum install -y gcc make libevent
[[email protected] fdfs_soft]# yum install -y libevent-devel-2.0.21-4.el7.x86_64.rpm
2、安裝tracker
[

[email protected] fdfs_soft]# tar xzf FastDFS_v4.06.tar.gz
[[email protected] fdfs_soft]# cd FastDFS/
[[email protected] FastDFS]# ./make.sh
[[email protected] FastDFS]# ./make.sh install
3、配置
[[email protected] FastDFS]# cp init.d/fdfs_trackerd /etc/init.d/
[[email protected] FastDFS]# mkdir -pv /data/fastdfs
[
[email protected]
FastDFS]# vim /etc/fdfs/tracker.conf
base_path=/data/fastdfs
max_connections=4096
store_group=group1
use_storage_id = true
storage_ids_filename = storage_ids.conf
[[email protected] FastDFS]# cp conf/storage_ids.conf /etc/fdfs/
[[email protected] FastDFS]# vim /etc/fdfs/storage_ids.conf
100001   group1  192.168.4.2
4、起動並驗證
[
[email protected]
FastDFS]# /etc/init.d/fdfs_trackerd start
[[email protected] FastDFS]# chkconfig fdfs_trackerd on
[[email protected] FastDFS]# netstat -tlnp | grep :22122
[[email protected] FastDFS]# systemctl status fdfs_trackerd.service
[[email protected] FastDFS]# vim /data/fastdfs/logs/trackerd.log

配置storage
1、安裝,與tracker完全一樣
2、準備磁碟,分割槽格式化
3、配置
[[email protected] FastDFS]# mkdir -pv /data/fastdfs
[[email protected] FastDFS]# blkid /dev/vdb1
[[email protected] FastDFS]# tail -1 /etc/fstab
UUID=08a6e59a-5e05-480e-9a5e-99cb3b7d9e94   /data/fastdfs   ext4    defaults    0 0
[[email protected] FastDFS]# mount -a
[[email protected] FastDFS]# cp init.d/fdfs_storaged /etc/init.d/
[[email protected] FastDFS]# vim /etc/fdfs/storage.conf
base_path=/data/fastdfs
max_connections=4096
store_path_count=1
store_path0=/data/fastdfs
tracker_server=192.168.4.1:22122
upload_priority=10
4、起動並測試
[[email protected] FastDFS]# /etc/init.d/fdfs_storaged start
[[email protected] FastDFS]# chkconfig fdfs_storaged on
[[email protected] FastDFS]# netstat -tlnp | grep :23000
[[email protected] FastDFS]# systemctl status fdfs_storaged
[[email protected] FastDFS]# vim /data/fastdfs/logs/storaged.log

配置客戶端,將物理主機作為客戶端
1、建立工作目錄,並拷貝工具
[[email protected] ~]# mkdir /tmp/fdfs_client
[[email protected] FastDFS]# scp /usr/local/bin/fdfs_* 192.168.4.254:/tmp/fdfs_client/
[[email protected] FastDFS]# scp /etc/fdfs/client.conf 192.168.4.254:/tmp/fdfs_client/
2、修改配置檔案
[[email protected] ~]# cd /tmp/fdfs_client/
[[email protected] fdfs_client]# vim client.conf
base_path=/tmp/fdfs_client
tracker_server=192.168.4.1:22122
3、使用測試命令
[[email protected] fdfs_client]# ./fdfs_test client.conf upload /etc/hosts
[[email protected] fdfs_client]# ./fdfs_test client.conf delete group1 M00/00/00/wKgEAlkxG6CAOSnXAAACsxL_eN41494789
[[email protected] fdfs_client]# ./fdfs_upload_file client.conf /etc/hosts
group1/M00/00/00/wKgEAlkxHe2AY4jGAAACsxL_eN42540304
[[email protected] fdfs_client]# ./fdfs_download_file client.conf group1/M00/00/00/wKgEAlkxHe2AY4jGAAACsxL_eN42540304 /tmp/zhuji.txt
[[email protected] fdfs_client]# ./fdfs_delete_file client.conf group1/M00/00/00/wKgEAlkxHe2AY4jGAAACsxL_eN42540304

配置web訪問
1、安裝依賴包
[[email protected] fdfs_soft]# yum install -y pcre-devel openssl-devel zlib-devel
2、建立執行帳戶
[[email protected] fdfs_soft]# useradd -s /sbin/nologin nginx
3、編譯安裝nginx
[[email protected] fdfs_soft]# tar xzf fastdfs-nginx-module_v1.16.tar.gz
[[email protected] fdfs_soft]# tar xzf nginx-1.7.10.tar.gz
[[email protected] fdfs_soft]# cd nginx-1.7.10/
[[email protected] nginx-1.7.10]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --add-module=../fastdfs-nginx-module/src/
[[email protected] nginx-1.7.10]# make && make install
4、配置
[[email protected] nginx-1.7.10]# cd ..
[[email protected] fdfs_soft]# cp fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
[[email protected] fdfs_soft]# vim /etc/fdfs/mod_fastdfs.conf
tracker_server=192.168.4.1:22122
group_name=group1
url_have_group_name = true
store_path0=/data/fastdfs
[[email protected] fdfs_soft]# vim /usr/local/nginx/conf/nginx.conf
        location / {
           # root   html;
           # index  index.html index.htm;
           ngx_fastdfs_module;
        }
5、起動並測試
[[email protected] fdfs_soft]# /usr/local/nginx/sbin/nginx
[[email protected] fdfs_client]# ./fdfs_upload_file client.conf /var/ftp/pub/fdfs_soft/tedu.jpg
group1/M00/00/00/wKgEAlkxKCCANP5mAACwEV-ILDc267.jpg
[[email protected] fdfs_client]# firefox http://192.168.4.2/group1/M00/00/00/wKgEAlkxKCCANP5mAACwEV-ILDc267.jpg &