FastDFS+Nginx轻量级分布式
一 简介
FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等。
FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。跟踪器主要做调度工作,在访问上起负载均衡的作用。
二 安装
1, 本次安装采用三台centos5.10 linux操作系统
192.168.80.100 tracker Nginx(注意这台不安装fastsfd-niginx插件)
192.168.80.101 storage nginx
192.168.80.102 storage nginx
操作系统的安装这里不多说。
2, 准备编译环境 yum -y install gcc gcc+ gcc-c++ openssl openssl-devel pcre pcre-devel 三台机器都进行安装,并且创建两个新用户fastdfs 和nginx
useradd fastdfs -M -s /sbin/nologin useradd nginx -M -s /sbin/nologin
为了方便测试 请关闭防火墙 service iptables stop
3, 下载源码
敲 cd /usr/local/src/ 进入该目录下,运行如下命令,下载fastDFS 5.01
下载 nginx 1.7.0
wget http://nginx.org/download/nginx-1.7.0.tar.gz
下载fastdfs-nginx-module_v1.16
wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
4, 安装FastDFS (三台机器都要安装)
tar xf FastDFS_v5.01.tar.gz
cd FastDFS
./make.sh && ./make.sh install
5, 解压fastDFS-nginx-module
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar xf fastdfs-nginx-module_v1.16.tar.gz
6, 安装Nginx
192.168.80.100 tarcker 机器的安装
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar xf nginx-1.7.0.tar.gz
[root@localhost src]# cd nginx-1.7.0
[root@localhost nginx-1.7.0]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx
[root@localhost nginx-1.7.0]# make
[root@localhost nginx-1.7.0]# make install
192.168.80.101,102 stroage nginx的安装
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar xf nginx-1.7.0.tar.gz
[root@localhost src]# cd nginx-1.7.0
[root@localhost nginx-1.7.0]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx
--add-module=../fastdfs-nginx-module/src //storage 安装nginx时需要加载该模块
[root@localhost nginx-1.7.0]# make
[root@localhost nginx-1.7.0]# make install
三 配置
192.168.80.100 tracker的配置
1,创建tracker数据以及日志存放目录
[root@localhost ~]# mkdir -p /data/fastdfs/tracker
2,修改FastDFS的tracker.conf配置 文件
[root@localhost ~]# vim /etc/fdfs/tracker.conf
base_path=/data/fastdfs/tracker
max_connections=1024
work_threads=8
store_lookup=0
store_path=0
reserved_storage_space=4G //
run_by_group=fastdfs
run_by_user=fastdfs
rotate_error_log=true
配置的解析请参照我的以一篇文章 tracker配置文件解析
3,修改Nginx的配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; //此处为已经建立好的用户 和分组
worker_processes 3;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 1024;
events {
use epoll; // epoll是Linux内核为处理大批量文件描述符而作了改进的poll
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /usr/local/nginx/logs/access.log main;
upstream server_g1{
server 192.168.80.101:80; //这里配置的是storage的IP 可以配多台
server 192.168.80.102:80;
}
server {
listen 80;
server_name localhost;
location /g1 {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://server_g1;
}
}
}
4,将tracker交给service管理并且设置开机启动
[root@localhost ~]# cp /usr/local/src/FastDFS/init.d/fdfs_trackerd /etc/init.d/
[root@localhost ~]# chkconfig --add fdfs_trackerd
[root@localhost ~]# chkconfig fdfs_trackerd on
配置storage (分别在192.168.80.101,102上进行配置)
1, 创建数据存放目录
[root@localhost ~]# mkdir -p /data/fastdfs/storage/data
2,修改FastDFS的storage.conf配置文件
[root@localhost ~]# vim /etc/fdfs/storage.conf
group_name=g1
base_path=/data/fastdfs
##工作线程数,通常设置为 CPU 数
work_threads=8
store_path_count=1
store_path0=/data/fastdfs/storage
##tracker_server 的地址
tracker_server=192.168.80.100:22122
##运行 FastDFS 的用户组
run_by_group=fastdfs
##运行 FastDFS 的用户
run_by_user=fastdfs
file_distribute_path_mode=1
rotate_error_log=true
3,把nginx模块的配置文件拷贝到 /etc/fdfs中,进行修改
[root@localhost ~]# cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
[root@localhost ~]# vim /etc/fdfs/mod_fastdfs.conf
connect_timeout=30
tracker_server=192.168.80.100:22122
group_name=g1
url_have_group_name = true
store_path_count=1
store_path0=/data/fastdfs/storage
4,修改nginx配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
user nginx nginx;
worker_processes 8;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 1024;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /usr/local/nginx/logs/access.log main;
server {
listen 80;
server_name localhost;
location /g1/M00{
root /data/fastdfs/storage/data;
ngx_fastdfs_module;
}
}
}
5,把storage 交[root@localhost ~]# cp /usr/local/src/FastDFS/init.d/fdfs_storaged /etc/init.d/
[root@localhost ~]# chkconfig --add fdfs_storaged
[root@localhost ~]# chkconfig fdfs_storaged on
[root@localhost ~]# service fdfs_storaged start给service管理并设置开机启动
//创建软连接
[root@localhost ~]# ln -s /data/fastdfs/storage/data /data/fastdfs/storage/data/M00
四 测试
1,在192.168.80.100 上启动tracker,nginx
[root@localhost ~]# service fdfs_trackerd start
[root@localhost ~]# /usr/local/nginx/sbin/nginx
2,在192.168.80.101,102上面分别启动storage和nginx
[root@localhost ~]# service fdfs_storaged start
[root@localhost ~]# /usr/local/nginx/sbin/nginx
3配置一个client 在tracker上进行
[root@localhost ~]# vim /etc/fdfs/client.conf
base_path=/data/fastdfs
tracker_server=192.168.80.100:22122
4,查看集群详细
[root@localhost ~]# fdfs_monitor /etc/fdfs/client.conf
5,测上传
root@localhost ~]# fdfs_upload_file /etc/fdfs/client.conf aa.jpg
g1/M00/AC/2F/wKgKDVMppoGAMCFNAAIFvJcyojY165.jpg
FastDFS+Nginx轻量级分布式的更多相关文章
- centos6.5安装配置fastdfs+nginx实现分布式图片服务器
一.准备 yum groupinstall -y "Development Tools"yum install -y wget libevent-devel pcre-devel ...
- docker+fastdfs+nginx 实现分布式大文件存储系统以及视频缓存播放
废话不多说,直接开撸 首先是一些准备工作: 1.关闭防火墙 service iptables stop --- fastdfs虽然在docker部署,但是使用的是主机网络,所以关闭防火墙. 2 下载 ...
- FastDFS 与 Nginx 实现分布式图片服务器
FastDFS 与 Nginx 实现分布式图片服务器 本人的 Ubuntu18.04 用户名为 jj 点我下载所有所需的压缩包文件 一.FastDFS安装 1.安装 fastdfs 依赖包 ① 解压 ...
- 轻量级分布式文件系统FastDFS使用安装说明手册(新手入门级)
轻量级分布式文件系统FastDFS使用安装说明手册(新手入门级) 实验室所在的课题组以研究云计算为主,但所有的研究都是在基于理论的凭空想像,缺少分布式环境的平台的实践,云计算神马的都是浮云了.因此,我 ...
- FastDFS轻量级分布式文件系统部署
FastDFS介绍 FastDFS 是一个由 C 语言实现的开源轻量级分布式文件系统,作者余庆,支持 Linux.FreeBSD.AID 等 Unix 系统,解决了大数据存储和读写负载均衡等问题,适合 ...
- 分布式FastDfs+nginx缓存高可用集群构建
介绍: FastDFS:开源的高性能分布式文件系统:主要功能包括:文件存储,文件同步和文件访问,以及高容量和负载平衡 FastDFS:角色:跟踪服务器(Tracker Server).存储服务器(St ...
- 开源轻量级分布式文件系统--FastDFS
FastDFS一个高效的分布式文件系统 分布式文件系统FastDFS原理介绍 分布式文件系统FastDFS设计原理 FastDFS安装.配置.部署(一)-安装和部署 分布式文件系统 - FastDFS ...
- miya--图片上传--搭建分布式文件服务器(FastDFS+Nginx)
资料获取(FastDFS+Nginx): 链接:https://pan.baidu.com/s/1kUI5WH5 密码:kzfd 安装rz,sz功能: yum install lrzsz 主攻: 利用 ...
- centos 系统下安装FastDFS+nginx+fastdfs-nginx-module安装配置
前言: 以前的项目上传的文件都是保存到本地或者是局域网内的共享文件夹下,由于数据量,服务器的负载均衡(分机的某些图片无法访问的问题处理)等因素的情况下,就想到用fastdfs来文件管理,花了几天时间硬 ...
随机推荐
- [转]非OpenVZ下利用谷歌TCP-BBR协议单边加速你的VPS
前段时间谷歌推出了新的 TCP-BBR 开源算法,可以起到单边加速 TCP 连接的效果,也就是不用客户端的配合,用来替代收费的锐速再合适不过,毕竟开源免费.TCP-BBR 的目的是要尽量跑满带宽,并且 ...
- 用CSS让未知高度内容垂直方向居中
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title> ...
- MSSQL 之事务订单存储过程
1. 赋值 set 或者 select 运算符 2.全局,局部变量区别,生命域 (全局变量用户不能定义) 3.@@identity 返回最后插入行的标识列的列值. 4.delete 只删除了数 ...
- MongoDB 安装记录
之前使用一直没记录,防再次掉坑,记录下 echo 开始 D: cd D:\Program Files\MongoDB\Server\3.2\bin mongod --install --service ...
- C# 解析百度天气数据,Rss解析百度新闻以及根据IP获取所在城市
百度天气 接口地址:http://api.map.baidu.com/telematics/v3/weather?location=上海&output=json&ak=hXWAgbsC ...
- GET方法传递中文参数乱码解决办法
1.在页面中对你的URL进行编码 使用------encodeURI(你要使用的中文参数值)如:...?username"+encodeURI(“小甜甜") 2.在后台通过解码来接 ...
- Tips7:Unity中 Scene视图 和 Game视图 中 视角(Camera)的控制
选中你要改变的相机,然后点击GameObject-->Align With View 选项(快捷键Ctrl+Shift+F)使相机视角和当前Sence视图中一样 通过这样可以控制在Game视图( ...
- 使用Html5+C#+微信 开发移动端游戏详细教程 :(五)游戏图像的加载与操作
当我们进入游戏时,是不可能看到所有的图像的,很多图像都是随着游戏功能的打开而出现, 比如只有我打开了"宝石"菜单才会显示宝石的图像,如果是需要显示的时候才加载, 会对用户体验大打折 ...
- node-gyp rebuild 卡住?
最近 npm install 时候经常遇到在 node-gyp rebuild 那里卡很久的情况(大于十分钟),于是研究了一下输出的错误日志解决了这个问题,在这里分享一下. 首先,请检查 node-g ...
- 性能测试类,让你写法代码养成经常测试的好习惯 -ASP.NET C#
介绍: 可以很方便的在代码里循环执行 需要测试的函数 自动统计出执行时间,支持多线程. 使用方法: PerformanceTest p = new PerformanceTest(); p.SetC ...