首页 > 数据库 >使用ansible安装mongodb分片集群

使用ansible安装mongodb分片集群

时间:2024-08-07 17:06:11浏览次数:14  
标签:x.187 ok 10 mongodb x.188 item ansible x.21 分片

【说明】

使用ansible安装一个分片集群,三台服务器,三个mongos,三个config,三个分片节点,每三个分片有三个副本(每个节点运行三个端口的mongod)

 

 

                [mongo_servers]
                10.x.x.21  ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=mongo1 mongod_port=2700
                10.x.x.187 ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=mongo2 mongod_port=2701
                10.x.x.188 ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=mongo3 mongod_port=2702
                
                #The list of servers where replication should happen, including the master server.
                [replication_servers]
                10.x.x.21  ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=mongo3
                10.x.x.187 ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=mongo1
                10.x.x.188 ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=mongo2
                
                #The list of mongodb configuration servers, make sure it is 1 or 3.
                [mongoc_servers]
                10.x.x.21  ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=mongo1
                10.x.x.187 ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=mongo2
                10.x.x.188 ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=mongo3
                
                #The list of servers where mongos servers would run.
                [mongos_servers]
                10.x.x.21  ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=mongo1
                10.x.x.187 ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=mongo2
                10.x.x.188 ansible_user=root ansible_ssh_pass=xxxxxxxx cluster_role=mongo3

 

使用GitHub上面的一个脚本来修改:https://github.com/a-h/ansible-mongodb-cluster/tree/master

修改了mongodb7版本的信息,使用hosts具体IP信息来运行剧本,修改mongodb的配置参数,修改mongos的配置参数,在mongodb时候创建管理用户,修改卸载内容,添加mongosh内容,修改测试分片数据脚本

特别注意:这里清理的目录会被删掉,确认好里面没有其他重要文件

说明:由于剧本信息较多,如有需要请说明。

【剧本说明】

[root@mysqlbackup:/root/auto/ansible-mongodb-cluster]$ tree mongodb7/
mongodb7/
├── clean.yml
├── group_vars
│   └── all.yml
├── hosts
├── mongod.yml
├── roles
│   ├── common
│   │   ├── files
│   │   │   ├── Centos-ali.repo
│   │   │   ├── epel.repo.j2
│   │   │   ├── mongodb-org-3.2.repo
│   │   │   ├── pip.conf
│   │   │   └── RPM-GPG-KEY-EPEL-6
│   │   ├── handlers
│   │   │   └── main.yml
│   │   ├── tasks
│   │   │   ├── main.yml
│   │   │   └── main.yml_bak
│   │   ├── templates
│   │   │   ├── hosts.j2
│   │   │   ├── hosts.j2_bak
│   │   │   └── iptables.j2
│   │   └── vars
│   ├── mongoc
│   │   ├── files
│   │   │   └── secret
│   │   ├── tasks
│   │   │   └── main.yml
│   │   └── templates
│   │       ├── mongoc.conf.j2
│   │       ├── mongoc_init.js.j2
│   │       └── mongoc.service
│   ├── mongod
│   │   ├── files
│   │   │   └── secret
│   │   ├── tasks
│   │   │   ├── main.yml
│   │   │   └── main.yml_bak
│   │   └── templates
│   │       ├── mongod.conf.j2
│   │       ├── mongod_init.js.j2
│   │       ├── mongod.service.j2
│   │       ├── mongod_user.js.j2
│   │       └── shard_init.j2
│   ├── mongos
│   │   ├── files
│   │   │   └── secret
│   │   ├── tasks
│   │   │   └── main.yml
│   │   ├── templates
│   │   │   ├── mongos.conf.j2
│   │   │   ├── mongos_init.js.j2
│   │   │   └── mongos.service.j2
│   │   └── vars
│   │       └── main.yml
│   └── shard_test
│       ├── tasks
│       │   └── main.yml
│       └── templates
│           └── shard_test.js
├── shard_test.yml
└── site.yml

 

【运行结果】

[root@mysqlbackup:/root/auto/ansible-mongodb-cluster-master/mongodb7]$ ansible-playbook -i hosts  site.yml                   

