Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有副本集的mongodb的Statefulset_Mongodb_Kubernetes_Minikube_Replicaset - Fatal编程技术网

具有副本集的mongodb的Statefulset

具有副本集的mongodb的Statefulset,mongodb,kubernetes,minikube,replicaset,Mongodb,Kubernetes,Minikube,Replicaset,我想使用副本集mongo从mongo映像创建一个Statefulset 为此,我有我的状态集: apiVersion: apps/v1 kind: StatefulSet metadata: name: mongo-test spec: selector: matchLabels: app: mongo-test serviceName: "mongo-test" replicas: 1 template: metadata: labe

我想使用副本集mongo从mongo映像创建一个Statefulset

为此,我有我的状态集:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongo-test
spec:
  selector:
    matchLabels:
      app: mongo-test
  serviceName: "mongo-test"
  replicas: 1
  template:
    metadata:
      labels:
        app: mongo-test
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: mongodb
        image: mongo:4.2.1
        ports:
        - containerPort: 27017
          name: web
        command: ["/bin/sh","-c"]
        args: ["mongod --oplogSize 128 --replSet rs0 --bind_ip_all && mongo --eval \"rs.initiate()\""]
        volumeMounts:
        - name: mongo-persistent-storage
          mountPath: /data/db
  volumeClaimTemplates:
  - metadata:
      name: mongo-persistent-storage
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 2Gi
Statefulset和pod创建正常,但副本集未初始化。我发送命令:mongo-eval rs.initiate以创建复制副本,但由于某些原因,复制副本没有创建

我还使用了命令:在rs.initiate命令之前睡眠30分钟,就像延迟一样,但没有运气

我的命令有问题吗

警察局。我没有详细介绍其余的配置服务,pvc,pv,因为一切都正常

-更新

添加日志:

