1,centos6上安装mongodb:
2,新建可以远程访问的用户,以便可以远程访问:
[root@localhost ~]# cd /usr/local/mongodb/bin/
[root@localhost bin]# ./mongo
> use admin # 切换到admin用户
switched to db admin
> db.createUser({user:"admin",pwd:"123456",roles:[{"role":"userAdminAnyDatabase","db":"admin"},{"role":"readWrite","db":"test"}]}) # 创建可以远程访问的用户admin
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "readWrite",
"db" : "test"
}
]
}
>
9,在其他的内网机器上过来方位测试(本步骤是在另外一台机器上操作,ip地址为192.168.13.128)
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz # 安装mongo命令:
tar fx mongodb-linux-x86_64-3.0.6.tgz
mv mongodb-linux-x86_64-3.0.6 /usr/local/mongodb
cd /usr/local/mongodb/bin
export PATH=/usr/local/mongodb/bin:$PATH ./mongo 192.168.13.167:27017/admin -u admin -p # 输入13.167这台mongodb服务端的密码
MongoDB shell version: 3.0.6
Enter password:
connecting to: 192.168.13.167:27017/admin
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:
2018-06-19T18:00:06.197+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-06-19T18:00:06.198+0800 I CONTROL [initandlisten]
2018-06-19T18:00:06.198+0800 I CONTROL [initandlisten]
2018-06-19T18:00:06.198+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-06-19T18:00:06.198+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-06-19T18:00:06.198+0800 I CONTROL [initandlisten]
2018-06-19T18:00:06.198+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-06-19T18:00:06.198+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-06-19T18:00:06.198+0800 I CONTROL [initandlisten]
>
>show dbs
admin 0.078GB
local 0.078GB
>