PLAY [all] **********************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [common : download rpm] ****************************************************************************************************************************************************************************
ok: [10.x.x.21] => (item={u'name': u'mongodb-org-database-tools-extra-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.188] => (item={u'name': u'mongodb-org-database-tools-extra-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.187] => (item={u'name': u'mongodb-org-database-tools-extra-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.21] => (item={u'name': u'mongodb-org-database-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.188] => (item={u'name': u'mongodb-org-database-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.21] => (item={u'name': u'mongodb-org-tools-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.187] => (item={u'name': u'mongodb-org-database-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.188] => (item={u'name': u'mongodb-org-tools-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.187] => (item={u'name': u'mongodb-org-tools-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.21] => (item={u'name': u'mongodb-org-server-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.188] => (item={u'name': u'mongodb-org-server-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.187] => (item={u'name': u'mongodb-org-server-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.21] => (item={u'name': u'mongodb-org-mongos-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.188] => (item={u'name': u'mongodb-org-mongos-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.187] => (item={u'name': u'mongodb-org-mongos-7.0.12-1.el7.x86_64.rpm'})
ok: [10.x.x.188] => (item={u'name': u'mongodb-mongosh-2.2.12.x86_64.rpm'})
ok: [10.x.x.187] => (item={u'name': u'mongodb-mongosh-2.2.12.x86_64.rpm'})
ok: [10.x.x.188] => (item={u'name': u'mongodb-database-tools-100.10.0-1.x86_64.rpm'})
ok: [10.x.x.21] => (item={u'name': u'mongodb-mongosh-2.2.12.x86_64.rpm'})
ok: [10.x.x.187] => (item={u'name': u'mongodb-database-tools-100.10.0-1.x86_64.rpm'})
ok: [10.x.x.21] => (item={u'name': u'mongodb-database-tools-100.10.0-1.x86_64.rpm'})

TASK [common : install rpm] *****************************************************************************************************************************************************************************
changed: [10.x.x.21] => (item=[u'/tmp/mongodb-org-database-tools-extra-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-org-database-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-org-tools-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-org-server-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-org-mongos-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-mongosh-2.2.12.x86_64.rpm', u'/tmp/mongodb-database-tools-100.10.0-1.x86_64.rpm'])
changed: [10.x.x.188] => (item=[u'/tmp/mongodb-org-database-tools-extra-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-org-database-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-org-tools-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-org-server-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-org-mongos-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-mongosh-2.2.12.x86_64.rpm', u'/tmp/mongodb-database-tools-100.10.0-1.x86_64.rpm'])
changed: [10.x.x.187] => (item=[u'/tmp/mongodb-org-database-tools-extra-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-org-database-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-org-tools-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-org-server-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-org-mongos-7.0.12-1.el7.x86_64.rpm', u'/tmp/mongodb-mongosh-2.2.12.x86_64.rpm', u'/tmp/mongodb-database-tools-100.10.0-1.x86_64.rpm'])

TASK [common : Create the mongod user] ******************************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [common : Create the data directory for the namenode metadata] *************************************************************************************************************************************
changed: [10.x.x.21]
changed: [10.x.x.187]
changed: [10.x.x.188]

TASK [common : create log directory for mongodb] ********************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [common : create run directory for mongodb] ********************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [common : Generate /etc/hosts content] *************************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [common : Read content from remote /tmp/hosts_content] *********************************************************************************************************************************************
changed: [10.x.x.21 -> 10.x.x.21]
changed: [10.x.x.188 -> 10.x.x.188]
changed: [10.x.x.187 -> 10.x.x.187]

TASK [common : Use the content read from the remote file] ***********************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

PLAY [mongo_servers] ************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************
ok: [10.x.x.188]
ok: [10.x.x.21]
ok: [10.x.x.187]

TASK [create data directory for mongodb] ****************************************************************************************************************************************************************
changed: [10.x.x.21 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.187 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.188 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.21 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.187 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.188 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.21 -> 10.x.x.188] => (item=10.x.x.188)
changed: [10.x.x.187 -> 10.x.x.188] => (item=10.x.x.188)
changed: [10.x.x.188 -> 10.x.x.188] => (item=10.x.x.188)

TASK [Create the mongodb startup file] ******************************************************************************************************************************************************************
ok: [10.x.x.21 -> 10.x.x.21] => (item=10.x.x.21)
ok: [10.x.x.187 -> 10.x.x.21] => (item=10.x.x.21)
ok: [10.x.x.188 -> 10.x.x.21] => (item=10.x.x.21)
ok: [10.x.x.187 -> 10.x.x.187] => (item=10.x.x.187)
ok: [10.x.x.21 -> 10.x.x.187] => (item=10.x.x.187)
ok: [10.x.x.188 -> 10.x.x.187] => (item=10.x.x.187)
ok: [10.x.x.187 -> 10.x.x.188] => (item=10.x.x.188)
ok: [10.x.x.21 -> 10.x.x.188] => (item=10.x.x.188)
ok: [10.x.x.188 -> 10.x.x.188] => (item=10.x.x.188)

TASK [mongod : authorization] ***************************************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.187]
ok: [10.x.x.188]

TASK [Create the mongodb configuration file] ************************************************************************************************************************************************************
changed: [10.x.x.187 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.188 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.21 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.21 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.188 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.187 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.188 -> 10.x.x.188] => (item=10.x.x.188)
changed: [10.x.x.187 -> 10.x.x.188] => (item=10.x.x.188)
changed: [10.x.x.21 -> 10.x.x.188] => (item=10.x.x.188)

TASK [mongod : Copy the keyfile for authentication] *****************************************************************************************************************************************************
changed: [10.x.x.21]
changed: [10.x.x.188]
changed: [10.x.x.187]

TASK [Start the mongodb service] ************************************************************************************************************************************************************************
changed: [10.x.x.21 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.188 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.187 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.21 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.187 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.188 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.187 -> 10.x.x.188] => (item=10.x.x.188)
changed: [10.x.x.188 -> 10.x.x.188] => (item=10.x.x.188)
changed: [10.x.x.21 -> 10.x.x.188] => (item=10.x.x.188)

TASK [mongod : wait_for] ********************************************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [Create the file to initialize the mongod users] ***************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [Initialize the mongod users] **********************************************************************************************************************************************************************
changed: [10.x.x.187]
changed: [10.x.x.188]
changed: [10.x.x.21]

TASK [mongod : set authorization] ***********************************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.187]
ok: [10.x.x.188]

TASK [Create the mongodb authorization  configuration file] *********************************************************************************************************************************************
changed: [10.x.x.21 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.187 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.188 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.188 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.187 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.21 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.187 -> 10.x.x.188] => (item=10.x.x.188)
changed: [10.x.x.188 -> 10.x.x.188] => (item=10.x.x.188)
changed: [10.x.x.21 -> 10.x.x.188] => (item=10.x.x.188)

TASK [reStart the mongodb service] **********************************************************************************************************************************************************************
changed: [10.x.x.21 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.187 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.188 -> 10.x.x.21] => (item=10.x.x.21)
changed: [10.x.x.21 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.187 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.188 -> 10.x.x.187] => (item=10.x.x.187)
changed: [10.x.x.188 -> 10.x.x.188] => (item=10.x.x.188)
changed: [10.x.x.21 -> 10.x.x.188] => (item=10.x.x.188)
changed: [10.x.x.187 -> 10.x.x.188] => (item=10.x.x.188)

TASK [Create the file to initialize the mongod replica set] *********************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [mongod : Initialize the replication set] **********************************************************************************************************************************************************
changed: [10.x.x.21]
changed: [10.x.x.188]
changed: [10.x.x.187]

PLAY [mongoc_servers] ***********************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************
ok: [10.x.x.188]
ok: [10.x.x.21]
ok: [10.x.x.187]

TASK [Create data directory for mongoc configuration server] ********************************************************************************************************************************************
changed: [10.x.x.21]
changed: [10.x.x.188]
changed: [10.x.x.187]

TASK [mongoc : Create the mongodb startup file] *********************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [mongoc : Create the mongodb configuration file] ***************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.187]
ok: [10.x.x.188]

TASK [mongoc : Copy the keyfile for authentication] *****************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [mongoc : Start the mongodb service] ***************************************************************************************************************************************************************
changed: [10.x.x.21]
changed: [10.x.x.188]
changed: [10.x.x.187]

TASK [mongoc : wait_for] ********************************************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [mongoc : Create the file to initialize mongo user] ************************************************************************************************************************************************
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{inventory_hostname == groups['mongoc_servers'][0]}}
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{inventory_hostname == groups['mongoc_servers'][0]}}
skipping: [10.x.x.187]
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{inventory_hostname == groups['mongoc_servers'][0]}}
skipping: [10.x.x.188]
ok: [10.x.x.21]

TASK [mongoc : Create admin User] ***********************************************************************************************************************************************************************
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{inventory_hostname == groups['mongoc_servers'][0]}}
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{inventory_hostname == groups['mongoc_servers'][0]}}
skipping: [10.x.x.187]
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{inventory_hostname == groups['mongoc_servers'][0]}}
skipping: [10.x.x.188]
changed: [10.x.x.21]

