前言:請各大網友尊重本人原創知識分享,謹記本人博客:南國以南i
背景:solr默認安裝沒帶權限控制,每次進入頁面直接操作都有點裸奔的感覺,要使用基本身份驗證您必須先創建一個security.json檔案,對于基本身份驗證,security.json檔案必須有一個authentication部分,它定義用于身份驗證的類,可以在創建檔案時添加用戶名和密碼(例如:sha256(password+salt) hash),或者可以稍后使用基本驗證API添加,
1.示例security.json顯示了如下所示的顯示兩個部分:
{ "authentication":{ 【1】 "blockUnknown": true, 【2】 "class":"solr.BasicAuthPlugin", "credentials":{"solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="} 【3】 }, "authorization":{ "class":"solr.RuleBasedAuthorizationPlugin", "permissions":[{"name":"security-edit", "role":"admin"}], 【4】 "user-role":{"solr":"admin"} 【5】 } }
以下的解釋對應于上述的序號:
- 啟用基本身份驗證和基于規則的授權插件,
- 引數 "blockUnknown": true 表示不允許未經身份驗證的請求通過,
- 已定義了一個名為 "solr" 的用戶,其中有密碼 "SolrRocks",
- "admin" 角色已定義,并且具有編輯安全設定的權限,
- "solr" 用戶已被定義為 "admin" 角色,
獨立模式使用Solr:將您的設定保存到名為security.json的本地檔案中,則應將此檔案放在 solr _home 中,
SolrCloud模式必須上傳security.json到ZooKeeper,首先登入ZooKeeper終端,輸入示例命令(內json欄位已在上述說明)
#進入ZooKeeper終端 ./zkCli.sh
#修改ZooKeeper內security.josn節點檔案 set /security.json '{"authentication":{"blockUnknown":true,"class":"solr.BasicAuthPlugin","credentials":{"solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="}},"authorization":{"class":"solr.RuleBasedAuthorizationPlugin","permissions":[{"name":"security-edit","role":"admin"}],"user-role":{"solr":"admin"}}}'
2.重啟solr訪問,此時solr必須輸入用戶名和密碼進行登入驗證,這里配置了用戶名密碼是:solr:SolrRocks

3.solr用戶管理Api
#新增或修改密碼(如果用戶名存在,就修改密碼,否則就創建用戶) curl --user solr:SolrRocks http://localhost:8983/api/cluster/security/authentication -H 'Content-type:application/json' -d '{"set-user": {"solr":"solr","tom":"tom"}}' #洗掉用戶 curl --user solr:SolrRocks http://localhost:8983/api/cluster/security/authentication -H 'Content-type:application/json' -d '{"delete-user": ["tom"]}'

參考鏈接一、參考鏈接二、
個人總結:
我是南國以南i記錄點滴每天成長一點點,學習是永無止境的!轉載請附原文鏈接!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/281114.html
標籤:Java
下一篇:作業系統之中斷處理
