mongodb安装教程

mongodb安装教程

  1. 下载源文件
    下载地址(按需选择):https://www.mongodb.com/download-center/community
    这里的试用地址:https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.11.tgz

  2. 安装

tar -zxvf mongodb-linux-x86_64-3.6.11.tgz
mv mongodb-linux-x86_64-3.6.11 /usr/local

  1. 定义配置文件
storage:
  dbPath: /var/data/mongodb
  journal:
    enabled: true
systemLog:
  path: /var/log/mongodb/mongodb.log
  destination: file
  logAppend: true
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
net:
  port: 27017 
  bindIpAll: true #所有ip都可以 方便远程访问
 # bindIp: 127.0.0.1
security:
  authorization: disabled #初始安装先关闭没得默认值
  1. 启动

/usr/local/mongodb-linux-x86_64-3.6.11/bin/mongod --config /etc/mongodb.conf

  1. 配置环境变量

vim /etc/profile
export /usr/local/mongodb-linux-x86_64-3.6.11/bin
source /etc/profile

  1. 制作systemctl启动

cd /lib/systemd/system
touch mongodb.service
vim mongodb.service

[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/mongodb/mongod.pid
ExecStart=/usr/local/mongodb-linux-x86_64-3.6.11/bin/mongod --config /etc/mongodb.conf
ExecStop=/usr/local/mongodb-linux-x86_64-3.6.11/bin/mongod --shutdown --config /etc/mongodb.conf
PrivateTmp=false

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl start mongodb

  1. 访问

mongo
show dbs #显示多有的数据库
use admin #使用哪个数据库
show collections #显示所有的集合(同数据库表)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值