How to auto-start MongoDB on CentOS reboot?

Your best bet is to install the rpms provided by 10gen (makers of mongodb)

http://www.mongodb.org/display/DOCS/CentOS+and+Fedora+Packages

That will install a init.d script for you that you can run

//mongod service

chkconfig mongod on

You need to write an "init script" to start the service when the system boots. A quick Google search for "writing init scripts redhat" will turn up several useful references. This seemed like a reasonable start:

  • http://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html

If you want a quick-and-dirty solution, you can simply add your command to the end of /etc/rc.d/rc.local, which gets executed after all the other init scripts have completed.