Ref: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04
Install GrandNode eCommerce Platform on Ubuntu 16.04 | 18.04 | 18.10
This tutorial installs MongoDB 4.0 Community Edition . For other versions of MongoDB, refer to the corresponding version of the manual.
1. Import the public key used by the package management system.
The Ubuntu package management tools (i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys. Issue the following command to import theMongoDB public GPG Key:
|
1 2 3 4 5 6 7 8 9 10 |
teddy@teddy:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 [sudo] password for teddy: \Executing: /tmp/tmp.boZZpFlZy6/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 gpg: requesting key E52529D4 from hkp server keyserver.ubuntu.com gpg: key E52529D4: public key "MongoDB 4.0 Release Signing Key <packaging@mongodb.com>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) |
2. Create a list file for MongoDB.
Create the list file /etc/apt/sources.list.d/mongodb-org-4.0.list for your version of Ubuntu.
Click on the appropriate tab for your version of Ubuntu. If you are unsure of what Ubuntu version the host is running, open a terminal or shell on the host and execute lsb_release -dc.
|
1 2 |
teddy@teddy:~$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse |
3. Reload local package database.
Issue the following command to reload the local package database:
|
1 |
sudo apt-get update |
4. Install the MongoDB packages.
You can install either the latest stable version of MongoDB or a specific version of MongoDB.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
teddy@teddy:~$ sudo apt-get install -y mongodb-org Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: exuberant-ctags geany-plugin-addons geany-plugin-autoclose geany-plugin-automark geany-plugin-codenav geany-plugin-commander geany-plugin-ctags geany-plugin-defineformat geany-plugin-doc geany-plugin-extrasel geany-plugin-gendoc geany-plugin-geniuspaste geany-plugin-insertnum geany-plugin-keyrecord geany-plugin-latex geany-plugin-lineoperations geany-plugin-lipsum geany-plugin-lua geany-plugin-macro geany-plugin-miniscript geany-plugin-numberedbookmarks geany-plugin-overview geany-plugin-pairtaghighlighter geany-plugin-pg geany-plugin-pohelper geany-plugin-prettyprinter geany-plugin-prj geany-plugin-projectorganizer geany-plugin-sendmail geany-plugin-shiftcolumn geany-plugin-spellcheck geany-plugin-tableconvert geany-plugin-treebrowser geany-plugin-updatechecker geany-plugin-vc geany-plugin-workbench geany-plugin-xmlsnippets geany-plugins-common libctpl2 libssh2-1 libtidy5 libzip5 php7.2-sqlite3 python-cliapp python-markdown python-ttystatus python-yaml qtdeclarative5-controls-plugin qtdeclarative5-dialogs-plugin Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools The following NEW packages will be installed: mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools 0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded. Need to get 73,9 MB of archives. After this operation, 269 MB of additional disk space will be used. Get:1 https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0/multiverse amd64 mongodb-org-shell amd64 4.0.10 [9.797 kB] Get:2 https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0/multiverse amd64 mongodb-org-server amd64 4.0.10 [15,7 MB] Get:3 https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0/multiverse amd64 mongodb-org-mongos amd64 4.0.10 [8.790 kB] Get:4 https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0/multiverse amd64 mongodb-org-tools amd64 4.0.10 [39,6 MB] Get:5 https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0/multiverse amd64 mongodb-org amd64 4.0.10 [3.514 B] Fetched 73,9 MB in 37s (1.948 kB/s) Selecting previously unselected package mongodb-org-shell. (Reading database ... 343352 files and directories currently installed.) Preparing to unpack .../mongodb-org-shell_4.0.10_amd64.deb ... Unpacking mongodb-org-shell (4.0.10) ... Selecting previously unselected package mongodb-org-server. Preparing to unpack .../mongodb-org-server_4.0.10_amd64.deb ... Unpacking mongodb-org-server (4.0.10) ... Selecting previously unselected package mongodb-org-mongos. Preparing to unpack .../mongodb-org-mongos_4.0.10_amd64.deb ... Unpacking mongodb-org-mongos (4.0.10) ... Selecting previously unselected package mongodb-org-tools. Preparing to unpack .../mongodb-org-tools_4.0.10_amd64.deb ... Unpacking mongodb-org-tools (4.0.10) ... Selecting previously unselected package mongodb-org. Preparing to unpack .../mongodb-org_4.0.10_amd64.deb ... Unpacking mongodb-org (4.0.10) ... Processing triggers for man-db (2.7.5-1) ... Setting up mongodb-org-shell (4.0.10) ... Setting up mongodb-org-server (4.0.10) ... Adding system user `mongodb' (UID 127) ... Adding new user `mongodb' (UID 127) with group `nogroup' ... Not creating home directory `/home/mongodb'. Adding group `mongodb' (GID 135) ... Done. Adding user `mongodb' to group `mongodb' ... Adding user mongodb to group mongodb Done. Setting up mongodb-org-mongos (4.0.10) ... Setting up mongodb-org-tools (4.0.10) ... Setting up mongodb-org (4.0.10) ... |
Start MongoDb service
|
1 |
teddy@teddy:~$ sudo service mongod start |
Check MongoDb status
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
teddy@teddy:~$ sudo service mongod status ● mongod.service - MongoDB Database Server Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: Active: active (running) since Rab 2019-06-26 14:40:32 WIB; 9s ago Docs: https://docs.mongodb.org/manual Main PID: 7509 (mongod) Tasks: 27 Memory: 42.4M CPU: 559ms CGroup: /system.slice/mongod.service └─7509 /usr/bin/mongod --config /etc/mongod.conf Jun 26 14:40:32 teddy systemd[1]: Started MongoDB Database Server. |
Verify that the mongod process has started successfully by checking the contents of the log file at/var/log/mongodb/mongod.log for a line reading
|
1 2 3 |
... 2019-06-26T14:40:33.004+0700 I CONTROL [initandlisten] MongoDB starting : pid=7509 port=27017 dbpath=/var/lib/mongodb 64-bit host=teddy ... |
27017 is the default port the standalone mongod listens on.
Create a database
NOTE: Make sure mongodb already start or start it
|
1 |
teddy@teddy:~$ sudo service mongod start |
then run ‘sudo mongo’:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
teddy@teddy:~$ sudo mongo MongoDB shell version v4.0.10 connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("20bf4404-9ed8-44f2-961c-ff5ffc8176e9") } MongoDB server version: 4.0.10 Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user Server has startup warnings: 2019-06-26T20:57:28.164+0700 I STORAGE [initandlisten] 2019-06-26T20:57:28.164+0700 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine 2019-06-26T20:57:28.164+0700 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem 2019-06-26T20:57:28.924+0700 I CONTROL [initandlisten] 2019-06-26T20:57:28.924+0700 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2019-06-26T20:57:28.924+0700 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2019-06-26T20:57:28.924+0700 I CONTROL [initandlisten] --- Enable MongoDB's free cloud-based monitoring service, which will then receive and display metrics about your deployment (disk utilization, CPU, operation statistics, etc). The monitoring data will be available on a MongoDB website with a unique URL accessible to you and anyone you share the URL with. MongoDB may use this information to make product improvements and to suggest MongoDB products and deployment options to you. To enable free monitoring, run the following command: db.enableFreeMonitoring() To permanently disable this reminder, run the following command: db.disableFreeMonitoring() --- > |
type in the terminal this script
|
1 2 3 4 5 6 7 8 |
use grandnode db.createUser( { user: "grandnodeuser", pwd: "grandnode", roles: [ "dbOwner" ] } ) |
it will look:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
> use grandnode switched to db grandnode > db.createUser( ... { ... user: "grandnodeuser", ... pwd: "grandnode", ... roles: ["dbOwner"] ... } ... ) Successfully added user: { "user" : "grandnodeuser", "roles" : [ "dbOwner" ] } > exit bye |