FastDFS集群文件系统搭建轻版教程(在线版)
来源:互联网 发布:华为云计算招聘 编辑:程序博客网 时间:2024/06/08 12:04
FastDFS集群文件系统搭建轻版教程(在线版)
楔子
不知道啥意思但是一直想用这个词^_^,这个教程是在线版,需要连接网络,如果你的虚拟机是离线状态,可以参考这个教程。
http://还在写。。。别着急,,,
1.虚拟机搭建
首先你要有地方来装这个文件系统,这里我们的集群需要搭建六个个虚拟机,这个虚拟机怎么弄就不赘述了,要是不会的话,看看这个文档http://blog.csdn.net/xuchen1994/article/details/78652785
2.FastDFS文件系统架构
当你把虚拟机都装好了,IP也都配好了,确定能上网了,我们就可以简单看一下这个文件系统的架构了。
FastDFS集群文件系统有两个比较核心的元素分别是,Tracker和Storage,翻译过来叫跟踪器和存储器。跟踪器用于处理客户端的请求,存储器用于存储文件。
简单场景:客户端向跟踪器发出文件处理请求,跟踪器按照FastDFS的配置和它内部的算法返回一个最优的存储器的地址,客户端再按照这个地址访问存储器,进行文件操作
当然这只是单点的FastDFS,我们的目标是集群文件系统,只有单点的话,文件系统就太脆弱了。
我们的集群文件系统一共有六台虚拟机,分别是两台跟踪器和四台存储器,存储器分为两组,每组两个,跟踪器跟两个组都有关联,每个组内的存储器的内容是实时同步的。
另外为了达到高可用,负载均衡等等的目标,我们的跟踪器和存储器都要和Nginx集成,具体的原理就不赘述了(我也不懂)。
3.安装
现在开始的操作是所有六个节点全部执行
(1)安装软件和一些基础操作
gcc yum install -y make cmake gcc gcc-c++automake autoconf libtool perl
vim yum -y install vim*
unzip yum install -y unzip zip
iptables-services yum install iptables-services
关闭防火墙
(别问为什么,干就完了)
关闭 systemctl stop firewalld.service
禁止开机启动 systemctl disable firewalld.service
查看状态 firewall-cmd --state
下面用到的压缩包安装包什么的,直接百度,去官网下,这里不能传文件
(2)安装libfastcommon
<1>上传libfastcommon-master.zip到/usr/local/software下,进行解压:
命令:unzip libfastcommon-master.zip -d /usr/local/fast/
注:
1、这里注意一下命令的空格
2、简单介绍一下怎么往虚拟机里面拷贝文件,看这个文档http://blog.csdn.net/xuchen1994/article/details/78654977
<2>进入目录,编译安装
命令 cd /usr/local/fast/libfastcommon-master
命令 ./make.sh
命令 ./make.sh install
<3>进行软连接创建。FastDFS主程序设置目录为/usr/local/lib/,所以我们需要创建/usr/lib64/下的一些核心程序的软连接文件
命令 mkdir /usr/local/lib/
命令 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
(3)安装FastDFS
<1>进入目录,解压FastDFS(当然你要先把文件拷贝过去)
命令 cd /usr/local/software
命令 tar -zxvf FastDFS_v5.05.tar.gz -C /usr/loacl/fast/
<2>安装编译
命令 cd /usr/loacl/fast/FastDFS/
命令 ./make.sh
命令 ./make.sh install
<3>因为FastDFS服务脚本设置的bin目录为/usr/local/bin/下,但是实际我们安装在了/usr/bin/下面。所以我们需要修改FastDFS配置文件中的路径,也就是需要修改两个配置文件
命令 vim /etc/init.d/fdfs_storaged
命令(打一个冒号,然后敲命令) %s+/usr/local/bin+/usr/bin
命令 vim /etc/init.d/fdfs_trackerd
命令(打一个冒号,然后敲命令) %s+/usr/local/bin+/usr/bin
接下来的操作是跟踪器节点执行
(4)配置两台跟踪器节点(192.168.29.21&192.168.29.22)
<1>进入目录,copy一份配置文件
命令 cd /etc/fdfs/
命令 cp tracker.conf.sample tracker.conf
<2>编辑跟踪器文件
命令 vim tracker.conf
修改这个地方base_path=/fastdfs/tracker
<3>创建文件夹
命令 mkdir -p /fastdfs/tracker
<4>启动跟踪器
命令 /etc/init.d/fdfs_trackerd start
接下来我们要配置四个存储器节点
(5)配置存储节点(192.168.29.23&192.168.29.24&192.168.29.25&192.168.29.26)
<1>进入四台机器的配置文件目录,copy配置文件
命令 cd /etc/fdfs
命令 cp storage.conf.sample storage,conf
<2>编辑配置文件
命令 vim storage.conf
注意:23,24为group1,25,26为group2
内容为:
disabled=false #启用配置文件
group_name=group1 #组名,第一组为group1,第二组为group2
Port=23000 #storage端口号,同一个组的端口号必须相同
base_path=/fastdfs/storage #设置storage的日志目录
store_path_count=1 #存储路径个数,需要和store_path个数匹配
store_path0=/fastdfs/storage #设置存储路径
tracker_server=192.168.29.21 #tracker服务器的IP和端口
tracker_server=192.168.29.22 #多个tracker直接添加多条配置
Http.server_port=8888 #设置http端口号
<3>建立存储目录
存储目录需要和base_path=/fastdfs/storage保持一致,四个存储节点都建立
命令 mkdir -p /fastdfs/storage
<4>启动storage
命令 /etc/init.d/fdfs_storaged start
注意要先启动跟踪器再启动存储器
到这里我们的存储节点算是初步搭建完成了,你可以上传文件试试
4.测试
(1)搞一个跟踪器节点作客户端,上传文件试试
命令 cd /etc/fdfs
命令 cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
命令 vim /etc/fdfs/client.conf
修改内容
base_path=/fastdfs/tracker
tracker_server=192.168.29.21:22122
tracker_server=192.168.29.22:22122
命令 /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/software/FastDFS_v5.05.tar.fz
最后这个是你要传的文件,你随便搞一个就行。你可以多传几个试试,看看同一个组的storage有没有同步,再看看每次传的时候都存到哪个组里了。
5配置Nginx
一、接下来的操作是在四个存储节点进行
(1)安装fastdfs-nginx
命令 cd /usr/local/software
命令 tar -zxvf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/fast/
命令 cd /usr/local/fast/fastdfs-nginx-module/src/
命令 vim /usr/local/fast/fastdfs-nginx-module/src/config
把第四行的两个local/删掉
(2)下载需要的依赖库文件
命令 yum install pcre
命令 yum install pcre-devel
命令 yum install zlib
命令 yum install zlib-devel
(3)解压安装nginx,加入模块
命令 cd /usr/local/software
命令 tar -zxvf nginx-1.12.2.tar.gz -C /usr/local/
命令 cd /usr/local/nginx-1.12.2/
命令 ./configure --add-module=/usr/local/fast/fastdfs-nginx-module/src/
命令 make && make install
(4)配置nginx
命令 cd /usr/local/fast/fastdfs-nginx-module/src/
命令 cp /usr/local/fast/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
命令 cd /etc/fdfs
命令 vim /etc/fdfs/mod_fastdfs.conf
修改内容:比如连接超时时间、跟踪器路径、group配置等等
connect_timeout=10tracker_server=192.168.29.21:22122tracker_server=192.168.29.22:22122storage_server_port=23000url_have_group_name = truestore_path0=/fastdfs/storagegroup_name=group1 #第一组为group1,第二组为group2group_count = 2[group1]group_name=group1storage_server_port=23000store_path_count=1store_path0=/fastdfs/storage[group2]group_name=group2storage_server_port=23000store_path_count=1store_path0=/fastdfs/storage
保存退出,记得其他几个存储节点也要修改
(5)复制两个FastDFS的配置文件
命令 cd /usr/local/fast/FastDFS/conf
命令 cp http.conf mime.types /etc/fdfs/
(6)创建软连接
命令 ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
(7)修改Nginx配置文件
命令 cd /usr/local/nginx/conf/
命令 vim nginx.conf
修改内容如下:
listen 8888; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location ~/group([0-9])/M00 { ngx_fastdfs_module; }
注意别把括号结构改错了,而且这里的端口号要和之前配置FastDFS存储中的storage.conf文件配置一致,也就是(http.server_port=8888)
(8)启动nginx
命令 /usr/local/nginx/sbin/nginx
二、接下来的操作在两个跟踪器执行
(1)解压,下载依赖,干就完了
命令 tar -zxvf ngx_cache_purge-2.3.tar.gz -C /usr/local/fast/
命令 yum install pcre
命令 yum install pcre-devel
命令 yum install zlib
命令 yum install zlib-devel
(2)解压nginx,加入模块
命令 cd /usr/local/software
命令 tar -zxvf nginx-1.12.2.tar.gz -C /usr/local/
命令 cd /usr/local/nginx-1.12.2/
命令 ./configure --add-module=/usr/local/fast/fastdfs-nginx-module/src/
命令 make && make install
(3)配置nginx负载均衡和缓存
命令 vim /usr/local/nginx/conf/nginx.conf
修改内容如下:
#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 1024; use epoll;}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 logs/access.log main; sendfile on; tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; #cache server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 300m; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; #setting proxy_cache_path /fastdfs/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:200m max_size=1g inactive=30d; proxy_temp_path /fastdfs/cache/nginx/proxy_cache/tmp; #group1 upstream fdfs_group1{ server 192.168.29.23:8888 weight=1 max_fails=2 fail_timeout=30s; server 192.168.29.24:8888 weight=1 max_fails=2 fail_timeout=30s; } #gruop2 upstream fdfs_group2{ server 192.168.29.25:8888 weight=1 max_fails=2 fail_timeout=30s; server 192.168.29.26:8888 weight=1 max_fails=2 fail_timeout=30s; } server { listen 8000; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location /group1/M00 { #root html; #index index.html index.htm; proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache http-cache; proxy_cache_valid 200 304 12h; proxy_cache_key $uri$is_args$args; #group1 server setting proxy_pass http://fdfs_group1; expires 30d; } location /group2/M00{ proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache http-cache; proxy_cache_valid 200 304 12h; proxy_cache_key $uri$is_args$args; #group2 server setting proxy_pass http://fdfs_group2; expires 30d; } #cache authority location ~/purge(/.*){ allow 127.0.0.1; allow 192.168.29.0/24; deny all; proxy_cache_purge http-cache $1$is_args$args; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}
内容比较多,一定要仔细,不要错
(4)创建缓存目录
命令 mkdir -p /fastdfs/cache/nginx/proxy_cache
mkdir -p /fastdfs/cache/nginx/proxy_cache/tmp
(5)启动nginx
命令 /usr/local/nginx/sbin/nginx
查看命令 ps -el|grep nginx
(6)实现高可用节点,可以再简单修改一下配置
命令 cd /usr/local/nginx/conf/
vim /usr/local/nginx/conf/nginx.conf
添加以下内容
upstream fastdfs_tracker { server 192.168.29.21:8000 weight=1 max_fails=2 fail_timeout=30s; server 192.168.29.22:8000 weight=1 max_fails=2 fail_timeout=30s;}location /fastdfs{ root html; index index.html index.htm; proxy_pass http://fastdfs_tracker/; proxy_set_header Host $http_host; proxy_set_header Cookie $http_cookie; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; client_max_body_size 300m; }
(7)重启nginx
命令 /usr/local/nginx/sbin/nginx
service keepalived start
到这里基本就配置完了,你可以登录浏览器访问你的文件路径
- FastDFS集群文件系统搭建轻版教程(在线版)
- FastDFS分布式文件系统的安装(集群)
- FastDFS(分布式文件系统)高可用集群
- 搭建fastdfs文件系统
- nginx+FastDFS文件系统搭建
- Linux搭建FastDfs+nginx(非集群)
- FastDFS集群服务器搭建
- fastdfs集群搭建
- FastDFS集群搭建
- FastDFS分布式文件系统集群安装
- Centos安装FastDFS集群文件系统
- FastDFS+Nginx搭建分布式文件系统
- fastDFS集群理解+搭建笔记
- FastDFS文件集群服务器搭建
- 搭建单机版fastDFS环境
- FastDFS分布式文件系统集群安装与配置
- FastDFS分布式文件系统集群安装与配置
- FastDFS分布式文件系统集群安装与配置
- 最新手机号码验证正则表达式
- 架构浅谈之 MVC
- MySQL常用函数
- android 监听标题栏颜色渐变
- 数据仓库和数据集市的区别
- FastDFS集群文件系统搭建轻版教程(在线版)
- 融云发送视频消息
- JanusGraph->Index Backends -> Search Predicates and Data Types
- Android studio DELETE_FAILED_INTERNAL_ERROR Error while Installing APKs
- Android memory leak detect
- 用xcode往码云上传项目
- Linux学习——基础入门命令
- 批量打印带文字的二维码
- transient 关键字的简单用法