2019-11-19T15:10:05.257+0000 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-11-19T15:10:05.259+0000 I  CONTROL  [initandlisten] MongoDB starting : pid=8 port=27017 dbpath=/data/db 64-bit host=mongo-test-0
2019-11-19T15:10:05.259+0000 I  CONTROL  [initandlisten] db version v4.2.1
2019-11-19T15:10:05.259+0000 I  CONTROL  [initandlisten] git version: edf6d45851c0b9ee15548f0f847df141764a317e
2019-11-19T15:10:05.259+0000 I  CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
2019-11-19T15:10:05.259+0000 I  CONTROL  [initandlisten] allocator: tcmalloc
2019-11-19T15:10:05.259+0000 I  CONTROL  [initandlisten] modules: none
2019-11-19T15:10:05.259+0000 I  CONTROL  [initandlisten] build environment:
2019-11-19T15:10:05.259+0000 I  CONTROL  [initandlisten]     distmod: ubuntu1804
2019-11-19T15:10:05.259+0000 I  CONTROL  [initandlisten]     distarch: x86_64
2019-11-19T15:10:05.259+0000 I  CONTROL  [initandlisten]     target_arch: x86_64
2019-11-19T15:10:05.259+0000 I  CONTROL  [initandlisten] options: { net: { bindIp: "*" }, replication: { oplogSizeMB: 128, replSet: "rs0" } }
2019-11-19T15:10:05.259+0000 I  STORAGE  [initandlisten] 
2019-11-19T15:10:05.259+0000 I  STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-11-19T15:10:05.259+0000 I  STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-11-19T15:10:05.259+0000 I  STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=5442M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
2019-11-19T15:10:06.307+0000 I  STORAGE  [initandlisten] WiredTiger message [1574176206:307928][8:0x7fa43d4aeb00], txn-recover: Set global recovery timestamp: (0,0)
2019-11-19T15:10:06.721+0000 I  RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2019-11-19T15:10:07.142+0000 I  STORAGE  [initandlisten] Timestamp monitor starting
2019-11-19T15:10:07.272+0000 I  CONTROL  [initandlisten] 
2019-11-19T15:10:07.272+0000 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-11-19T15:10:07.272+0000 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-11-19T15:10:07.272+0000 I  CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-11-19T15:10:07.272+0000 I  CONTROL  [initandlisten] 
2019-11-19T15:10:07.273+0000 I  SHARDING [initandlisten] Marking collection local.system.replset as collection version: <unsharded>
2019-11-19T15:10:07.273+0000 I  STORAGE  [initandlisten] Flow Control is enabled on this deployment.
2019-11-19T15:10:07.273+0000 I  SHARDING [initandlisten] Marking collection admin.system.roles as collection version: <unsharded>
2019-11-19T15:10:07.273+0000 I  SHARDING [initandlisten] Marking collection admin.system.version as collection version: <unsharded>
2019-11-19T15:10:07.273+0000 I  STORAGE  [initandlisten] createCollection: local.startup_log with generated UUID: acb2882f-a531-456a-8150-9d4eb0273ef1 and options: { capped: true, size: 10485760 }
2019-11-19T15:10:07.532+0000 I  INDEX    [initandlisten] index build: done building index _id_ on ns local.startup_log
2019-11-19T15:10:07.532+0000 I  SHARDING [initandlisten] Marking collection local.startup_log as collection version: <unsharded>
2019-11-19T15:10:07.532+0000 I  FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2019-11-19T15:10:07.533+0000 I  STORAGE  [initandlisten] createCollection: local.replset.oplogTruncateAfterPoint with generated UUID: 6c30e1dc-7da5-4698-a96e-d6736e450999 and options: {}
2019-11-19T15:10:07.773+0000 I  INDEX    [initandlisten] index build: done building index _id_ on ns local.replset.oplogTruncateAfterPoint
2019-11-19T15:10:07.774+0000 I  STORAGE  [initandlisten] createCollection: local.replset.minvalid with generated UUID: 703fef2a-479a-4ae9-9052-6c04cf942af4 and options: {}
2019-11-19T15:10:07.997+0000 I  INDEX    [initandlisten] index build: done building index _id_ on ns local.replset.minvalid
2019-11-19T15:10:07.997+0000 I  SHARDING [initandlisten] Marking collection local.replset.minvalid as collection version: <unsharded>
2019-11-19T15:10:07.998+0000 I  STORAGE  [initandlisten] createCollection: local.replset.election with generated UUID: 950b0919-e330-4983-a1ff-537fb0e28d72 and options: {}
2019-11-19T15:10:08.153+0000 I  INDEX    [initandlisten] index build: done building index _id_ on ns local.replset.election
2019-11-19T15:10:08.153+0000 I  SHARDING [ftdc] Marking collection local.oplog.rs as collection version: <unsharded>
2019-11-19T15:10:08.153+0000 W  REPL     [ftdc] Rollback ID is not initialized yet.
2019-11-19T15:10:08.154+0000 I  SHARDING [initandlisten] Marking collection local.replset.election as collection version: <unsharded>
2019-11-19T15:10:08.155+0000 I  REPL     [initandlisten] Did not find local initialized voted for document at startup.
2019-11-19T15:10:08.155+0000 I  REPL     [initandlisten] Did not find local Rollback ID document at startup. Creating one.
2019-11-19T15:10:08.156+0000 I  STORAGE  [initandlisten] createCollection: local.system.rollback.id with generated UUID: 9e2939db-087f-40a9-9710-585b4b26c57b and options: {}
2019-11-19T15:10:08.330+0000 I  INDEX    [initandlisten] index build: done building index _id_ on ns local.system.rollback.id
2019-11-19T15:10:08.330+0000 I  SHARDING [initandlisten] Marking collection local.system.rollback.id as collection version: <unsharded>
2019-11-19T15:10:08.331+0000 I  REPL     [initandlisten] Initialized the rollback ID to 1
2019-11-19T15:10:08.331+0000 I  REPL     [initandlisten] Did not find local replica set configuration document at startup;  NoMatchingDocument: Did not find replica set configuration document in local.system.replset
2019-11-19T15:10:08.332+0000 I  CONTROL  [LogicalSessionCacheRefresh] Sessions collection is not set up; waiting until next sessions refresh interval: Replication has not yet been configured
2019-11-19T15:10:08.333+0000 I  NETWORK  [initandlisten] Listening on /tmp/mongodb-27017.sock
2019-11-19T15:10:08.333+0000 I  NETWORK  [initandlisten] Listening on 0.0.0.0
2019-11-19T15:10:08.333+0000 I  NETWORK  [initandlisten] waiting for connections on port 27017
2019-11-19T15:10:08.339+0000 I  SHARDING [LogicalSessionCacheReap] Marking collection config.system.sessions as collection version: <unsharded>
2019-11-19T15:10:08.339+0000 I  CONTROL  [LogicalSessionCacheReap] Sessions collection is not set up; waiting until next sessions reap interval: config.system.sessions does not exist
你可以试试这个

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: mongo
  app: mongodb
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      terminationGracePeriodSeconds: 10
      containers:
        - name: mongo
          image: mongo
          command:
            - mongod
            - "--replSet"
            - rs0
            - "--smallfiles"
            - "--noprealloc"
          ports:
            - containerPort: 27017
          volumeMounts:
            - name: mongo-persistent-volume
              mountPath: /data/db
  volumeClaimTemplates:
  - metadata:
      name: mongo-persistent-volume
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 5Gi

