How to Re-intialize MongoDB in Openstack

Following is the procedure to re-initialize MongoDB in OpenStack

1. Stop mongod on all the nodes (if it is running). If service is in fail state then leave it as is

2. Remove all the files in /var/lib/mongod. If you are moving the mongodb directory and making new one make sure to run restorecon command
    # mv /var/lib/mongodb /var/lib/mongodb-old 
    # mkdir /var/lib/mongodb
    # chown mongodb.mongodb /var/lib/mongodb
    # restorecon /var/lib/mongodb

3. start the mongodb on first controller

4. Get the mongo service ip from ceilometer.conf file
    # cat /etc/ceilometer/ceilometer.conf | grep mongo

5. login to the mongodb
    # mongo x.y.z.a

6. Intiate the replicaset
    > rs.initiate()

7. Make the current node as master

8. Start the mongodb on other two controllers

9. Add other two nodes as members from first controller

10. Confirm the replica set status

11. Restart the Ceilometer collector service
      # systemctl restart openstack-ceilometer-collector.service

The above procedure helps in reclaiming the space taken up MongoDB. You can also reduce the time_to_live parameter in ceilometer.conf file to reduce the size of DB.