-f
同 --config,启动时每次在命令行指定参数容易遗漏也较为麻烦,最好把所有参数都放于mongod.cnf文件(此文件可随意命名)中,非常方便。而且同时支持文件+命令行参数。
<pre name="code" class="sql">mongod -f mongo27018.cnf --bind_ip 192.168.7.221
cat mongo27018.cnf
<pre name="code" class="sql">port=27018
dbpath=/home/mongo/27018/data/
logpath=/home/mongo/27018/log/mongodb.log
logappend=true
bind_ip=192.168.7.221
auth=true
slave=true
source=192.168.7.221:27017
不过文件中的参数与命令参数略有区别。如命令行指定参数:--port 27018、--logappend。而文件形式为port=27018 logappend=true
port=27018
指定mongodb的运行端口,不使用默认端口(27017),连接时同样必须指定端口。
# mongo 192.168.7.221:27018
MongoDB shell version: 3.0.5
connecting to: 192.168.7.221:27018/test
>
dbpath=/home/mongo/27018/data/
数据文件目录
logpath=/home/mongo/27018/log/mongodb.log
日志文件目录
logappend=true
指定日志到日志文件为追加,不会覆盖
bind_ip=192.168.7.221
指定特定的IP连接mongodb服务
#mongo localhost:27018
MongoDB shell version: 3.0.5
connecting to: localhost:27018/test
2015-08-25T10:57:28.867+0800 W NETWORK Failed to connect to 127.0.0.1:27018, reason: errno:111 Connection refused
2015-08-25T10:57:29.073+0800 E QUERY Error: couldn't connect to server localhost:27018 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:181:14)
at (connect):1:6 at src/mongo/shell/mongo.js:181
exception: connect failed
#mongo 192.168.7.221:27018
MongoDB shell version: 3.0.5
connecting to: 192.168.7.221:27018/test
>
auth=true
安全模式运行,连接时验证用户名密码,前提是创建用户并设置密码fork=true
后台启动
#mongod -f mongo27018.cnf --fork
about to fork child process, waiting until server is ready for connections.
forked process: 16068
child process started successfully, parent exiting
slave=true(master=true)
说明此服务为从库服务器(为主库)。
source=192.168.7.221:27017
指定为从库后,指定主库,包括IP和端口。