容器化部署文fastdfs件存储

2024-06-04 08:20
文章标签 部署 存储 容器 fastdfs

本文主要是介绍容器化部署文fastdfs件存储,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

一、软件信息

二、构建fastdfs镜像

三、docker 启动fdfs服务

四、k8s部署fdfs服务

1、fdfs部署文件

五、外部服务访问


一、软件信息

  1. fastdfs版本:fastdfs:V5.11

  2. libfastcommon版本: V1.0.36

  3. fastdfs-nginx-module版本:V1.20

  4. nginx版本:1.18.0

二、构建fastdfs镜像

        为了减少操作了文件数,我是直接把启动文件和dockerfile写一起了,也可以把启动脚本 start.sh 单独于dockerfile;然后在构建镜像的时候把启动文件 COPY 到镜像里。

        以下是包括了启动文件为一起的dockerfile构建文件。直接使用该dockerfile即可完成镜像构建。然后按照自己的实际情况来修改配置文件和挂载,即可完成容器化运行fastdfs件存储服务。

FROM centos:7LABEL creator=tudou date="2024-06-02"ENV FASTDFS_PATH=/var/fastdfs \TZ=Asia/Shanghai \TRACKER_PORT= \STORAGE_PORT= \TRACKER_SERVER= \GROUP_NAME= #get all the dependences
RUN yum install -y git wget zip unzip gcc make \perl openssl openssl-devel pcre pcre-devel zlib zlib-devel libevent libevent-devel \&& yum clean all \&& mkdir -p ${FASTDFS_PATH}/filesRUN git clone --branch V1.0.36 --depth 1 https://github.com/happyfish100/libfastcommon.git ${FASTDFS_PATH}/libfastcommon \&& cd ${FASTDFS_PATH}/libfastcommon \&& ./make.sh \&& ./make.sh install \&& rm -rf ${FASTDFS_PATH}/libfastcommonRUN git clone --branch V5.11 --depth 1 https://github.com/happyfish100/fastdfs.git ${FASTDFS_PATH}/fastdfs \&& cd ${FASTDFS_PATH}/fastdfs  \&& ./make.sh \&& ./make.sh install \&& cp -r  conf/*.* /etc/fdfs/ \&& rm -rf ${FASTDFS_PATH}/fastdfs RUN git clone --branch V1.20 https://github.com/happyfish100/fastdfs-nginx-module.git /usr/local/fastdfs-nginx-module \&& cp /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so \&& sed -i "s@/usr/local/include@/usr/include/fastdfs /usr/include/fastcommon@g" /usr/local/fastdfs-nginx-module/src/config \&& cd ${FASTDFS_PATH} \&& wget https://nginx.org/download/nginx-1.18.0.tar.gz \&& tar -xzvf nginx-1.18.0.tar.gz \&& cd nginx-1.18.0 \&& ./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module/src \&& make \&& make install \&& cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf  /etc/fdfs/ \&& rm -rf ${FASTDFS_PATH}/nginx-1.18.0* WORKDIR ${FASTDFS_PATH}# 启动脚本 start.sh
RUN cat > /usr/bin/start.sh <<-EOF
#!/bin/bashcd \$(dirname \$0)# start.sh trackerd 
# start.sh storaged# # 自定义环境变量初始化,若无自定义环境变量,则直接跳过使用配置文件的默认值
function init_config(){if [[ -n \${STORAGE_PORT} ]];thensed -i "s|^port=.*$|port=\${STORAGE_PORT}|g" /etc/fdfs/storage.conffiif [[ -n \${TRACKER_PORT} ]];thensed -i "s|^port=.*$|port=\${TRACKER_PORT}|g" /etc/fdfs/tracker.conffiif [[ -n \${GROUP_NAME} ]];thensed -i "s|group_name=.*$|group_name=\${GROUP_NAME}|g" /etc/fdfs/storage.confsed -i "s|group_name=.*$|group_name=\${GROUP_NAME}|g" /etc/fdfs/mod_fastdfs.confsed -i "s|url_have_group_name =.*$|url_have_group_name = true|g" /etc/fdfs/mod_fastdfs.conffiif [[ -n \${TRACKER_SERVER} ]];thensed -i "s|tracker_server=.*$|tracker_server=\${TRACKER_SERVER}|g" /etc/fdfs/storage.confsed -i "s|tracker_server=.*$|tracker_server=\${TRACKER_SERVER}|g" /etc/fdfs/client.confsed -i "s|tracker_server=.*$|tracker_server=\${TRACKER_SERVER}|g" /etc/fdfs/mod_fastdfs.conffised -i "s|base_path=.*$|base_path=\${FASTDFS_PATH}|g" /etc/fdfs/tracker.confsed -i "s|base_path=.*$|base_path=\${FASTDFS_PATH}|g" /etc/fdfs/storage.confsed -i "s|base_path=.*$|base_path=\${FASTDFS_PATH}|g" /etc/fdfs/client.confsed -i "s|base_path=.*$|base_path=\${FASTDFS_PATH}|g" /etc/fdfs/mod_fastdfs.conf
}init_configcase \$1 intrackerd)echo "start trackerd ..."fdfs_trackerd /etc/fdfs/tracker.conf start  && tail -f ${FASTDFS_PATH}/logs/trackerd.log;;storaged)sed -i "s|store_path0.*$|store_path0=\${FASTDFS_PATH}/files|g" /etc/fdfs/storage.confsed -i "s|store_path0.*$|store_path0=\${FASTDFS_PATH}/files|g" /etc/fdfs/mod_fastdfs.confecho "start storaged ..."fdfs_storaged /etc/fdfs/storage.conf start \&& /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf \&& tail -f ${FASTDFS_PATH}/logs/storaged.log;;*)echo "USAGE sh $0 [ trackerd|storaged ]"exit 1;;
esacEOF
# 启动脚本 start.sh# 默认fastdfs端口
EXPOSE 22122 23000 8080 8888 80RUN chmod a+x /usr/bin/start.sh ENTRYPOINT ["/usr/bin/start.sh"]
CMD ["trackerd"]
#CMD ["storaged"]
# 构建 fdfs 应用镜像# docker build -t fdfs:v1.0 -f dockerfile . --no-cachedocker build -t fdfs:v1.0 -f dockerfile . 

