diff --git a/solr/defaults/main.yml b/solr/defaults/main.yml new file mode 100644 index 0000000..929ddf6 --- /dev/null +++ b/solr/defaults/main.yml @@ -0,0 +1,32 @@ +--- +# solr +solr_install: True +solr_http_port: 8983 + +solr_version: 5.5.0 +solr_service: -solr +solr_config_name: hindex +solr_shards: 1 +solr_instance: '{{ solr_service }}' +solr_log_level: INFO +solr_http_port_1: '{{ solr_http_port }}' +solr_zoo_port: 9983 +solr_zoo_port_1: 9984 +solr_zoo_port_2: 9985 +solr_jmx_port_1: 8601 +solr_user: solr +solr_group: solr +# We need to define this one because we are using the tomcat multiple instances role +solr_base_dir: /opt/solr-files +solr_data_dir: '{{ solr_base_dir }}/solr' +solr_heap: 1024M +solr_mode: solrcloud +solr_download_dir: '{{ solr_base_dir }}/download' +solr_zookeeper_data_dir: '{{ solr_data_dir }}/zoo_data' +solr_install_collection1: False +solr_download_url: 'http://www-eu.apache.org/dist/lucene/solr/{{ solr_version }}/solr-{{ solr_version }}.tgz' +solr_jar_files: + - contrib/analysis-extras/lib/icu4*.jar + - contrib/analysis-extras/lucene-libs/lucene-analyzers-icu*.jar + + diff --git a/solr/files/solr b/solr/files/solr new file mode 100755 index 0000000..7412bb3 --- /dev/null +++ b/solr/files/solr @@ -0,0 +1,80 @@ +#!/bin/sh +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +### BEGIN INIT INFO +# Provides: solr +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: Controls Apache Solr as a Service +### END INIT INFO + +# Example of a very simple *nix init script that delegates commands to the bin/solr script +# Typical usage is to do: +# +# cp bin/init.d/solr /etc/init.d/solr +# chmod 755 /etc/init.d/solr +# chown root:root /etc/init.d/solr +# update-rc.d solr defaults +# update-rc.d solr enable + +# Where you extracted the Solr distribution bundle +SOLR_INSTALL_DIR="/opt/solr" +# Specify the user to run Solr as; if not set, then Solr will run as root. +# Running Solr as root is not recommended for production environments + +# Path to an include file that defines environment specific settings to override default +# variables used by the bin/solr script. It's highly recommended to define this script so +# that you can keep the Solr binary files separated from live files (pid, logs, index data, etc) +# see bin/solr.in.sh for an example +SOLR_ENV="/etc/default/solr" + +RUNAS="solr" + +if [ ! -f "$SOLR_ENV" ]; then + echo "$SOLR_ENV not found! Please check the SOLR_ENV setting in your $0 script." + exit 1 +else + . $SOLR_ENV +fi + +if [ ! -d "$SOLR_INSTALL_DIR" ]; then + echo "$SOLR_INSTALL_DIR not found! Please check the SOLR_INSTALL_DIR setting in your $0 script." + exit 1 +fi + +# verify the specified run as user exists +runas_uid="`id -u "$RUNAS"`" +if [ $? -ne 0 ]; then + echo "User $RUNAS not found! Please create the $RUNAS user before running this script." + exit 1 +fi + +case "$1" in + start|stop|restart|status) + SOLR_CMD="$1" + ;; + *) + echo "Usage: $0 {start|stop|restart|status}" + exit +esac + +if [ -n "$RUNAS" ]; then + su -c "SOLR_INCLUDE=\"$SOLR_ENV\" \"$SOLR_INSTALL_DIR/bin/solr\" $SOLR_CMD" - "$RUNAS" +else + SOLR_INCLUDE="$SOLR_ENV" "$SOLR_INSTALL_DIR/bin/solr" "$SOLR_CMD" +fi diff --git a/solr/handlers/main.yml b/solr/handlers/main.yml new file mode 100644 index 0000000..1533111 --- /dev/null +++ b/solr/handlers/main.yml @@ -0,0 +1,4 @@ +--- +- name: tomcat solr restart + service: name=tomcat-instance-'{{ solr_http_port }}' state=restarted sleep=20 + diff --git a/solr/tasks/main.yml b/solr/tasks/main.yml new file mode 100644 index 0000000..8822466 --- /dev/null +++ b/solr/tasks/main.yml @@ -0,0 +1,40 @@ +--- +- block: + + - name: Create a solr user + become: False + user: name={{ solr_user }} home={{ solr_base_dir }} createhome=yes shell=/bin/bash + + - name: Create the solr service and download directories + file: path={{ item }} state=directory + with_items: [ '{{ solr_data_dir }}', '{{ solr_download_dir }}' ] + + - name: Download solr + get_url: url='{{ solr_download_url }}' dest={{ solr_download_dir }}/solr-{{ solr_version }}.tgz validate_certs=no + + - name: Unarchive solr release + unarchive: src={{ solr_download_dir }}/solr-{{ solr_version }}.tgz dest={{ solr_data_dir }} + + - name: create solr lib dir + file: path={{ solr_data_dir }}/server/solr/lib + + - name: copy extra libraries + shell: cd {{ solr_data_dir }}; cp -u {{ item }} {{ solr_data_dir }}/server/solr/lib + with_items: '{{ solr_jar_files }}' + + - name: install the solr init script + become: False + copy: src=solr dest=/etc/init.d/solr mode=0755 owner=root group=root + + - name: Install the solr default + become: False + template: src=solr-default.j2 dest=/etc/default/solr mode=0644 owner=root group=root + + - name: Start and enable the solr service + become: False + service: name=solr state=started enabled=yes + + become: True + become_user: '{{ solr_user }}' + when: solr_install + tags: solr diff --git a/solr/templates/solr-default.j2 b/solr/templates/solr-default.j2 new file mode 100644 index 0000000..8901769 --- /dev/null +++ b/solr/templates/solr-default.j2 @@ -0,0 +1,126 @@ +SOLR_INSTALL_DIR="{{ solr_data_dir }}" +RUNAS="{{ solr_user }}" + + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# By default the script will use JAVA_HOME to determine which java +# to use, but you can set a specific path for Solr to use without +# affecting other Java applications on your server/workstation. +#SOLR_JAVA_HOME="" + +# Increase Java Heap as needed to support your indexing / query needs +SOLR_HEAP="{{ solr_heap }}" + +# Expert: If you want finer control over memory options, specify them directly +# Comment out SOLR_HEAP if you are using this though, that takes precedence +#SOLR_JAVA_MEM="-Xms512m -Xmx512m" + +# Enable verbose GC logging +GC_LOG_OPTS="-verbose:gc -XX:+PrintHeapAtGC -XX:+PrintGCDetails \ +-XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime" + +# These GC settings have shown to work well for a number of common Solr workloads +GC_TUNE="-XX:NewRatio=3 \ +-XX:SurvivorRatio=4 \ +-XX:TargetSurvivorRatio=90 \ +-XX:MaxTenuringThreshold=8 \ +-XX:+UseConcMarkSweepGC \ +-XX:+UseParNewGC \ +-XX:ConcGCThreads=4 -XX:ParallelGCThreads=4 \ +-XX:+CMSScavengeBeforeRemark \ +-XX:PretenureSizeThreshold=64m \ +-XX:+UseCMSInitiatingOccupancyOnly \ +-XX:CMSInitiatingOccupancyFraction=50 \ +-XX:CMSMaxAbortablePrecleanTime=6000 \ +-XX:+CMSParallelRemarkEnabled \ +-XX:+ParallelRefProcEnabled" + +# Set the ZooKeeper connection string if using an external ZooKeeper ensemble +# e.g. host1:2181,host2:2181/chroot +# Leave empty if not using SolrCloud +#ZK_HOST="" + +# Set the ZooKeeper client timeout (for SolrCloud mode) +#ZK_CLIENT_TIMEOUT="15000" + +# By default the start script uses "localhost"; override the hostname here +# for production SolrCloud environments to control the hostname exposed to cluster state +#SOLR_HOST="192.168.1.1" + +# By default the start script uses UTC; override the timezone if needed +#SOLR_TIMEZONE="UTC" + +# Set to true to activate the JMX RMI connector to allow remote JMX client applications +# to monitor the JVM hosting Solr; set to "false" to disable that behavior +# (false is recommended in production environments) +ENABLE_REMOTE_JMX_OPTS="false" + +# The script will use SOLR_PORT+10000 for the RMI_PORT or you can set it here +# RMI_PORT=18983 + +# Set the thread stack size +SOLR_OPTS="$SOLR_OPTS -Xss256k" + +SOLR_MODE={{ solr_mode }} + +# Anything you add to the SOLR_OPTS variable will be included in the java +# start command line as-is, in ADDITION to other options. If you specify the +# -a option on start script, those options will be appended as well. Examples: +#SOLR_OPTS="$SOLR_OPTS -Dsolr.autoSoftCommit.maxTime=3000" +#SOLR_OPTS="$SOLR_OPTS -Dsolr.autoCommit.maxTime=60000" +#SOLR_OPTS="$SOLR_OPTS -Dsolr.clustering.enabled=true" + +# Location where the bin/solr script will save PID files for running instances +# If not set, the script will create PID files in $SOLR_TIP/bin +#SOLR_PID_DIR= + +# Path to a directory for Solr to store cores and their data. By default, Solr will use server/solr +# If solr.xml is not stored in ZooKeeper, this directory needs to contain solr.xml +#SOLR_HOME= + +# Solr provides a default Log4J configuration properties file in server/resources +# however, you may want to customize the log settings and file appender location +# so you can point the script to use a different log4j.properties file +#LOG4J_PROPS=/var/solr/log4j.properties + +# Location where Solr should write logs to; should agree with the file appender +# settings in server/resources/log4j.properties +#SOLR_LOGS_DIR= + +# Sets the port Solr binds to, default is 8983 +#SOLR_PORT=8983 + +# Uncomment to set SSL-related system properties +# Be sure to update the paths to the correct keystore for your environment +#SOLR_SSL_KEY_STORE=etc/solr-ssl.keystore.jks +#SOLR_SSL_KEY_STORE_PASSWORD=secret +#SOLR_SSL_TRUST_STORE=etc/solr-ssl.keystore.jks +#SOLR_SSL_TRUST_STORE_PASSWORD=secret +#SOLR_SSL_NEED_CLIENT_AUTH=false +#SOLR_SSL_WANT_CLIENT_AUTH=false + +# Uncomment if you want to override previously defined SSL values for HTTP client +# otherwise keep them commented and the above values will automatically be set for HTTP clients +#SOLR_SSL_CLIENT_KEY_STORE= +#SOLR_SSL_CLIENT_KEY_STORE_PASSWORD= +#SOLR_SSL_CLIENT_TRUST_STORE= +#SOLR_SSL_CLIENT_TRUST_STORE_PASSWORD= + +# Settings for authentication +#SOLR_AUTHENTICATION_CLIENT_CONFIGURER= +#SOLR_AUTHENTICATION_OPTS= +