我不是这方面的专家,但根据您的日志,您的选项是在启动期间通过的:

options: { net: { bindIp: "*" }, replication: { oplogSizeMB: 128, replSet: "rs0" } }
但是mongodb在启动期间找不到repl设置:

Did not find local replica set configuration document at startup;
  NoMatchingDocument: Did not find replica set configuration document in local.system.replset
第二个问题是附加参数:

从版本4.2开始,MongoDB将删除不推荐使用的MMAPv1存储引擎和特定于MMAPv1的配置选项:

已删除命令行选项:

mongod-小型文件 mongod-noprealloc 我所做的: 我申请了以下参数:

args:
  - mongod
  - "--replSet"
  - rs0
  - "--bind_ip_all"
有关主机名、稳定网络标识符,请参阅statefulset基础:

对于具有N个副本的StatefulSet,StatefulSet中的每个Pod将被分配一个整数序号,从0到N-1,该序号在该集上是唯一的 StatefulSet可以使用无头服务来控制其pod的域。此服务管理的域的形式为:$Service name.$namespace.svc.cluster.local,其中“cluster.local”是群集域。创建每个Pod时,它将获得一个匹配的DNS子域,其形式为:$podname.$Governang service domain,其中治理服务由StatefulSet上的serviceName字段定义

如限制部分所述,您负责创建负责POD网络标识的Headless服务

根据我的示例中的这些规则,我还创建了headless服务,并在mongodb初始化期间提供了这些信息:

host: "mongo-test-0.mongo-test"
host: "mongo-test-1.mongo-test"
在运行的pod中,我已使用以下命令初始化集群:

rs.initiate( {_id: "rs0", version:1, members: [
      { _id: 0, host: "mongo-test-0.mongo-test:27017" },
      { _id: 1, host: "mongo-test-1.mongo-test:27017" },
   ]
})

{
    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1574614871, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    },
    "operationTime" : Timestamp(1574614871, 1)
}
核查:

rs0:PRIMARY> rs.config()
{
    "_id" : "rs0",
    "version" : 1,
    "protocolVersion" : NumberLong(1),
    "writeConcernMajorityJournalDefault" : true,
    "members" : [
        {
            "_id" : 0,
            "host" : "mongo-test-0.mongo-test:27017",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1,
            "tags" : {

            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        },
        {
            "_id" : 1,
            "host" : "mongo-test-1.mongo-test:27017",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1,
            "tags" : {

            },

rs0:PRIMARY> rs.isMaster()
{
    "hosts" : [
        "mongo-test-0.mongo-test:27017",
        "mongo-test-1.mongo-test:27017"
    ],
    "setName" : "rs0",
    "setVersion" : 1,
    "ismaster" : true,
有关mongodb复制平台的更多信息,请参阅官方网站

我认为,为了管理f.e.正确的主机名、稳定的网络标识符、复制和初始化,您应该准备环境变量和应用于部署的其他脚本/入口点

作为一个例子,我建议使用。
希望得到帮助。

什么是rs.initiate?@suren这是一个启动mongo副本集的命令。请尝试:args:[mongod-oplogSize 128-replSet rs0-bind_ip_all&&mongo localhost:27017-eval\rs.initiate\]@Hanx它不起作用谢谢,但是启动mongo副本集的命令呢?我不想要mongo的版本3,我想要版本4.2.1。更新的答案请检查,如果不起作用请告诉我。它不起作用,因为无法读取-smallfiles选项。Kubernetes将每一行作为不同的命令。谢谢@Hanx。正如您在我的问题中看到的,我没有使用smallfiles或prealloc。因此,这不是问题所在。是的,正如你所说,我正在创建一个包含所有初始化脚本的映像。如上所述,您可能应该在脚本中提供来自env变量的信息作为示例。每个成员都应该根据运行的配置验证这些参数。此外,请使用稳定的mongo图。