centos 安装 mongodb4.2

原创
2020/02/21 20:57
阅读数 695

创建yum repos

  • 进入yum文件夹
cd /etc/yum.repos.d/

vi mongodb-org-4.2.repo

  • 黏贴以下代码
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
  • 保存 点击ESC 退出编辑,并使用:wq 进行保存

  • 安装mongodb

sudo yum install -y mongodb-org
  • 启动mongodb
sudo systemctl start mongod
  • 查询mongodb状态
sudo systemctl status mongod
  • 停止mongodb
sudo systemctl stop mongod
  • 重启mongodb
sudo systemctl restart mongod
  • 进入mongodb
mongo
  • 查询mongodb所有数据库
show dbs
  • 创建超级用户
user admin

db.createUser({"user":"admin","pwd":"jjds1234","roles":[{"role":"userAdmin","db":"admin"},{"role":"root","db":"admin"},{"role":"userAdminAnyDatabase","db":"admin"}]})

  • 添加mongodb用户权限,修改/etc/mongodb.conf如下,并重启服务
# 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:
#  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

security:
  authorization: enabled

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

  • 创建数据库
mongo

use admin

db.auth("admin","jjds1234")

use logistics

db.logistics.insert({"name":"物流"})

db.createUser({user:"jjds",pwd:"123456",roles:[{role:"dbOwner",db:"logistics"}]})
  • 显示库下用户
show users
  • 删除用户
 db.dropUser("jjds")
展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部