参照文档配置了数据清理,但是看日志总是清理失败,请问是哪里配置不对吗
[应用数据清理 | 明道云私有部署 (mingdao.com)]
[root@localhost MDPrivateDeployment]# docker logs $(docker ps | grep dataclean | awk '{print $1}')
Start
定时清理任务,开始执行!! time :11/30/2023 02:00:00
执行时间 11/30/2023 02:00:00,删除7天之前的数据,删除应用范围: 11/23/2023 00:00:00 之前
AppActivityService_删除应用job执行异常,具体异常信息:
System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "127.0.0.1:27017" }", EndPoint: "127.0.0.1:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server.
---> System.Net.Sockets.SocketException (111): Connection refused
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
at MongoDB.Driver.Core.Connections.TcpStreamFactory.ConnectAsync(Socket socket, EndPoint endPoint, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Connections.TcpStreamFactory.CreateStreamAsync(EndPoint endPoint, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
at MongoDB.Driver.Core.Servers.ServerMonitor.InitializeConnectionAsync(CancellationToken cancellationToken)
at MongoDB.Driver.Core.Servers.ServerMonitor.HeartbeatAsync(CancellationToken cancellationToken)", LastHeartbeatTimestamp: "2023-11-29T18:00:30.1127692Z", LastUpdateTimestamp: "2023-11-29T18:00:30.1127708Z" }] }.
at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask)
at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChanged(IServerSelector selector, ClusterDescription description, Task descriptionChangedTask, TimeSpan timeout, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Clusters.Cluster.SelectServer(IServerSelector selector, CancellationToken cancellationToken)
at MongoDB.Driver.MongoClient.AreSessionsSupportedAfterServerSelection(CancellationToken cancellationToken)
at MongoDB.Driver.MongoClient.AreSessionsSupported(CancellationToken cancellationToken)
at MongoDB.Driver.MongoClient.StartImplicitSession(CancellationToken cancellationToken)
at MongoDB.Driver.OperationExecutor.StartImplicitSession(CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSession[TResult](Func`2 func, CancellationToken cancellationToken)
at MongoDB.Driver.MongoCollectionImpl`1.FindSync[TProjection](FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken) at MD.MongoDB.MongoBaseRepository`1.Find(FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken)
at MD.AppActivityTask.Repositories.ApkRepository.GetAllApk(DateTime time) in /data/jenkins/workspace/private_schedulertool/MDSchedulerTools/MD.AppActivityTask/Repositories/ApkRepository.cs:line 85
at MD.AppActivityTask.Services.AppActivityService.Run(Nullable`1 startDate, Nullable`1 endDate, Boolean isPrivate) in /data/jenkins/workspace/private_schedulertool/MDSchedulerTools/MD.AppActivityTask/Services/AppActivityService.cs:line 122
定时清理任务,执行完成!! time: 11/30/2023 02:00:30
配置文件 appsettings.json
{
"WorksheetConnStr": "mongodb://127.0.0.1:27017/mdworksheet",
"MD_WSService1": "mongodb://127.0.0.1:27017/mdwsrows",
"MD_WSService2": "mongodb://127.0.0.1:27017/mdwsrows",
"MD_WSService3": "mongodb://127.0.0.1:27017/mdwsrows",
"MD_WSService4": "mongodb://127.0.0.1:27017/mdwsrows",
"MD_WSService5": "mongodb://127.0.0.1:27017/mdwsrows",
"MD_WSService6": "mongodb://127.0.0.1:27017/mdwsrows",
"MD_WSService7": "mongodb://127.0.0.1:27017/mdwsrows",
"MD_WSService8": "mongodb://127.0.0.1:27017/mdwsrows",
"MD_WSService9": "mongodb://127.0.0.1:27017/mdwsrows",
"MD_WSService10": "mongodb://127.0.0.1:27017/mdwsrows",
"MD_WSLogService1": "mongodb://127.0.0.1:27017/mdworksheetlog",
"ApkConnStr": "mongodb://127.0.0.1:27017/mdapps",
"AppRoleConnStr": "mongodb://127.0.0.1:27017/mdapproles",
"MD.Worksheet.DbName": "mdworksheet",
"MD.WorksheetRow.DbName": "mdwsrows",
"DeleteDay": 7,
"DeleteRowByNomal": 1,
"DelateRowDay": 7,
"DelateRowTotal": 1000,
"Corn": "0 0 2 * * ? "
}
配置文件 dataclean.yaml
version: '3'
services:
app:
image: registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-dataclean-app:1.0.0
volumes:
- ./appsettings.json:/app/Config/appsettings.json
确实,我还是按照教程里面的命令启动,离开集群,用 docker-compose 启动成功了。👍 多谢,多谢 😄
你启动的时候是否使用的还是这个命令
![image.png]()
docker stack deploy -c dataclean.yaml dataclean?下面这个截图复现了和你一样的错误
docker swarm init这一步我没有做另外,你可以看下现有的 docker 网络是什么情况 docker network ls
我得去补一下 docker 的网络知识,改了不行,没在一个作用域了
network "script_default" is declared as external, but it is not in the right scope: "local" instead of "swarm"补充下,docker-compose 的启动效果
![image.png]()
另外,这个问题涉及到了 docker 的网络知识,不同容器之间如何进行访问,可以把服务端口都暴露到宿主机上,也可以将两个不同的容器挂载到同一个 docker network 中,应该也还有其他方法
好的,非常感谢!我去调整了试试。
docker swarm 启动的 dataclean 容器,没有访问到 script_app_1 的容器里面的 MongoDB 服务,有两个方法可以解决
script_default这个,整个配置如下然后,在访问 script_app_1 里面的 MongoDB 服务时,使用 Docker DNS Server 的原理,具体配置如下
![image.png]()
你先试试,不行可以再沟通,昨天我刚测试过这个方式
![image.png]()