linux mongodb4.0.13安装
■A安装环境
1.linux:CentOS7
2.MongoDB:mongodb-linux-x86_64-4.0.13.tgz
[root@mongodb ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.13.tgz
■B安装过程
1.将下载好的文件解压缩。
2.在解压后的文件夹中创建data,log文件夹。在log文件夹中创建mongodb.log文件.
[root@mongodb ~]# tar xf mongodb-linux-x86_64-4.0.13.tgz |
3.创建MongoDB的配置文件:my.conf
[root@mongodb ~]# cd /data/www/mongodb/
[root@mongodb mongodb]# vim my.conf
port=27017 ##端口,默认27017,可以自定义 |
4.启动MongoDB
[root@mongodb mongodb]# ./bin/mongod --config /data/www/mongodb/my.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3893
child process started successfully, parent exiting
这样就启动成功了。我们可以使用MongoDB啦。
5.使用MongoDB
[root@mongodb mongodb]# vim /etc/profile
export PATH=$PATH:/data/www/mongodb/bin |
[root@mongodb mongodb]# source /etc/profile
[root@mongodb mongodb]# mongo
MongoDB shell version v4.0.13
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("43bd322f-7ae8-4d2b-beaf-b39708c60e5a") }
MongoDB server version: 4.0.13
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2019-10-29T22:38:34.815-0400 I CONTROL [initandlisten]
2019-10-29T22:38:34.815-0400 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-10-29T22:38:34.815-0400 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-10-29T22:38:34.816-0400 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-10-29T22:38:34.816-0400 I CONTROL [initandlisten]
>
在>后就可以输入MongoDB命令了。
让我们来试试show dbs命令。
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
>
■C使用Robomongo管理MongoDB
如果要远程访问MongoDB就必须要绑定IP地址。
[root@mongodb ~]# cd /data/www/mongodb/
[root@mongodb mongodb]# vim my.conf
port=27017 ##端口,默认27017,可以自定义 |
这样远程访问就成功了。
下面说说建立用户。
> use admin
switched to db admin
> db.createUser({user:"sharpfire",pwd:"sharpfire",roles:[{role:"root",db:"admin"}]});
Successfully added user: {
"user" : "sharpfire",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
>
这里建立了一个用户sharpfire,密码是sharpfire,对应DB是admin,角色是root。