How do I create a Solr core on my server?

At some point you may want to set up a Solr core for the search feature on your site. Now you can ask us to do that, which will be done on your support time, or you can follow this simple guide to create your own Solr cores.

To determine which version of Solr your server is running, you'll need to log in to your Solr Webapp. To do that, go to: http:// yoursolrdomain .codeenigma.com:9090/manager/html. If you're unsure of the domain, port number (9090 in this case) or username/password combination (you should be prompted for a username and password to access the webapp), please raise a ticket in Redmine requesting these details.

Click on the solr/ link, in the Applications table. If you are presented with a GUI like the one below, the version of Solr on the server is 4.x:

If you are presented with a very basic screen with a list of cores, then the version of Solr being used is 3.x.

Click here for the guide for Solr 4.x

Solr 3.x

Solr cores are normally located in one of the following locations: /var/lib/tomcat6/solr or /usr/share/tomcat6/solr. You can see where the environment home is by looking at the solr.xml file in /etc/tomcat6/Catalina/localhost/. The line to look for is something like this:

<Environment name="solr/home" type="java.lang.String" value="/var/lib/tomcat6/solr" override="true" />

To begin setting up a new solr core, you will first need to copy one of the existing cores in your Solr environment and rename it. In this example, you can see there are two cores:

To copy one of the cores to a new core, run this command:

sudo cp -r core0 nameofcore

You will be prompted for your sudo password, which is your LDAP password. You'll need to make sure the ownership of the new core (both the parent directory and all sub-directories and files) is tomcat6:tomcat6:

sudo chown -R tomcat6:tomcat6 nameofcore

Next, you need to delete anything inside the data directory of your new core by first moving to it:

cd nameofcore/data

And then running the following command:

sudo rm -rf *

Next, you will need to replace the files in the conf directory (/var/lib/tomcat6/solr/nameofcore/conf/) with the files required by your search module, be it Search API Solr or another module. So, for example, if you are using the Search API Solr module, you would need to copy the files from sites/all/modules/contrib/search_api_solr/solr-conf/3.x/ to /var/lib/tomcat6/solr/nameofcore/conf/ and ensure the ownership of those files are tomcat6:tomcat6.

The next step is to edit the solr.xml file back in the Solr home environment (/var/lib/tomcat6/solr), by running:

sudo nano solr.xml

At the bottom of that file, you should see something similar to this (probably with a different number of cores and different names):

<cores adminPath="/admin/cores">
    <core name="prod" instanceDir="prod" />
    <core name="core0" instanceDir="core0" />
  </cores>

Add another value to the end of that list for your new core:

<core name="nameofcore" instanceDir="nameofcore" />

Finally, you need to restart the tomcat6 service so your new core can be utilised:

sudo service tomcat6 restart

This service takes a little while to come back fully after being restarted, so bear that in mind if you see an error after refreshing the Solr Manager Webapp.

After the service has fully restarted, you will see the new core has appeared in your Webapp:

If you are unsure as to how to access your webapp, it can normally be accessed via a URL similar to: yourdomain-solr1.codeenigma.com:9090/manager/html. The port, 9090 in this example, may be different for you. If you are unsure of the port your solr instance is served on please create a ticket in Redmine and a sysadmin will get back to you.

When you go to the Webapp, you will be presented with a screen very similar to this:

Click the /solr link and you will be presented with a screen much like the previous image.

Solr 4.x

Once again, the location of the Solr cores could be in /var/lib/tomcat6/solr or /usr/share/tomcat6/solr. To create a new core, simply copy one of the existing cores and rename it. In the example below, you can see there is one core, core0.

To copy the entire contents of that directory to another, run this command:

sudo cp -r core0 nameofcore

Be sure the owner of this new directory is tomcat6. You can run this command to recursively change the ownership of the directory:

sudo chown -R tomcat6 nameofcore/

Next, you will need to delete anything inside the data directory inside your new core.

You can run a command like this:

sudo rm -rf *

This will delete everything in the current working directory.

Next, you will need to replace the files in the conf directory (/usr/share/tomcat6/solr/testcore/conf/) with the files required by your search module, be it Search API Solr or another module. So, for example, if you are using the Search API Solr module, you would need to copy the files from sites/all/modules/contrib/search_api_solr/solr-conf/4.x/ to /usr/share/tomcat6/solr/testcore/conf/ and ensure the ownership of those files are tomcat6:root.

Next, go to your Solr manager web interface, usually something like this: yourdomain-solr.codeenigma.com:9090/manager/html. Bear in mind that the port your Solr instance is running on may be different. If in doubt, raise a ticket in Redmine and a sysadmin will check for you. You may be prompted for a username and password to view this page. These would have been set upon installation of Solr, so if you do not know them, please raise a ticket in Redmine requesting the details.

You will be presented with a screen very similar to this:

Click /solr to take you to the core admin page. Solr 4.x and later offers a helpful GUI, which provides the ability to add cores without the need to restart tomcat6. Select Core Admin from the menu on the left, then press Add Core. Fill in the name and instanceDir fields with the same name as the directory you created earlier when copying an existing core.

Once you press Add Core, your new core will be added to the list of cores.

However, it would appear that if the tomcat6 service is restarted later, the core that was added via the admin interface 'disappears'. To prevent this from happening if the service is restarted, you will need to edit the the solr.xml file in /usr/share/tomcat6/solr to include this line:

​<core name="testcore" instanceDir="testcore" />

inside the <cores> block at the bottom of the file:

<cores adminPath="/admin/cores" host="${host:}" hostPort="${jetty.port:8983}" hostContext="${hostContext:solr}">

In this example, that block looks like this:

<cores adminPath="/admin/cores" host="${host:}" hostPort="${jetty.port:8983}" hostContext="${hostContext:solr}">
<core name="core0" instanceDir="core0" />
<core name="testcore" instanceDir="testcore" />
</cores>

Note that the <cores adminPath... line is on one line, not two.