关于MongoDB的一个小问题。
我目前使用的版本4.4.18MongoDB
我在Kubernetes中使用这个清单部署它,没有任何问题,一切都很好,非常高兴。
apiVersion: v1
kind: ConfigMap
metadata:
name: mongo-config
data:
mongo.conf: |
storage:
dbPath: /data/db
ensure-users.js: |
const targetDbStr = 'test';
const rootUser = cat('/etc/k8-test/admin/MONGO_ROOT_USERNAME');
const rootPass = cat('/etc/k8-test/admin/MONGO_ROOT_PASSWORD');
const usersStr = cat('/etc/k8-test/MONGO_USERS_LIST');
const adminDb = db.getSiblingDB('admin');
adminDb.auth(rootUser, rootPass);
print('Successfully authenticated admin user');
const targetDb = db.getSiblingDB(targetDbStr);
const customRoles = adminDb
.getRoles({rolesInfo: 1, showBuiltinRoles: false})
.map(role => role.role)
.filter(Boolean);
usersStr
.trim()
.split(';')
.map(s => s.split(':'))
.forEach(user => {
const username = user[0];
const rolesStr = user[1];
const password = user[2];
if (!rolesStr || !password) {
return;
}
const roles = rolesStr.split(',');
const userDoc = {
user: username,
pwd: password,
};
userDoc.roles = roles.map(role => {
if (!~customRoles.indexOf(role)) {
return role;
}
return {role: role, db: 'admin'};
});
try {
targetDb.createUser(userDoc);
} catch (err) {
if (!~err.message.toLowerCase().indexOf('duplicate')) {
throw err;
}
}
});
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongo
spec:
serviceName: mongo
replicas: 1
selector:
matchLabels:
app: mongo
template:
metadata:
labels:
app: mongo
spec:
terminationGracePeriodSeconds: 30
containers:
- name: mongo
image: docker.io/mongo:4.4.18
# image: docker.io/mongo:6.0
command: ["/bin/sh"]
args: ["-c", "mongod --replSet=rs0 --bind_ip_all"]
resources:
limits:
cpu: 1000m
memory: 1G
requests:
cpu: 100m
memory: 1G
ports:
- containerPort: 27017
name: mongo
protocol: TCP
volumeMounts:
- name: data
mountPath: /data/db
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: nfs-1
resources:
requests:
storage: 50Mi
---
apiVersion: v1
kind: Service
metadata:
name: mongo
labels:
app: mongo
spec:
selector:
app: mongo
ports:
- port: 27017
targetPort: 27017
name: mongo
clusterIP: None
现在,我只想把版本升级到6.0,实际上只是替换了这一行(被注释掉的那一行),其余的都保持不变。
然后我部署这个新版本,不幸的是,发生了这种情况。
NAME READY STATUS RESTARTS AGE
pod/mongo-0 0/1 CrashLoopBackOff 1 (10s ago) 24s
当跟踪日志时,我确实看到:
{"t":{"$date":"2022-12-07T06:50:10.048+00:00"},"s":"F", "c":"CONTROL", "id":20573, "ctx":"initandlisten","msg":"Wrong mongod version","attr":{"error":"UPGRADE PROBLEM: Found an invalid featureCompatibilityVersion document (ERROR: Location4926900: Invalid featureCompatibilityVersion document in admin.system.version: { _id: "featureCompatibilityVersion", version: "4.2" }. See https://docs.mongodb.com/master/release-notes/5.0-compatibility/#feature-compatibility. :: caused by :: Invalid feature compatibility version value, expected '5.0' or '5.3' or '6.0. See https://docs.mongodb.com/master/release-notes/5.0-compatibility/#feature-compatibility.). If the current featureCompatibilityVersion is below 5.0, see the documentation on upgrading at https://docs.mongodb.com/master/release-notes/5.0/#upgrade-procedures."}}
我去看了文档,但主要是关于迁移到5.0的。请问我的6.0少了什么?
谢谢
mongodb版本与/data/db
挂载的数据文件不兼容。
版本之间的差距太大。正如@WernfriedDomscheit所评论的那样,您需要分步骤升级它:
- 4.4至5.0 https://www.mongodb.com/docs/v6.0/release-notes/5.0-upgrade-replica-set/
- 5.0 ~ 6.0 https://www.mongodb.com/docs/v6.0/release-notes/6.0-upgrade-replica-set/
如果数据集大小允许,您可以通过从v4.4备份数据,从v6开始将新的空卷挂载到/data/db,并从备份中恢复数据库。