=====Overview===== In this method, we simply export the database from the old release and import it in the new release. During this, the old database can be removed but it is best practice advise to keep the old release working on the old server just in case. The steps for this method are simple: - Make a backup of the database or server (using mongodump) - Install the new software (preferably the latest) - Import the backup into the release (using mongorestore) So let's get going: =====Backup===== As mentioned before, mongo has two types of backup: * Physical * Logical In that method, we are using the LOGICAL one, as the physical will NOT be compatible with the new release. [root@localhost backup]# mongodump --out /root/backup/`date +"%m-%d-%y"` 2019-09-16T06:31:47.226-0400 writing admin.system.version to 2019-09-16T06:31:47.227-0400 done dumping admin.system.version (1 document) 2019-09-16T06:31:47.227-0400 writing admin.artists to 2019-09-16T06:31:47.227-0400 done dumping admin.artists (2 documents) [root@localhost backup]# This command will export all not system databases and relations in the system. =====Install new release===== After that install the new software, either on the same server: By deleting the old one and installing the new one OR on a new server. [root@localhost ~]# yum install mongodb-org-server.x86_64 Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.it4i.cz * extras: mirror.it4i.cz * updates: mirror.it4i.cz | 2.5 kB 00:00:00 mongodb-org-4.2 | 2.5 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package mongodb-org-server.x86_64 0:4.2.14-1.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================================================================================================================= Updating: mongodb-org-server x86_64 4.2.14-1.el7 mongodb-org-4.2 20 M Transaction Summary ============================================================================================================================================================================================================================================= Upgrade 1 Package Total download size: 20 M Is this ok [y/d/N]: y Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. mongodb-org-server-4.2.14-1.el7.x86_64.rpm | 20 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : mongodb-org-server-4.2.14-1.el7.x86_64 1/2 2/2 Verifying : mongodb-org-server-4.2.14-1.el7.x86_64 1/2 2/2 Updated: mongodb-org-server.x86_64 0:4.2.14-1.el7 Complete! [root@localhost ~]# =====Instance Modifcations===== There are couple changes to be done in order to secure our databases: ====Change the IP==== In order to change the IP, modify the /etc/mongod.conf file as so: # network interfaces net: port: 27017 bindIp: 172.27.1.245 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. Restart the instance with: [root@hostname hunter_dev]# service mongod restart Redirecting to /bin/systemctl restart mongod.service ====Add users==== Users have to be added so we can enable security authentication: [root@tbp-cx-mdb01 hunter_dev]# mongo 172.27.1.245 MongoDB shell version v4.0.13 connecting to: mongodb://172.27.1.245:27017/test?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("4c9e2e3d-4224-4731-89ad-3a2cca29110a") } MongoDB server version: 4.0.13 Server has startup warnings: 2019-10-25T15:48:26.654+0200 I STORAGE [initandlisten] 2019-10-25T15:48:26.655+0200 I STORAGE [initandlisten] ** WARNING: Support for MMAPV1 storage engine has been deprecated and will be 2019-10-25T15:48:26.655+0200 I STORAGE [initandlisten] ** removed in version 4.2. Please plan to migrate to the wiredTiger 2019-10-25T15:48:26.655+0200 I STORAGE [initandlisten] ** storage engine. 2019-10-25T15:48:26.655+0200 I STORAGE [initandlisten] 2019-10-25T15:48:26.662+0200 I STORAGE [initandlisten] 2019-10-25T15:48:26.662+0200 I STORAGE [initandlisten] ** WARNING: Readahead for /var/lib/mongo is set to 4096KB 2019-10-25T15:48:26.662+0200 I STORAGE [initandlisten] ** We suggest setting it to 256KB (512 sectors) or less 2019-10-25T15:48:26.662+0200 I STORAGE [initandlisten] ** http://dochub.mongodb.org/core/readahead 2019-10-25T15:48:27.012+0200 I CONTROL [initandlisten] 2019-10-25T15:48:27.012+0200 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2019-10-25T15:48:27.012+0200 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2019-10-25T15:48:27.012+0200 I CONTROL [initandlisten] 2019-10-25T15:48:27.013+0200 I CONTROL [initandlisten] 2019-10-25T15:48:27.013+0200 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2019-10-25T15:48:27.013+0200 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2019-10-25T15:48:27.013+0200 I CONTROL [initandlisten] 2019-10-25T15:48:27.013+0200 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2019-10-25T15:48:27.013+0200 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2019-10-25T15:48:27.013+0200 I CONTROL [initandlisten] --- Enable MongoDB's free cloud-based monitoring service, which will then receive and display metrics about your deployment (disk utilization, CPU, operation statistics, etc). The monitoring data will be available on a MongoDB website with a unique URL accessible to you and anyone you share the URL with. MongoDB may use this information to make product improvements and to suggest MongoDB products and deployment options to you. To enable free monitoring, run the following command: db.enableFreeMonitoring() To permanently disable this reminder, run the following command: db.disableFreeMonitoring() --- > use admin switched to db admin > db.createUser( ... { ... "user" : "adminDBA", ... pwd: "3kHq9mNqMcxIDITbbEEq", ... "roles" : [ ... { ... "role" : "userAdminAnyDatabase", ... "db" : "admin" ... }, ... { ... "role" : "root", ... "db" : "admin" ... }, ... { ... "role" : "dbOwner", ... "db" : "admin" ... }, ... { ... "role" : "userAdmin", ... "db" : "admin" ... } ... ] ... } ... ) ====Enable security==== Secure authentication has to be enabled again in the /etc/mongod.conf as follows: security: authorization: enabled Again restart the service: [root@hostname hunter_dev]# service mongod restart Redirecting to /bin/systemctl restart mongod.service [root@hostname hunter_dev]# =====Import the backup into the new release===== After that, we can simply import the exported data into the new release as follows: [root@hostname hunter_dev]# mongorestore --host 172.27.1.245 -u adminDBA -p 'password' --port 27017 /root/backup/10-25-19/ 2019-10-25T16:15:55.813+0200 preparing collections to restore from 2019-10-25T16:15:55.855+0200 reading metadata for hunter_dev.livefishs.rar.chunks from /root/backup/10-25-19/hunter_dev/livefishs.rar.chunks.metadata.json 2019-10-25T16:15:55.879+0200 reading metadata for monitor.config from /root/backup/10-25-19/monitor/config.metadata.json ------------------------------------------------------------------------------ 2019-10-25T16:15:58.564+0200 finished restoring hunter_dev.billFish (0 documents) 2019-10-25T16:15:58.564+0200 restoring users from /root/backup/10-25-19/admin/system.users.bson 2019-10-25T16:15:58.638+0200 done