未加星标

MongoDB Walkthrough

字体大小 | |
[数据库(综合) 所属分类 数据库(综合) | 发布者 店小二03 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏

INTRODUCTION

MongoDB is a quite popular no-SQL database system. In this article, I am going to write somethingabout this database system. Yes, no-SQL databases are meant for performanceand scalability, however, like relational databases, there exists no relation between tables or collections in the database.

MongoDB is super easy, can be run in a single host, and data is stored in document format(as JSON objects) which makes very easy to analyzeor export. It provides a nice client GUI tool called "MongoDB Compass". The storage of data is transparent in the sense that we can copy the database and reuseit. Also, there are flexibilities regarding the log files, data files, and config files.

I have used another alternative no-SQL databasecalled Cassandra , which is also powerful and popular. Cassandra, however, requires more resources than MongoDB. Also, I could not get any better GUI client tools. Configuration is also a bit different compared to MongoDB. Cassandra is Java-based, MongoDB is C++ based.

INSTALLATION:

There are methods to install:

1) Using Debianfile available from

https://repo.mongodb.org/apt/ubuntu/dists/xenial/mongodb-org/4.0/multiverse/binary-amd64/mongodb-org-server_4.0.4_amd64.deb

2) Using Terminal

sudo apt install mongodb-server

sudo apt install mongodb-clients

3) Using installation files from

http://downloads.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-v4.0-latest.tgz

CONFIGURATION


The above mentioned two methods are quite straightforward, do not basically need any configuration.

I am writing the configuration of installation step 3 mentioned above.

# After downloading, extract the file and place contents into /opt/mongodb. Create a short link of the original extracted folder into /etc/mongodb.

# Set /opt/mongodb/bin as PATH variable so that we can directlyrun MongoDB commands.

# Create a folder /data/db

sudo mkdir -p /data/db

# Start Server

sudo mongod --dbpath /data/db --logpath /var/log/mongodb/mongod.log --fork


or create a config file /etc/mongod.conf with the following contents:

# mongod.conf

systemLog:

destination: file

path: "/var/log/mongodb/mongod.log"

logAppend: true

storage:

journal:

enabled: true

processManagement:

fork: true

net:

bindIp: 0.0.0.0

port: 27017

And run the following command:

sudo mongod -f /etc/mongod.conf


# Stop Server


sudomongod--shutdown
# Change bind address
The default is localhost can connect to the server, and any connections from outside are blocked. So, we need to change the bind address.
We change the file /etc/mongod.conf created above step.
Default is:
net:

bindIp: 127.0.0.1


Change it to
net:

bindIp: 0.0.0.0 # allow connections from anywhere


# Configure autostart

Everytime system restarts, the server should also start. We define a cronjob for that(/etc/cron.d/mongodb) with the following content:

@reboot root sleep 60 && /opt/mongodb/bin/mongod -f /etc/mongod.conf

We have defined one minute(60 seconds) sleep before starting mongodb server.

An alternative will be to create a service, and we can enable service to start at the time system starts.

CLIENTS:

1. Command Line Tool : mongo

We can connect using mongo. Mongo uses default values to connect to the server. There are several options for this command.

After running the command, we go into environment we can run mongodb commands to access database and carry out sevaral dabtase related operations.

2. GUI Administration: MongoDB Compass

This is a nice GUI tool, we can carry out operations on collections and documents using this nice GUI tool.

3. Create user

Using mongo command line tool, we create a user.

use admin

db.createUser(

{

user: "myUserAdmin",

pwd: "abc123",

roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]

}

)


We have to provide option--auth in mongod command to enable authorizaton.
Or add the following line in the /etc/mongod.conf file:
security:

authorization: enabled

本文数据库(综合)相关术语:系统安全软件

代码区博客精选文章
分页:12
转载请注明
本文标题:MongoDB Walkthrough
本站链接:https://www.codesec.net/view/621394.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(综合) | 评论(0) | 阅读(53)