0%

安装配置 FastDFS 文件系统

安装配置 FastDFS 文件系统

在两台虚拟机上安装 FastDFS 文件系统,用来学习与测试。

服务器信息:test01(192.168.115.131)、test02(192.168.155.132)

OS 版本:CentOS release 6.7 (Final)

FastDFS 版本:5.08

上传安装介质(both)

创建相关目录

1
2
mkdir /root/fastdfs
mkdir -p /home/fastdfs_data/client /home/fastdfs_data/module /home/fastdfs_data/storage /home/fastdfs_data/tracker

上传安装文件到 /root/fastdfs 目录

1
2
3
4
fastdfs-nginx-module_v1.16.tar.gz
FastDFS_v5.08.tar.gz
libfastcommon-master.zip
nginx-1.10.1.tar.gz

编译安装 libfastcommon(both)

1
2
3
4
5
6
7
8
9
10
yum install -y gcc perl libevent
cd /root/fastdfs
unzip libfastcommon-master.zip
cd libfastcommon-master
./make.sh
./make.sh install
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

编译安装 FastDFS(both)

1
2
3
4
5
cd /root/fastdfs
tar -zxvf FastDFS_v5.08.tar.gz
cd FastDFS
./make.sh
./make.sh install

配置 FastDFS(both)

配置 tracker

拷贝配置文件:

1
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf

修改 /etc/fdfs/tracker.conf 参数:

1
base_path=/home/fastdfs_data/tracker

启动 tracker 进程:

1
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

配置 storage

拷贝配置文件:

1
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf

修改 /etc/fdfs/storage.conf 参数:

1
2
3
4
base_path=/home/fastdfs_data/storage
store_path0=/home/fastdfs_data
tracker_server=192.168.115.131:22122
tracker_server=192.168.115.132:22122

启动 storage:

1
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

配置 client

拷贝配置文件:

1
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf

修改 /etc/fdfs/client.conf 参数:

1
2
3
base_path=/home/fastdfs_data/client
tracker_server=192.168.115.131:22122
tracker_server=192.168.115.132:22122

测试:

1
fdfs_test /etc/fdfs/client.conf upload Lighthouse.jpg

以下输出表示配置正确:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    This is FastDFS client test program v5.08

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.

[2016-09-14 15:05:58] DEBUG - base_path=/home/fastdfs_data/client, connect_timeout=30, network_timeout=60, tracker_server_count=2, 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.115.131, port=23000
server 2. group_name=, ip_addr=192.168.115.132, port=23000

group_name=group1, ip_addr=192.168.115.132, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKhzhFfY9taAOvjKAAiQfKHDaaQ960.jpg
source ip address: 192.168.115.132
file timestamp=2016-09-14 15:05:58
file size=561276
file crc32=2713938340
example file url: http://192.168.115.131/group1/M00/00/00/wKhzhFfY9taAOvjKAAiQfKHDaaQ960.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKhzhFfY9taAOvjKAAiQfKHDaaQ960_big.jpg
source ip address: 192.168.115.132
file timestamp=2016-09-14 15:05:58
file size=561276
file crc32=2713938340
example file url: http://192.168.115.131/group1/M00/00/00/wKhzhFfY9taAOvjKAAiQfKHDaaQ960_big.jpg

编译安装配置 nginx(test01)

配置 fastdfs-nginx-module

解压修改配置文件:

1
2
cd /root/fastdfs
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz

修改 fastdfs-nginx-module/src/config 参数:

1
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

拷贝配置文件:

1
2
3
cp /root/fastdfs/FastDFS/conf/http.conf /etc/fdfs/
cp /root/fastdfs/FastDFS/conf/mime.types /etc/fdfs/
cp /root/fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs

修改 /etc/fdfs/mod_fastdfs.conf 参数:

1
2
3
4
5
base_path=/home/fastdfs_data/module
tracker_server=192.168.115.131:22122
tracker_server=192.168.115.132:22122
url_have_group_name = true
store_path0=/home/fastdfs_data

编译安装 nginx

yum 安装依赖包:

1
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

创建日志目录:

1
mkdir -p /usr/local/nginx /var/log/nginx /var/temp/nginx /var/lock/nginx

编译 nginx:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cd /root/fastdfs
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/local/nginx/nginx.pid \
--lock-path=/var/lock/nginx/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=/root/fastdfs/fastdfs-nginx-module/src

安装 nginx:

1
2
make
make install

修改 /usr/local/nginx/conf/nginx.conf 参数:

1
2
3
4
user  root;
location /group1/M00 {
ngx_fastdfs_module;
}

启动 nginx:

1
/usr/local/nginx/sbin/nginx

浏览器访问测试:

1
http://192.168.115.131/group1/M00/00/00/wKhzhFfY9taAOvjKAAiQfKHDaaQ960_big.jpg