Skip to content

Commit

Permalink
Adding in Vagrant and Ansible configurations/setup for AWS EC2 Kafka …
Browse files Browse the repository at this point in the history
…and MongoDB
  • Loading branch information
rocket-ron committed Aug 21, 2016
1 parent 4ec18ff commit 0f68f1f
Show file tree
Hide file tree
Showing 37 changed files with 1,197 additions and 163 deletions.
6 changes: 6 additions & 0 deletions kafka/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions kafka/.idea/kafka.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions kafka/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions kafka/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions kafka/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions kafka/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "dummy"

config.vm.provider :aws do |aws, override|
aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
aws.access_key_id = ENV['AWS_ACCESS_KEY_ID']
aws.keypair_name = ENV['AWS_KEYPAIR_NAME']
aws.ami = 'ami-a2490dc2'
aws.region = "us-west-1"
aws.instance_type = 'm3.large'
aws.security_groups = "mongodb"
aws.iam_instance_profile_name = 'mongodb'

aws.tags = {
"Name" => "Kafka Instance",
}
aws.block_device_mapping = [{
'DeviceName' => '/dev/sda1',
'Ebs.VolumeSize' => 16,
'Ebs.VolumeType' => 'gp2' }]

override.ssh.username = "ec2-user"
override.ssh.private_key_path = ENV['PRIVATE_AWS_SSH_KEY_PATH']
override.nfs.functional = false
end

config.vm.provision "ansible" do |ansible|
# ansible.verbose = 'vvvv'
ansible.playbook = "kafka.yml"
end
end
6 changes: 6 additions & 0 deletions kafka/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[ssh_connection]
control_path = /tmp/%%h-%%p-%%r

[defaults]
nocows=1
host_key_checking = False
5 changes: 5 additions & 0 deletions kafka/kafka.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: all
roles:
- zookeeper
- kafka
7 changes: 7 additions & 0 deletions kafka/roles/kafka/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: start kafka
sudo: yes
shell: "{{kafka.symlink}}/bin/kafka-server-start.sh {{kafka.symlink}}/config/server.properties &"
args:
chdir: "{{kafka.symlink}}"
register: command_start_kafka
21 changes: 21 additions & 0 deletions kafka/roles/kafka/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Get Kafka {{kafka.version}}
get_url: url={{kafka.url}} dest={{kafka.tgz}} timeout=60

- name: Create the remote directory for Kafka
sudo: yes
file: path={{kafka.untar_to}} state=directory mode=0755

- name: Unarchive Kafka
sudo: yes
unarchive: copy=no src={{kafka.tgz}} dest={{kafka.untar_to}}

- name: Symlink to the Kafka version
sudo: yes
file: path={{kafka.symlink}} src={{kafka.symlink_to}} state=link

- name: Generate the Kafka properties configuration
sudo: yes
template: src=server.properties.j2 dest=/usr/local/lib/kafka/config/server.properties mode=0644
notify:
- start kafka
121 changes: 121 additions & 0 deletions kafka/roles/kafka/templates/server.properties.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# 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.
# see kafka.server.KafkaConfig for additional details and defaults

############################# Server Basics #############################

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0

############################# Socket Server Settings #############################

# The port the socket server listens on
port=9092

# Hostname the broker will bind to. If not set, the server will bind to all interfaces
#host.name=localhost

# Hostname the broker will advertise to producers and consumers. If not set, it uses the
# value for "host.name" if configured. Otherwise, it will use the value returned from
# java.net.InetAddress.getCanonicalHostName().
#advertised.host.name=<hostname routable by clients>

# The port to publish to ZooKeeper for clients to use. If this is not set,
# it will publish the same port that the broker binds to.
#advertised.port=<port accessible by clients>

# The number of threads handling network requests
num.network.threads=3

# The number of threads doing disk I/O
num.io.threads=8

# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400

# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=102400

# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600


