bin/solr腳本允許某些操作影響ZooKeeper。這些操作僅適用於Solrcloud模式。這些操作可以作爲子命令使用,每個子命令都有自己的選項集。
bin/solr zk [sub-command] [options]
bin/solr zk -help
在發出這些命令以使用znodes所期望的初始化zookeeper之前,應該至少啓動一次solr。初始化ZooKeeper後,solr不需要在任何節點上運行就可以使用這些命令。
- 上傳配置集
使用zk upconfig命令將預先配置的配置集或自定義配置集之一上傳到zookeeper。
ZK Upload Parameters
以下所有參數都是必需的。
-n <name>
在ZooKeeper中設置的配置的名稱。此命令將配置集上傳到“configs”zookeeper節點,並給出指定的名稱。
您可以通過雲屏幕在管理用戶界面中看到所有上傳的配置集。選擇cloud->tree->configs查看它們。
如果指定了預先存在的配置集,它將在ZooKeeper中被覆蓋。
Example: -n myconfig
-d <configset dir>
要上傳的配置集的路徑。它的下面應該有一個conf目錄,該目錄依次包含solrconfig.xml等。
如果只提供了一個名稱,那麼將檢$solr_home/server/solr/configsets路徑下以獲取該名稱。也可以提供絕對路徑替換。
Examples:
- -d directory_under_configsets
- -d /path/to/configset/source
-z <zkHost>
zoomkeepr連接字符串。如果zk_主機在solr.in.sh或solr.in.cmd中定義,則不需要。
Example: -z 123.321.23.43:2181
包含所有參數的此命令示例如下:
bin/solr zk upconfig -z 111.222.333.444:2181 -n mynewconfig -d /path/to/configset
更改配置時重新加載集合
此命令不會自動使更改生效!它只是將配置集上傳到ZooKeeper。可以使用集合API的reload命令重新加載使用此配置集的任何集合。
- 下載配置集合
使用zk downconfig命令將配置集從zookeeper下載到本地文件系統。
ZK Download Parameters
下面列出的所有參數都是必需的。
-n <name>
要下載的ZooKeeper中設置的配置名稱。admin ui cloud->tree->configs節點列出了所有可用的配置集。
Example: -n myconfig
-d <configset dir>
將下載的配置集寫入的路徑。如果只提供一個名稱,$solr_home/server/solr/configsets將是父級。也可以提供絕對路徑。在這兩種情況下,目標上預先存在的配置都將被覆蓋!
Examples:
- -d directory_under_configsets
- -d /path/to/configset/destination
-z <zkHost>
zoomkeepr連接字符串。如果zk_主機在solr.in.sh或solr.in.cmd中定義,則不需要。
Example: -z 123.321.23.43:2181
An example of this command with all parameters is:
bin/solr zk downconfig -z 111.222.333.444:2181 -n mynewconfig -d /path/to/configset
“最佳實踐”是將配置集以某種形式的版本控制保存爲記錄系統。在這種情況下,不應該使用downconfig。
- 在本地文件和zoom keeper znodes之間複製
使用zk cp命令在ZooKeeper znodes和本地驅動器之間傳輸文件和目錄。此命令將從本地驅動器複製到ZooKeeper ,從ZooKeeper 到本地驅動器,或從ZooKeeper 複製到ZooKeeper 。
ZK Copy Parameters
-r
可選的。執行遞歸複製。除非指定了“-r”,否則如果<src>具有子級,則該命令將失敗。
Example: -r
<src>
要從中複製的文件或路徑。如果前綴爲zk:則假定源爲zookeeper。如果沒有前綴或前綴是'file:'這是本地驅動器。必須至少在<src>或<dest>前面加上'zk'前綴,否則命令將失敗。
Examples:
- zk:/configs/myconfigs/solrconfig.xml
- file:/Users/apache/configs/src
<dest>
要複製到的文件或路徑。如果前綴爲zk:則假定源爲zookeeper。如果沒有前綴或前綴是文件:這是本地驅動器。
必須在<src>或<dest>中至少有一個前面加上zk:否則命令將失敗。如果<dest>以Examples:
- zk:/configs/myconfigs/solrconfig.xml
- file:/Users/apache/configs/src
斜槓字符結尾,則命名目錄。
-z <zkHost>
zoomkeepr連接字符串。如果zk_主機在solr.in.sh或solr.in.cmd中定義,則不需要。
Example: -z 123.321.23.43:2181
An example of this command with the parameters is:
Recursively copy a directory from local to ZooKeeper.
bin/solr zk cp -r file:/apache/confgs/whatever/conf zk:/configs/myconf -z 111.222.333.444:2181
Copy a single file from ZooKeeper to local.
bin/solr zk cp zk:/configs/myconf/managed_schema /configs/myconf/managed_schema -z 111.222.333.444:2181
-
Remove a znode from ZooKeeper
Use the zk rm command to remove a znode (and optionally all child nodes) from ZooKeeper.
ZK Remove Parameters
-r
Optional. Do a recursive removal. The command will fail if the <path> has children unless '-r' is specified.
Example: -r
<path>
The path to remove from ZooKeeper, either a parent or leaf node.
There are limited safety checks, you cannot remove '/' or '/zookeeper' nodes.
The path is assumed to be a ZooKeeper node, no zk: prefix is necessary.
Examples:
- /configs
- /configs/myconfigset
- /configs/myconfigset/solrconfig.xml
-z <zkHost>
zoomkeepr連接字符串。如果zk_主機在solr.in.sh或solr.in.cmd中定義,則不需要。
Example: -z 123.321.23.43:2181
Examples of this command with the parameters are:
bin/solr zk rm -r /configs
bin/solr zk rm /configs/myconfigset/schema.xml
-
Move One ZooKeeper znode to Another (Rename)
使用zk mv命令移動(重命名)ZooKeeper znode。
ZK Move Parameters
<src>
The znode to rename. The zk: prefix is assumed.
Example: /configs/oldconfigset
<dest>
The new name of the znode. The zk: prefix is assumed.
Example: /configs/newconfigset
-z <zkHost>
The ZooKeeper connection string. Unnecessary if ZK_HOST is defined in solr.in.sh or solr.in.cmd.
Example: -z 123.321.23.43:2181
An example of this command is:
bin/solr zk mv /configs/oldconfigset /configs/newconfigset
-
List a ZooKeeper znode’s Children
Use the zk ls command to see the children of a znode.
ZK List Parameters
-r Optional. Recursively list all descendants of a znode.
+ Example: -r
<path>
The path on ZooKeeper to list.
Example: /collections/mycollection
-z <zkHost>
The ZooKeeper connection string. Unnecessary if ZK_HOST is defined in solr.in.sh or solr.in.cmd.
Example: -z 123.321.23.43:2181
An example of this command with the parameters is:
bin/solr zk ls -r /collections/mycollection
bin/solr zk ls /collections
-
Create a znode (supports chroot)
使用zk mkroot命令創建znode。這個命令的主要用例支持ZooKeeper的“chroot”概念。但是,它也可以用於創建任意路徑
Create znode Parameters
<path>
The path on ZooKeeper to create. Intermediate znodes will be created if necessary. A leading slash is assumed even if not specified.
Example: /solr
-z <zkHost>
The ZooKeeper connection string. Unnecessary if ZK_HOST is defined in solr.in.sh or solr.in.cmd.
Example: -z 123.321.23.43:2181
Examples of this command:
bin/solr zk mkroot /solr -z 123.321.23.43:2181
bin/solr zk mkroot /solr/production