Centos7 安装Mongodb

前言

在Centos7默认仓库没有Mongodb下载源,大家可通过Mongodb官网下载源码包自行编译或者下载Mongodb官方yum仓库进行安装。这里要示范的是通过yum源进行安装Mongodb5.0.5。

官方下载地址

安装

下载Mongodb的repo源

Mongodb repo源:https://repo.mongodb.org/yum/redhat/7/mongodb-org/5.0/x86_64/RPMS/

根据自己服务器系统版本,选择对应的RPM包下载。若使用命令行方式下载,可在shell下使用 wget 下载。

安装Mongodb之前需要将对应版本的依赖包也一起下载下来。

wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/5.0/x86_64/RPMS/mongodb-org-5.0.5-1.el7.x86_64.rpm

wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/5.0/x86_64/RPMS/mongodb-org-mongos-5.0.5-1.el7.x86_64.rpm

wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/5.0/x86_64/RPMS/mongodb-org-server-5.0.5-1.el7.x86_64.rpm

wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/5.0/x86_64/RPMS/mongodb-org-shell-5.0.5-1.el7.x86_64.rpm

wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/5.0/x86_64/RPMS/mongodb-org-tools-5.0.5-1.el7.x86_64.rpm

安装Mongodb

下载后先安装依赖,再安装Mongodb

rpm -ivh mongodb-org-mongos-5.0.5-1.el7.x86_64.rpm

rpm -ivh mongodb-org-server-5.0.5-1.el7.x86_64.rpm

rpm -ivh mongodb-org-shell-5.0.5-1.el7.x86_64.rpm

rpm -ivh mongodb-org-tools-5.0.5-1.el7.x86_64.rpm

rpm -ivh mongodb-org-5.0.5-1.el7.x86_64.rpm

启动Mongodb服务

启动Mongodb服务

systemctl start mongod

检查其运行状态

systemctl status mongod

输出:

● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-03-16 18:26:03 CST; 6h ago
     Docs: https://docs.mongodb.org/manual
  Process: 22109 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
  Process: 22107 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 22105 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 22104 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 22112 (mongod)
   CGroup: /system.slice/mongod.service
           └─22112 /usr/bin/mongod -f /etc/mongod.conf

Mar 16 18:26:02 localhost.localdomain systemd[1]: Stopped MongoDB Database Server.
Mar 16 18:26:02 localhost.localdomain systemd[1]: Starting MongoDB Database Server...
Mar 16 18:26:02 localhost.localdomain mongod[22109]: 2022-03-16T18:26:02.560+0800 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
Mar 16 18:26:02 localhost.localdomain mongod[22109]: about to fork child process, waiting until server is ready for connections.
Mar 16 18:26:02 localhost.localdomain mongod[22109]: forked process: 22112
Mar 16 18:26:03 localhost.localdomain systemd[1]: Started MongoDB Database Server.

开机启动Mongodb服务

systemctl enable mongod

如果您正在运行防火墙(firewalld),则还需要打开27017端口:

firewall-cmd --permanent --zone=public --add-port=27017/tcp
firewall-cmd --reload

配置文件

Mongodb的配置文件为 /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
  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.


#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

systemLog.path 日志存储目录

storage.dbPath 数据存储目录

net.port 数据库端口

net.bindIp 访问IP,如果改成 0.0.0.0 即不限制ip

修改配置后记得重启服务

systemctl restart mongod

你可能感兴趣的:(mongodb,数据库,nosql)