本次部署参考以下文章
docker、kubernetes安装部署fastdfs文件集群系统_网络_jiangbenchu的博客-CSDN博客
github克隆项目
git clone --branch V6.06 --depth 1 https://github.com/happyfish100/fastdfs.git
镜像构建
进入docker 目录构建镜像,经过多次尝试,其中dockerfile_local本地构建的Dockerfile有问题,运行的命令不太对,文件都没有解压,使用网络版本目录(dockerfile_network)成功构建
docker build -t aaaa:1.0 .
image
编写tracker.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: tracker-deploy
namespace: fastdfs
labels:
name: tracker-deploy
spec:
selector:
matchLabels:
app: tracker
replicas: 1
template:
metadata:
labels:
app: tracker
spec:
nodeSelector:
fastdfs-tracker: "tracker"
terminationGracePeriodSeconds: 0
containers:
- name: tracker
image: aaaa:1.0
imagePullPolicy: IfNotPresent
env:
- name: FASTDFS_IPADDR
value: 192.168.1.222 # 这是我的宿主机地址 ,资源有限 都跑在了master节点上
ports:
- containerPort: 22122
- containerPort: 23000
- containerPort: 8080
- containerPort: 8888
volumeMounts:
- name: tracker-volume
mountPath: /home/dfs # 地址在/home/dfs
command: ["/home/fastdfs.sh","tracker"]
volumes:
- name: tracker-volume
nfs: #这是我的nfs路径 可以用其他挂载卷代替
path: /data/nfs/sre/fastdfs-tracker
server: 192.168.1.222
---
apiVersion: v1
kind: Service
metadata:
name: tracker
labels:
app: tracker
namespace: fastdfs
spec:
selector:
app: tracker
type: NodePort
ports:
- name: "22122"
port: 22122
targetPort: 22122
nodePort: 22122
- name: nginx
port: 8888
targetPort: 8888
nodePort: 28888
编写storage.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: storage0-deploy
namespace: fastdfs
labels:
name: storage0-deploy
spec:
selector:
matchLabels:
app: storage0
replicas: 1
template:
metadata:
labels:
app: storage0
spec:
nodeSelector:
fastdfs: "storage0"
terminationGracePeriodSeconds: 0
containers:
- name: storage0
image: aaaa:1.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 22122
- containerPort: 23000
- containerPort: 8080
- containerPort: 8888
volumeMounts:
- name: storage0-volume
mountPath: /home/dfs
env:
- name: TRACKER_SERVER
value: 192.168.1.122:22122
- name: FASTDFS_IPADDR
value: 192.168.1.222
command: ["/home/fastdfs.sh","storage"]
volumes:
- name: storage0-volume
nfs:
path: /data/nfs/sre/fastdfs-storage0
server: 192.168.1.222
---
apiVersion: v1
kind: Service
metadata:
name: storage0
labels:
app: storage0
namespace: fastdfs
spec:
selector:
app: storage0
type: NodePort
ports:
- name: "23000"
port: 23000
targetPort: 23000
nodePort: 23000
- name: nginx1
port: 8888
targetPort: 8888
nodePort: 38888
注: 环境变量TRACKER_SERVER 应该是无效 我是配置了FASTDFS_IPADDR 之后才识别到tracker地址(/etc/fdfs/storage.conf ),没有FASTDFS_IPADDR 时 tracker_server只有一个端口,应该是我与参考文章构建镜像的方式不同
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.1.222:22122
java端连通测试
java客户端依赖如下jar包
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
</dependency>
application.yaml配置
fdfs:
so-timeout: 1501 # 超时时间
connect-timeout: 601 # 连接超时时间
thumb-image: # 缩略图
width: 60
height: 60
tracker-list: # tracker地址
- 192.168.1.222:22122
配置
@Configuration
@Import(FdfsClientConfig.class)
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
public class FastClientImporter {
}
测试代码
@SpringBootTest
@RunWith(SpringRunner.class)
public class TestUpload {
@Autowired
private FastFileStorageClient storageClient;
@Test
public void testUpload() throws FileNotFoundException {
File file = new File("D:\\add.svg");
StorePath storePath = this.storageClient.uploadFile(
new FileInputStream(file), file.length(), "svg", null);
System.out.println(storePath.getFullPath());
}
}
下载
通过tracker service的nodeProt暴漏的的nginx端口 28888 无法访问,但是通过storage service暴漏的38888 可以直接获取到资源(url的path地址为storePath.getFullPath获取到的地址),不确定这里是否有问题,查阅资料是客户端通过tracker获取到可用的storage,然后客户端与storage通讯完成下载
image.png
网友评论