微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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:

修改内容有:

image

image

(5)修改自启动文件

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

image

生效配置:

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

(6)启动mongodb并创建用户

systemctl start mongod.service 

image

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

vim /etc/mongod.conf

添加

security:
 authorization: enabled

然后:

systemctl restart mongod.service 

image

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