服务器 | IP | 服务(端口) |
---|---|---|
服务器1 | 192.168.2.130 | tracker0(22122) |
服务器2 | 192.168.2.150 | tracker1(22122) |
服务器3 | 192.168.2.124 | storage0(23000)、nginx(8888) |
服务器4 | 192.168.2.119 | storage1(23000)、nginx(8888) |
对外开放的服务器 | 公网IP/域名 | nginx(80/443) |
文件 | 描述 | 下载 |
---|---|---|
libfastcommon_V1.0.43.tar.gz | FastDFS分离出的一些公用函数包 | 下载 |
fastdfs_V6.06.tar.gz | FastDFS本体 | 下载 |
fastdfs-nginx-module_V1.22.tar.gz | FastDFS和nginx的关联模块,解决组内同步延迟问题 | 下载 |
nginx-1.16.1.tar.gz | 下载 |
官方文档
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
tar -zxvf libfastcommon_V1.0.43.tar.gz
cd libfastcommon-1.0.43/
./make.sh
./make.sh install
cd ..
tar -zxvf fastdfs_V6.06.tar.gz
cd fastdfs-6.06/
./make.sh
./make.sh install
cd ..
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
vim /etc/fdfs/tracker.conf
#需要修改的内容如下
port=22122 # tracker服务器端口(默认22122,一般不修改)
base_path=/data/fastdfs # 存储日志和数据的根目录
use_storage_id = true # 使用id来区分storage,方便迁移
storage_ids_filename = storage_ids.conf
id_type_in_filename = id
确保配置文件的目录都存在
mkdir -p /data/fastdfs
cp /etc/fdfs/storage_ids.conf.sample /etc/fdfs/storage_ids.conf
vim /etc/fdfs/storage_ids.conf
# 将storage的ip添加进去
100001 group1 172.18.0.2
100002 group1 172.18.0.3
# 启动
fdfs_trackerd /etc/fdfs/tracker.conf start
# 停止
fdfs_trackerd /etc/fdfs/tracker.conf stop
# 重启
fdfs_trackerd /etc/fdfs/tracker.conf restart
部署方式同服务器1
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
tar -zxvf libfastcommon_V1.0.43.tar.gz
cd libfastcommon-1.0.43/
./make.sh
./make.sh install
cd ..
tar -zxvf fastdfs_V6.06.tar.gz
cd fastdfs-6.06/
./make.sh
./make.sh install
cd ..
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
vim /etc/fdfs/storage.conf
#需要修改的内容如下
port=9000 # storage服务端口(默认23000,一般不修改)
base_path=/data/fastdfs # 数据和日志文件存储根目录
store_path0=/data/fastdfs/store_path0 # 文件存储目录,可根据磁盘设置
tracker_server = 192.168.2.130:22122 # tracker服务器IP和端口
tracker_server = 192.168.2.150:22122 # tracker服务器IP和端口
http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
确保配置文件中设置的目录都存在
mkdir -p /data/fastdfs
mkdir -p /data/fastdfs/store_path0
# 启动
fdfs_storaged /etc/fdfs/storage.conf start
# 停止
fdfs_storaged /etc/fdfs/storage.conf stop
# 重启
fdfs_storaged /etc/fdfs/storage.conf restart
#查看集群状态
fdfs_monitor /etc/fdfs/storage.conf list
tar -zxvf fastdfs-nginx-module_V1.22.tar.gz
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure --add-module=../fastdfs-nginx-module-1.22/src/
make
make install
cd ..
cp fastdfs-6.06/conf/http.conf /etc/fdfs/
cp fastdfs-6.06/conf/mime.types /etc/fdfs/
cp fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf
#需要修改的内容如下
tracker_server = 192.168.2.130:22122 # tracker服务器IP和端口
tracker_server = 192.168.2.150:22122 # tracker服务器IP和端口
storage_server_port=23000
url_have_group_name=true
store_path0=/data/fastdfs/store_path0
vim /usr/local/nginx/conf/nginx.conf
#添加如下配置
server {
listen 8888; ## 该端口为storage.conf中的http.server_port相同
server_name localhost;
location ~/group1/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# 启动
/usr/local/nginx/sbin/nginx
# 停止
/usr/local/nginx/sbin/nginx -s stop
# 重启
/usr/local/nginx/sbin/nginx -s reload
部署方式同服务器3
可在任意安装了FastDFS上的服务器上运行测试
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vim /etc/fdfs/client.conf
#需要修改的内容如下
base_path=/data/fastdfs_client # 数据和日志文件存储根目录
tracker_server = 192.168.2.130:22122 # tracker服务器IP和端口
tracker_server = 192.168.2.150:22122 # tracker服务器IP和端口
use_storage_id = true # 使用id来区分storage,方便迁移
确保配置文件中的目录都存在
mkdir -p /data/fastdfs_client
# 测试上传,上传成功后返回文件路径:group1/M00/00/00/rBIAAV6ZN62AKxKOAA_ZI6CZBeI.tar.gz
fdfs_upload_file /etc/fdfs/client.conf /root/fastdfs/nginx-1.17.8.tar.gz
参考配置
upstream fdfs_group01 {
server 192.168.2.124:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.2.119:8888 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /files {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://fdfs_group01/;
expires 30d;
}
}
尝试在浏览器中访问
http://127.0.0.1/files/group1/M00/00/00/rBIAAV6ZN62AKxKOAA_ZI6CZBeI.tar.gz
这里127.0.0.1应换成外网可访问的nginx的地址
一切正常时,会弹出下载框
开启后访问文件需要一个定期失效的token,以防止链接被滥用。
vim /etc/fdfs/http.conf
# 需要配置的内容如下
# if use token to anti-steal
# default value is false (0)
# 是否做token检查,缺省值为false。
http.anti_steal.check_token=true
# token TTL (time to live), seconds
# default value is 600
# TTL,即生成token的有效时长(秒)
http.anti_steal.token_ttl=3600
# secret key to generate anti-steal token
# this parameter must be set when http.anti_steal.check_token set to true
# the length of the secret key should not exceed 128 bytes
# 生成token的密钥,尽量设置得长一些,千万不要泄露出去
http.anti_steal.secret_key=14789632
# return the content of the file when check token fail
# default value is empty (no file sepecified)
# 检查失败,返回的文件内容,需指定本地文件名
http.anti_steal.token_check_fail=
# 重启tracker
fdfs_trackerd /etc/fdfs/tracker.conf restart
# 重启storage
fdfs_storaged /etc/fdfs/storage.conf restart
# 重启nginx
./nginx -s reload