system info:
centos 7 64-bit
MongoDB v3.2.1
基础知识:
mongo | 客户端程序,连接MongoDB |
mongod | 服务端程序,启动MongoDB |
mongodump | 备份程序 |
mongoexport | 数据导出程序 |
mongofiles | GridFS工具,内建的分布式文件系统 |
mongoimport | 数据导入程序 |
mongorestore | 数据恢复程序 |
mongos | 数据分片程序,支持数据的横向扩展 |
mongostat | 监视程序 |
一、启动说明:
mongod 启动服务,运行mongo运行shell窗口;
mongoDB常用指令:
启动并开机启动: systemctl start mongod
重启: systemctl restart mongod
关闭服务: systemctl stop mongod
查看服务列表: systemctl list-units --type=service
二、设置database用户;
1、要先建立一个管理用户的管理员到admin库;
use admin db.createUser( { user: "myUserAdmin", pwd: "abc123", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } )
2、再用这个管理用户的管理员添加管理相应数据库的数据库管理员;
use datebase db.createUser( { user: "xxxx", pwd: "abc123", roles:[{ role: "readWrite", db: "datebase" } ] } )
3、在mongod.conf里面bind_ip设置公网IP;
4、修改默认端口:2xxxx;
5、修改防火墙开放端口:
firewall-cmd --add-port=2xxxx/tcp --permanent firewall-cmd --add-port=2xxxx/udp --permanent # 重新加载防火墙规则 firewall-cmd --reload # 查看当前防火墙规则 firewall-cmd --list-all