Search code examples
ruby-on-railssolrdebiansunspotproduction

How can I set up rails sunspot solr production on debian 8?


I have two rails web applications with sunspot solr.

They works very well in development environment ( starting solr with rake sunspot:solr:start ), but in production environment I would like to install a separated multicore solr service using both of the rails application.

How can I do it?


Solution

  • A working solution:

    1. Install Java8 using this or this instructions.
    2. Download solr. I'm using version 6.2.0.
    3. Unpack from solr-x.y.z.tgz the install_solr_service.sh script from the bin directory ( bin/install_solr_service.sh ).
    4. Run this script with the name of the tgz file above as the first parameter ( ./install_solr_service.sh solr-x.y.z.tgz ). It will install the solr for your system. The core will be in the /opt/solr directory, and the data will be in the /var/solr.
    5. Start the service with service solr start command. The deamon will be executed in name of the solr user. (This user was created by the install_solr_service.sh script.) By default it will listen on port 8983.
    6. You can access its management GUI via http://your_server_name:8983/solr/ . You can find more info here.
    7. Create your solr cores:
    cd /opt/solr
    su - solr
    ./bin/solr create -c corename1
    ./bin/solr create -c corename2
    
    1. Stop your solr with service solr stop

    2. Change the solr core config to your config. You can find your config files under /path/to/your/rails/application/solr/configsets/sunspot/conf . Copy these file (lang subdirectory is not necessary to change) to your solr core config directory ( /var/solr/data/coranane1/conf/ ). Be sure, that after you change these files, the owner of them will be the solr user.

    3. Start your solr with service solr start

    4. Change your rails solr config file ( config/sunspot.yml ) to something similar:

    production:
      solr:
        hostname: localhost
        port: 8983
        path: '/solr/corename1'
        log_level: WARNING
        pid_dir: '/var/run'
    
    1. Reindex solr in your rails application:
    RAILS_ENV=production rake sunspot:solr:reindex
    
    1. Enjoy. :) And don't forget to protect your solr admin interface ( http://your_server_name:8983/solr/ ) via iptables or similar!