PLAY [mongos_servers] ***********************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [Create the mongos startup file] *******************************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [Create the mongos configuration file] *************************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.187]
ok: [10.x.x.188]

TASK [mongos : Copy the keyfile for authentication] *****************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [Start the mongos service] *************************************************************************************************************************************************************************
changed: [10.x.x.21]
changed: [10.x.x.187]
changed: [10.x.x.188]

TASK [mongos : wait_for] ********************************************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.188]
ok: [10.x.x.187]

TASK [mongos : Initialize mongo_servers_group] **********************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.187]
ok: [10.x.x.188]

TASK [mongos : Populate mongo_servers_group with mongod_port] *******************************************************************************************************************************************
ok: [10.x.x.21] => (item=10.x.x.21)
ok: [10.x.x.21] => (item=10.x.x.187)
ok: [10.x.x.187] => (item=10.x.x.21)
ok: [10.x.x.21] => (item=10.x.x.188)
ok: [10.x.x.187] => (item=10.x.x.187)
ok: [10.x.x.188] => (item=10.x.x.21)
ok: [10.x.x.188] => (item=10.x.x.187)
ok: [10.x.x.187] => (item=10.x.x.188)
ok: [10.x.x.188] => (item=10.x.x.188)

TASK [mongos : debug] ***********************************************************************************************************************************************************************************
ok: [10.x.x.21] => {
    "mongo_servers_group": [
        2700, 
        2701, 
        2702
    ]
}
ok: [10.x.x.187] => {
    "mongo_servers_group": [
        2700, 
        2701, 
        2702
    ]
}
ok: [10.x.x.188] => {
    "mongo_servers_group": [
        2700, 
        2701, 
        2702
    ]
}

