Recently I have encountered some problems during my internship. One of our server suddenly goes very very slow, when I try to ping the server, it's always 2000-5000. After checked everything I think may cause the problem and got no answer, I decided to reboot the server.
After hard reboot the virtual machine, it's just the start of the hell. First, I found there's some warning about ruby, then, the mongodb on the server can't restart after reboot.
Luckily, we have already backup our data since one time that we delete our database without "where". We backup our database every two hours to another server. So nothing too bad happens.
Mongodb is such a nasty guy, when I try to restart with ⌘ mongod -f /etc/mongod.conf --fork
, it got stuck. And never showed a single message. At last, I had to delete my exist db and pull it back from our backup server, and then put it into another folder, and re-write the config file, change dbpath parameter, and start with ⌘ mongod -f /etc/mongod.conf --fork
.
Something good about mongo is that it can set a master db and a slave db for backup. For this, all you have to do is start mongo with a config file, and set master=true
or slave=true
in config file.
For example, on you master db server, you should write config file like this:
dbpath=[a-folder]
logpath=[a-folder]
master=true
...
...
On your slave db server, you should write mongo config file like this
port=a-port-different-from-master-db
dbpath=[some-place-to-store-db]
logpath=[some-place-to-store-log]
slave=true
slavedelay=7200// set as seconds
source=[master-db-ip-address]:[master-db-port]
After start both server, your mongodb will sync from you master server to your slave server every 2 hours.
Some tricks about mongod ⌘
Usually start with --dbpath parameter, or use --config(-f as abbr) to start with a config file.
--fork parameter can let mongod server runs on the background.
A single example of this is:
mongod -f /etc/mongod.conf --fork