############################# Log Basics #############################

# A comma seperated list of directories under which to store log files
log.dirs=/var/log/kafka-logs

# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
# the brokers.
num.partitions=1

# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
# This value is recommended to be increased for installations with data dirs located in RAID array.
num.recovery.threads.per.data.dir=1

############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk.
# There are a few important trade-offs here:
# 1. Durability: Unflushed data may be lost if you are not using replication.
# 2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.
# 3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to exceessive seeks.
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# The number of messages to accept before forcing a flush of data to disk
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

############################# Log Retention Policy #############################

# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# The minimum age of a log file to be eligible for deletion
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log as long as the remaining
# segments don't drop below log.retention.bytes.
#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

# By default the log cleaner is disabled and the log retention policy will default to just delete segments after their retention expires.
# If log.cleaner.enable=true is set the cleaner will be enabled and individual logs can then be marked for log compaction.
log.cleaner.enable=false

############################# Zookeeper #############################

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=6000
8 changes: 8 additions & 0 deletions kafka/roles/kafka/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
kafka:
version: 0.10.0.1
url: http://apache.mirrors.pair.com/kafka/0.10.0.1/kafka_2.11-0.10.0.1.tgz
tgz: /tmp/kafka_2.11-0.10.0.1.tgz
untar_to: /usr/local/lib
symlink_to: /usr/local/lib/kafka_2.11-0.10.0.1
symlink: /usr/local/lib/kafka
16 changes: 16 additions & 0 deletions kafka/roles/zookeeper/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: stop zookeeper
sudo: yes
command: bin/zkServer.sh stop
args:
chdir: "{{zookeeper.symlink}}"
removes: /var/lib/zookeeper/zookeeper_server.pid

- name: start zookeeper
sudo: yes
command: bin/zkServer.sh start
args:
chdir: "{{zookeeper.symlink}}"
creates: /var/lib/zookeeper/zookeeper_server.pid
register: zookeeper_start_results
failed_when: "'FAILED' in zookeeper_start_results.stderr"
56 changes: 56 additions & 0 deletions kafka/roles/zookeeper/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
- name: Update all packages
yum: name=* state=latest
sudo: yes

- name: download oracle java8
command: "wget -q -O {{java.java_archive}} --no-cookies --no-check-certificate --header 'Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie' {{java.java8_download_url}} creates={{java.java_archive}}"
sudo: yes

- name: upack Java8 archive
sudo: yes
unarchive:
src={{java.java_archive}}
dest={{java.java8_download_folder}}
copy=no

- name: fix Java8 ownership
sudo: yes
file:
state=directory
path={{java.java_name}}
owner=root
group=root
recurse=yes

- name: make java available for system
sudo: yes
command: 'alternatives --install "/usr/bin/java" "java" "{{java.java_name}}/bin/java" 2000'

- name: cleanup
sudo: yes
file:
state=absent
path={{java.java_archive}}

- name: Download ZooKeeper {{zookeeper.version}}
get_url: url={{zookeeper.url}} dest={{zookeeper.tgz}} timeout=60

- name: Create the remote directory for ZooKeeper
sudo: yes
file: path={{zookeeper.untar_to}} state=directory mode=0755

- name: Unarchive ZooKeeper
sudo: yes
unarchive: copy=no src={{zookeeper.tgz}} dest={{zookeeper.untar_to}}

- name: Symlink to the ZooKeeper version
sudo: yes
file: path={{zookeeper.symlink}} src={{zookeeper.symlink_to}} state=link

- name: Create the ZooKeeper configuration
sudo: yes
template: src=zoo.cfg.j2 dest={{zookeeper.symlink}}/conf/zoo.cfg
notify:
- stop zookeeper
- start zookeeper
3 changes: 3 additions & 0 deletions kafka/roles/zookeeper/templates/zoo.cfg.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
Loading

0 comments on commit 0f68f1f

Please sign in to comment.