三、docker 启动fdfs服务

# 容器启动 trackerd 服务,并且自定义环境变量值,可不指定环境变量值docker run -itd --name trackerd -e TRACKER_PORT=22122 -e TRACKER_SERVER=192.168.159.132:22122 -p 22122:22122   fdfs:v1.0 trackerd# 容器启动 storaged 服务,并且自定义环境变量值,可不指定环境变量值docker run -itd --name storage -e STORAGE_PORT=23000 -e TRACKER_SERVER=192.168.159.132:22122 -p 23000:23000   fdfs:v1.0 storaged

# 分别查看容器应用的日志docker logs trackerddocker logs storage

四、k8s部署fdfs服务

1、fdfs部署文件

         由于storage存储是各自独立的,所以要使用有状态部署。
# kubectl apply -f fdfs.yaml -n fdfs# fdfs 配置文件
---
kind: ConfigMap
apiVersion: v1
metadata:name: fdfs-confignamespace: fdfsannotations:kubesphere.io/creator: admin
data:mod_fastdfs.conf: |-base_path=/var/fastdfstracker_server=tracker-svc:22122storage_server_port=23000group_name=group1url_have_group_name = truestore_path_count=1store_path0=/var/fastdfs/filesgroup_count = 1# 在末尾增加组的具体信息 [group1] group_name=group1 storage_server_port=23000 store_path_count=1 store_path0=/var/fastdfs/files[group2] group_name=group2 storage_server_port=23000 store_path_count=1 store_path0=/data/fastdfs nginx.conf: |-user root;worker_processes  2;events {worker_connections  65535;use epoll;}http {include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  localhost;charset utf-8;server_tokens off;location ~group[0-9]/M00 {root /var/fastdfs/files/data;ngx_fastdfs_module;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}}storage.conf: |-group_name=group1port=23000base_path=/var/fastdfsstore_path_count=1store_path0=/var/fastdfs/filestracker_server=tracker-svc:22122tracker.conf: |-disabled=falseport=22122base_path=/var/fastdfshttp.server_port=8080---# kubectl apply -f fdfs-trackerd.yaml -n fdfs
---
apiVersion: apps/v1
kind: Deployment
metadata:labels:app: fdfs-trackerdname: fdfs-trackerdnamespace: fdfs
spec:replicas: 1selector:matchLabels:app: fdfs-trackerdstrategy:rollingUpdate:maxSurge: 25%maxUnavailable: 25%type: RollingUpdatetemplate:metadata:labels:app: fdfs-trackerdspec:containers:- args:- trackerdcommand:- /usr/bin/start.shimage: swr.cn-south-1.myhuaweicloud.com/tudou/fastdfs:latestimagePullPolicy: IfNotPresentname: trackerdports:- containerPort: 22122name: http-0protocol: TCP- containerPort: 8080name: http-1protocol: TCPresources: {}terminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /etc/fdfs/tracker.confname: volume-b8e30ireadOnly: truesubPath: tracker.confdnsPolicy: ClusterFirstrestartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}serviceAccount: defaultserviceAccountName: defaultterminationGracePeriodSeconds: 30volumes:- configMap:defaultMode: 420name: fdfs-configname: volume-b8e30i
---
---
apiVersion: v1
kind: Service
metadata:labels:app: fdfs-trackerdname: fdfs-trackerdnamespace: fdfs
spec:ports:- name: port-1port: 22122protocol: TCPtargetPort: 22122- name: port-2port: 8080protocol: TCPtargetPort: 8080selector:app: fdfs-trackerdtype: ClusterIP
---# kubectl apply -f fdfs-storaged.yaml -n fdfs
---
apiVersion: apps/v1
kind: StatefulSet
metadata:labels:app: fdfs-storagedname: fdfs-storagednamespace: fdfs
spec:podManagementPolicy: OrderedReadyreplicas: 2revisionHistoryLimit: 10selector:matchLabels:app: fdfs-storagedserviceName: fdfs-storagedtemplate:metadata:labels:app: fdfs-storagedspec:containers:- args:- storagedcommand:- /usr/bin/start.shimage: swr.cn-south-1.myhuaweicloud.com/tudou/fastdfs:latestimagePullPolicy: IfNotPresentname: storageports:- containerPort: 23000name: http-0protocol: TCP- containerPort: 8888name: http-1protocol: TCP- containerPort: 80name: http-2protocol: TCPresources: {}terminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /etc/fdfs/storage.confname: volume-ssmj62readOnly: truesubPath: storage.conf- mountPath: /etc/fdfs/mod_fastdfs.confname: volume-zlknkzreadOnly: truesubPath: mod_fastdfs.conf- mountPath: /usr/local/nginx/conf/nginx.confname: volume-q4ylwbreadOnly: truesubPath: nginx.conf- mountPath: /var/fastdfsname: fdfs-storage-datadnsPolicy: ClusterFirstrestartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}serviceAccount: defaultserviceAccountName: defaultterminationGracePeriodSeconds: 30volumes:- configMap:defaultMode: 420name: fdfs-configname: volume-ssmj62- configMap:defaultMode: 420name: fdfs-configname: volume-zlknkz- configMap:defaultMode: 420name: fdfs-configname: volume-q4ylwbupdateStrategy:rollingUpdate:partition: 0type: RollingUpdatevolumeClaimTemplates:- apiVersion: v1kind: PersistentVolumeClaimmetadata:name: fdfs-storage-dataspec:accessModes:- ReadWriteOnceresources:requests:storage: 120GistorageClassName: localvolumeMode: Filesystem
---
---
apiVersion: v1
kind: Service
metadata:labels:app: fdfs-storagedname: fdfs-storagednamespace: fdfs
spec:clusterIP: NoneclusterIPs:- NoneinternalTrafficPolicy: ClusteripFamilies:- IPv4ipFamilyPolicy: SingleStackports:- name: http-0port: 23000protocol: TCPtargetPort: 23000- name: http-1port: 8888protocol: TCPtargetPort: 8888- name: http-2port: 80protocol: TCPtargetPort: 80selector:app: fdfs-storagedsessionAffinity: Nonetype: ClusterIP
---

