CentOS7使用阿里镜像安装mongodb4.0

时间:2022-06-01 19:10:36

 安装

cd /etc/yum.repos.d
vim mongodb-org.repo

[mogodb-org]
name=MongoDB Repository
baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.0/x86_64/
gpgcheck=0
enabled=1

yum -y install mongodb-org

配置

vim /etc/mongod.conf

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 27017
  # 修改ip
  bindIp: 0.0.0.0  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

开机启动脚本

cd /etc/init.d
vim mongod

#! /bin/bash

# chkconfig: 2345 90 91
# description: Start and Stop mongodb
# processname: mongod

EXEC=/usr/bin/mongod
CONF=/etc/mongod.conf
LOCKFILE=/var/lock/subsys/mongod
RETVAL=0
case "$1" in
    start)
        echo -n $"Starting mongod: "
        $EXEC -f $CONF
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] @amp;@amp; touch $LOCKFILE
        ;;
    stop)
        echo -n $"Stopping mongod: "
        $EXEC -f $CONF --shutdown
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] @amp;@amp; rm -f $LOCKFILE
        ;;
    restart)
        ${0} stop
        ${0} start
        ;;
    *)
        echo "Usage: /etc/init.d/mongod {start|stop|restart}" @gt;@amp;2
        exit 1
esac 

运行权限

chkconfig --add mongod

加入开机启动

systemctl enable mongod

启动

service mongod start

停止

service mongod stop

重启

service mongod restart

卸载

# 停止服务
service mongod stop
# 删除安装的包
yum erase $(rpm -qa | grep mongodb-org)
# 删除数据和日志
rm -rf /var/log/mongodb
rm -rf /var/lib/mongo

到此这篇关于CentOS7使用阿里镜像安装mongodb4.0的详细过程的文章就介绍到这了,更多相关CentOS7使用阿里镜像安装mongodb内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文地址:https://blog.csdn.net/qq_35433926/article/details/89680721