Linux环境下搭建MongoDB

Linux环境下搭建MongoDB

MongoDB企业版官方下载地址,下载版本:

在这里插入图片描述

说明选择
VersionMongodb版本最新版本(5.0.1)
Platform 运行平台CentOS 7.0
Package打包形式tgz

使用远程工具登录Linux系统后, 将Mongodb压缩文件上传到/usr/local目录下解压缩

cd /usr/local
tar -zxvf 压缩包名称

将解压好的mongodb文件名修改为mongodb-server【看个人喜好,可以不做修改】

mv 原文件名 mongodb-server

mongodb-server目录下为mongodb配置数据库保存的目录、日志保存的目录以及配置文件

cd /usr/local/mongodb-server
mkdir data #数据库保存的目录
mkdir logs #日志保存的目录
mkdir etc/mongodb.conf #启动配置文件

cd /usr/local/mongodb-server
mkdir data logs etc/mongodb.conf

编辑配置文件

vim /usr/local/etc/mongodb.conf

配置文件内容

dbpath=/usr/local/mongodb-server/data #数据库保存的目录,后续创建的数据库和数据表都会保存在该目录下
logpath=/usr/local/mongodb-server/logs/mongodb.log #日志文件保存目录,mongodb.log文件无需自己创建,mongodb会为我们自动生成
port=27017 #指定端口
fork=true #启动后,开启后台运行
journal=false
bind_ip=0.0.0.0 #允许外网访问【记得防火墙打开端口】
auth=false #不使用身份认证进行登录,默认使用root权限

启动mongodb

cd /usr/local/mongodb-server
./mongod -f /usr/local/mongodb-server/etc/mongodb.conf

启动成功反馈

about to fork child process, waiting until server is ready for connections.
forked process: 26352
child process started successfully, parent exiting

进入mongodb客户端

cd /usr/local/mongodb-server
./mongo

进入成功界面

MongoDB shell version v5.0.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("29cb300f-a182-4b9b-bfda-4a1173fa7792") }
MongoDB server version: 5.0.0
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
We recommend you begin using "mongosh".
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
---
The server generated these startup warnings when booting: 
        2021-07-23T16:27:59.830+08:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
        2021-07-23T16:28:00.363+08:00: You are running this process as the root user, which is not recommended
        2021-07-23T16:28:00.363+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
        2021-07-23T16:28:00.363+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'

停止服务

cd /usr/local/mongodb-server
./mongod --shutdown -f /usr/local/mongodb-server/etc/mongodb.conf

停止服务成功

{"t":{"$date":"2021-07-23T08:32:19.408Z"},"s":"I",  "c":"CONTROL",  "id":20697,   "ctx":"-","msg":"Renamed existing log file","attr":{"oldLogPath":"/usr/local/mongodb-server/logs/mongodb.log","newLogPath":"/usr/local/mongodb-server/logs/mongodb.log.2021-07-23T08-32-19"}}
killing process with pid: 26352

开放端口

# 查看防火墙状态 
systemctl status firewalld
# 开启防火墙 
systemctl start firewalld  
# 关闭防火墙 
systemctl stop firewalld
# 开启防火墙 
service firewalld start 
# 若遇到无法开启
先用:systemctl unmask firewalld.service 
然后:systemctl start firewalld.service

# 添加指定需要开放的端口:
firewall-cmd --add-port = 端口号/tcp --permanent
# 重载入添加的端口:
firewall-cmd --reload
# 查询指定端口是否开启成功,如果端口已开启,返回yes:
firewall-cmd --query-port = 端口号/tcp
# 移除指定端口:
firewall-cmd --permanent --remove-port=123/tcp
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值