五、外部服务访问

        当外部服务需要访问fdfs时,需要将服务的 22122和服务的 80 端口暴露。可以将这两个端口对应的服务创建NodePort类型的服务来实现端口暴露。

这篇关于容器化部署文fastdfs件存储的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1029554

相关文章

Spring核心思想之浅谈IoC容器与依赖倒置(DI)

《Spring核心思想之浅谈IoC容器与依赖倒置(DI)》文章介绍了Spring的IoC和DI机制,以及MyBatis的动态代理,通过注解和反射,Spring能够自动管理对象的创建和依赖注入,而MyB... 目录一、控制反转 IoC二、依赖倒置 DI1. 详细概念2. Spring 中 DI 的实现原理三、

k8s部署MongDB全过程

《k8s部署MongDB全过程》文章介绍了如何在Kubernetes集群中部署MongoDB,包括环境准备、创建Secret、创建服务和Deployment,并通过Robo3T工具测试连接... 目录一、环境准备1.1 环境说明1.2 创建 namespace1.3 创建mongdb账号/密码二、创建Sec

Java中的Opencv简介与开发环境部署方法

《Java中的Opencv简介与开发环境部署方法》OpenCV是一个开源的计算机视觉和图像处理库,提供了丰富的图像处理算法和工具,它支持多种图像处理和计算机视觉算法,可以用于物体识别与跟踪、图像分割与... 目录1.Opencv简介Opencv的应用2.Java使用OpenCV进行图像操作opencv安装j

