Overview
Kibana + ElasticSearch + Logstash + Redis on RHEL 6
- ElasticSearch: Log search engine
- Redis: Queuing system broker
- Logstash: Log shipper and indexer
- Kibana: UI
Manual configuration steps
ElasticSearch
| Warning Your ElasticSearch must match the version of ElasticSearch in logstash! In this case, we have to install ElasticSearch 0.20.2 because we’re using logstash 1.1.9.http://logstash.net/docs/1.1.9/outputs/elasticsearch |
Install ElasticSearch
Download
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.2.tar.gz tar xvf elasticsearch-0.20.2.tar.gz mv elasticsearch-0.20.2 elasticsearch
elasticsearch.yml
cluster.name: elasticsearch-kibana node.name: r6x64o11-pv084 path.conf: /usr/local/elasticsearch/config path.data: /mnt/storage/es-data path.work: /usr/local/elasticsearch/tmp path.logs: /usr/local/elasticsearch/logs bootstrap.mlockall: true
Configure Java Service Wrapper
Get the service wrapper
wget http://github.com/elasticsearch/elasticsearch-servicewrapper/archive/master.zip unzip master mv elasticsearch-servicewrapper-master/service/ . rm -rf master rm -rf elasticsearch-servicewrapper-master/
Configure elasticsearch.conf
set.default.ES_HOME=/usr/local/elasticsearch set.default.ES_HEAP_SIZE=4096 wrapper.java.additional.10=-Des.max-open-files=true wrapper.logfile.maxsize=5m wrapper.logfile.maxfiles=5
Add ES home to root user’s .bash_profile
# ElasticSearch export ES_HOME=/usr/local/elasticsearch
Create elasticsearch user
useradd -d /home/elasticsearch -s /bin/sh elasticsearch chown -R elasticsearch:elasticsearch $ES_HOME chown -R elasticsearch:elasticsearch /mnt/storage/es-data
Edit elasticsearch user’s .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
# JAVA_HOME needs to be the latest 1.7 JDK on the system
JAVA_HOME=/usr/local/jdk7
export JAVA_HOME
#Add JAVA_HOME to the PATH
PATH=$JAVA_HOME/bin:$PATH
# ElasticSearch
export ES_HOME=/usr/local/elasticsearch
unset USERNAME
/etc/security/limits.conf (optional as this will be set in the service script, too)
elasticsearch soft nofile 65535 elasticsearch hard nofile 65535
Verify the file descriptor limit
sudo -u elasticsearch -s ulimit -Sn
Disable firewall
# /etc/init.d/iptables save # /etc/init.d/iptables stop # chkconfig iptables off
Install the service
bin/service/elasticsearch install
/etc/init.d/elasticsearch
# Java JAVA_HOME=/usr/local/jdk7 export JAVA_HOME PATH=$JAVA_HOME/bin:$PATH RUN_AS_USER=elasticsearch ULIMIT_N=65535
Run the service
bin/service/elasticsearch start or service elasticsearch start
ElasticSearch Head
http://kibana.pd.local:9200/_plugin/head/
bin/plugin -install mobz/elasticsearch-head
Redis
Install
wget http://redis.googlecode.com/files/redis-2.6.12.tar.gz tar xzf redis-2.6.12.tar.gz mv redis-2.6.12 /usr/local/redis cd /usr/local/redis make
Configure Redis – cp redis.conf 6379.conf
daemonize yes pidfile /var/run/redis/redis_6379.pid port 6379 timeout 300 tcp-keepalive 60 logfile /var/log/redis/redis_6379.log
Add REDIS home to root user’s .bash_profile
# Redis export REDIS_HOME=/usr/local/redis
Create redis user
useradd -d /home/redis -s /bin/sh redis chown -R redis:redis $REDIS_HOME chmod 700 $REDIS_HOME
Copy Redis init script
cp utils/redis_init_script /etc/init.d/redis_6379
Configure Redis init script
# chkconfig: - 85 15 # description: Redis is a persistent key-value database # processname: redis REDISUSER="redis" REDISPORT=6379 EXEC=/usr/local/redis/src/redis-server CLIEXEC=/usr/local/redis/src/redis-cli PIDFILE=/var/run/redis/redis_6379.pid CONF="/usr/local/redis/6379.conf" $EXEC $CONF ==change to==> /bin/su - $REDISUSER -c "$EXEC $CONF"
Activate Redis service
mkdir /var/run/redis /var/log/redis chown redis:adm /var/run/redis /var/log/redis sudo chmod 750 /var/log/redis cd /etc/init.d chkconfig --add redis_6379
Start
service redis start
Logstash
Download logstash on kibana.pd.local and the log producer
mkdir /usr/local/logstash cd /usr/local/logstash wget https://logstash.objects.dreamhost.com/release/logstash-1.1.9-monolithic.jar
Indexer configuration – vi indexer.conf
input {
redis {
host => "kibana.pd.local"
type => "redis-input"
data_type => "list"
key => "logstash"
format => "json_event"
}
}
filter{
multiline {
type => "bb-services"
pattern => "^20(.)*"
negate => true
what => "previous"
}
multiline {
type => "tomcat-std"
pattern => "^(.*\|){3}\s((?!Caused by)[^\s]).*"
negate => true
what => "previous"
}
multiline {
type => "catalina"
pattern => "^(SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST)(.)*"
negate => true
what => "previous"
}
}
output {
stdout { debug => true debug_format => "json"}
elasticsearch {
host => "localhost"
port => "9300"
cluster => "elasticsearch-kibana"
}
}
Shipper configuration – vi shipper.conf
input {
file {
type => "bb-services"
path => "/usr/local/blackboard/logs/bb-services-log.txt"
}
file {
type => "apache-access"
path => "/usr/local/blackboard/logs/tomcat/bb-access-log*"
}
file {
type => "tomcat-std"
path => "/usr/local/blackboard/logs/tomcat/stdout-stderr*"
}
file {
type => "catalina"
path => "/usr/local/blackboard/logs/tomcat/catalina-log.txt"
}
}
output {
stdout { debug => true debug_format => "json"}
redis {
host => "kibana.pd.local"
data_type => "list"
key => "logstash"
}
}
Fire up shipper and indexer (TODO: run as service)
java -jar logstash-1.1.9-monolithic.jar agent -f indexer.conf & java -jar logstash-1.1.9-monolithic.jar agent -f shipper.conf &
Note: Used http://java-regex-tester.appspot.com/ for regex testing.
Kibana
Setup Ruby
rpm -Uvh http://rbel.frameos.org/rbel6 yum install ruby ruby-devel ruby-ri ruby-rdoc cd /usr/local wget http://production.cf.rubygems.org/rubygems/rubygems-2.0.3.zip unzip rubygems-2.0.3.zip ruby rubygems-2.0.3.zip/setup.rb
Get Kibana
wget https://github.com/rashidkpc/Kibana/archive/v0.2.0.zip unzip v0.2.0 cd Kibana* gem install bundler bundle install
Configure Kibana
Elasticsearch = "kibana.pd.local:9200" KibanaPort = 80 KibanaHost = 'kibana.pd.local'
Run Kibana
bundle exec ruby kibana.rb
Chef
| Warning Not complete |
Setup Chef
- Sign up for hosted Chef: http://www.opscode.com/hosted-chef/
- Setup workstation: https://learnchef.opscode.com/quickstart/
I had to upgrade ruby-build to install the target Ruby version in the Chef doc.
brew upgrade ruby-build
Chef Cookbook
We’ll probably fork this:
https://github.com/lusis/chef-logstash