龙空技术网

「干货」在麒麟服务器上部署FastDFS

湖南长城科技 207

前言:

目前我们对“centosfastdfsnginx”大体比较珍视,咱们都需要了解一些“centosfastdfsnginx”的相关知识。那么小编也在网上收集了一些有关“centosfastdfsnginx””的相关内容,希望姐妹们能喜欢,我们一起来学习一下吧!

前言:本文为大家如何在麒麟服务器上部署FastDFS,请大家多多点赞、收藏、评论、关注哦![来看我]

什么是FastDFS

FastDFS 是一个开源的高性能分布式文件系统(DFS)。 它的主要功能包括:文件存储,文件同步和文件访问,以及高容量和负载平衡。

FastDFS 系统有三个角色:跟踪服务器(Tracker Server)、存储服务器(Storage Server)和客户端(Client)。

Tracker Server: 跟踪服务器,主要做调度工作,起到均衡的作用;负责管理所有的storage server和group,每个 storage 在启动后会连接 Tracker,告知自己所属 group 等信息,并保持周期性心跳。多个 Tracker 之间是对等关系,不存在单点故障。Storage Server: 存储服务器,主要提供容量和备份服务;以 group 为单位,每个 group 内可以有多台 storage server,组内的storage server上的数据互为备份。Client:客户端,上传下载数据的服务器。1 部署 FastDFS

系统软件说明:

CentOS 7.6libfastcommon: FastDFS分离出的一些公用函数包FastDFS: FastDFS本体fastdfs-nginx-module: FastDFS 和 nginx 的关联模块,解决组内同步延迟问题nginx

整个搭建所需环境资源及用途如下表:

(1) 下载libfastcommon

wget

(2)下载 FastDFS

wget

(3)下载 nginx

wget

(4)下载 nginx 编译依赖

pcre

wget

zlib

wget

openssl

wget

fastdfs-nginx-module

wget

(5) 安装需要的软件

<span style="font-weight: normal;">vim /etc/fdfs/tracker.conf需要修改的内容如下port=22122  # tracker服务器端口(默认22122,一般不修改)base_path=/data/fastdfs  # 存储日志和数据的根目录 启动 fastdfs-tracker 服务并加入自动启动systemctl start fdfs_trackerdsystemctl enable fdfs_trackerd# centos 可以使用 systemctl enable 命令,但kylin操作系统运行会报错,需要# 安装 chkconfig 命令(apt install sysv-rc-conf),使用 chkconfig 来设置自动启动(将# fdfs_trackerd 的 2,3,4,5项启用即可)。 netstat -tulnp  # 查看服务是否启动,端口是否打开</span>

(6) 编译安装libfastcommon

<span style="font-weight: normal;">vim /etc/fdfs/tracker.conf需要修改的内容如下port=22122  # tracker服务器端口(默认22122,一般不修改)base_path=/data/fastdfs  # 存储日志和数据的根目录 启动 fastdfs-tracker 服务并加入自动启动systemctl start fdfs_trackerdsystemctl enable fdfs_trackerd# centos 可以使用 systemctl enable 命令,但kylin操作系统运行会报错,需要# 安装 chkconfig 命令(apt install sysv-rc-conf),使用 chkconfig 来设置自动启动(将# fdfs_trackerd 的 2,3,4,5项启用即可)。 netstat -tulnp  # 查看服务是否启动,端口是否打开</span>

(7)编译安装FastDFS

unzip V6.06.zipcd fastdfs-6.06./make.sh./make.sh install 重新载入系统服务脚本systemctl daemon-reload 准备配置文件cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf  # tracker节点cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf  # storage节点cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf  # 客户端文件,测试用cp /root/fastdfs/fastdfs-6.06/conf/http.conf /etc/fdfs/  # 供nginx访问使用cp /root/fastdfs/fastdfs-6.06/conf/mime.types /etc/fdfs/  # 供nginx访问使用

tracker server配置:

vim /etc/fdfs/storage.conf需要修改的内容如下port=23000  # storage服务端口(默认23000,一般不修改)base_path=/data/fastdfs  # 数据和日志文件存储根目录store_path0=/data/fastdfs  # 第一个存储目录tracker_server=192.168.0.1:22122  # tracker服务器IP和端口tracker_server=192.168.0.2:22122  # tracker服务器IP和端口http.server_port=8888  # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)  启动 fastdfs-storage 服务并加入自动启动systemctl start fdfs_storagedsystemctl enable fdfs_storaged# centos 可以使用 systemctl enable 命令,但kylin操作系统运行会报错,需要# 安装 chkconfig 命令(apt install sysv-rc-conf),使用 chkconfig 来设置自动启动(将# fdfs_storaged 的 2,3,4,5项启用即可)。 netstat -tulnp  # 查看服务是否启动,端口是否打开

