FastDFS cluster installation process

Cluster Installation production environment, the best cross-regional inter-network across the room to configure, just in case:
192.168.1.173
tarcker-group1
192.168.1.174
tarcker-group2
192.168.1.175
storage-group1-1
192.168.1.176
storage-group1-2
192.168.1.177
storage-group2-1
192.168.1.178
storage-group2-2
Copy the files need to install on the node, the / usr / local / software under
Six first portion machine machine simultaneously
a, installation GCC . Command: yum install the make cmake gcc gcc-c ++
b, installation libfastcommon
1 upload libfastcommon-master.zip to / usr / local / software under
Decompress libfastcommon-master.zip :
Command: the unzip libfastcommon-master.zip -d / usr / local / the FAST /
2 into the directory: CD / usr / local / FAST / libfastcommon-Master / build and install:
命令: ./make.sh
命令: ./make.sh install
注意安装的路径:也就是说,我们的 libfastcommon 默认安装到了
/usr/lib64/ 这个位置。
3 进行软件创建。 FastDFS 主程序设置的目录为 /usr/local/lib/ ,所以我们
需要创建 /usr/lib64/ 下的一些核心执行程序的软连接文件。
命令: mk dir /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
c、安装 FastDFS
1 进入到 cd /usr/local/software 下,解压 FastDFS_v5.05.tar.gz 文件
命令: cd /usr/local/software
命令: tar -zxvf FastDFS_v5.05.tar.gz -C /usr/local/fast/ 2 安装编译
命令: cd /usr/local/fast/FastDFS/
编译命令: ./make.sh
安装命令: ./make.sh install
3 因为 FastDFS 服务脚本设置的 bin 目录为 /usr/local/bin/ , 但是实际我们
安装在了 /u
sr/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
第二部分 两台节点配置跟踪器( 192.168.1.173 192.168.1.174 节点)
1 进入 cd/etc/fdfs/ 目录配置跟踪器文件 (注意是 192.168.1.173 192.168.1.174
节点),把 tracker.conf.sample 文件进行 cope 一份:去修改 tracker.conf 文件
命令:cp tracker.conf.sample tracker.conf
2 修改 tracker.conf 文件
命令: vim /etc/fdfs/tracker.conf
修改为自己的路径地址: base_path=/fastdfs/tracker
修改上传文件的模式: store_lookup=0
一定要创建之前定义好的目录(也就是 /fastdfs/tracker ):
命令: mkdir -p /fastdfs/tracker
3 关闭防火墙:(我们在学习时可以不用考虑防火墙的问题)
vim /etc/sysconfig/iptables
添加: -A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEP
重启: service iptables restart
4 启动跟踪器
目录命令: cd /fastdfs/tracker/ && ll
启动 tracker 命令: /etc/init.d/fdfs_trackerd start
查看进程命令: ps -ef | grep fdfs
查看启动日志:tail –n 100 –f /fastdfs/tracker/logs/trackerd.log
停止 tracker 命令: /etc/init.d/fdfs_trackerd stop
5、可以设置开机启动跟踪器:(一般生产环境需要开机启动一些服务,如
keepalived、 linux、 tomcat 等等)
命令: vim /etc/rc.d/rc.local
加入配置: /etc/init.d/fdfs_trackerd start 第三部分 配置 FastDFS 存储节点( 192.168.1.175 ~192.168.1.178 节点)
四个节点,同一组配置要相同,175 176 一组(group1),177 178 一组(group2)
1、进入文件目录: cd /etc/fdfs/,进行 copy storage 文件一份
命令: cd /etc/fdfs/
命令: cp storage.conf.sample storage.conf
2 修改 storage.conf 文件
命令: vim /etc/fdfs/storage.conf
修改内容: 175 176 一组(group1),177 178 一组(group2)
disabled=false
group_name=group1 #组名,第一组为 group1 第二组为 group2
port=23000 #storage 端口号,同组的端口号必须相同
base_path=/fastdfs/storage
store_path_count=1 #存储路径个数 需要和 store_path 个数匹配
store_path0=/fastdfs/storage #设置存储路径
tracker_server=192.168.1.173:22122 #tracker 服务器的 ip 和端口
tracker_server=192.168.1.174:22122 #多个 tracker 直接添加多条记录
http.server_port=8888 #设置 http 端口号
3 创建存储目录(需要和 base_path=/fastdfs/storage 保持一致)
四个节点都建立: 命令:mkdir -p /fastdfs/storage
4 打开防火墙:
命令: vim /etc/sysconfig/iptables
添加: -A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -
j ACCEPT
重启: service iptables restart
5 启动存储( storage) 需要保证 tracker 已启动
命令:/etc/init.d/fdfs_storaged start
关闭: /etc/init.d/fdfs_storaged stop
查看日志命令: tail -n 100 -f /fastdfs/storage/logs/storaged.log
(初次启动成功后会在/fastdbf/storage/ 目录下创建 data、 logs 俩个目录)
当集群环境能互相知道对方存在的时候,启动成功。 6 查看 FastDFS storage 是否启动成功
命令: ps -ef | grep fdfs
并且我们进入到/fastdfs/storage/data/文件夹下会看到一些目录文件
命令: cd /fastdfs/storage/data/ && ls
7 同理,也可以设置 开机启动存 储器:(一般生产环境需要开机启动一些服
务,如 keepalived、 linux、 tomcat 等等)
命令: vim /etc/rc.d/rc.local
加入配置: /etc/init.d/fdfs_storaged start
8、可以测试一下:如上图,174 是 leader,我们在 174 上执行
命令:/etc/init.d/fdfs_trackerd stop
查看日志文件:4 台存储机器节点 都会显示 leader 变更为 173
启动 174 上的 tracker 查看日志 会发现又能连上 174 了。不会报 error
命令:/etc/init.d/fdfs_trackerd start
9、当所有的 tracker 和 storage 节点都启动成功后,我们可以在任意的一
个存储节点上查看存储集群的信息:
命令:/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
集群信息:
group1 storage 信息
 
