Install MongoDB to Ubuntu 18.04

Import the public key used by the package management system

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

Create a list file for MongoDB.

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

Reload local package database

sudo apt update

Install the latest version of MongoDB

sudo apt install -y mongodb-org

mongodb client

lwk@ubuntu1804:~$ sudo systemctl status mongodb
Unit mongodb.service could not be found.
lwk@ubuntu1804:~$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: https://docs.mongodb.org/manual
lwk@ubuntu1804:~$ sudo systemctl start mongod
lwk@ubuntu1804:~$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-08-23 08:23:39 UTC; 3s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 2268 (mongod)
   CGroup: /system.slice/mongod.service
           └─2268 /usr/bin/mongod --config /etc/mongod.conf

Aug 23 08:23:39 ubuntu1804 systemd[1]: Started MongoDB Database Server.
Aug 23 08:23:39 ubuntu1804 mongod[2268]: 2018-08-23T08:23:39.507+0000 I CONTROL  [main] Automatically disabling TLS 1.0, to force-ena
lwk@ubuntu1804:~$
lwk@ubuntu1804:~$ mongo
MongoDB shell version v4.0.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.1
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: 
2018-08-23T08:23:39.590+0000 I STORAGE  [initandlisten] 
2018-08-23T08:23:39.590+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2018-08-23T08:23:39.590+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2018-08-23T08:23:40.125+0000 I CONTROL  [initandlisten] 
2018-08-23T08:23:40.125+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-23T08:23:40.125+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-08-23T08:23:40.125+0000 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()
---

> 

遠程連接

lwk@qwfys:~$ mongo 01.ubuntu.qwfys.com:27017/test
MongoDB shell version v4.0.1
connecting to: mongodb://01.ubuntu.qwfys.com:27017/test
2018-08-23T17:38:03.153+0800 E QUERY    [js] Error: couldn't connect to server 01.ubuntu.qwfys.com:27017, connection attempt failed: SocketException: Error connecting to 01.ubuntu.qwfys.com:27017 (192.168.56.101:27017) :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed
lwk@qwfys:~$

連接不上,需要將mongodb配置文件/etc/mongod.conf

lwk@ubuntu1804:~$ cat /etc/mongod.conf 
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:
lwk@ubuntu1804:~$ 

中的bindIp的值改爲0.0.0.0,然後重啓服務。修改後,重啓服務後再連接:

lwk@qwfys:~$ mongo 01.ubuntu.qwfys.com:27017/test
MongoDB shell version v4.0.1
connecting to: mongodb://01.ubuntu.qwfys.com:27017/test
MongoDB server version: 4.0.1
Server has startup warnings: 
2018-08-23T09:41:05.597+0000 I STORAGE  [initandlisten] 
2018-08-23T09:41:05.597+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2018-08-23T09:41:05.597+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2018-08-23T09:41:06.326+0000 I CONTROL  [initandlisten] 
2018-08-23T09:41:06.326+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-23T09:41:06.326+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-08-23T09:41:06.326+0000 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()
---

> 

說明已遠程連接成功。

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章