Skip to main content

Install and setup Apache SOLR v.4+ for Drupal, using Ansible

Drupal ver.: 
7.x
Category: 
DevOps
Tutorial
Tags: 
Apache SOLR
drupal
Ansible

Hi, in this article I’ll try to write a guide about how to install Apache Solr & setup it with Drupal configs from scratch. I’m going to reuse existing opensource solutions to avoid manual code writing in the console and automate this routine in case when anyone want to do the same.

So the first thing that we need it’s Ansible - the simplest way to automate our work.

We are going to use the latest Ansible version and installation script that might look like:

#! /bin/bash
 
# Only install if not exists
if [ ! -x /usr/bin/ansible ]; then
  echo ">>> Installing ansible";
 
  apt-get update
  apt-get install python-pip python-dev git -y
 
  pip install PyYAML jinja2 paramiko
  git clone https://github.com/ansible/ansible.git
 
  cd ansible
  # fix error https://github.com/ansible/ansible/issues/5412
  git submodule update --init --recursive
 
  make install
  mkdir /etc/ansible
 
  cp ~/ansible/examples/hosts /etc/ansible/
  ln -s /root/ansible/bin/ansible /usr/bin/ansible
fi

I assume that Ansible should be installed to the root folder in this script, but feel free to change it up to your requirements.

Next one: we'll use this great ansible-multicore-solr role to install all the stuff and even setup solr too!

$ cd ~
$ git clone https://github.com/jiv-e/ansible-multicore-solr.git 
$ cd ansible-multicore-solr

Next one: we'll override role variables like: solr version, drupal integration module, solar cores list.

$ mkdir group_vars
$ nano group_vars/solr

And put them here:

jiv_solr__version: 4.10.2
jiv_solr__searchApiSolrVersion: 7.x-1.6
jiv_solr__cores:
  # Just for example
  - { name: core1, coreType: default, keepChanges: no }
  # Just for example
  - { name: core2, coreType: drupal_apachesolr, keepChanges: no }
  - { name: abcmoda, coreType: drupal_search_api_solr, keepChanges: no }

Continue, apply our config overrides to the current host:

$ nano hosts

And add this:

[solr]
192.168.2.104

Finally we are going to run Ansible and let it do all the stuff:

$ ansible-playbook -i hosts play.yml -c local
$ ansible-playbook -i hosts play.yml -c local -e jiv_solr__uninstall=1

Go to Drupal website, navigate to the admin/config/search/search_api/server/[YOUR_SERVER_ID]/edit and add Solr path parameter:

/solr/abcmoda

Summarizing we could short this to the:

$ cd ~ && wget https://gist.github.com/vladdancer/cf4948c3e2db7ef65191/raw/4d6fa5df498496ff5026b28161d10478e2fbbc5b/do_install_ansible_ubuntu_10_plus.sh
$ sh do_install_ansible_ubuntu_10_plus.sh
 
$ git clone https://github.com/jiv-e/ansible-multicore-solr.git 
$ cd ansible-multicore-solr
$ mkdir group_vars
$ wget -O group_vars/solr https://gist.github.com/vladdancer/cf4948c3e2db7ef65191/raw/b701118ddcffab7a3dac12049bdbc77143b69a7f/solr
 
# Add your overrides
$ nano hosts
 
$ ansible-playbook -i hosts play.yml -c local

Bonus: you can store search API server settings config in the settings.php. http://www.wunderkraut.com/blog/search-api-server-in-settingsphp/2013-02-22

Leave a Comment

Plain text

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