[iyunv@clinton mongodb]# ./bin/mongod --port 10001 --dbpath data/ --logpath log/mongodb.log
2015-03-12T16:18:33.489+0800 I CONTROL log file "/usr/local/mongodb/log/mongodb.log" exists; moved to "/usr/local/mongodb/log/mongodb.log.2015-03-12T08-18-33".
[iyunv@clinton mongodb]# ./bin/mongod --port 10001 --dbpath data/ --fork
BadValue --fork has to be used with --logpath or --syslog
try './bin/mongod --help' for more information
[iyunv@clinton mongodb]# ./bin/mongod --port 10001 --dbpath data/ --fork --logpath=log/mongodb.log
about to fork child process, waiting until server is ready for connections.
forked process: 6288
child process started successfully, parent exiting
[iyunv@clinton mongodb]# ps -ef|grep mongodb
root 6288 1 1 16:27 ? 00:00:00 ./bin/mongod --port 10001 --dbpath data/ --fork --logpath=log/mongodb.log
root 6304 2292 0 16:27 pts/0 00:00:00 grep --color=auto mongodb
[iyunv@clinton mongodb]#
3、客户端连接
将目录切换到mongodb目录下,并使用mongo命令来连接该数据库
[iyunv@clinton mongodb]# pwd
/usr/local/mongodb
[iyunv@clinton mongodb]# ./bin/mongo localhost:10001
MongoDB shell version: 3.0.0
connecting to: localhost:10001/test
Server has startup warnings:
2015-03-12T16:27:20.453+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2015-03-12T16:27:20.453+0800 I CONTROL [initandlisten]
2015-03-12T16:27:20.453+0800 I CONTROL [initandlisten]
2015-03-12T16:27:20.453+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2015-03-12T16:27:20.453+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2015-03-12T16:27:20.453+0800 I CONTROL [initandlisten]
2015-03-12T16:27:20.453+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-03-12T16:27:20.453+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2015-03-12T16:27:20.453+0800 I CONTROL [initandlisten]
>
通过浏览器访问
在浏览器地址栏输入: http://localhost:10001/ 然后回车访问 (localhost可以换成具体的服务器IP)
可以看到如下提示:It looks like you are trying to access MongoDB over HTTP on the native driver port.
不知道什么原因,google了一下,发现在官网有如下解释:
--httpinterface
New in version 2.6.
Enables the HTTP interface. Enabling the interface can increase network exposure.
Leave the HTTP interface disabled for production deployments. If you do enable this interface, you should only allow trusted clients to access this port. See Firewalls.
应该是自2.6版本以后默认就不开启HTTP接口访问,于是重启加上--httpinterface启动
[iyunv@clinton mongodb]# ./bin/mongod --port 10001 --dbpath data/ --fork --logpath=log/mongodb.log --httpinterface
about to fork child process, waiting until server is ready for connections.
forked process: 7760
child process started successfully, parent exiting
再在地址栏中输入:http://localhost:10001/ 回车
发现仍然有上面的提示:It looks like you are trying to access MongoDB over HTTP on the native driver port.
之前的版本直接访问10001端口会提示:You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number
[iyunv@clinton mongodb]# ./bin/mongod -f conf/mongodb.conf --httpinterface
about to fork child process, waiting until server is ready for connections.
forked process: 8421
child process started successfully, parent exiting