我通过创建自签名证书使用SSL运行Elastic Search
实例。通过elastic
包从R连接时遇到问题。
这是我的进步:
启用SSL后,当我尝试连接到Elastic Search实例时,出现以下错误:
$ curl -u $USER:$PASS 'https://localhost:9200/_cat/health?v'
curl: (60) Peer certificate cannot be authenticated with known CA certificates
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
显然,此问题是由于证书不受信任。一种方法是将自签名证书添加到信任库中,但我不知道它在哪里。另一种方法是通过添加-k来跳过证书验证。但是我想执行它。
因此,我找到了一种解决方法,只需指定
root-ca.pem
如下:$ curl -u $USER:$PASS 'https://localhost:9200/_cat/health?v' --cacert /home/user/root-ca.pem
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1479462058 03:40:58 es-cluster yellow 1 1 365 365 0 0 364 0 - 50.1%
然后另一个SO问题帮助我创建了一个文件
~/.curlrc
,如下所示:$ cat ~/.curlrc
capath=/home/user/
在那之后,我什至不必指定证书。
$ curl -u $USER:$PASS 'https://localhost:9200/_cat/health?v'
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1479462172 03:42:52 es-cluster yellow 1 1 365 365 0 0 364 0 - 50.1%
到目前为止,一切都很好,但是现在当我尝试从
R
连接到Elastic Search时。我收到以下错误。> library(elastic)
> connect(es_base = "https://localhost", es_port = 9200, es_user = USER, es_pwd = PASS)
Error:
Failed to connect to https://127.0.0.1:9200
Remember to start Elasticsearch before connecting
日志报告
unknown_ca
错误。 elastic
R包可能正在使用httr / curl进行连接,但是我不知道如何指定证书。我提到了解决方案here,但它适用于
RCurl
。请提出建议。
版本:
最佳答案
正如@sckott所建议的那样,我必须设置cainfo
参数。
以下是在我的情况下有效的方法:
library(elastic)
library(httr)
set_config(config(cainfo = "/home/user/root-ca.pem"))
connect(es_base = "https://localhost", es_port = 9200, es_user = USER, es_pwd = PASS)
谢谢Sckott。
关于r - 使用来自Elastic R包的自签名证书连接到Secured Elastic Search,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40674437/