为了账号安全,请及时绑定邮箱和手机立即绑定

mongo-01-linux安装MongoServer

标签:
MongoDB

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

机器准备:Centos7

图片描述

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
> 

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消