Skip to main content

Install Solr 5.x for Search Api Solr using Ansible

Drupal ver.: 

As stated at official site, Solr is:

the popular, blazing-fast, open source enterprise search platform built on Apache Lucene™.

In order to use its features on Drupal site, we have to install Search Api Solr module and get Solr up & ready.
At the moment of writing this article, latest stable version, supportable by Search Api Solr is 5.4.1. Which is we going to install.
What makes this task much easier is Ansible and its roles, contributed by other developers.

If you don’t have Ansible installed, check out official docs.

Current instance, where we’ll be installing Solr is Ubuntu 16.04.

1. Download Geerlingguy’s Ansible roles solr & java.

  • In order to do this, we have to create folder, which will contain our ansible playbook. Let’s name it solr-ansible. Then make requirements.yml file with next contents:

      - src:    
      - src: geerlingguy.solr
  • Run next command:

    ansible-galaxy install --roles-path . -r requirements.yml
    Which, basically, tells ansible to download latest versions of listed above roles into the current directory.

2. Make playbook.

  • Create file, named main.yml which should contain main instructions for ansible.
    Contents of the file:

      - name: Install solr
        hosts: localhost
        become: yes
        become_method: sudo
          solr_version: 5.4.1
            - main_core
            - second_core
          - geerlingguy.solr

name is the name for the playbook.
hosts tells Ansible on which machines this playbook should be ran.

vars contains variables, that will be used in roles.
solr_cores - here you can enlist cores, that you want to install.

3. Run playbook.

  • Run next command:

      ansible-playbook main.yml -vvv

Solr will be installed in /opt/solr folder.
Cores main_core and second_core can be found at /var/solr/data.

4. Apply configs.

  • Locate folder which contains Search Api Solr module. There’s subfolder solr-conf, that contains configs for different Sol versions. Because we’re using 5.4.1 version, we have to copy contents of 5.x subfolder of solr-conf to /var/solr/data/main_core/conf with overwriting contents. We’re going to configure only main_core core.

  • Contents of should be placed within file, which can be found at /var/solr/data/main_core folder. Make sure that next variables have mentioned values:

  • If you want to use file extractors (extract text from pdf files, e.g.), make sure to replace following line:

      <!--<lib dir="../../dist/" regex="apache-solr-cell-\d.*\.jar" />-->

    with this one:

      <lib dir="${solr.contrib.dir:../../../contrib}/../dist/" regex="solr-cell-\d.*\.jar" />

inside solrconfig.xml file.

  • Restart Solr:

      sudo service solr restart

To make sure cores are running, we can go to: Solr dashboard

5. Enable Basic http authentication.

This is optional step, because secure connection could be established via SSL. Or by any other means.

  • Navigate to /opt/solr/server/etc.

  • Put next code at the end of jetty.xml file before </Configure> tag:

    <!-- Configure Basic http authentication -->
    <Call name="addBean">
        <New class="">
          <Set name="name">Solr Realm</Set>
          <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/</Set>
          <Set name="refreshInterval">0</Set>
  • Put next code at the end of webdefault.xml before </web-app>:

          <web-resource-name>Solr authenticated application</web-resource-name>
        <realm-name>Solr Realm</realm-name>
  • Create file in the current directory with next contents:

      admin: admin, admin-role

    User name: admin
    User password: admin
    Role: admin-role. Note: should be the same as the value within <role-name> tag from snippet above.

  • Restart Solr:

      sudo service solr restart

Right now in order to go to Solr dashboard, we have to enter user name & user password, matching ones in file.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.