gpt4 book ai didi

linux - 带有 bash 的 Mongodb : Creating replica sets gets 'error command line: unknown option fork use --help for help'

转载 作者:太空宇宙 更新时间:2023-11-04 11:12:27 25 4
gpt4 key购买 nike

我注意到 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

最佳答案

我不熟悉如何使用 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

关于linux - 带有 bash 的 Mongodb : Creating replica sets gets 'error command line: unknown option fork use --help for help' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22475231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com