mongodb学习日记(二)--mongodb搭建

mongodb学习日记(二)--mongodb搭建

1、mongodb单机版rpm方式搭建

硬件条件:centos 双核4G阿里云服务器
rpm方式安装简单
(1)配置下载环境
命令:

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

添加以下内容:

[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc

(2)下载

yum install --downloaddir=/media/mongodb-rpm-package/ --downloadonly mongodb-org

(3)安装

cd /media
rpm -ivh mongodb-rpm-package/*

这种安装方式会自动创建用户mongod和用户组mongod

(4)修改配置
创建数据文件假和日志文件夹

mkdir -p /media/mongodb
mkdir -p /media/mongodb/mongo
mkdir -p /media/mongodb/log
touch /media/mongodb/log/mongod.log
chown -R mongod:mongod /media/mongodb

编辑配置文件

# 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: /media/mongodb/log/mongod.log

# Where and how to store data.
storage:
  dbPath: /media/mongodb/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

# 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.

#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:

修改内容有:
mongodb学习日记(二)--mongodb搭建

mongodb学习日记(二)--mongodb搭建

(5)修改自启动文件

cd /usr/lib/systemd/system
vim mongod.service

mongodb学习日记(二)--mongodb搭建

生效配置:

#开机自启动
systemctl enable mongod.service  
systemctl daemon-reload  

(6)启动mongodb并创建用户

systemctl start mongod.service 

mongodb学习日记(二)--mongodb搭建

(7)添加密码配置再重启

vim /etc/mongod.conf

添加:

security:
 authorization: enabled

然后:

systemctl restart mongod.service 

mongodb学习日记(二)--mongodb搭建

单价版搭建就结束了,能正常使用,下节介绍集群搭建的两种主流方式

上一篇:2021-06-21


下一篇:rem布局方式