侧边栏壁纸
博主头像
zyixin

当你觉得为时已晚的时候,恰恰是最早的时候

  • 累计撰写 66 篇文章
  • 累计创建 0 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

MongoDB单机部署

zyixin
2022-04-01 / 0 评论 / 0 点赞 / 3,339 阅读 / 3,730 字
温馨提示:
本文最后更新于 2022-05-10,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

MongoDB单机部署

一、环境

系统:centos7.8
DB版本:mongodb-shell-linux-x86_64-rhel70-4.4.6.tgz

官网地址:https://www.mongodb.com/try/download/community
mongodb下载

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.6.tgz

二、安装

[root@ecs-mongodb setup]# tar -zxvf mongodb-linux-x86_64-rhel70-4.4.6.tgz
[root@ecs-mongodb setup]# mv mongodb-linux-x86_64-rhel70-4.4.6 mongodb
[root@ecs-mongodb mongodb]# cd mongodb
创建日志、数据、配置文件、pid目录
[root@ecs-mongodb mongodb]# mkdir {logs,data,config,pid}
创建启动配置文件
[root@ecs-mongodb mongodb]# cd config/
[root@ecs-mongodb config]# vim mongodb.conf
#端口号
port=27017
#数据目录
dbpath=/home/setup/mongodb/data
#日志目录
logpath=/home/setup/mongodb/logs/mongodb.log
#pid目录
pidfilepath=/home/setup/mongodb/pid/mongodb.pid
#设置后台运行
fork=true
#日志输出方式
logappend=true
#本地ip
bind_ip=192.168.0.2

三、启动

[root@ecs-mongodb config]# cd /home/setup/mongodb/bin/
[root@ecs-mongodb bin]# ./mongod --config ../config/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 18253
child process started successfully, parent exiting

检查是否启动成功
[root@ecs-mongodb bin]# ps -ef| grep mongodb
root     18253     1  1 17:32 ?        00:00:00 ./mongod --config ../config/mongodb.conf
root     18288  7751  0 17:32 pts/0    00:00:00 grep --color=auto mongodb
[root@ecs-mongodb bin]# netstat -lntup | grep 27017
tcp        0      0 192.168.0.2:27017       0.0.0.0:*               LISTEN      18253/./mongod

四、进入数据库

[root@ecs-mongodb bin]# ./mongo 192.168.0.2:27017
MongoDB shell version v4.4.6
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("106cad5f-292b-4377-b1ef-0354c2870957") }
MongoDB server version: 4.4.6
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-06-04T17:43:23.385+08:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
        2021-06-04T17:43:24.045+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2021-06-04T17:43:24.045+08:00: You are running this process as the root user, which is not recommended
        2021-06-04T17:43:24.045+08:00: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning
        2021-06-04T17:43:24.045+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
        2021-06-04T17:43:24.045+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
---
---
        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()
---
>

验证mongodb读写功能
查看数据库
> show dbs;
admin   0.000GB
config  0.000GB
local   0.000GB

切换到config数据库下
> use config
switched to db config

查看config数据库下全部集合
> show collections
system.sessions

db.test.insert({id:1,name:'test'})---插入数据
> db.test.insert({id:1,name:'test'})
WriteResult({ "nInserted" : 1 })

查看
> db.test.find()
{ "_id" : ObjectId("60b9f7ff527c9f2cb009aea6"), "id" : 1, "name" : "test" }

格式美化
> db.test.find().pretty()
0

评论区