NoSQL 数据库案例实战 -- Mongodb 环境部署

Mongodb 环境部署

  • 一、环境准备
  • 二、yum 安装
  • 二、源码安装

本环境是基于 Centos 7.8 系统构建mongodb学习环境
安装mongodb-enterprise-4.2.8


一、环境准备

硬件环境

操作系统:centos-7.8 cpu:1*1 硬盘:20G 内存:2G

软件准备

# 操作系统--mini安装
[root@wan ~]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)
# 禁用防火墙
[root@wan ~]# systemctl stop firewalld
[root@wan ~]# systemctl disable firewalld
# 禁用selinux
[root@wan ~]# vim /etc/selinux/config
SELINUX=disable
# 设置 DNS 服务器
[root@wan ~]# vim /etc/resolv.conf 
# Generated by NetworkManager
nameserver 223.5.5.5
nameserver 114.114.114.114
nameserver 8.8.8.8
# 安装 所需软件
[root@wan ~]# yum install wget bash-completion lrzsz tree zip unzip psmisc net-tools vim -y
# 配置扩展源
[root@wan ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

二、yum 安装

配置mingdb yum安装源

[root@node01 ~]# vim /etc/yum.repos.d/mongodb-enterprise-4.2.repo
[mongodb-enterprise-4.2]
name=mongodb-enterprise-4.2
baseurl=https://repo.mongodb.com/yum/redhat/7Server/mongodb-enterprise/4.2/x86_64
gpgcheck=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

[root@node01 ~]# yum list | grep -i mongodb
collectd-write_mongodb.x86_64             5.8.1-1.el7                  epel     
mongodb-enterprise.x86_64                 4.2.12-1.el7                 mongodb-enterprise-4.2
mongodb-enterprise-cryptd.x86_64          4.2.12-1.el7                 mongodb-enterprise-4.2
mongodb-enterprise-mongos.x86_64          4.2.12-1.el7                 mongodb-enterprise-4.2
mongodb-enterprise-server.x86_64          4.2.12-1.el7                 mongodb-enterprise-4.2
mongodb-enterprise-shell.x86_64           4.2.12-1.el7                 mongodb-enterprise-4.2
mongodb-enterprise-tools.x86_64           4.2.12-1.el7                 mongodb-enterprise-4.2
nodejs-mongodb.noarch                     1.4.7-1.el7                  epel     
php-mongodb.noarch                        1.0.4-1.el7                  epel     
php-pecl-mongodb.x86_64                   1.1.10-1.el7                 epel     
poco-mongodb.x86_64                       1.6.1-3.el7                  epel     
syslog-ng-mongodb.x86_64                  3.5.6-3.el7                  epel 

安装mongodb

[root@node01 ~]# yum install mongodb-enterprise-4.2.8 -y

启动mongodb服务

[root@node01 ~]# systemctl enable --now mongod
[root@node01 ~]# netstat -lnutp | grep mongod
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      12083/mongod

登录数据库

[root@node01 ~]# mongo
MongoDB shell version v4.2.8
MongoDB Enterprise > 
MongoDB Enterprise > db
test
MongoDB Enterprise > show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
MongoDB Enterprise > exit
bye
[root@node01 ~]# 

二、源码安装

# 上传源码包
[root@node02 ~]# ll mongodb-linux-x86_64-rhel70-4.2.8.tgz 
-rw-r--r--. 1 root root 132768194 Feb 14 19:07 mongodb-linux-x86_64-rhel70-4.2.8.tgz

# 解压到指定目录
[root@node02 ~]# tar xf mongodb-linux-x86_64-rhel70-4.2.8.tgz -C /usr/local/
[root@node02 ~]# cd /usr/local/
[root@node02 local]# ln -sv mongodb-linux-x86_64-rhel70-4.2.8/ mongodb
‘mongodb’ -> ‘mongodb-linux-x86_64-rhel70-4.2.8/’

# 创建存放数据、日志、pid文件的目录
[root@node02 ~]# mkdir -p /var/log/mongodb /var/run/mongodb /var/lib/mongo

# 提供配置文件
[root@node02 local]# vim /etc/mongod.conf 
# 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:
#  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


# 提供服务脚本
[root@node02 local]# vim /usr/lib/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mongodb/bin/mongod -f /etc/mongod.conf
ExecStop=/usr/local/mongodb/bin/mongod --shutdown -f /etc/mongod.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target


# 更改权限
[root@node02 local]# chown -R mongod.mongod /usr/local/mongodb/*

# 配置环境变量
[root@node02 local]# more /etc/profile.d/mongodb.sh
export PATH=$PATH:/usr/local/mongodb/bin
[root@node02 local]# source /etc/profile.d/mongodb.sh


# 启动服务
[root@node02 local]# systemctl start mongod
[root@node02 local]# netstat -lnutp | grep mongod
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      9919/mongod 
[root@node02 local]# ps -ef | grep mongod
root       9919      1  0 20:07 ?        00:00:03 /usr/local/mongodb/bin/mongod -f /etc/mongod.conf
root       9990   1367  0 20:15 pts/0    00:00:00 grep --color=auto mongod
[root@node02 local]# mongo
MongoDB shell version v4.2.8
> db
test
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
> exit
bye
[root@node02 local]#

你可能感兴趣的:(Mongodb,数据库,NoSQL,MongoDB,MongoDB环境搭建,运维)