TASK [mongos : Copy the file enable  sharding] **********************************************************************************************************************************************************
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{inventory_hostname == groups['mongos_servers'][0]}}
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{inventory_hostname == groups['mongos_servers'][0]}}
skipping: [10.x.x.187]
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{inventory_hostname == groups['mongos_servers'][0]}}
skipping: [10.x.x.188]
changed: [10.x.x.21]

TASK [mongos : Create sharding] *************************************************************************************************************************************************************************
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{inventory_hostname == groups['mongos_servers'][0]}}
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{inventory_hostname == groups['mongos_servers'][0]}}
skipping: [10.x.x.187]
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{inventory_hostname == groups['mongos_servers'][0]}}
skipping: [10.x.x.188]
changed: [10.x.x.21]

TASK [mongos : debug] ***********************************************************************************************************************************************************************************
ok: [10.x.x.21] => {
    "msg": {
        "changed": true, 
        "cmd": "/usr/bin/mongosh \"localhost:27017/admin\" /tmp/mongos_init.js", 
        "delta": "0:00:03.807226", 
        "end": "2024-08-07 16:07:25.260496", 
        "failed": false, 
        "rc": 0, 
        "start": "2024-08-07 16:07:21.453270", 
        "stderr": "", 
        "stderr_lines": [], 
        "stdout": "shardingVersion\n{\n  _id: 1,\n  clusterId: ObjectId('66b32b29c13841878d598d3c')\n}\n---\nshards\n[\n  {\n    _id: 'mongo1',\n    host: 'mongo1/mongo1:2700,mongo2:2700,mongo3:2700',\n    state: 1,\n    topologyTime: Timestamp({ t: 1723018042, i: 3 })\n  },\n  {\n    _id: 'mongo2',\n    host: 'mongo2/mongo1:2701,mongo2:2701,mongo3:2701',\n    state: 1,\n    topologyTime: Timestamp({ t: 1723018042, i: 7 })\n  },\n  {\n    _id: 'mongo3',\n    host: 'mongo3/mongo3:2702,mongo1:2702,mongo2:2702',\n    state: 1,\n    topologyTime: Timestamp({ t: 1723018043, i: 6 })\n  }\n]\n---\nactive mongoses\n[\n  {\n    '7.0.12': 3\n  }\n]\n---\nautosplit\n{\n  'Currently enabled': 'yes'\n}\n---\nbalancer\n{\n  'Currently enabled': 'yes',\n  'Failed balancer rounds in last 5 attempts': 0,\n  'Currently running': 'no',\n  'Migration Results for the last 24 hours': 'No recent migrations'\n}\n---\ndatabases\n[\n  {\n    database: {\n      _id: 'config',\n      primary: 'config',\n      partitioned: true\n    },\n    collections: {}\n  }\n]", 
        "stdout_lines": [
            "shardingVersion", 
            "{", 
            "  _id: 1,", 
            "  clusterId: ObjectId('66b32b29c13841878d598d3c')", 
            "}", 
            "---", 
            "shards", 
            "[", 
            "  {", 
            "    _id: 'mongo1',", 
            "    host: 'mongo1/mongo1:2700,mongo2:2700,mongo3:2700',", 
            "    state: 1,", 
            "    topologyTime: Timestamp({ t: 1723018042, i: 3 })", 
            "  },", 
            "  {", 
            "    _id: 'mongo2',", 
            "    host: 'mongo2/mongo1:2701,mongo2:2701,mongo3:2701',", 
            "    state: 1,", 
            "    topologyTime: Timestamp({ t: 1723018042, i: 7 })", 
            "  },", 
            "  {", 
            "    _id: 'mongo3',", 
            "    host: 'mongo3/mongo3:2702,mongo1:2702,mongo2:2702',", 
            "    state: 1,", 
            "    topologyTime: Timestamp({ t: 1723018043, i: 6 })", 
            "  }", 
            "]", 
            "---", 
            "active mongoses", 
            "[", 
            "  {", 
            "    '7.0.12': 3", 
            "  }", 
            "]", 
            "---", 
            "autosplit", 
            "{", 
            "  'Currently enabled': 'yes'", 
            "}", 
            "---", 
            "balancer", 
            "{", 
            "  'Currently enabled': 'yes',", 
            "  'Failed balancer rounds in last 5 attempts': 0,", 
            "  'Currently running': 'no',", 
            "  'Migration Results for the last 24 hours': 'No recent migrations'", 
            "}", 
            "---", 
            "databases", 
            "[", 
            "  {", 
            "    database: {", 
            "      _id: 'config',", 
            "      primary: 'config',", 
            "      partitioned: true", 
            "    },", 
            "    collections: {}", 
            "  }", 
            "]"
        ]
    }
}
ok: [10.x.x.187] => {
    "msg": {
        "changed": false, 
        "skip_reason": "Conditional result was False", 
        "skipped": true
    }
}
ok: [10.x.x.188] => {
    "msg": {
        "changed": false, 
        "skip_reason": "Conditional result was False", 
        "skipped": true
    }
}

