小编Mr.*_*ris的帖子

MongoDB:无法启动副本集; '已有数据,无法启动设置'

我有一个MongoDB实例,使用配置文件和密钥文件进行设置.

我想用pymongo启动一个副本集.当我尝试启动replcia集时,通过对将成为副本集主服务器的服务器执行python脚本,如下:

from pymongo import MongoClient

uri = "mongodb://correctWorkingUsername:password@localhost:27017"
c = MongoClient(uri)

config = {'_id': 'RelicaSetName', 'members': [
{'_id': 0, 'host': 'FirstServer:27017'},
{'_id': 1, 'host': 'SecondServer:27017'},
{'_id': 2, 'host': 'ThirdServer:27017'}]}

c.admin.command("replSetInitiate", config)
Run Code Online (Sandbox Code Playgroud)

我收到一条错误消息,如下:

'SecondSErver:27017' has data already, cannot initiate set
Run Code Online (Sandbox Code Playgroud)

但是,如果我使用数据库进行身份验证

mongo admin -u correctWorkingUsername -p password
Run Code Online (Sandbox Code Playgroud)

我可以启动复制,并成功添加成员:

rs.initiate()
rs.add('SecondServer:27017')
Run Code Online (Sandbox Code Playgroud)

我不确定这是否与密钥文件身份验证有关,或者是否由用户脚本在其他服务器上创建了ALREADY.每个服务器也都使用配置文件mongod.conf启动,该文件包含副本集名称.

为什么这会失败?rs.initiate()和rs.add()完美地工作,但python脚本虽然可以实际连接到数据库但不起作用.

python mongodb pymongo replicaset

13
推荐指数
1
解决办法
3436
查看次数

在 Powershell 中,$input 是做什么用的?

我试图创建一个哈希表,

$input = @{'G'=100;'E'=50;'D'=35;'A'=100}
Run Code Online (Sandbox Code Playgroud)

并且无法弄清楚为什么它不会像往常一样使用像write-host, 或简单的$input. write-host回来了System.Collections.ArrayList+ArrayListEnumeratorSimple$input什么也没回。没有抛出错误。

凭直觉,我重命名了哈希表,然后繁荣,它看起来很正常。在 ISE 中打开一个新的 powershell 选项卡,我观察到变量$input填充了智能感知,即使我没有在这个环境中定义它。

现在我很好奇:这个系统变量 $input 有什么用?我在第 4 版。

powershell

8
推荐指数
1
解决办法
5172
查看次数

SCP 通过 Python 子进程 Popen:“身份文件无法访问”

从 subprocess.popen 执行 SCP 时,我收到错误:Warning: Identity File ./id_rsa.key not accessible: no such file or directory. 问题解释如下。

我想使用 python 脚本将文件从本地计算机 SCP 到远程计算机,并且我想指定执行 SCP 时使用的密钥(使用 -i 选项)。

我的本地计算机是 Windows 10 企业版。我的“远程”机器目前是一个在我的本地主机上运行 Alpine linux 的 Docker 容器。

当我在提升的 shell 中运行该命令时,它可以工作:

scp -i ./id_rsa.key -P 2222 ./test.plan root@127.0.0.1:/go/
Run Code Online (Sandbox Code Playgroud)

当我通过 Python 3.6 subprocess.popen 执行命令时:

SSH = subprocess.Popen(['scp', '-i ./id_rsa.key', '-P 2222', './test.plan', 'root@127.0.0.1:/go/'],
    cwd = r'C:\ThePathToThisStuff',
    shell = False,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE
)
Run Code Online (Sandbox Code Playgroud)

它提示我输入密码,root@127.0.0.1's password:当我输入密码时,它会抛出以下错误,表明它无法找到 RSA 密钥:

<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'> ERROR: [b'Warning: …
Run Code Online (Sandbox Code Playgroud)

python subprocess scp popen python-3.x

2
推荐指数
1
解决办法
1756
查看次数