Using Martini with a remote Solr instance
For ease of installation and deployment1, Martini ships with an embedded instance of Apache Solr. Solr is used internally by custom search indices, Tracker, and Monitor. But aside from using the default embedded Solr instance, you can configure Martini to connect to a stand-alone Solr server2 instead. This is useful when you have a cluster of Martini servers or if you simply want to have a dedicated instance of Solr. To learn more about how to do this, follow the steps below.
Remote and SolrCloud instances of Solr do not have the ability to create new cores
Unlike embedded Solr instances which can dynamically create new cores upon the demand of Martini packages, remote and SolrCloud instances of Solr cannot. If a package needs a certain core or collection and you're using a remote or SolrCloud instance of Solr which doesn't have the required core or collection yet, the package will not start. You have to create them manually.
Delegating Solr servers
As with SolrCloud instances, you can use the embedded Solr instance in place of the configured remote Solr server in
the event that it becomes unavailable. To enable this behavior, you must set the solr.enable-embedded-fallback
application property to true
.
Solr and Martini Runtime on the same server
If you plan on running Solr and Martini Runtime on the same server, make sure to use the required java version for each to avoid java related issues as newer versions of Solr require Java 11 and Martini Runtime 1.x requires Java 8.
Procedure
-
Update your instance properties file to let Martini know that you'll be using a remote Solr server.
It's recommended to create an
override.properties
file if one doesn't exist yet, and then adding or modifying these key-value pairs in the file:1 2
solr.mode=remote solr.url=http://<solr-server-url>
... where you replace
<solr-server-url>
with the URL of your remote Solr instance.If you have multiple Martini servers and you want them to connect to a single remote Solr instance, you can also assign a unique Solr core prefix for each instance. To do so, set each Martini server's
solr.core-prefix
instance property.1
solr.core-prefix=<prefix>
Having a prefix will help every Martini server determine which Solr cores belong to them and thus, will prevent instances from touching other instances' search index data if need be.
-
Copy the configuration files of Martini's required Solr cores to Solr.
Navigate to the
<martini-home>/conf/solr/cores
directory, and copy thetracker
andinvoke_monitor
directories, then paste them to your<solr-home>/server/solr
directory.1 2 3 4 5 6 7
<solr-home>/server/solr ├── configsets ├── invoke_monitor ├── README.txt ├── solr.xml ├── tracker ├── zoo.cfg
If you have set the value of
solr.core-prefix
, you must also rename the required Solr cores such that their names follow the format<prefix>_<core_name>
. Otherwise, Martini won't be able to find them and will shift back to using embedded Solr.Renaming cores is a simple matter of renaming the directories where they reside, for example in macOS and Linux, this can be done by executing the following command:
1 2
mv invoke_monitor <solr-prefix>_invoke_monitor mv tracker <solr-prefix>_tracker
Next, edit the contents of their respective
core.properties
files:1
name=<solr-prefix>_invoke_monitor
1
name=<solr-prefix>_tracker
-
If you wish to retain the
tracker
andinvoke_monitor
cores' existing data, you must create copies of their data files in your remote Solr server.If you have been previously using embedded Solr, then this is as easy as copying the contents of the
<martini-home>/data/solr/tracker
and<martini-home>/data/solr/invoke_monitor
directories and placing them under the<solr-home>/server/solr/tracker/data
and<solr-home>/server/solr/invoke_monitor/data
folders, respectively.After copying them, change file permission of the core directory from
root
tosolr
. You can do this by executing this command:chown -R solr:solr /var/solr/data/*
-
If you have other Solr cores you'd like to keep, steps #3 and #4 above still apply. Simply copy their configuration folders to the
<solr-home>/server/solr
directory and rename them accordingly such that they follow the format<core_name>
or<prefix>_<core_name>
, depending on whether or not you have configured the instance'ssolr.core-prefix
property. Copy over the data of their cores, if you wish to retain them. -
Start or restart your remote Solr by executing
./solr start
under the<solr-home>/bin
directory. You should have new cores namedtracker
andinvoke_monitor
displayed on your Solr admin page like the following:If you have configured other custom Solr cores, you should see them as well.
-
Restart your Martini instance. Upon startup, Martini should print logs like the following if it has been able to successfully communicate to the remote Solr instance:
1 2 3 4
25/04/18 16:39:19.749 INFO [RemoteSolrClient] Starting core: 'invoke_monitor' 25/04/18 16:39:19.755 INFO [RemoteSolrClient] Starting core: 'invoke_monitor' completed 25/04/18 16:39:19.222 INFO [RemoteSolrClient] Starting core: 'tracker' 25/04/18 16:39:19.737 INFO [RemoteSolrClient] Starting core: 'tracker' completed