mongodb 解压安装_mongo01linux安装MongoServer

937e12b727a0415e9f77d59834c35b6a.png

MongoDB Community Server 下载
MongoDB官网地址: https://www.mongodb.com/try/download/community
我下载的是:mongodb-linux-x86_64-rhel70-4.4.3.tgz

机器准备:Centos7

aaf4d2a9ed3c37b5b80b8a892a22d080.png

1. 安装 mongodb

1.1 解压

解压 mongodb-linux-x86_64-rhel70-4.4.3.tgz 到 /usr/local,然后将解压目录重命名为 mongodb-4.4.3

[root@docker01 local]# pwd
/usr/local
[root@docker01 local]# ll mongodb-linux-x86_64-rhel70-4.4.3.tgz
-rw-r--r--. 1 root root 71417896 1月 14 2021 mongodb-linux-x86_64-rhel70-4.4.3.tgz
# 解压 `mongodb-linux-x86_64-rhel70-4.4.3.tgz`
[root@docker01 local]# tar -zxvf mongodb-linux-x86_64-rhel70-4.4.3.tgz
mongodb-linux-x86_64-rhel70-4.4.3/LICENSE-Community.txt
mongodb-linux-x86_64-rhel70-4.4.3/MPL-2
mongodb-linux-x86_64-rhel70-4.4.3/README
mongodb-linux-x86_64-rhel70-4.4.3/THIRD-PARTY-NOTICES
mongodb-linux-x86_64-rhel70-4.4.3/bin/install_compass
mongodb-linux-x86_64-rhel70-4.4.3/bin/mongo
mongodb-linux-x86_64-rhel70-4.4.3/bin/mongod
mongodb-linux-x86_64-rhel70-4.4.3/bin/mongos
# 将解压目录重命名为 `mongodb-4.4.3`
[root@docker01 local]# mv mongodb-linux-x86_64-rhel70-4.4.3 mongodb-4.4.3
[root@docker01 local]# ll mongodb-4.4.3/
总用量 132
drwxr-xr-x. 2 root root 70 1月 13 22:53 bin
-rw-r--r--. 1 root root 30608 12月 22 07:19 LICENSE-Community.txt
-rw-r--r--. 1 root root 16726 12月 22 07:19 MPL-2
-rw-r--r--. 1 root root 1977 12月 22 07:19 README
-rw-r--r--. 1 root root 75685 12月 22 07:19 THIRD-PARTY-NOTICES
[root@docker01 local]#

1.2 新建数据目录和日志目录

# 新建数据目录
[root@docker01 local]# mkdir -p /var/lib/mongodb
# 新建日志目录
[root@docker01 local]# mkdir -p /var/log/mongodb

1.3 新建配置文件 mongo.conf

在 /usr/local/mongodb-4.4.3/ 新建 mongo.conf 文件

# mongod.conf

#以守护程序的方式启用
fork=true

# 端口
port=27017

#这里默认是127.0.0.1, 设置成0.0.0.0是表示所有IP地址都可以访问
bindIp=0.0.0.0

# 数据存储目录
dbPath=/var/lib/mongodb

# 日志存储路径
logAppend=true
logPath=/var/log/mongodb/mongod.log

2. 启动mongo服务

通过 mongod -f mongo.conf 启动mongo服务,并检查 27017 端口已经启动

[root@docker01 local]# /usr/local/mongodb-4.4.3/bin/mongod -f /usr/local/mongodb-4.4.3/mongodb.conf 
about to fork child process, waiting until server is ready for connections.
forked process: 21674
child process started successfully, parent exiting
[root@docker01 local]# ss -nultp | grep 27017
tcp LISTEN 0 128 *:27017 *:* users:(("mongod",pid=21674,fd=11))

3. mongo客户端连接

通过安装包自带的客户端 mongo 来连接刚刚启动的 mongod 服务。

--host 指定主机名--port 指定端口名

连接服务器成功后,show databases 显示已有的数据库,admin、local、config这3个是默认的数据库。

[root@docker01 local]# /usr/local/mongodb-4.4.3/bin/mongo --host localhost --port 27017
MongoDB shell version v4.4.3
connecting to: mongodb://localhost:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("c8fd1b77-523b-43ec-8fd2-b4f54a6f517d") }
MongoDB server version: 4.4.3
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
https://community.mongodb.com
---
The server generated these startup warnings when booting:
2021-01-13T23:08:55.449+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2021-01-13T23:08:55.449+08:00: You are running this process as the root user, which is not recommended
2021-01-13T23:08:55.449+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
2021-01-13T23:08:55.449+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
2021-01-13T23:08:55.449+08:00: Soft rlimits too low
2021-01-13T23:08:55.449+08:00: currentValue: 1024
2021-01-13T23:08:55.449+08:00: recommendedMinimum: 64000
---
---
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()
---
> show databases;
admin 0.000GB
config 0.000GB
local 0.000GB
>

好了,到此为止,mongo服务安装并启动成功。

[CSDN同步:mongo-01-linux安装MongoServer] https://blog.csdn.net/qq_20633779/article/details/112637009
[慕课手记同步:mongo-01-linux安装MongoServer] https://www.imooc.com/article/314327


欢迎关注文章同步公众号"黑桃"

d3547f0059b753e0f0472c72c1748bd5.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值