1、备份数据
官方文档:https://docs.mongodb.com/manual/core/backups/
- 1.1、备份 mongodump(https://docs.mongodb.com/manual/core/backups/#back-up-with-mongodump)
mongodump -h 192.168.1.235:27017 -d test -o /home/data/dump
- 1.2、恢复备份 mongorestore
mongorestore -h 192.168.1.235:27017 -d test /home/data/dump/test
2、升级
相关文档参考:
https://docs.mongodb.com/manual/release-notes/4.0-upgrade-standalone/
https://docs.mongodb.com/manual/administration/install-on-linux/
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
- 2.1、创建mongodb-org-4.0.repo文件
vim /etc/yum.repos.d/mongodb-org-4.0.repo
内容如下:
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
- 2.2、停止mongodb服务
service mongod stop
- 2.3、更新mongodb安装源与安装
$ sudo yum install -y mongodb-org
$ sudo yum install -y mongodb-org-4.0.10 mongodb-org-server-4.0.10 mongodb-org-shell-4.0.10 mongodb-org-mongos-4.0.10 mongodb-org-tools-4.0.10
You can specify any available version of MongoDB.
However yum upgrades the packages when a newer version becomes available.
To prevent unintended upgrades, pin the package. To pin a package, add the following exclude directive to your /etc/yum.conf
file:
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools
- 2.3、设置兼容版本号
(重点)
查看当前兼容版本:
db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
设置兼容版本:
db.adminCommand( { setFeatureCompatibilityVersion: "4.0" } )
再次使用db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ) 语句查看确认修改成功
- 常用维护命令
service mongod start // 启动mongodb服务
service mongod status // 检查mongodb服务状态
service mongod restart // 重启mongodb服务
service mongod stop // 停止mongodb服务
3、配置复制集
搭建复制集,我是参考开源中国的王孟君 这位朋友的博文,非常感谢他文章。如下给出各个复制集节点关键的配置文件内容:
-
rs0
# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # where to write logging data. systemLog: destination: file logAppend: true path: /usr/local/mongodb/rs0/logs/mongod.log # Where and how to store data. storage: dbPath: /usr/local/mongodb/rs0/data journal: enabled: true # engine: # mmapv1: # wiredTiger: # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo # network interfaces net: port: 27017 bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces. #security: #operationProfiling: replication: oplogSizeMB: 1024 replSetName: sw_dev_mongodb #sharding: ## Enterprise-Only Options #auditLog: #snmp:
-
rs1
# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # where to write logging data. systemLog: destination: file logAppend: true path: /usr/local/mongodb/rs1/logs/mongod.log # Where and how to store data. storage: dbPath: /usr/local/mongodb/rs1/data journal: enabled: true # engine: # mmapv1: # wiredTiger: # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo # network interfaces net: port: 27017 bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces. #security: #operationProfiling: replication: oplogSizeMB: 1024 replSetName: sw_dev_mongodb #sharding: ## Enterprise-Only Options #auditLog: #snmp:
-
rs2
# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # where to write logging data. systemLog: destination: file logAppend: true path: /usr/local/mongodb/rs2/logs/mongod.log # Where and how to store data. storage: dbPath: /usr/local/mongodb/rs2/data journal: enabled: true # engine: # mmapv1: # wiredTiger: # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo # network interfaces net: port: 27017 bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces. #security: #operationProfiling: replication: oplogSizeMB: 1024 replSetName: sw_dev_mongodb #sharding: ## Enterprise-Only Options #auditLog: #snmp:
本文介绍完毕。明天进步一点,积少成多!!!nice,加油!
转载于:https://www.cnblogs.com/kevinlia0/p/11232927.html