亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
JAVA開發工程師
手記
粉絲
11
獲贊與收藏
8

關注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消