The system
# cat /etc/issue /etc/debian_version Debian GNU/Linux 7 \n \l 7.9
import the mongodb.org debian repositories key
# apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
add the mongodb.org debian wheezy repository to the apt sources
# echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" > /etc/apt/sources.list.d/mongodb-org-3.0.list
update repositories
# apt-get update
Install the latest release of mongodb-org-shell , mongodb-org-server , mongodb-org-mongos and mongodb-org-tools
# apt-get install mongodb-org
Hold mongodb-org packages
# echo "mongodb-org hold" | dpkg --set-selections # echo "mongodb-org-server hold" | dpkg --set-selections # echo "mongodb-org-shell hold" | dpkg --set-selections # echo "mongodb-org-mongos hold" | dpkg --set-selections # echo "mongodb-org-tools hold" | dpkg --set-selections # grep -A 1 "Package: mongodb-org" /var/lib/dpkg/status Package: mongodb-org-mongos Status: hold ok installed -- Package: mongodb-org-tools Status: hold ok installed -- Package: mongodb-org-server Status: hold ok installed -- Package: mongodb-org-shell Status: hold ok installed -- Package: mongodb-org Status: hold ok installed
Create an Administrator
# mongo > use admin > db.createUser( ... { ... user: "admin" , ... pwd: "passwd" , ... roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] ... } ... )
Enable authentication and change the IP address the mongo server daemon binds to
# egrep -A 1 "bind|security" /etc/mongod.conf #bindIp: 127.0.0.1 bindIp: 192.168.101.86 -- security: authorization: enabledyou may use bindIp: 0.0.0.0 to to bind the MongoDB daemon to all the system IP addresses
restart the mongodb server
# service mongod stop # service mongod start
Log in as admin locally
# mongo --host 192.168.101.86 --port 27017 -u "admin" -p "passwd" --authenticationDatabase "admin"
Log in from a remote host
You better uninstall the official debian repositories mongo stuff and install mongo-org-shell from mongodb.org. I did not encounter any issues using wheezy repositories on jessie hosts. Many "Error: 18 { code: 18, ok: 0.0, errmsg: "auth fails" } " errors are caused when old mongo clients or driver-libraries are trying to talk to new versions of mongodb servers.
# apt-get remove mongodb mongodb-clients mongodb-dev mongodb-server # echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" > /etc/apt/sources.list.d/mongodb-org-3.0.list # apt-get update # apt-get install mongodb-org-shell # echo "mongodb-org-shell hold" | dpkg --set-selectionsand finally login from a remote host
$ mongo 192.168.101.86/admin -u admin -p passwd MongoDB shell version: 3.0.7 connecting to: 192.168.101.86/admin >
Create a database
use amongodb
Create a user that can read and write on the amongodb
> db.createUser( ... { user: "amongouser" , ... pwd: "somepasswd" , ... roles: [ { role: "readWrite", db: "amongodb" } ] ... } ... )
and login from a remote host
$ mongo 192.168.101.86/amongodb -u amongouser -p somepasswd
MongoDB on debian notes