MongoDB 分片集群修改管理员密码

文章目录


MongoDB分片集群主机规划:

主机名称 主机IP CPU 内存 mongos端口 config端口 share1端口 share2端口 share3端口 操作系统及软件版本
mongodb01 192.168.91.61 2*4 16GB 27017 27019 27101 27102 27103 CentOS 7.9 mongo 4.4.29 mongos 4.4.29 mongod 4.4.29 mongosh 2.2.29
mongodb02 192.168.91.62 2*4 16GB 27017 27019 27101 27102 27103 CentOS 7.9 mongo 4.4.29 mongos 4.4.29 mongod 4.4.29 mongosh 2.2.29
mongodb03 192.168.91.63 2*4 16GB 27017 27019 27101 27102 27103 CentOS 7.9 mongo 4.4.29 mongos 4.4.29 mongod 4.4.29 mongosh 2.2.29

一、注释MongoDB分片集群认证参数(三台主机都要操作)

1、停止MongoDB分片集群所有容器
bash 复制代码
systemctl stop mongos
systemctl stop shard3
systemctl stop shard2
systemctl stop shard1
systemctl stop mongod

systemctl status mongos
systemctl status shard3
systemctl status shard2
systemctl status shard1
systemctl status mongod
2、注释用户认证参数
bash 复制代码
[root@epmongodb01 ~]#vim /data/mongodb/configsvr/conf/configsvr.conf
#security:
#  keyFile: /data/mongodb/keyfile/keyfile
#  authorization: enabled

[root@epmongodb01 ~]#vim /data/mongodb/shard1/conf/shard1.conf
#security:
#  keyFile: /data/mongodb/keyfile/keyfile
#  authorization: enabled

[root@epmongodb01 ~]#vim /data/mongodb/shard2/conf/shard2.conf
#security:
#  keyFile: /data/mongodb/keyfile/keyfile
#  authorization: enabled

[root@epmongodb01 ~]#vim /data/mongodb/shard3/conf/shard3.conf
#security:
#  keyFile: /data/mongodb/keyfile/keyfile
#  authorization: enabled

[root@epmongodb01 ~]#vim /data/mongodb/mongos/conf/mongos.conf
#security:
#  keyFile: /data/mongodb/keyfile/keyfile
3、启动MongoDB分片集群所有容器
bash 复制代码
systemctl start mongod
systemctl start shard1
systemctl start shard2
systemctl start shard3
systemctl start mongos

systemctl status mongod
systemctl status shard1
systemctl status shard2
systemctl status mongos
4、验证MongoDB分片conf服务、shared1、shared2、shared3是否不需要用户和密码登录
bash 复制代码
### 验证conf服务
mongosh --host 192.168.91.61 --port 27017
show dbs
exit

### 验证shared1服务
mongosh --host 192.168.91.61 --port 27101
show dbs
exit

### 验证shared2服务
mongosh --host 192.168.91.61 --port 27102
show dbs
exit

### 验证shared3服务
mongosh --host 192.168.91.61 --port 27103
show dbs
exit

二、修改MongoDB分片集群管理员密码

提示:MongoDB分片集群可以修改管理员密码,也可以删除掉原来的管理员再重新创建新的管理员。

1、修改config服务主节点管理员密码
bash 复制代码
mongosh --host 192.168.91.61 --port 27019

use admin 
db.system.users.find();

db.changeUserPassword('root','123456');
db.auth('root','123456')
2、修改shared1分片主节点管理员密码
bash 复制代码
mongosh --host 192.168.91.61 --port 27101

use admin 
db.system.users.find();

db.changeUserPassword('root','123456');
db.auth('root','123456')
3、修改shared2分片主节点管理员密码
bash 复制代码
mongosh --host 192.168.91.61 --port 27102

use admin 
db.system.users.find();

db.changeUserPassword('root','123456');
db.auth('root','123456')
4、修改shared3分片主节点管理员密码
bash 复制代码
mongosh --host 192.168.91.61 --port 27103

use admin 
db.system.users.find();

db.changeUserPassword('root','123456');
db.auth('root','123456')

三、去掉MongoDB分片集群认证参数注释(三台主机都要操作)

1、停止MongoDB分片集群所有容器
bash 复制代码
systemctl stop mongos
systemctl stop shard3
systemctl stop shard2
systemctl stop shard1
systemctl stop mongod

systemctl status mongos
systemctl status shard3
systemctl status shard2
systemctl status shard1
systemctl status mongod
2、去掉注释用户认证参数
bash 复制代码
[root@epmongodb01 ~]#vim /data/mongodb/configsvr/conf/configsvr.conf
security:
  keyFile: /data/mongodb/keyfile/keyfile
  authorization: enabled

[root@epmongodb01 ~]#vim /data/mongodb/shard1/conf/shard1.conf
security:
  keyFile: /data/mongodb/keyfile/keyfile
  authorization: enabled

[root@epmongodb01 ~]#vim /data/mongodb/shard2/conf/shard2.conf
security:
  keyFile: /data/mongodb/keyfile/keyfile
  authorization: enabled

[root@epmongodb01 ~]#vim /data/mongodb/shard3/conf/shard3.conf
security:
  keyFile: /data/mongodb/keyfile/keyfile
  authorization: enabled

[root@epmongodb01 ~]#vim /data/mongodb/mongos/conf/mongos.conf
security:
  keyFile: /data/mongodb/keyfile/keyfile
3、启动MongoDB分片集群所有容器
bash 复制代码
systemctl start mongod
systemctl start shard1
systemctl start shard2
systemctl start shard3
systemctl start mongos

systemctl status mongod
systemctl status shard1
systemctl status shard2
systemctl status mongos
4、验证MongoDB分片conf服务、shared1、shared2、shared3使用用户和密码登录
bash 复制代码
### 验证conf服务
mongosh --host 192.168.91.61 --port 27017 -u root --p 123456
show dbs
exit

### 验证shared1服务
mongosh --host 192.168.91.61 --port 27101 -u root --p 123456
show dbs
exit

### 验证shared2服务
mongosh --host 192.168.91.61 --port 27102 -u root --p 123456
show dbs
exit

### 验证shared3服务
mongosh --host 192.168.91.61 --port 27103 -u root --p 123456
show dbs
exit
相关推荐
赵锦川几秒前
Oracle数据库序列的创建
数据库
柱子jason33 分钟前
使用IOT-Tree对接工业现场PLC并把采集数据记录到关系数据库中
数据库·物联网·plc·工业物联网·工业自动化·iot-tree·生产线配套
2301_8223754436 分钟前
Python虚拟环境(venv)完全指南:隔离项目依赖
jvm·数据库·python
2301_7903009637 分钟前
Python类型提示(Type Hints)详解
jvm·数据库·python
一路向北⁢1 小时前
Spring Boot 3 整合 SSE (Server-Sent Events) 企业级最佳实践(二)
java·数据库·spring boot·sse·通信
远方16091 小时前
112-Oracle database 26ai下载和安装环境准备
大数据·数据库·sql·oracle·database
2401_838472511 小时前
Python多线程与多进程:如何选择?(GIL全局解释器锁详解)
jvm·数据库·python
光影少年1 小时前
非关系数据库和关系型数据库都有哪些?
数据库·数据库开发·非关系型数据库
2301_822363601 小时前
Python单元测试(unittest)实战指南
jvm·数据库·python
麦兜*1 小时前
深入解析分布式数据库TiDB核心架构:基于Raft一致性协议与HTAP混合负载实现金融级高可用与实时分析的工程实践
数据库·分布式·tidb