将Python应用部署到生产环境的小技巧分享

《将Python应用部署到生产环境的小技巧分享》文章主要讲述了在将Python应用程序部署到生产环境之前,需要进行的准备工作和最佳实践,包括心态调整、代码审查、测试覆盖率提升、配置文件优化、日志记录完... 目录部署前夜:从开发到生产的心理准备与检查清单环境搭建:打造稳固的应用运行平台自动化流水线:让部署像

Python项目打包部署到服务器的实现

《Python项目打包部署到服务器的实现》本文主要介绍了PyCharm和Ubuntu服务器部署Python项目,包括打包、上传、安装和设置自启动服务的步骤,具有一定的参考价值,感兴趣的可以了解一下... 目录一、准备工作二、项目打包三、部署到服务器四、设置服务自启动一、准备工作开发环境:本文以PyChar

centos7基于keepalived+nginx部署k8s1.26.0高可用集群

《centos7基于keepalived+nginx部署k8s1.26.0高可用集群》Kubernetes是一个开源的容器编排平台,用于自动化地部署、扩展和管理容器化应用程序,在生产环境中,为了确保集... 目录一、初始化(所有节点都执行)二、安装containerd(所有节点都执行)三、安装docker-

在Ubuntu上部署SpringBoot应用的操作步骤

《在Ubuntu上部署SpringBoot应用的操作步骤》随着云计算和容器化技术的普及,Linux服务器已成为部署Web应用程序的主流平台之一,Java作为一种跨平台的编程语言,具有广泛的应用场景,本... 目录一、部署准备二、安装 Java 环境1. 安装 JDK2. 验证 Java 安装三、安装 mys

使用JavaScript操作本地存储

《使用JavaScript操作本地存储》这篇文章主要为大家详细介绍了JavaScript中操作本地存储的相关知识,文中的示例代码讲解详细,具有一定的借鉴价值,有需要的小伙伴可以参考一下... 目录本地存储:localStorage 和 sessionStorage基本使用方法1. localStorage

Jenkins中自动化部署Spring Boot项目的全过程

《Jenkins中自动化部署SpringBoot项目的全过程》:本文主要介绍如何使用Jenkins从Git仓库拉取SpringBoot项目并进行自动化部署,通过配置Jenkins任务,实现项目的... 目录准备工作启动 Jenkins配置 Jenkins创建及配置任务源码管理构建触发器构建构建后操作构建任务

若依部署Nginx和Tomcat全过程

《若依部署Nginx和Tomcat全过程》文章总结了两种部署方法:Nginx部署和Tomcat部署,Nginx部署包括打包、将dist文件拉到指定目录、配置nginx.conf等步骤,Tomcat部署... 目录Nginx部署后端部署Tomcat部署出现问题:点击刷新404总结Nginx部署第一步:打包