amazon-web-services - 无法使用 URL 访问 AWS 实例上的 CouchDB

标签 amazon-web-services ssh amazon-ec2 couchdb

我已在 AWS Linux 实例上安装了 CouchDB,并且可以通过 SSH 成功访问它,但无法使用实例公开可用的 URL 访问它。

在 SSH 中,我可以运行 curl -X GET http://127.0.0.1:5984/_all_dbs 它给我 ["_replicator","_users","baseball"] 这正是我所期待的。

如果我尝试在 Chrome 中使用我的 AWS 实例 URL:http://ec2-xx-xxx-xx-xx.eu-central-1.compute.amazonaws.com:5984/_utils Chrome 表示网站拒绝连接。

我已编辑 CouchDB local.ini 文件以添加 CORS。 local.ini 现在看起来像这样:

; CouchDB Configuration Settings

; Custom settings should be made in this file. They will override settings
; in default.ini, but unlike changes made to default.ini, this file won't be
; overwritten on server upgrade.

[couchdb]
;max_document_size = 4294967296 ; bytes

[httpd]
enable_cors = true
bind_address = 0.0.0.0

[cors]
origins = *

;port = 5984
;bind_address = 127.0.0.1
; Options for the MochiWeb HTTP server.
;server_options = [{backlog, 128}, {acceptor_pool_size, 16}]
; For more socket options, consult Erlang's module 'inet' man page.
;socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]

; Uncomment next line to trigger basic-auth popup on unauthorized requests.
;WWW-Authenticate = Basic realm="administrator"

; Uncomment next line to set the configuration modification whitelist. Only
; whitelisted values may be changed via the /_config URLs. To allow the admin
; to change this value over HTTP, remember to include {httpd,config_whitelist}
; itself. Excluding it from the list would require editing this file to update
; the whitelist.
;config_whitelist = [{httpd,config_whitelist}, {log,level}, {etc,etc}]

[query_servers]
;nodejs = /usr/local/bin/couchjs-node /path/to/couchdb/share/server/main.js


[httpd_global_handlers]
;_google = {couch_httpd_proxy, handle_proxy_req, <<"http://www.google.com">>}

[couch_httpd_auth]
; If you set this to true, you should also uncomment the WWW-Authenticate line
; above. If you don't configure a WWW-Authenticate header, CouchDB will send
; Basic realm="server" in order to prevent you getting logged out.
; require_valid_user = false

[log]
;level = debug

