Mongodb with bash:创建副本集得到'错误命令行:未知选项fork使用--help for help'

时间:2014-03-18 09:33:50

标签: linux bash mongodb

我注意到Windows遇到了这个问题,但我正在运行Ubuntu 13.10(使用Bash),所以我不知道出了什么问题。

尝试设置我的副本集,运行以下命令:

sudo bash < create_replica_set.sh

sudo bash create_replica_set.sh

但我的输出是这样的:

error command line: unknown option fork
use --help for help
error command line: unknown option fork
use --help for help
error command line: unknown option fork
use --help for help

这是我的create_replica_set.sh脚本:

mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27020 --oplogSize 64 --smallfiles --fork
mongod --replSet m101 --logpath "2.log" --dbpath /data/rs2 --port 27018 --oplogSize 64 --smallfiles --fork
mongod --replSet m101 --logpath "3.log" --dbpath /data/rs3 --port 27019 --oplogSize 64 --smallfiles --fork

我的/data/rs*个文件夹已经创建。

奇怪的是,如果我直接复制/粘贴到终端中,这是有效的:

lucas@lucas-ThinkPad-W520:~/class/M101P/6week$ sudo mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27020 --oplogSize 64 --smallfiles --fork
about to fork child process, waiting until server is ready for connections.
forked process: 13128
all output going to: /home/lucas/Dropbox/class/M101P/6week/1.log
log file [/home/lucas/Dropbox/class/M101P/6week/1.log] exists; copied to temporary file [/home/lucas/Dropbox/class/M101P/6week/1.log.2014-03-18T09-35-37]
child process started successfully, parent exiting

如果重要,请点击此处/etc/mongo.conf(我已尝试在最后添加fork=true):

# mongodb.conf

# Where to store the data.

# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
dbpath=/var/lib/mongodb

#where to log
logpath=/var/log/mongodb/mongodb.log

logappend=true

#port = 27017

# Disables write-ahead journaling
# nojournal = true

# Enables periodic logging of CPU utilization and I/O wait
#cpu = true

# Turn on/off security.  Off is currently the default
#noauth = true
#auth = true

# Verbose logging output.
#verbose = true

# Inspect all client data for validity on receipt (useful for
# developing drivers)
#objcheck = true

# Enable db quota management
#quota = true

# Set oplogging level where n is
#   0=off (default)
#   1=W
#   2=R
#   3=both
#   7=W+some reads
#diaglog = 0

# Ignore query hints
#nohints = true

# Disable the HTTP interface (Defaults to localhost:28017).
#nohttpinterface = true

# Turns off server-side scripting.  This will result in greatly limited
# functionality
#noscripting = true

# Turns off table scans.  Any query that would do a table scan fails.
#notablescan = true

# Disable data file preallocation.
#noprealloc = true

# Specify .ns file size for new databases.
# nssize = <size>

# Accout token for Mongo monitoring server.
#mms-token = <token>

# Server name for Mongo monitoring server.
#mms-name = <server-name>

# Ping interval for Mongo monitoring server.
#mms-interval = <seconds>

# Replication Options

# in master/slave replicated mongo databases, specify here whether
# this is a slave or master
#slave = true
#source = master.example.com
# Slave only: specify a single database to replicate
#only = master.example.com
# or
#master = true
#source = slave.example.com
# in replica set configuration, specify the name of the replica set
# replSet = setname 
fork=true

1 个答案:

答案 0 :(得分:1)

我不熟悉如何使用mongod,但是因为你说直接输入shell时你的命令会运行尝试将脚本更改为

sudo mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27020 --oplogSize 64 --smallfiles --fork
sudo mongod --replSet m101 --logpath "2.log" --dbpath /data/rs2 --port 27018 --oplogSize 64 --smallfiles --fork
sudo mongod --replSet m101 --logpath "3.log" --dbpath /data/rs3 --port 27019 --oplogSize 64 --smallfiles --fork

然后运行

. create_replica_set.sh

这将在当前shell中运行(或源代码)脚本,而不是尝试在子进程中执行命令。所以它就像你一次输入一个一样。您不希望使用所有脚本执行此操作,但这似乎是一种特殊情况。

关于评论:

如果您无法运行./create_replica_set.sh,可能是因为您没有授予其可执行权限。

待办事项

chmod +x create_replica_set.sh

首先。并确保脚本的第一行有#!/bin/bash