PLAY [mongos_servers] ***********************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************
ok: [10.x.x.21]
ok: [10.x.x.187]
ok: [10.x.x.188]

TASK [shard_test : Copy the test script] ****************************************************************************************************************************************************************
skipping: [10.x.x.187]
skipping: [10.x.x.188]
changed: [10.x.x.21]

TASK [shard_test : Run test script] *********************************************************************************************************************************************************************
skipping: [10.x.x.187]
skipping: [10.x.x.188]
changed: [10.x.x.21]

TASK [shard_test : debug] *******************************************************************************************************************************************************************************
ok: [10.x.x.21] => {
    "msg": {
        "changed": true, 
        "cmd": "/usr/bin/mongosh \"localhost:27017/admin\" /tmp/shard_test.js -u admin -p 123456", 
        "delta": "0:19:29.515139", 
        "end": "2024-08-07 16:27:01.526747", 
        "failed": false, 
        "rc": 0, 
        "start": "2024-08-07 16:07:32.011608", 
        "stderr": "", 
        "stderr_lines": [], 
        "stdout": "", 
        "stdout_lines": []
    }
}
skipping: [10.x.x.187]
skipping: [10.x.x.188]

PLAY RECAP **********************************************************************************************************************************************************************************************
10.x.x.187                 : ok=43   changed=14   unreachable=0    failed=0    skipped=7    rescued=0    ignored=0   
10.x.x.188                 : ok=43   changed=14   unreachable=0    failed=0    skipped=7    rescued=0    ignored=0   
10.x.x.21                  : ok=50   changed=19   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

