Setting up Mongoser database webserver

Post date: Jul 13, 2014 1:55:10 AM

* Download and start mongodb. Can also use mongo shell for debugging (window version only works correctly in window cmd, not in cygwin)

Enable authentication with --auth

mongod -dbpath data/db --auth

Connect via localhost exception, first time only. Create admin user in admin db. Exit

mongo

> use admin

> db.createUser({user:<user>, pwd:<pwd>, roles:[{role:"userAdminAnyDatabase", db:"admin"}, {role:"dbAdminAnyDatabase", db:"admin"}, {role:"readWriteAnyDatabase", db:"admin"}, {role:"clusterAdmin", db:"admin"}]})

> exit

Login to admin db, authenticate using admin db (can be authenticated by a different db by using --authenticationDatabase <db>) to create/udpate other users.

Note that a role can be defined in another db but is applied to the current db.

mongo -u <adminUser> -p <adminPass> admin

> use <db>

> db.updateUser(<user>, {roles:[{role:"readWrite", db:<db>}]})

> db.createUser({user:<user>, pwd:<pwd>, roles:[{role:"read", db:<db>}]})

> db.getUsers()

Add default indexing for GridFS collections (if driver didn't already create them)

> db.<col>.chunks.ensureIndex( { files_id: 1, n: 1 }, { unique: true } );

> db.<col>.files.ensureIndex( {filename: 1, updateDate: 1} );

(Optional) Login to a database with username and password

mongo -u <user> -p <pass> <db> 

* Download the tarball (not github clone) and build memcached. Note that libevent is a major dependency. Be sure that firewall/antivirus shields are off, otherwise test will hang indefinitely.

configure --with-libevent=/usr/lib/

make

make test  % some test will fail, but should not hang indefinitely.

make install % should be in /usr/local/bin

memcached % default port 11211

memcached -p 11212

* Configure Mongoser according to this link https://sites.google.com/site/mongodbjavarestserver/con. Build mongoser using ant. mongoser.sh only works in ubuntu due to different in classpath separator, i.e. ";" in window and ":" in ubuntu.

ant resolve % in the folder with build.xml

mkdir logs % create log folder

ant run

(For SSL server) Generate key pair and self-signed certificate using openssl. Loading Keys and Certificates via PKCS12 format to Mongoser's config. More on SSL http://wiki.eclipse.org/Jetty/Howto/Configure_SSL.

openssl genrsa -aes256 -out jetty.key 2048 % gen key pair

openssl req -new -x509 -key jetty.key -out jetty.crt -days 10000 % gen self-signed cert

(Alternative) openssl req -new -key jetty.key -out jetty.csr % generate a cert signing request for CA

openssl pkcs12 -inkey jetty.key -in jetty.crt -export -out jetty.pkcs12  % combines the keys in jetty.key and the certificate in the jetty.crt file into the jetty.pkcs12 file

keytool -importkeystore -srckeystore jetty.pkcs12 -srcstoretype PKCS12 -destkeystore keystore % use keytool to import a PKCS12 file

(Optional) keytool -list -keystore <store> -storepass <pwd> -v

(Optional) keytool -delete -alias <alias> -keystore <store> -storepass <pwd>

(Optional) openssl x509 -in <in.crt> -outform PEM -out <out.crt>

For Android certificate. More info can be found in [1]

importcert.sh <CA cert pem file> % gen Bouncy Castle key store file (BKS format) for android

(Optional) Enable ICMP server on Window 7 for simple connection testing: http://www.hammer-software.com/icmpgphowto.shtml

Note:

Mongodb is 6 hours ahead of the Mongoser webserver/Central Time (US)

[1] http://nelenkov.blogspot.com/2011/12/using-custom-certificate-trust-store-on.html