centos7篇—centos7中安装mongodb

centos7中安装mongodb

方式一:

1. 安装环境

系统:centos7

mongodb版本:mongodb-linux-x86_64-rhel70-6.0.0.tgz

2. 安装过程

(1)将安装包上传到 centos7系统中

(2)解压到 /opt 目录下,并重命名

tar zxvf mongodb-linux-x86_64-rhel70-6.0.0.tgz -C /opt

mv mongodb-linux-x86_64-rhel70-6.0.0 mongodb

centos7篇---centos7中安装mongodb
(3)配置环境变量

在 /etc/profile 中加入下面一行:

export PATH=/opt/mongodb/bin:$PATH

然后 source /etc/profile 使之生效

(4)创建数据库目录和日志目录

mkdir -p /opt/mongodb/logs
mkdir -p /opt/mongodb/db

touch /opt/mongodb/logs/mongodb.log
chmod 777 /opt/mongodb/logs
chmod 777 /opt/mongodb/db

centos7篇---centos7中安装mongodb
(5)创建配置文件

vim /opt/mongodb/mongodb.conf

port= 27017
dbpath=/opt/mongodb/db
logpath=/opt/mongodb/logs/mongodb.log
logappend=true
fork=true
maxConns=100
noauth=true
journal=true
storageEngine=wiredTiger
bind_ip=0.0.0.0

centos7篇---centos7中安装mongodb

(6)启动mongodb

mongod --config /opt/mongodb/mongodb.conf

centos7篇---centos7中安装mongodb

启用授权验证

mongod --config /opt/mongodb/mongodb.conf --auth

停止 mongodb:

mongod --config /opt/mongodb/mongodb.conf --shutdown

(7)配置开机启动

vim /etc/init.d/mongodb


start() {
 /opt/mongodb/bin/mongod --config /opt/mongodb/mongodb.conf
}

stop() {
  /opt/mongodb/bin/mongod --config /opt/mongodb/mongodb.conf --shutdown
}

case "$1" in
  start)
 start
 ;;
  stop)
 stop
 ;;
  restart)
 stop
 start
 ;;
  *)
 echo $"Usage: $0 {start|stop|restart}"
 exit 1
esac
cd /etc/init.d/

chkconfig --add mongodb
chmod +x  mongodb
chkconfig mongodb on

centos7篇---centos7中安装mongodb

配置完成后可使用以下命令:


service mongodb start

service mongodb stop

centos7篇---centos7中安装mongodb
(8)shell中登录mongodb

centos7篇---centos7中安装mongodb
注意:上述启动为root账户启动,权限太大,如果需要启用验证,则需要将配置文件(/opt/mongodb/mongodb.conf)中的 noauth 设置为 false

方式二:

RHEL/CentOS 用户

新建 /etc/yum.repos.d/mongodb.repo,内容为

[mongodb-org]
name=MongoDB Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el$releasever/
gpgcheck=0
enabled=1

centos7篇---centos7中安装mongodb

刷新缓存并安装 mongodb-org。

sudo yum makecache
sudo yum install mongodb-org

centos7篇---centos7中安装mongodb
centos7篇---centos7中安装mongodb

创建数据库目录和日志目录

mkdir -p /opt/mongodb/logs
mkdir -p /opt/mongodb/db

touch /opt/mongodb/logs/mongodb.log
chmod 777 /opt/mongodb/logs
chmod 777 /opt/mongodb/db

创建配置文件

vim /opt/mongodb/mongodb.conf

port= 27017
dbpath=/opt/mongodb/db
logpath=/opt/mongodb/logs/mongodb.log
logappend=true
fork=true
maxConns=100
noauth=true
journal=true
storageEngine=wiredTiger
bind_ip=0.0.0.0

启动mongodb

mongod --config /opt/mongodb/mongodb.conf

centos7篇---centos7中安装mongodb

shell 连接进入 mongo

centos7篇---centos7中安装mongodb

参考文献:
https://mirror.tuna.tsinghua.edu.cn/help/mongodb/

Original: https://blog.csdn.net/m0_46825740/article/details/126137014
Author: 心惠天意
Title: centos7篇—centos7中安装mongodb

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/725951/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球