Linux安装MongoDB,并设置开机启动

一 基础环境设置

操作系统版本  :centos-7.5

MongoDB版本:MongoDB 4.2.21

1 关闭防火墙

# 关闭防火墙
[root@mongodbenterprise lib]# systemctl stop firewalld.service

# 禁止firewall开机启动
[root@mongodbenterprise lib]# systemctl disable firewalld.service 

# 确认防火墙为not running状态
[root@mongodbenterprise lib]# firewall-cmd --state
not running

2 关闭selinux 

[root@mongodbenterprise lib]# vim /etc/selinux/config
SELINUX=disabled

3 安装依赖包

yum install -y libcurl openssl

二 安装MongoDB

安装路径规划:

安装路径:/usr/soft/mongo-4.2/ 

数据文件路径:/usr/soft/mongo-4.2/data/

错误日志路径:/usr/soft/mongo-4.2/log/mongodb.log

配置文件:/usr/soft/mongo-4.2/mongodb.conf

1 下载安装包

下载MongoDB安装包,官网地址:MongoDB Community Download | MongoDB

CSDN下载链接:https://download.csdn.net/download/feritylamb/86249045 

 需要注意的是,redhat/centos是类似的Linux系统,可以简单地理解为:centos是redhat的社区版。因此直接下载os为redhat7的tar包即可

 2 解压安装包

[root@mongoserver ~]# ls
anaconda-ks.cfg  mongodb-linux-x86_64-rhel70-4.2.7.tgz
 [root@mongoserver ~]# tar -xzvf mongodb-linux-x86_64-rhel70-4.2.7.tgz 
 [root@mongoserver ~]# ls
 anaconda-ks.cfg  mongodb-linux-x86_64-rhel70-4.2.7  mongodb-linux-x86_64-rhel70-4.2.7.tgz

 3 安装MongoDB

tar包是不需要安装的,解压到安装位置即可,我的安装位置是/usr/soft/mongo-4.2

mv mongodb-linux-x86_64-rhel70-4.2.21 /usr/soft/mongo-4.2

4 添加配置文件/usr/soft/mongo-4.2/mongodb.conf

vim mongodb.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: /usr/soft/mongo-4.2/log/mongodb.log

# Where and how to store data.
 storage:
   dbPath: /usr/soft/mongo-4.2/data/
   journal:
     enabled: true
#  engine:
#  wiredTiger:

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

# network interfaces
 net:
   port: 27017
   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.

创建相关路径:

mkdir -p /usr/soft/mongo-4.2/log/
mkdir -p /usr/soft/mongo-4.2/data/
mkdir -p /usr/soft/mongo-4.2/process/  #守护进程路径

5 将mongo的目录添加到PATH中,以便于操作系统能识别到mongo命令 

[root@mongoserver ~]# vim /etc/profile
 # 在文件末尾添加
PATH=$PATH:$HOME/bin:/usr/soft/mongo-4.2/bin

# 使profile中的参数生效
[root@mongoserver ~]# source /etc/profile

6 创建运行用户mongod 

[root@mongoserver ~]# groupadd mongod
[root@mongoserver ~]# useradd -g mongod mongod

授权:
[root@mongoserver ~]# chown -R mongod:mongod /usr/soft/mongo-4.2

7 运行MongoDB

[root@mongoserver log]# mongod -config /usr/soft/mongo-4.2/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 2137
child process started successfully, parent exiting

# 或下面的方式
mongod -f /usr/soft/mongo-4.2/mongodb.conf

 8 查看运行状态

[root@localhost mongo-4.2]# ps -ef|grep mongo
root     12215     1  2 08:18 ?        00:00:00 mongod -config /usr/soft/mongo-4.2/mongodb.conf
root     12545 15089  0 08:19 pts/1    00:00:00 grep --color=auto mongo

9 关闭MongoDB 

[root@mongoserver log]# mongod --shutdown --config /usr/soft/mongo-4.2/mongodb.conf
 killing process with pid: 2082

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值