Linux下(乌班图)安装MongoDb

Mongodb的安装

第一步:更新软件源列表

打开Linux终端 (管他三七二十一,我们先对软件源列表更新下,防止安装软件的时候出现无法定位软件包的问题)

执行更新软件源列表命令:sudo apt-get udpate-get udpate

第二步:安装MongoDb

执行安装MongoDb命令:sudo apt-get install mongodbsudo apt-get install mongodb

第三部:启动MongoDb服务

执行启动MongoDb命令:sudo service mongodb startsudo service mongodb start

第四步:修改配置文件

用vi打开MongoDb的配置文件,将bind_ip=127.0.0.1注释掉,或改成bind_ip=0.0.0.0

如有需要请参考:mongodb.conf配置文件详解

bind_ip:绑定地址。默认127.0.0.1,只能通过本地连接。进程绑定和监听来自这个地址上的应用连接。要是需要给其他服务器连接,则需要注释掉这个或则把IP改成本机地址,如192.168.200.201[其他服务器用 mongo --host=192.168.200.201 连接] ,可以用一个逗号分隔的列表绑定多个IP地址。

执行启动MongoDb命令:sudo vi /etc/mongodb.confsudo vi /etc/mongodb.conf

第五步:重启MongoDb服务

执行重启MongoDb命令:sudo service mongodb restartsudo service mongodb restart
sudo service mongod start
sudo service mongod restart
sudo service mongod stop

第六步:添加防火墙规则

允许指定的IP访问这个MongoDb服务 (Mongodb默认的端口号是27017)

Mongodb的卸载

一:删除Mongodb包本身

这将删除只是 mongodb 包本身。

执行删除MongoDb包命令:sudo apt-get remove mongodbsudo apt-get remove mongodb

二:卸载 mongodb 和它的依赖项

这将删除 mongodb 软件包和不再需要的任何其他依赖项包

执行卸载MongoDb及依赖项命令:sudo apt-get remove --auto-remove mongodbsudo apt-get remove --auto-remove mongodb

三:清除您的配置数据

如果你还想要删除您的本地/config 文件为 mongodb,请执行以下命令。

sudo apt-get purge mongodb
或者
sudo apt-get purge --auto-remove mongodb

MongoDB GUI 客户端的安装

MongoDB客户端有很多,有免费的、有收费的,这里推荐一个Robo 3T

配置文件内容:英文

# 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 on 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 will result in greatly limited
# functionality
#noscripting = true

# Turns off table scans.  Any query that 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 this 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

配置文件中文

#日志文件位置
logpath=/data/db/journal/mongodb.log  (这些都是可以自定义修改的)

# 以追加方式写入日志
logappend=true

# 是否以守护进程方式运行
fork = true

# 默认27017
#port = 27017

# 数据库文件位置
dbpath=/data/db

# 启用定期记录CPU利用率和 I/O 等待
#cpu = true

# 是否以安全认证方式运行,默认是不认证的非安全方式
#noauth = true
#auth = true

# 详细记录输出
#verbose = true

# Inspect all client data for validity on receipt (useful for
# developing drivers)用于开发驱动程序时验证客户端请求
#objcheck = true

# Enable db quota management
# 启用数据库配额管理
#quota = true
# 设置oplog记录等级
# Set oplogging level where n is
#   0=off (default)
#   1=W
#   2=R
#   3=both
#   7=W+some reads
#diaglog=0

# Diagnostic/debugging option 动态调试项
#nocursors = true

# Ignore query hints 忽略查询提示
#nohints = true
# 禁用http界面,默认为localhost:28017
#nohttpinterface = true

# 关闭服务器端脚本,这将极大的限制功能
# Turns off server-side scripting.  This will result in greatly limited
# functionality
#noscripting = true
# 关闭扫描表,任何查询将会是扫描失败
# Turns off table scans.  Any query that would do a table scan fails.
#notablescan = true
# 关闭数据文件预分配
# Disable data file preallocation.
#noprealloc = true
# 为新数据库指定.ns文件的大小,单位:MB
# Specify .ns file size for new databases.
# nssize =

# Replication Options 复制选项
# in replicated mongo databases, specify the replica set name here
#replSet=setname
# maximum size in megabytes for replication operation log
#oplogSize=1024
# path to a key file storing authentication info for connections
# between replica set members
#指定存储身份验证信息的密钥文件的路径
#keyFile=/path/to/keyfile

猜你喜欢

转载自blog.csdn.net/Fanbin168/article/details/80988803