CentOS 7 Linux Installation MongoDB - yum installation (how to do zgbn)

Keywords: MongoDB yum vim CentOS

CentOS 7 Linux Installation MongoDB - yum installation

1. Build repo resources of CentOS7

Enter / etc/yum.repos.d/ directory, create mongodb-org.repo file, edit this file with vim, and add repo resources.
Http://mirrors.aliyun.com/mongodb/yum/redhat/7server/mongodb-org/3.0/x86_/ is the resource address provided by Alibaba cloud, where 3.0 is the version number, which can be replaced by the corresponding version number after visiting the resource address.

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

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

2. Install MongoDB, yum

Execute the command to view the MongoDB information in the yum resource package

]# yum list | grep mongodb

mongodb-org.x86_64                       3.0.15-1.el7                   @mongodb-v3.0
mongodb-org-mongos.x86_64                3.0.15-1.el7                   @mongodb-v3.0
mongodb-org-server.x86_64                3.0.15-1.el7                   @mongodb-v3.0
mongodb-org-shell.x86_64                 3.0.15-1.el7                   @mongodb-v3.0
mongodb-org-tools.x86_64                 3.0.15-1.el7                   @mongodb-v3.0

Install MongoDB. I installed version 3.0 in this place

]# yum install mongodb-org

3. View and modify the configuration of MongoDB

The configuration file, / etc/mongod.conf, will be installed in the / etc directory by default.
Use vim /etc/mongod.conf to view and edit the configuration file. Here I only modify the default port number.

# 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
  ### Default log file
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  ### Default data file
  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

# network interfaces
net:
  ### Modify the default port for security
  port: 27017
  ### Binding IP, can only be accessed locally, for security reasons
  bindIp: 127.0.0.1  # Listen to local interface only, comment to listen on all interfaces.

4. Start test MongoDB service

Startup service

]# service mongod start
Starting mongod (via systemctl):                           [  OK  ]

Out of Service

]# service mongod stop
Stopping mongod (via systemctl):                           [  OK  ]

Restart service

]# service mongod restart
Restarting mongod (via systemctl):                         [  OK  ]

5. Set MongoDB service to startup

Set service startup

]# chkconfig mongod on

Posted by Karlos2394 on Thu, 19 Dec 2019 11:01:25 -0800