Group2 storage 信息
 
到此为止我们的 FastDFS 集群环境已经搭建完成。
第四部分 测试文件上传 需要修改配置跟踪器的客户端
1、任意一个跟踪器节点 如 173,在跟踪器( 192.168.1173)里 copy 一份
client.conf 文件。
命令: cd /etc/fdfs/
命令: cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
2 编辑 client.conf 文件
命令: vim /etc/fdfs/client.conf
修改内容:
base_path=/fastdfs/tracker
tracker_server=192.168.1.173:22122
tracker_server=192.168.1.174:22122
3 我们找到命令的脚本位置,并且使用命令,进行文件的上传:
命令: cd /usr/bin/
命令: ls | grep fdfs
4 使用命令 fdfs_upload_file 进行上传操作:
首先,我们先看一下存储器( 192.168.1.175),进入到 data 下,在进入 00 文
件夹
下,发现 00 文件夹下还有一堆文件夹,然后继续进入 00 文件夹下,最终我们所
进入的文件夹为:
/fastdfs/storage/data/00/00 里面什么文件都没有。
然后,我们进行上传操作,比如把之前的/usr/local/software/文件夹下的某一
个文件上传到 FastDFS 系统中去,在跟踪器( 192.168.1.173)中上传文件,命
令如下: 命令:
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf  /usr/local/software/FastDFS_v5.05.tar.gz
最后我们发现,命令执行完毕后,返回一个 group1/M00/00/00/...的 ID,其实
就 是返回当前所上传的文件在存储器( 192.168.1.175)中的哪一个组、哪一个目
录位置,所以我们查看存储器中的/fastdfs/storage/data/00/00 文件夹位置,
发现已经存在了刚才上传的文件,(175 176 都能看到这个文件,但是 177 178 肯
定是看不到的,它们是 group2)
再次上传一个文件,返回的是 group2/… (177 178 都能看到这个文件,但
是 175 176 肯定是看不到的,它们是 group1)
是由这个 lookup=0 决定的,lookup=0 代表上传文件不同group间交替上传,比如第一次上传的组为group1 第二次则上传到组group2 上
测试:175 宕机后,如果还有文件上传,就上传到 176 上,再启动 175,176 的
数据会自动同步到 175 上。
到此为止,我们的测试上传文件已经 OK 了。
第五部分 配置 nginx ,首先 4 个存储节点配置 nginx ,然后 2 个跟踪器节点配置 nginx
1、首先 4 个存储节点下安装 fastdfs-nginxmodule_v1.16.tar.gz 包
进入目录命令: cd /usr/local/software/
解压命令: tar -zxvf /usr/local/software/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 文件层次,比如/usr/local/include/fastdfs 去掉后变为/usr/include/fastdfs
2、四个存储节点安装 nginx 依赖包 和 nginx,并添加 fastdfs 和 nginx 整合
模块下载需要的依赖库文件:
yum install pcre pcre-devel zlib zlib-devel
解压并安装 nginx,加入 fastdfs-nginx-module
命令: cd /usr/local/software/
命令: tar -zxvf nginx-1.9.9.tar.gz -C /usr/local
进入到 nginx 目录命令: cd /usr/local/nginx-1.9.9
加入模块命令: ./configure --add-module=/usr/local/fast/fastdfs-nginx-module/src/
重新编译命令: make && make install
复制 fastdfs-ngin-module 中的配置文件,到 /etc/fdfs 目录中,如图所示:
命令: cp /usr/local/fast/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
进行修改 /etc/fdfs/ 目录下,我们刚刚 copy 过来的 mod_fastdfs.conf 文
件。
命令: vim /etc/fdfs/mod_fastdfs.conf
修改内容:比如连接超时时间、跟踪器路径配置、 url 的 group 配置等
注意:第一组(175 176)和第二组(177 178) 节点修改内容,只有组名不同
connect_timeout=10
tracker_server=192.168.1.173:22122
tracker_server=192.168.1.174:22122
storage_server_port=23000
url_have_group_name = true
store_path0=/fastdfs/storage
group_name=group1 #第一组为 group1 第二组为 group2
group_count = 2
#追加以下内容
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/fastdfs/storage [group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/fastdfs/storage
复制 FastDFS 里的 2 个文件,到/etc/fdfs 目录中,4 个节点 如图所示:
目录命令: cd /usr/local/fast/FastDFS/conf/
Copy 命令: cp http.conf mime.types /etc/fdfs/
创建一个软连接,在/fastdfs/storage 文件存储目录下创建软连接,将其链
接到实际存放数据的目录。
命令: ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00
修改 Nginx 配置文件 4 个节点
命令:cd /usr/local/nginx/conf
命令:vim nginx.conf
修改内容为:
listen 8888;
server_name localhost;
location ~/group([0-9])/M00 {
#alias /fastdfs/storage/data;
ngx_fastdfs_module;
}
注意: nginx 里的端口要和第五步配置 FastDFS 存储中的 storage.conf 文件配
置一致,也就是( http.server_port=8888)
最后检查防火墙,然后我们启动 nginx 服务 4 个节点
启动命令: /usr/local/nginx/sbin/nginx
刚才上传了一个文件,根据返回的 ID,可以 使用这个 ID 用浏览器访问地址:
http://192.168.1.175:8888/group1/M00/00/00/wKgBrVaSvM6AddWWAAVFOL7FJU4.tar.gz
就可以下载这个文件。 测试 175 176 如果都可以,表示 group1 没问题 然后使用 group2 的 id 地址,如果 177 178 都可以访问, 那么安装完成。
运维注意:我们在使用 FastDFS 的时候,需要正常关机,不要使用 kill -9
强杀 FastDFS 进程,不然会在文件上传时出现丢数据的情况。
到此,我们的 FastDFS Nginx 整合完毕!!
第六部分 需要在两个跟踪器上安装 nginx 配置也就是 173 174 节点。以提供反向代理服
务,目的是使用统一 的一个 ip 地址对外提供服务
1、上传 nginx 缓存模块,ngx_cache_purge-2.3.tar.gz 并进行解压:
tar -zxvf ngx_cache_purge-2.3.tar.gz –C /usr/local/fast/
2、 下载依赖库文件: yum install pcre pcre-devel zlib zlib-devel
3、解压并安装 nginx,加入 ngx_cache_purge (加入缓存模块)
命令: cd /usr/local/software/
命令: tar -zxvf nginx-1.9.9.tar.gz -C /usr/local
进入到 nginx 目录命令: cd /usr/local/nginx-1.9.9
加入模块命令: ./configure --add-module=/usr/local/fast/ ngx_cache_purge-2.3
重新编译命令: make && make install
4、 修改 Nginx 配置文件 配置负载均衡和缓存 2 个跟踪器节点配置一致
命令:cd /usr/local/nginx/conf
命令:vim nginx.conf
events {
worker_connections 1024;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
# 设置缓存
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 Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 90;
proxy_read_timeout 90;
proxy_send_timeout 90;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
# 设置缓存存储路径、存储方式、分配内存大小、磁盘最大空间、缓存期限
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;
# weight 权重 max_fails 失败重试次数 fail_timeout 连接失败超时时间
# 设置 group1 的服务器
upstream fdfs_group1 {
server 192.168.1.175:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.1.176:8888 weight=1 max_fails=2 fail_timeout=30s;
}
# 设置 group2 的服务器
upstream fdfs_group2 {
server 192.168.1.177:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.1.178: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;
# 设置 group 的负载均衡参数
location /group1/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;
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;
proxy_pass http://fdfs_group2;
expires 30d;
}
# 设置清除缓存的访问权限
location ~/purge(/.*) {
allow 127.0.0.1;
allow 192.168.1.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;
}
}
5、按以上 nginx 配置文件的要求,创建对应的缓存目录 2 个跟踪器节点都需要:
mkdir -p /fastdfs/cache/nginx/proxy_cache
mkdir -p /fastdfs/cache/nginx/proxy_cache/tmp
6、检查防火墙,启动 nginx 即可(注意 nginx 端口号为 8000)
vim /etc/sysconfig/iptables
## 添加如下配置
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8000 -j ACCEPT
service iptables restart # 重新启动防火墙
/usr/local/nginx/sbin/nginx
ps -ef|grep nginx
7、测试,用命令上传文件,使用 http 访问,看是否能访问打开 或者 下载
访问 173 或 174 的地址,都能访问 group1 和 group2 上的文件,那么最
后,我们需要 keepalived,虚拟出一个 vip,对 2 台跟踪器节点做高可用配置
1 、 最后我们使用 Keepalived + Nginx 组成的高可用负载均衡集群,做两个 Tracker
节点 (173 174) Nginx 的负载均衡 , 从而实现了 分布式高可用文件系统。
修改 2 个节点 ( 可以在 173 174 上接着加 service 模块的配置 也可以另开 2 台机器 ( 假设是 180
181 节点 ) nginx.conf 配置文件: 命令:cd /usr/local/nginx/conf
命令:vim nginx.conf
## FastDFS Tracker Proxy 2 台跟踪器的 nginx 代理服务
upstream fastdfs_tracker {
server 192.168.1.173:8000 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.1.174:8000 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
## FastDFS Proxy 代理路径设置为 /fastdfs
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;
}
}
注意:千万不要使用 kill -9 命令强杀 FastDFS 进程,否则可能会导致 binlog 数据丢失。
通过虚拟 IP 访问文件测试 , 测试没问题的话,整个集群环境搭建完成,整体架构图如下:
为了节约服务器 跟踪器 tracker 和 存储器 storage 节点可以放在一个服务器上 关闭集群步骤:
1 180 181 两台一级负载节点
关闭 keepalived 命令: service keepalived stop
关闭 nginx 命令: /usr/local/nginx/sbin/nginx –s stop
2 173 174 两台二级负载节点,跟踪器节点
关闭 nginx 命令: /usr/local/nginx/sbin/nginx –s stop
关闭 trackerd 跟踪器命令: /etc/init.d/fdfs_trackerd stop
3、175 176 177 178 四台三季负载节点,存储节点
关闭 nginx 命令: /usr/local/nginx/sbin/nginx –s stop
关闭 storage 存储器命令: /etc/init.d/fdfs_storaged stop
注意:千万不要使用 kill -9 命令强杀 FastDFS 进程,否则可能会导致 binlog 数据丢失
启动命令:
启动 tracker 命令: /etc/init.d/fdfs_trackerd start
查看进程命令: ps -el | grep fdfs
启动 storage 命令: /etc/init.d/fdfs_storaged start
查看进程命令: ps -el | grep fdfs
启动 nginx 命令: /usr/local/nginx/sbin/nginx
停止命令:
停止 tracker 命令: /etc/init.d/fdfs_trackerd stop
关闭 storage 命令: /etc/init.d/fdfs_storaged stop
关闭 nginx 命令: /usr/local/nginx/sbin/nginx -s stop
发布了47 篇原创文章 · 获赞 15 · 访问量 13万+

Guess you like

Origin blog.csdn.net/LSSSSSS/article/details/104571658