MongoDB Learning: MONGO Installation and remote access

Source: Internet
Author: User
Tags mongodb server openssl openssl version dochub

One-click Installation via apt-get install MONGO under Linux MONGO

The configuration file for MONGO after installation is located in /etc/mongodb.conf. It 's inside . MONGO configuration, the file content is as follows: Important mainly have the following items:

1 DBPath: Where the database files are stored

2 logpath: where log is stored

3 Bind_ip = 127.0.0.1. When installed, only local access is allowed by default. The IP that restricts access is 127.0.0.1. If you want to allow all addresses to be accessed. You need to comment out this line

4 Port: Port number to access

5 Auth=true ( Add account , password Authentication )

[Email protected]:/home/zhf# cat/etc/mongodb.conf

# mongodb.conf

# Where to store the data.

Dbpath=/var/lib/mongodb

#where to log

Logpath=/var/log/mongodb/mongodb.log

Logappend=true

BIND_IP = 127.0.0.1

#port = 27017

# Enable Journaling, http://www.mongodb.org/display/DOCS/Journaling

Journal=true

# Enables periodic logging of CPU utilization and I/O wait

#cpu = True

# Turn on/off security. OFF is currently the default

#noauth = True

#auth = True

# Verbose logging output.

#verbose = True

# Inspect all client data for validity in receipt (useful for

# Developing drivers)

#objcheck = True

# Enable DB Quota Management

#quota = True

# Set oplogging level where n is

# 0=off (default)

# 1=w

# 2=r

# 3=both

# 7=w+some Reads

#oplog = 0

# diagnostic/debugging option

#nocursors = True

# Ignore Query Hints

#nohints = True

# Disable The HTTP interface (Defaults to localhost:27018).

#nohttpinterface = True

# Turns off server-side scripting. This would result in greatly limited

# functionality

#noscripting = True

# Turns off table scans. Any query this would do a table scan fails.

#notablescan = True

# Disable data File preallocation.

#noprealloc = True

# specify. ns file size for new databases.

# nssize = <size>

# Accout token for Mongo monitoring server.

#mms-token = <token>

# server name for Mongo monitoring server.

#mms-name = <server-name>

# Ping interval for Mongo monitoring server.

#mms-interval = <seconds>

# Replication Options

# in replicated MONGO databases, specify here whether the is a slave or master

#slave = True

#source = master.example.com

# Slave only:specify A single database to replicate

#only = master.example.com

# or

#master = True

#source = slave.example.com

# Address of a server to pair with.

#pairwith = <server:port>

# Address of Arbiter server.

#arbiter = <server:port>

# automatically resync if slave data is stale

#autoresync

# Custom size for replication operation log.

#oplogSize = <MB>

# Size limit for in-memory storage of op IDs.

#opIdMem = <bytes>

# SSL Options

# Enable SSL on normal ports

#sslOnNormalPorts = True

# SSL Key file and password

#sslPEMKeyFile =/etc/ssl/mongodb.pem

#sslPEMKeyPassword = Pass

After installation, enter the MONGO command to enter the Shell interface

[Email protected]:/home/zhf# MONGO

MongoDB Shell version v3.4.7

Connecting to:mongodb://127.0.0.1:27017

MongoDB Server version:3.4.7

Server has startup warnings:

2017-12-12t20:16:00.856+0800 I STORAGE [Initandlisten]

2017-12-12t20:16:00.856+0800 I STORAGE [initandlisten] * * warning:using The XFS filesystem is strongly recommended with The Wiredtiger storage Engine

2017-12-12t20:16:00.856+0800 I STORAGE [Initandlisten] * * See Http://dochub.mongodb.org/core/prodnotes-filesyste M

2017-12-12t20:16:04.012+0800 I CONTROL [Initandlisten]

2017-12-12t20:16:04.012+0800 I control [Initandlisten] * * warning:access CONTROL is not enabled for the database.

2017-12-12t20:16:04.012+0800 I CONTROL [initandlisten] * * Read and Write access to data and configuration is UNR Estricted.

2017-12-12t20:16:04.012+0800 I CONTROL [Initandlisten]

All users can be queried by Db.system.users.find ()

Add user name and account

> Db.createuser ({User: ' ZHF ', pwd: ' 123 ', roles:[' Useradminanydatabase ']})

