mongo的安装

1.在MongoDB官网下载安装包:https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.5.tgz

linux下载方式:

cd /usr/opt/
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.5.tgz
tar -zxvf mongodb-linux-x86_64-rhel70-3.6.5.tgz
mv mongodb-linux-x86_64-rhel70-3.6.5 mongodb

2.将文件上传到linux系统文件夹:/usr/opt 解压,解压后删除压缩包节ls省空间。将解压后的文件名重命名:

3.进入mongodb目录:

cd /usr/opt/mongodb

mkdir data

mkdir logs

4.进入bin目录:

cd /usr/opt/mongodb/bin

vi mongodb.conf

添加代码:

systemLog:
    destination: file
    path: "/usr/opt/mongodb/logs/mongodb.log"
    logAppend: true
storage:
    dbPath: "/usr/opt/mongodb/data/"
    journal:
         enabled: true
processManagement:
    fork: true
    pidFilePath: "/usr/opt/mongodb/mongodb.pid"
net:
    port: 27017
    bindIp: 0.0.0.0
setParameter:
    enableLocalhostAuthBypass: false

5.创建mongodb启动脚本            vi /etc/init.d/mongodb

#!/bin/sh
#chkconfig: 2345 80 90
#description: mongodb
start() {
/usr/opt/mongodb/bin/mongod -f /usr/opt/mongodb/bin/mongodb.conf
}

stop() {
/usr/opt/mongodb/bin/mongod -f /usr/opt/mongodb/bin/mongodb.conf --shutdown
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac

给脚本权限:chmod +x /etc/init.d/mongodb

将mongodb设置开机自启:chkconfig --level 35 mongodb on

将mongodb注册为系统服务:chkconfig --add mongodb

启动mongodb服务:/etc/init.d/mongodb start

停止mongodb服务:/etc/init.d/mongodb stop

重启mongodb服务:/etc/init.d/mongodb restart

开启端口:

firewall-cmd --zone=public --add-port=27017/tcp --permanent

firewall-cmd --zone=public --add-port=27017/udp --permanent

firewall-cmd --reload

编辑环境变量:vi /etc/profile

末尾添加:export PATH=$PATH:/usr/opt/mongodb/bin

执行环境变量:source /etc/profile

通过命令:mongo进入mongodb

添加用户:db.createUser({user:"root",pwd:"123456",roles:[{role:"root",db:"admin"}]})

开启认证:

先停止服务:/etc/init.d/mongodb stop
编辑:vi /usr/opt/mongodb/bin/mongodb.conf 添加代码

security:
  authorization: enabled

开启服务:/etc/init.d/mongodb start

 连接mongodb:mongo -u 用户名-p 密码 数据库

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值