[log_level_by_module]
; In this section you can specify any of the four log levels 'none', 'info',
; 'error' or 'debug' on a per-module basis. See src/*/*.erl for various
; modules.
;couch_httpd = error


[os_daemons]
; For any commands listed here, CouchDB will attempt to ensure that
; the process remains alive. Daemons should monitor their environment
; to know when to exit. This can most easily be accomplished by exiting
; when stdin is closed.
;foo = /path/to/command -with args

[daemons]
; enable SSL support by uncommenting the following line and supply the PEM's below.
; the default ssl port CouchDB listens on is 6984
; httpsd = {couch_httpd, start_link, [https]}

[ssl]
;cert_file = /full/path/to/server_cert.pem
;key_file = /full/path/to/server_key.pem
;password = somepassword
; set to true to validate peer certificates
verify_ssl_certificates = false
; Path to file containing PEM encoded CA certificates (trusted
; certificates used for verifying a peer certificate). May be omitted if
; you do not want to verify the peer.
;cacert_file = /full/path/to/cacertf
; The verification fun (optional) if not specified, the default
; verification fun will be used.
;verify_fun = {Module, VerifyFun}
; maximum peer certificate depth
ssl_certificate_max_depth = 1

; To enable Virtual Hosts in CouchDB, add a vhost = path directive. All requests to
; the Virual Host will be redirected to the path. In the example below all requests
; to http://example.com/ are redirected to /database.
; If you run CouchDB on a specific port, include the port number in the vhost:
; example.com:5984 = /database
[vhosts]
;example.com = /database/

[update_notification]
;unique notifier name=/full/path/to/exe -with "cmd line arg"

; To create an admin account uncomment the '[admins]' section below and add a
; line in the format 'username = password'. When you next start CouchDB, it
; will change the password to a hash (so that your passwords don't linger
; around in plain-text files). You can add more admin accounts with more
; 'username = password' lines. Don't forget to restart CouchDB after
; changing this.
[admins]
;admin = mysecretpassword

:更新:

运行时:

netstat -a -n | grep 5984

我得到:

tcp        0      0 127.0.0.1:5984              0.0.0.0:*                   LISTEN

127.0.0.1 但应该是 0.0.0.0 因为我已经在 etc/couchdb/local.ini 中设置了绑定(bind)etc/couchdb/default.ini 为 0.0.0.0。

看起来 couchdb 正在从其他地方获取它的设置?当我运行时:

couchdb -c

我得到:

/usr/local/etc/couchdb/default.ini
/usr/local/etc/couchdb/local.ini

当通过 SSH 连接到 AWS 实例时,根目录包含两个条目:

apache-couchdb-1.6.1  apache-couchdb-1.6.1.tar.gz

cdapache-couchdb-1.6.1 并编辑 ini 文件:

vim etc/couchdb/local.ini

我认为这与/usr/local/etc/couchdb/local.ini相同?

我已停止并重新启动 couchdb 并重新启动 AWS 实例,但 couchdb 仍然没有从配置文件中获取绑定(bind)地址。

已排序

事实证明,/usr/local/etc/couchdb/local.inietc/couchdb/local.ini不同。当我将绑定(bind)放入正确的 ini 时,一切正常!

最佳答案

要使其在外部可见,只需要做两件事:您应该绑定(bind)外部 IP 地址(在 EC2 实例属性中显示为公共(public) IP)并在防火墙上打开它。所以它必须介于两者之间。

我看到您将绑定(bind)地址更改为 0.0.0.0。这应该通过绑定(bind)所有接口(interface)来解决绑定(bind)步骤。

但是您仍然使用 ssh 使用 localhost 进行连接。那么你就不会检查同样的事情。尝试使用curl进行测试时,尝试使用机器IP地址而不是127.0.0.1。它应该是在 EC2 实例属性中显示为公共(public) IP 的 IP。但如果有疑问,请使用 ifconfig -a找出您拥有的 IP 地址。您还可以通过运行以下命令 netstat -a -n | grep 5984 来检查它实际绑定(bind)的接口(interface)。 。它必须将 0.0.0.0:5984(或 *:5984)显示为 LISTEN(而不是 127.0.0.1:5984)。否则它不会绑定(bind)到正确的端口,您应该检查 CouchDb 配置文件以了解原因。检查 CouchDB 是否真正使用您正在编辑的配置也是值得的。

在防火墙端 - 检查您是否已在正确的安全组上打开它。它必须是您的 EC2 实例的“安全组”属性中显示的规则,并且您打开的规则必须是入站规则。

有时实例防火墙也会介入并引起麻烦。但我只在 Windows 机器上遇到这个问题。我相信它在 AWS Linux 机器上被禁用(至少我从来不需要在那里调整任何东西 - 安全组规则总是足够的)。

如果这仍然不起作用。我只能建议尝试使用 telnet 测试它是否完全连接。由于浏览器有时会错误报告确切的阶段,以使普通用户更简单。使用 telnet 连接是一个较低级别的测试,但请记住,您需要使用 telnet 的空格而不是冒号来分隔端口,例如telnet 1.2.3.4 5984其中 1.2.3.4 是服务器的 IP 地址。

关于amazon-web-services - 无法使用 URL 访问 AWS 实例上的 CouchDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41704531/

相关文章:

amazon-web-services - 我正在尝试在 cloudformation 中创建 ECS 服务,并且我想使用它创建的默认 VPC,并选择任何子网

amazon-web-services - 如何从dockerized spring boot上收集AWS上的日志?

python - 从 python 发起 SSH 隧道的问题

linux - AWS 上从 Windows 到 Debian 的远程桌面?

django - 来自 AWS EC2 上重新定位的实例的 502 错误网关

amazon-web-services - 创建多个用户时出现 Cloudform 错误

amazon-ec2 - 为什么我的额外自动扩展 EC2 实例无法终止?

wordpress - 为负载均衡器(EC2)创建多个实例的正确方法

带有 Play Framework 和链文件的 SSL 配置

git - 如何在ansible中转发ssh key 以从源头 checkout 目标机器上的git存储库?