MongoDB:ubuntu18安装安装MongoDB 4.0社区版

环境:

ocean@ubuntu:~$ lsb_release -dc
Description:	Ubuntu 18.10
Codename:	cosmic

安装

1、导入mongodb public gpg密钥:

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
Executing: /tmp/apt-key-gpghome.UW1KoNPvQr/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
gpg: key 68818C72E52529D4: public key "MongoDB 4.0 Release Signing Key <packaging@mongodb.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1

2、为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
deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse

3、下载数据库

$ sudo apt-get update
$ sudo apt-get install -y mongodb-org
  • 这是通过包管理器安装,在安装过程中会创建数据目录/var/lib/mongodb和日志目录/var/log/mongodb。
  • 默认情况下,mongodb使用mongodb用户帐户运行。如果更改运行MongoDB进程的用户,还必须修改对数据和日志目录的权限,以便此用户可以访问这些目录。
  • 官方的mongodb包包含一个配置文件(/etc/mongod.conf)。这些设置(如数据目录和日志目录规范)在启动时生效。也就是说,如果在MongoDB实例运行时更改配置文件,则必须重新启动该实例以使更改生效。
$ sudo 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:

运行

1、重启、启动、停止、查看mongoDB的状态

$ sudo service mongod start
$ sudo service mongod status
$ sudo service mongod stop
$ sudo service mongod restart

2、启动mongoDB的shell

$ mongo
MongoDB shell version v4.0.6
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("db4c1099-8f86-4b65-9814-8027c63d368e") }
MongoDB server version: 4.0.6
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-03-17T15:46:20.063+0800 I STORAGE  [initandlisten] 
2019-03-17T15:46:20.063+0800 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-03-17T15:46:20.063+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-03-17T15:46:21.055+0800 I CONTROL  [initandlisten] 
2019-03-17T15:46:21.055+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-03-17T15:46:21.055+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-03-17T15:46:21.055+0800 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()
---

完全卸载

$ sudo service mongod stop
$ sudo apt-get purge mongodb-org*
$ sudo rm -r /var/log/mongodb
$ sudo rm -r /var/lib/mongodb

参考:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/#uninstall-mongodb-community-edition

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值