1、上传部署安装包
[ecx@evm-cfdoa2v9upsudl9c27i0 mongo-4.0.3-deploy]$ tree
.
├── bin
│ ├── mongo
│ ├── mongod
│ ├── mongodump
│ ├── mongorestore
│ └── mongos
├── conf
│ ├── Default-Cluster-Configsvr-4.0.conf
│ ├── Default-Cluster-Mongo-4.0.conf
│ ├── Default-Cluster-Mongos-4.0.conf
│ └── Default-Mongo-4.0.conf
├── data
└── log
4 directories, 9 files
2.部署config server
注意记得开启security
2.1 修改配置文件 Default-Cluster-Configsvr-4.0.conf
security:
authorization: enabled
keyFile: /data/mongo4.0_mirror/mongo-4.0.3-deploy/keyfile
# 配置clusterRole
sharding:
clusterRole: configsv
2.2 启动mongod进程
[ecx@evm-cfdoa2v9upsudl9c27h0 conf]$ /data/mongo4.0_mirror/mongo-4.0.3-deploy/bin/mongod -f /data/mongo4.0_mirror/mongo-4.0.3-deploy/conf/Default-Cluster-Configsvr-4.0.conf
2023-02-06T06:42:17.019+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
about to fork child process, waiting until server is ready for connections.
forked process: 32542
child process started successfully, parent exiting
2.3 另外两台机执行相同操作
2.4 初始化副本集
# 连接任意一个mongod进程,使用rs.initiate 进行副本集初始化,使用本地登录
[ecx@evm-cfdoa2v9upsudl9c27i0 tzj]$ /data/mongo4.0_mirror/mongo-4.0.3-deploy/bin/mongo --host /tmp/mongodb-27019.sock
MongoDB shell version v4.0.4
connecting to: mongodb://127.0.0.1:27019/
Implicit session: session { "id" : UUID("64fd777f-1259-464e-8ff0-da27bb26f1ed") }
MongoDB server version: 4.0.3
>
2.5 服务验证
3.部署shard
shard的部署与config server的部署基本相同,主要是配置文件存在如下差异,这里不再重复阐述。
#sharding:
sharding:
clusterRole: shardsvr
部署后,连接其中一台机器的进程,进行初始化
4.部署mongos
4.1 配置参数
sharding:
configDB: set_configserver/ip1:port,ip2:port
4.2 启动mongos进程
4.3 添加shard