[root@mysqlbackup:/root/auto/ansible-mongodb-cluster-master/mongodb7]$

 

【结果】

最后有测试插入数据最终结果

[direct: mongos] admin> sh.status()
shardingVersion
{ _id: 1, clusterId: ObjectId('66b32b29c13841878d598d3c') }
---
shards
[
  {
    _id: 'mongo1',
    host: 'mongo1/mongo1:2700,mongo2:2700,mongo3:2700',
    state: 1,
    topologyTime: Timestamp({ t: 1723018042, i: 3 })
  },
  {
    _id: 'mongo2',
    host: 'mongo2/mongo1:2701,mongo2:2701,mongo3:2701',
    state: 1,
    topologyTime: Timestamp({ t: 1723018042, i: 7 })
  },
  {
    _id: 'mongo3',
    host: 'mongo3/mongo1:2702,mongo2:2702,mongo3:2702',
    state: 1,
    topologyTime: Timestamp({ t: 1723018043, i: 6 })
  }
]
---
active mongoses
[ { '7.0.12': 3 } ]
---
autosplit
{ 'Currently enabled': 'yes' }
---
balancer
{
  'Currently enabled': 'yes',
  'Currently running': 'no',
  'Failed balancer rounds in last 5 attempts': 0,
  'Migration Results for the last 24 hours': { '1': 'Success' }
}
---
databases
[
  {
    database: { _id: 'config', primary: 'config', partitioned: true },
    collections: {
      'config.system.sessions': {
        shardKey: { _id: 1 },
        unique: false,
        balancing: true,
        chunkMetadata: [ { shard: 'mongo1', nChunks: 1 } ],
        chunks: [
          { min: { _id: MinKey() }, max: { _id: MaxKey() }, 'on shard': 'mongo1', 'last modified': Timestamp({ t: 1, i: 0 }) }
        ],
        tags: []
      }
    }
  },
  {
    database: {
      _id: 'test',
      primary: 'mongo2',
      partitioned: false,
      version: {
        uuid: UUID('92e9a984-f2f7-4f76-9963-9a7055a16c03'),
        timestamp: Timestamp({ t: 1723018043, i: 10 }),
        lastMod: 1
      }
    },
    collections: {
      'test.messages': {
        shardKey: { createTime: 1 },
        unique: false,
        balancing: true,
        chunkMetadata: [
          { shard: 'mongo1', nChunks: 1 },
          { shard: 'mongo2', nChunks: 1 }
        ],
        chunks: [
          { min: { createTime: MinKey() }, max: { createTime: ISODate('2024-04-30T22:52:30.020Z') }, 'on shard': 'mongo1', 'last modified': Timestamp({ t: 2, i: 0 }) },
          { min: { createTime: ISODate('2024-04-30T22:52:30.020Z') }, max: { createTime: MaxKey() }, 'on shard': 'mongo2', 'last modified': Timestamp({ t: 2, i: 1 }) }
        ],
        tags: []
      },
      'test.user': {
        shardKey: { _id: 'hashed' },
        unique: false,
        balancing: true,
        chunkMetadata: [
          { shard: 'mongo1', nChunks: 2 },
          { shard: 'mongo2', nChunks: 2 },
          { shard: 'mongo3', nChunks: 2 }
        ],
        chunks: [
          { min: { _id: MinKey() }, max: { _id: Long('-6148914691236517204') }, 'on shard': 'mongo3', 'last modified': Timestamp({ t: 1, i: 0 }) },
          { min: { _id: Long('-6148914691236517204') }, max: { _id: Long('-3074457345618258602') }, 'on shard': 'mongo3', 'last modified': Timestamp({ t: 1, i: 1 }) },
          { min: { _id: Long('-3074457345618258602') }, max: { _id: Long('0') }, 'on shard': 'mongo1', 'last modified': Timestamp({ t: 1, i: 2 }) },
          { min: { _id: Long('0') }, max: { _id: Long('3074457345618258602') }, 'on shard': 'mongo1', 'last modified': Timestamp({ t: 1, i: 3 }) },
          { min: { _id: Long('3074457345618258602') }, max: { _id: Long('6148914691236517204') }, 'on shard': 'mongo2', 'last modified': Timestamp({ t: 1, i: 4 }) },
          { min: { _id: Long('6148914691236517204') }, max: { _id: MaxKey() }, 'on shard': 'mongo2', 'last modified': Timestamp({ t: 1, i: 5 }) }
        ],
        tags: []
      }
    }
  }
]
[direct: mongos] admin> use test
switched to db test
[direct: mongos] test> db.user.find({_id: 1 }).explain()
{
  queryPlanner: {
    mongosPlannerVersion: 1,
    winningPlan: {
      stage: 'SINGLE_SHARD',
      shards: [
        {
          shardName: 'mongo2',
          connectionString: 'mongo2/mongo1:2701,mongo2:2701,mongo3:2701',
          serverInfo: {
            host: 'rac01',
            port: 2701,
            version: '7.0.12',
            gitVersion: 'b6513ce0781db6818e24619e8a461eae90bc94fc'
          },
          namespace: 'test.user',
          indexFilterSet: false,
          parsedQuery: { _id: { '$eq': 1 } },
          queryHash: '58F0F49D',
          planCacheKey: '0028A5F4',
          maxIndexedOrSolutionsReached: false,
          maxIndexedAndSolutionsReached: false,
          maxScansToExplodeReached: false,
          winningPlan: { stage: 'IDHACK' },
          rejectedPlans: []
        }
      ]
    }
  },
  serverInfo: {
    host: 'rac01',
    port: 27017,
    version: '7.0.12',
    gitVersion: 'b6513ce0781db6818e24619e8a461eae90bc94fc'
  },
  serverParameters: {
    internalQueryFacetBufferSizeBytes: 104857600,
    internalQueryFacetMaxOutputDocSizeBytes: 104857600,
    internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,
    internalDocumentSourceGroupMaxMemoryBytes: 104857600,
    internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,
    internalQueryProhibitBlockingMergeOnMongoS: 0,
    internalQueryMaxAddToSetBytes: 104857600,
    internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600,
    internalQueryFrameworkControl: 'trySbeRestricted'
  },
  command: {
    find: 'user',
    filter: { _id: 1 },
    lsid: { id: UUID('d34c23de-e826-4d77-9102-6da3dca6ad0e') },
    '$clusterTime': {
      clusterTime: Timestamp({ t: 1723019610, i: 1 }),
      signature: {
        hash: Binary.createFromBase64('yQ6iysm7mX1p2pdy3eaWLMoa/ac=', 0),
        keyId: Long('7400306067793510422')
      }
    },
    '$db': 'test'
  },
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1723019611, i: 1 }),
    signature: {
      hash: Binary.createFromBase64('ZOwt/iVN6eXlll2oMQ0ajq5d3Mg=', 0),
      keyId: Long('7400306067793510422')
    }
  },
  operationTime: Timestamp({ t: 1723019608, i: 1 })
}
[direct: mongos] test>

 

