一 简介
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
wget
下载 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_c/span>
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
c/span>
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
通过浏览器
http://192.168.80.101/g1/M00/AC/2F/wKgKDVMppoGAMCFNAAIFvJcyojY165.jpg
以上就介绍了FastDFS+Nginx轻量级分布式文件系统安装使用,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

PHP和Python各有优势,选择应基于项目需求。1.PHP适合web开发,语法简单,执行效率高。2.Python适用于数据科学和机器学习,语法简洁,库丰富。

PHP不是在消亡,而是在不断适应和进化。1)PHP从1994年起经历多次版本迭代,适应新技术趋势。2)目前广泛应用于电子商务、内容管理系统等领域。3)PHP8引入JIT编译器等功能,提升性能和现代化。4)使用OPcache和遵循PSR-12标准可优化性能和代码质量。

PHP的未来将通过适应新技术趋势和引入创新特性来实现:1)适应云计算、容器化和微服务架构,支持Docker和Kubernetes;2)引入JIT编译器和枚举类型,提升性能和数据处理效率;3)持续优化性能和推广最佳实践。

在PHP中,trait适用于需要方法复用但不适合使用继承的情况。1)trait允许在类中复用方法,避免多重继承复杂性。2)使用trait时需注意方法冲突,可通过insteadof和as关键字解决。3)应避免过度使用trait,保持其单一职责,以优化性能和提高代码可维护性。

依赖注入容器(DIC)是一种管理和提供对象依赖关系的工具,用于PHP项目中。DIC的主要好处包括:1.解耦,使组件独立,代码易维护和测试;2.灵活性,易替换或修改依赖关系;3.可测试性,方便注入mock对象进行单元测试。

SplFixedArray在PHP中是一种固定大小的数组,适用于需要高性能和低内存使用量的场景。1)它在创建时需指定大小,避免动态调整带来的开销。2)基于C语言数组,直接操作内存,访问速度快。3)适合大规模数据处理和内存敏感环境,但需谨慎使用,因其大小固定。

PHP通过$\_FILES变量处理文件上传,确保安全性的方法包括:1.检查上传错误,2.验证文件类型和大小,3.防止文件覆盖,4.移动文件到永久存储位置。

JavaScript中处理空值可以使用NullCoalescingOperator(??)和NullCoalescingAssignmentOperator(??=)。1.??返回第一个非null或非undefined的操作数。2.??=将变量赋值为右操作数的值,但前提是该变量为null或undefined。这些操作符简化了代码逻辑,提高了可读性和性能。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

Dreamweaver CS6
视觉化网页开发工具