美文网首页
centos7.6安装mongodb4.2.12

centos7.6安装mongodb4.2.12

作者: 云顶天宫写代码 | 来源:发表于2021-02-24 22:11 被阅读0次
  1. 下载rpm
#server
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/RPMS/mongodb-org-server-4.2.12-1.el7.x86_64.rpm 
#mongos
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/RPMS/mongodb-org-mongos-4.2.12-1.el7.x86_64.rpm
#shell
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/RPMS/mongodb-org-shell-4.2.12-1.el7.x86_64.rpm
#tools
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.2/x86_64/RPMS/mongodb-org-tools-4.2.12-1.el7.x86_64.rpm

2.安装程序

rpm -ivh mongodb-org-server-4.2.12-1.el7.x86_64.rpm
rpm -ivh mongodb-org-shell-4.2.12-1.el7.x86_64.rpm
rpm -ivh mongodb-org-tools-4.2.12-1.el7.x86_64.rpm
rpm -ivh mongodb-org-mongos-4.2.12-1.el7.x86_64.rpm

会生成一个 /etc/mongod.conf 的配置文件,配置了 mogoDB 默认的配置。默认的配置文件如下所示

# 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:
1. 保险起见,端口号27017需要修改为不常见得,比如30128
2. bindIp 127.0.0.1 修改为0.0.0.0 ,可以远程访问,这个看你自己的需求
  1. 启动服务
systemctl start mongod.service
systemctl enable mongod.service

  1. 连接服务
mongo --port 30128  # 30128修改成你的端口

6.创建数据库和账号

// demo数据库
> use demo
switched to db demo
> db.createUser({ user:"demoUser", pwd:"123456", roles:["readWrite", "dbAdmin"] })
Successfully added user: { "user" : "demoUser", "roles" : [ "readWrite", "dbAdmin" ] }

相关文章

网友评论

      本文标题:centos7.6安装mongodb4.2.12

      本文链接:https://www.haomeiwen.com/subject/qaasfltx.html