Solr の管理画面や API へのリクエストで HTTPS を使えるようにします。
自己署名証明書作成
プライベートなネットワーク内での利用を想定して自己署名証明書を作成します。
$ cd server/etc
$ keytool -genkeypair -alias solr-ssl -keyalg RSA -keysize 2048 -keypass secret -storepass secret -validity 9999 -keystore solr-ssl.keystore.p12 -storetype PKCS12 -ext SAN=DNS:localhost,IP:192.168.1.3,IP:127.0.0.1 -dname "CN=localhost, OU=Organizational Unit, O=Organization, L=Location, ST=State, C=Country"
$ openssl pkcs12 -in solr-ssl.keystore.p12 -out solr-ssl.pem
keytool は JDK に含まれるツールです。
IPの部分はSolrサーバのIPアドレスを指定します。
作成した証明書を参照するように solr.in.sh を設定します。
SOLR_SSL_ENABLED=true
SOLR_SSL_KEY_STORE=etc/solr-ssl.keystore.p12
SOLR_SSL_KEY_STORE_PASSWORD=secret
SOLR_SSL_TRUST_STORE=etc/solr-ssl.keystore.p12
SOLR_SSL_TRUST_STORE_PASSWORD=secret
SOLR_SSL_NEED_CLIENT_AUTH=false
SOLR_SSL_WANT_CLIENT_AUTH=false
SOLR_SSL_CHECK_PEER_NAME=true
HTTPS を使うように ZooKeeper を設定
SolrCloud での運用の場合は ZooKeeper で保持する設定を変更して Solr が HTTPS 通信を使うようにします。
$ server/scripts/cloud-scripts/zkcli.sh -zkhost localhost:2181 -cmd clusterprop -name urlScheme -val https
ZooKeeper 設定前に作成したコレクションの場合は以下を実行します。
$ curl 'http://localhost:8983/solr/admin/collections?action=CLUSTERPROP&name=urlScheme&val=https'
Solr起動
$ bin/solr -cloud -s example/cloud/node1 -z localhost:2181 -p 8984
動作確認
コレクションを作成して Collections API で状態を確認します。
bin/solr 等のツールは solr.in.sh の環境変数を使って HTTPS 通信してくれます。
curl での API コールの場合は pem ファイルを指定します。
$ bin/solr create -c mycollection -shards 2
$ curl -E solr-ssl.pem:secret --cacert solr-ssl.pem "https://localhost:8984/solr/admin/collections?action=CLUSTERSTATUS&indent=on"
{
"responseHeader":{
"status":0,
"QTime":1},
"cluster":{
"collections":{
"mycollection":{
"pullReplicas":"0",
"configName":"mycollection",
"replicationFactor":"1",
"shards":{
"shard1":{
"range":"80000000-ffffffff",
"state":"active",
"replicas":{"core_node4":{
"core":"mycollection_shard1_replica_n2",
"leader":"true",
"core_node_name":"core_node4",
"node_name":"localhost:8984_solr",
"base_url":"https://localhost:8984/solr",
"state":"active",
"collection":"mycollection",
"shard":"shard1",
"type":"NRT",
"force_set_state":"false"}},
"health":"GREEN"},
"shard2":{
"range":"0-7fffffff",
"state":"active",
"replicas":{"core_node3":{
"core":"mycollection_shard2_replica_n1",
"leader":"true",
"core_node_name":"core_node3",
"node_name":"localhost:8984_solr",
"base_url":"https://localhost:8984/solr",
"state":"active",
"collection":"mycollection",
"shard":"shard2",
"type":"NRT",
"force_set_state":"false"}},
"health":"GREEN"}},
"router":{"name":"compositeId"},
"nrtReplicas":"1",
"tlogReplicas":"0",
"health":"GREEN",
"znodeVersion":4}},
"properties":{"urlScheme":"https"},
"live_nodes":["localhost:8984_solr"]}}
CLUSTERSTATUS の応答に含まれる内部的な URL も https になっていることが分かります。