storage server 配置

vim /etc/fdfs/storage.conf需要修改的内容如下port=23000  # storage服务端口(默认23000,一般不修改)base_path=/data/fastdfs  # 数据和日志文件存储根目录store_path0=/data/fastdfs  # 第一个存储目录tracker_server=192.168.0.1:22122  # tracker服务器IP和端口tracker_server=192.168.0.2:22122  # tracker服务器IP和端口http.server_port=8888  # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)  启动 fastdfs-storage 服务并加入自动启动systemctl start fdfs_storagedsystemctl enable fdfs_storaged# centos 可以使用 systemctl enable 命令,但kylin操作系统运行会报错,需要# 安装 chkconfig 命令(apt install sysv-rc-conf),使用 chkconfig 来设置自动启动(将# fdfs_storaged 的 2,3,4,5项启用即可)。 netstat -tulnp  # 查看服务是否启动,端口是否打开

查看集群状态

# fdfs_monitor /etc/fdfs/storage.conf list

Client配置

# vim /etc/fdfs/client.conf

#需要修改的内容如下

base_path=/data/fastdfstracker_server=192.168.0.1:22122 # tracker服务器IP和端口tracker_server=192.168.0.2:22122 # tracker服务器IP和端口

上传文件测试:

# fdfs_upload_file /etc/fdfs/client.conf testfile.zip

测试返回文件路径和 ID 则表示成功,如:group1/M00/00/00/xxxxxx.zip

2 部署 nginx 和 fastdfs-nginx-module

(1)编译安装

参考编译安装 nginx 的文章 ,在编译过程中加入 fastdfs-nginx-module 模块即可:

./configure --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-openssl=../openssl-OpenSSL_1_1_1g --with-pcre=../pcre-8.44 --with-zlib=../zlib-1.2.11 --add-module=../fastdfs-nginx-module-1.22/src

# make

# make install

注意要先安装 libfastcommon,否则编译时会报错。

(2)配置运行

配置 fastdfs-nginx-module 配置文件:

# cp /root/fastdfs/nginx/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs# vim /etc/fdfs/mod_fastdfs.conf需要修改的内容如下:注意此处容易漏掉 tracker server 配置,导致 nginx 启动后异常,可查看 nginx 错误日志解决。tracker_server = 192.168.0.1:22122  # tracker服务器IP和端口tracker_server = 192.168.0.2:22122  # tracker服务器IP和端口url_have_group_name=truebase_path=/data/fastdfsstore_path0=/data/fastdfs

配置 nginx.conf:

# vim /usr/local/nginx/conf/nginx.conf 增加如下内容:server {        listen 8888; ## 该端口为storage.conf中的http.server_port相同        server_name localhost;        location ~/group[0-9]/ {            root /data/fastdfs;            ngx_fastdfs_module;        }        error_page 500 502 503 504 /50x.html;        location = /50x.html {            root html;        }    }

测试下载,用外部浏览器访问刚才已传过的文件,引用返回的 ID

弹出下载则目前 nginx 已经 OK。

3 配置文件访问的负载均衡和高可用

在192.168.0.100和101上安装nginx、keepalived

yum install -y nginx keepalived

nginx 关键配置文件如下:

upstream fdfs_group01 {    server 192.168.0.10:8888 weight=1 max_fails=2 fail_timeout=30s;    server 192.168.0.11:8888 weight=1 max_fails=2 fail_timeout=30s;}server {    listen 80;    server_name localhost;    location /group01{        proxy_next_upstream http_502 http_504 error timeout invalid_header;        proxy_pass ;        expires 30d;    }}

keepalived 关键配置文件如下:

global_defs {   router_id LVS_DEVEL} vrrp_script chk_ngx {    script "/etc/keepalived/check_nginx.sh"    interval 2    weight -5    fall 3      rise 2}  vrrp_instance VI_1 {    interface eno16777984    state MASTER    priority 100    virtual_router_id 11    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }     unicast_src_ip 192.168.0.100     unicast_peer {        192.168.0.101    }     virtual_ipaddress {        192.168.0.200    }     track_script {       chk_ngx    }    notify_master "/etc/keepalived/notify.sh master"      notify_backup "/etc/keepalived/notify.sh backup"      notify_fault "/etc/keepalived/notify.sh fault"}

nginx 监测脚本如下:

check_nginx.sh

#!/bin/bash counter=$(ps -C nginx --no-heading|wc -l)if [ "${counter}" = "0" ]; then    exit 1else    exit 0fi

作者:李凌

更多干货尽在【中国信创服务社区】,点击左下角“了解更多”即可进入!

标签: #centosfastdfsnginx