centos7 安装mongoDB

1官网下载: https://www.mongodb.com/download-center/communitylinux

2上传至目录 /opt/mongoDb 下mongodb

3解压数据库

tar zxvf mongodb-linux-x86_64-4.0.5.tgz

4添加配置文件vim

vim /opt/mongoDB/mongodb-linux-x86_64-4.0.5/bin/mongodb.conf

 

# 数据库文件路径
dbpath = /opt/mongoDB/mongodb-linux-x86_64-4.0.5/data
# 日志文件路径
logpath = /opt/mongoDB/mongodb-linux-x86_64-4.0.5/logs/mongodb.log
# 是否追加日志
logappend=true
# 端口
port=27017
# 是否后台程序启动
fork=true
# 是否启动受权认证
auth=true
# 开启连接权限
bind_ip=0.0.0.0

5配置mongodb服务app

vim /lib/systemd/system/mongodb.service

  

[Unit]

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

[Service]
Type=forking
ExecStart=/opt/mongoDB/mongodb-linux-x86_64-4.0.5/bin/mongod --config /opt/mongoDB/mongodb-linux-x86_64-4.0.5/bin/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/opt/mongoDB/mongodb-linux-x86_64-4.0.5/bin/mongod --shutdown --config /opt/mongoDB/mongodb-linux-x86_64-4.0.5/bin/mongodb.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

6设置权限spa

chmod 754 mongodb.service 日志

7启动关闭服务,设置开机启动code

#启动服务 blog

systemctl start mongodb.service   ip

#关闭服务   
systemctl stop mongodb.service   
#开机启动   
systemctl enable mongodb.service

 8建立数据库&用户

mongo 登陆

use admin

db.createUser({user: "admin",pwd: "123456",roles:[{role: "userAdminAnyDatabase",db: "admin"}]})
db.auth('admin', '123456')

use tdsdb.createUser({user: "ljyctds",pwd: "ljyctds",roles:[{role: "dbOwner",db: "tds"}]})

相关文章
相关标签/搜索