标签:x.187,ok,10,mongodb,x.188,item,ansible,x.21,分片
From: https://www.cnblogs.com/zetanchen/p/18347434

相关文章

  • 五、.Net Core Web Api连接MongoDB自动创建表格并实现CRUD功能
    五、.NetCoreWebApi连接MongoDB自动创建表格并实现CRUD功能1.注册MongoDB账号,并获取ConnectionString;MongoDB官网:MongoDB:TheDeveloperDataPlatform|MongoDB获取ConnectionString教程:ConnectionString获取在VSCodeforMac按下shift+command+p搜索Nuget......
  • mongoDB_04
    MongoDB_04Attribution:MongoDB:TheDefinitiveGuide,ThirdEditionbyShannonBradshaw,EoinBrazil,andKristinaChodorow(O’Reilly).Copyright2020ShannonBradshawandEoinBrazil,978-1-491-95446-1.UsingtheMongoDBShellThissectioncoversho......
  • Node.js 通过mongose连mongoDB
    直接用的mongoDBAtlas,有免费的云集群可以用,免费的mongoDBAtlasmongose是一个对象文档映射(ODM)库,用来在node.js上和mongoDB交互的。比较详细的介绍见这个:https://www.freecodecamp.org/news/introduction-to-mongoose-for-mongodb-d2a7aa593c57/建立连接这里的path是你的mo......
  • Ubuntu下安装MongoDB 7
    1.sudosed-i's/http:\/\/archive.ubuntu.com/https:\/\/mirrors.ustc.edu.cn/g'/etc/apt/sources.list2.sudoaptupdate&&sudoaptupgrade-y3.sudoaptinstallgnupgwgetapt-transport-httpsca-certificatessoftware-properties-......
  • MongoDB性能调优
    文章目录MongoDB性能调优MongoDB性能不佳原因影响MongoDB性能的因素MongoDB性能监控工具mongostatmongotopProfiler模块db.currentOp()MongoDB性能调优MongoDB性能不佳原因慢查询阻塞等待硬件资源不足1,2通常是因为模型/索引设计不佳导致的排查思路:按1-2-3依次......
  • MongoDB两地三中心集群架构设计、全球多写集群架构设计
    文章目录高级集群架构设计两地三中心集群架构设计容灾级别两地三中心方案:复制集跨中心部署两地三中心部署的考量点两地三中心复制集搭建环境准备整体架构配置域名解析启动5个MongoDB实例初始化复制集配置选举优先级启动持续写脚本(每2秒写一条记录)测试结果总结全球多......
  • MongoDB复制集/集群搭建详解
    文章目录复制集介绍三节点复制集模式Pss模式PSA模式典型三节点复制集环境搭建注意事项搭建配置复制集复制集状态查询复制集常用命令安全认证创建用户创建keyFile文件启动mongod复制集连接方式复制集成员角色属性成员角色配置隐藏节点配置延时节点添加投票节点移除复制......
  • ansible-yaml
    ansible-playbook简介playbooks记录并执行Ansible的配置、部署和编排功能。使用yaml格式,文件以yaml或者yml结尾官方网站:https://docs.ansible.com/ansible/latest/user_guide/playbooks.html#working-with-playbooksyaml语言YAML(YetAnotherMarkupLanguage)不是标记语言,它......
  • ansible常用模块
    ansible常见模块setup#收集远程主机的Facts(每个被管理节点在接收运行管理命令之前,会将自己主机相关信息,如操作系统,IP等信息传递给ansible主机)filter:用于进行条件过滤,如果设置,仅返回匹配过滤条件的信息ansiblehosts1-msetupansiblehosts1-msetup-a"filter=ansibl......
  • Ansible内置模块之file
    RHCE9.0 (点击查看课程介绍) 上课课时:72课时/12天+考试辅导1-2天开班频率:2个月开一期最新新班:7月27日周末班上课方式:面授/直播;提供随堂录播ansible.builtin.file模块用于管理文件和目录的属性。可以创建、删除文件或目录,修改文件权限、所有者等属性。01 选......