Successfully added User: {"user": "ZHF", "Roles": ["Useradminanydatabase"]

To set up a remote connection:

The configuration file is modified as follows: Comment out bind_ip,

#bind_ip = 127.0.0.1

Port = 27017

Add a routing development 27017 Port

[Email protected]:/home/zhf# iptables-a input-p tcp-m State--state new-m TCP--dport 27017-j ACCEPT

Start the Mong service.

[Email protected]:/var/lib/mongodb# mongod--dbpath/var/lib/mongodb

2017-12-12t22:39:13.060+0800 I CONTROL [Initandlisten] MongoDB starting:pid=16691 port=27017 Dbpath=/var/lib/mongodb 6 4-bit Host=zhf-maple

2017-12-12t22:39:13.061+0800 I CONTROL [initandlisten] DB version v3.4.7

2017-12-12t22:39:13.061+0800 I CONTROL [Initandlisten] git VERSION:CF38C1B8A0A8DCA4A11737581BEAFEF4FE120BCD

2017-12-12t22:39:13.061+0800 I CONTROL [Initandlisten] OpenSSL version:openssl 1.0.2g 1 Mar 2016

2017-12-12t22:39:13.061+0800 I CONTROL [Initandlisten] Allocator:tcmalloc

2017-12-12t22:39:13.061+0800 I CONTROL [Initandlisten] Modules:none

2017-12-12t22:39:13.061+0800 I CONTROL [Initandlisten] Build environment:

2017-12-12t22:39:13.061+0800 I CONTROL [Initandlisten] distarch:x86_64

2017-12-12t22:39:13.061+0800 I CONTROL [Initandlisten] target_arch:x86_64

2017-12-12t22:39:13.061+0800 I CONTROL [Initandlisten] options: {storage: {dbPath: '/var/lib/mongodb '}}

2017-12-12t22:39:13.079+0800 E NETWORK [Initandlisten] Listen (): Bind () failed Address already in use for socket:0.0.0.0 : 27017

2017-12-12t22:39:13.079+0800 E NETWORK [Initandlisten] addr already in use

2017-12-12t22:39:13.079+0800 E NETWORK [Initandlisten] Failed to set up sockets during startup.

2017-12-12t22:39:13.079+0800 E STORAGE [Initandlisten] Failed to set up listener:InternalError:Failed to set up sockets

2017-12-12t22:39:13.079+0800 I NETWORK [Initandlisten] shutdown:going to close listening sockets ...

2017-12-12t22:39:13.079+0800 I NETWORK [Initandlisten] shutdown:going to flush diaglog ...

2017-12-12t22:39:13.079+0800 I CONTROL [Initandlisten] now exiting

2017-12-12t22:39:13.079+0800 I CONTROL [Initandlisten] shutting down with code:48

This indicates that the port and address are already in use. With the netstat command you can see that there is indeed a

[Email protected]:/var/lib/mongodb# Netstat-anp|more

Activating an Internet connection ( Server and established connection )

Proto recv-q send-q Local address Foreign address State Pid/program Name

TCP 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 749/mongod

Kill the running process: kill-9 749 and restart the service again:

[Email protected]:/var/lib/mongodb# mongod--dbpath/var/lib/mongodb

2017-12-12t22:41:25.966+0800 I CONTROL [Initandlisten] MongoDB starting:pid=16780 port=27017 Dbpath=/var/lib/mongodb 6 4-bit Host=zhf-maple

2017-12-12t22:41:25.966+0800 I CONTROL [initandlisten] DB version v3.4.7

2017-12-12t22:41:25.966+0800 I CONTROL [Initandlisten] git VERSION:CF38C1B8A0A8DCA4A11737581BEAFEF4FE120BCD

2017-12-12t22:41:25.966+0800 I CONTROL [Initandlisten] OpenSSL version:openssl 1.0.2g 1 Mar 2016

2017-12-12t22:41:25.966+0800 I CONTROL [Initandlisten] Allocator:tcmalloc

2017-12-12t22:41:25.966+0800 I CONTROL [Initandlisten] Modules:none

2017-12-12t22:41:25.966+0800 I CONTROL [Initandlisten] Build environment:

2017-12-12t22:41:25.966+0800 I CONTROL [Initandlisten] distarch:x86_64

2017-12-12t22:41:25.966+0800 I CONTROL [Initandlisten] target_arch:x86_64

2017-12-12t22:41:25.966+0800 I CONTROL [Initandlisten] options: {storage: {dbPath: '/var/lib/mongodb '}}

2017-12-12t22:41:25.984+0800 I-[Initandlisten] detected data files In/var/lib/mongodb created by the ' Wiredtiger ' Storage engine, so setting the active storage engine to ' Wiredtiger '.

2017-12-12t22:41:25.984+0800 I STORAGE [Initandlisten]

2017-12-12t22:41:25.984+0800 I STORAGE [initandlisten] * * warning:using The XFS filesystem is strongly recommended with The Wiredtiger storage Engine

2017-12-12t22:41:25.984+0800 I STORAGE [Initandlisten] * * See Http://dochub.mongodb.org/core/prodnotes-filesyste M

2017-12-12t22:41:25.984+0800 I STORAGE [Initandlisten] Wiredtiger_open config:create,cache_size=3417m,session_max= 20000,eviction= (threads_min=4,threads_max=4), config_base=false,statistics= (FAST), log= (enabled=true,archive= True,path=journal,compressor=snappy), file_manager= (close_idle_time=100000), checkpoint= (Wait=60,log_size=2GB), Statistics_log= (wait=0),

2017-12-12t22:41:27.096+0800 I CONTROL [Initandlisten]

2017-12-12t22:41:27.096+0800 I control [Initandlisten] * * warning:access CONTROL is not enabled for the database.

2017-12-12t22:41:27.096+0800 I CONTROL [initandlisten] * * Read and Write access to data and configuration is UNR Estricted.

2017-12-12t22:41:27.096+0800 i CONTROL [initandlisten] * * Warning:you is running this process as the root user, which I s not recommended.

2017-12-12t22:41:27.096+0800 I CONTROL [Initandlisten]

2017-12-12t22:41:27.103+0800 I ftdc [Initandlisten] Initializing full-time diagnostic data capture with directory '/va R/lib/mongodb/diagnostic.data '

2017-12-12t22:41:27.104+0800 I NETWORK [thread1] waiting for connections on port 27017

2017-12-12t22:41:28.028+0800 I ftdc [FTDC] Unclean full-time diagnostic data capture shutdown detected, found interim File, some metrics may have been lost. Ok

2017-12-12t22:41:50.776+0800 I NETWORK [Thread1] connection accepted from 192.168.0.11:35718 #1 (1 connection now OPEN)

2017-12-12t22:46:10.454+0800 I-[conn1] End Connection 192.168.0.11:35718 (1 connection now OPEN)

2017-12-12t22:46:54.889+0800 I NETWORK [Thread1] connection accepted from 192.168.0.11:35734 #2 (1 connection now OPEN)

On behalf of the service opened successfully.

Access the server's admin database via MONGO 192.168.0.12:27017/admin on the client

[Email protected]:~# MONGO 192.168.0.12:27017/admin

MongoDB Shell version:2.6.10

Connecting To:192.168.0.12:27017/admin

Server has startup warnings:

2017-12-12t22:41:25.984+0800 I STORAGE [Initandlisten]

2017-12-12t22:41:25.984+0800 I STORAGE [initandlisten] * * warning:using The XFS filesystem is strongly recommended with The Wiredtiger storage Engine

2017-12-12t22:41:25.984+0800 I STORAGE [Initandlisten] * * See Http://dochub.mongodb.org/core/prodnotes-filesyste M

2017-12-12t22:41:27.096+0800 I CONTROL [Initandlisten]

2017-12-12t22:41:27.096+0800 I control [Initandlisten] * * warning:access CONTROL is not enabled for the database.

2017-12-12t22:41:27.096+0800 I CONTROL [initandlisten] * * Read and Write access to data and configuration is UNR Estricted.

2017-12-12t22:41:27.096+0800 i CONTROL [initandlisten] * * Warning:you is running this process as the root user, which I s not recommended.

2017-12-12t22:41:27.096+0800 I CONTROL [Initandlisten]

>

Shut down the server. There are two main ways of doing this:

1 Enter Ctrl + C to close. This shutdown will wait for the current ongoing operation to complete, so it is still a clean shutdown method.

2 log in to the database. Then enter the following command to close

> Use admin

Switched to DB admin

> Db.shutdownserver ()

Server should is down ...

MongoDB Learning: MONGO Installation and remote access

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.