centos7.9离线安装MongoDB4.4.17

前言

MongoDB 5.0开始要求CPU支持avx指令集,参考https://mp.weixin.qq.com/s/6FFXih1DEZYDFOk1hCu69w

环境

CentOS 7.9.2009 (Core)

MongoDB version v4.4.17

2023年7月18日更新

1、目前MongoDB最新稳定版本是:6.0.8

2、MongoDB 5+和6+版本已不支持centos6.2+系统,参考https://docs.mongoing.com/install-mongodb

3、centos6.5目前最高支持到MongoDB4.4.23,参考https://www.mongodb.com/try/download/community

  但MongoDB从4.2.24以后版本已不再内置mongorestore等工具,需要单独安装MongoDB Database Tools

4、MongoDB Database Tools目前最新版本是100.7.3, 还支持centos6.2+版本

安装

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

安装

#解压
tar zxvf mongodb-linux-x86_64-rhel70-4.4.17.tgz
#复制到目录
mv mongodb-linux-x86_64-rhel70-4.4.17 /usr/local/mongodb
#创建相关目录
mkdir -p /usr/local/mongodb/data 
mkdir -p /usr/local/mongodb/log 
mkdir -p /usr/local/mongodb/conf

 启动服务

cd /usr/local/mongodb/bin
./mongod --port=27017 --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/log/mongodb.log --fork

 

 访问mongo:./mongo

此时无法远程连接,因为默认绑定localhost

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

关闭服务:./mongod --port=27017 --dbpath=/usr/local/mongodb/data --shutdown

环境变量

编辑文件:vi /etc/profile在末尾添加内容

export MONGODB_HOME=/usr/local/mongodb
PATH=$PATH:$MONGODB_HOME/bin

使其立即生效:source /etc/profile 

配置系统服务

创建mongo配置文件:vi /usr/local/mongodb/conf/mongo.conf输入一下内容,注意缩进

systemLog:
  destination: file
  path: /usr/local/mongodb/log/mongod.log # log path
  logAppend: true
storage:
  dbPath: /usr/local/mongodb/data # data directory
  engine: wiredTiger #存储引擎
  #是否启用journal日志
  journal:
    enabled: true
net:
  bindIp: 0.0.0.0
  port: 27017 # port
processManagement:
  fork: true

 创建服务文件:vi /lib/systemd/system/mongodb.service输入以下内容,注意mongo的目录

[Unit]

Description=mongodb
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/mongodb/bin/mongod --config  /usr/local/mongodb/conf/mongo.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config  /usr/local/mongodb/conf/mongo.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 赋值权限:chmod 754 /usr/lib/systemd/system/mongodb.service

#启动服务
systemctl start mongodb
#关闭服务
systemctl stop mongodb
#开机启动
systemctl enable mongodb

因为配置文件里绑定了0.0.0.0启动服务后,就可以用studio3t连了

 end。 

posted @ 2022-11-11 16:22  xjournal  阅读(261)  评论(0编辑  收藏  举报