Skip to content

Commit 80211e9

Browse files
authored
Merge pull request #15 from 116davinder/feature/test-upgrade
Feature/test upgrade
2 parents dfb0ee5 + 31feaab commit 80211e9

27 files changed

+269
-210
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
.ansible*
44
*.vscode
55
terraform/*/.terraform
6-
terraform/*/*tfstate*
6+
terraform/*/*tfstate*
7+
*.gz
8+
*.tgz

Readme.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ It is a group of playbooks to manage apache kafka.
2525
* **Zookeeper Installation**
2626
https://github.com/116davinder/zookeeper-cluster-ansible
2727

28-
# **Production Environment Setup**
28+
## **Development Setup with Vagrant**
2929

30-
## **Cloud Infra Setup for Apache Kafka Using Terraform**
30+
### **Vagrant PreSetup for cluster**
31+
It will update `/etc/hosts` with required dns names.
32+
33+
```ansible-playbook -i inventory/development/cluster.ini clusterVagrantDnsUpdater.yml```
34+
35+
## **Development with Cloud Infra Setup for Apache Kafka Using Terraform**
3136

3237
* `terraform/aws`
3338
* `terraform/oci`
3439

35-
## **Apache Kafka Playbooks**
36-
3740
### **AWS Cloud PreSetup for cluster**
3841
It will enable following things on all nodes.
3942

@@ -46,6 +49,7 @@ It will enable following things on all nodes.
4649

4750
```ansible-playbook -i inventory/<environment>/cluster.ini clusterAwsPreSetup.yml```
4851

52+
## **Production Environment Setup**
4953

5054
### **To start new cluster**
5155
* Update Required vars in ```inventory/<environment>/group_vars/all.yml``` .
@@ -183,11 +187,11 @@ It will be installed in similar way to apache kafka but it will start apache kaf
183187
### **Tested OS**
184188
* CentOS 7
185189
* RedHat 7
186-
* Ubuntu / Debain ( under progress, might work :) )
190+
* Ubuntu
187191
* Amzaon Linux 2 ( under progress, might work :) )
188192

189193
### **Tested Ansible Version**
190194
```
191-
ansible: 3.2.0
192-
ansible-base: 2.10.7
195+
ansible: 6.1.0
196+
ansible-base: 2.13.2
193197
```

Vagrantfile

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
Vagrant.configure("2") do |config|
22

3-
######################### Cluster Nodes
3+
# Cluster Nodes
44
cluster_nodes=3
55

66
(1..cluster_nodes).each do |i|
77
config.vm.define "kafka-#{i}" do |node|
8-
node.vm.box = "centos/7"
8+
node.vm.box = "ubuntu/focal64"
99
node.vm.hostname = "kafka#{i}"
1010
node.vm.network :private_network, ip: "192.168.56.10#{i}"
11-
#node.vm.provision :hosts, :sync_hosts => true
11+
# expose JMX port
12+
node.vm.network "forwarded_port", guest: 9999, host: "1000#{i}", protocol: "tcp"
13+
# node.vm.provision :hosts, :sync_hosts => true
1214
end
1315
end
14-
##################### Setting CPU and Memory for All machines
16+
# Setting CPU and Memory for All machines
1517
config.vm.provider "virtualbox" do |vb|
1618
vb.gui = false
17-
vb.memory = "750"
19+
vb.memory = "1024"
1820
vb.cpus = 1
21+
vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ] # used for wsl2
1922
end
2023

21-
### Sharing Folder with machines
22-
### is not requried if using linux box
23-
# config.vm.synced_folder ".", "/home/vagrant/projects",
24-
# mount_options: ["dmode=775,fmode=664"]
25-
2624
# SSH config to use your local ssh key for auth instead of username/password
27-
config.ssh.insert_key = false
25+
config.ssh.insert_key = false
2826
config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "~/.ssh/authorized_keys"
27+
end

clusterJmxMonitoringSetup.yml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,17 @@
44
gather_facts: true
55
become: true
66
tasks:
7-
- name: install gcc and python-devel ( Redhat / CentOS )
8-
ansible.builtin.yum:
9-
name: "{{ item }}"
10-
state: present
11-
loop:
12-
- gcc
13-
- python3-devel
14-
when: ansible_distribution in ['CentOS', 'RedHat'] | list
7+
- name: install common utils
8+
ansible.builtin.include_role:
9+
name: common
10+
tasks_from: commonUtils.yml
1511

16-
- name: install gcc and python-devel ( Debain / Ubuntu )
17-
ansible.builtin.apt:
18-
name: "{{ item }}"
19-
state: present
20-
loop:
21-
- gcc
22-
- python3-dev
23-
when: ansible_distribution in ['Debian', 'Ubuntu'] | list
24-
25-
- name: copy kafka-python package
12+
- name: copy python requirements.txt
2613
ansible.builtin.copy:
2714
src: "roles/jmxMonitor/files/requirements.txt"
2815
dest: "/tmp/requirements.txt"
2916

30-
- name: installing kafka_python with pip3
17+
- name: installing requirements.txt with pip3
3118
ansible.builtin.pip:
3219
requirements: "/tmp/requirements.txt"
3320
executable: pip3

clusterVagrantDnsUpdater.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
3+
- hosts: clusterNodes:clusterAddNodes
4+
gather_facts: true
5+
become: true
6+
tasks:
7+
- name: "Update the /etc/hosts file with node name"
8+
ansible.builtin.lineinfile:
9+
dest: "/etc/hosts"
10+
line: "{{ item }}\t{{ hostvars[item]['ansible_fqdn']}}"
11+
state: "present"
12+
backup: true
13+
loop: "{{ query('inventory_hostnames', 'clusterNodes:clusterAddNodes') }}"

collections.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
collections:
44
- name: 'community.general'
5-
version: '3.1.0'
5+
version: '4.8.0'
66
- name: 'amazon.aws'
7-
version: '1.5.0'
7+
version: '3.3.1'
88
- name: 'community.aws'
9-
version: '1.5.0'
9+
version: '3.4.0'
1010
- name: 'ansible.posix'
11-
version: '1.2.0'
11+
version: '1.4.0'

inventory/development/cluster.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
ansible_connection=ssh
33
ansible_become_method=sudo
44
ansible_become=true
5+
ansible_user=vagrant
56
#ansible_ssh_private_key_file = ~/.vagrant.d/insecure_private_key
67

78
[clusterNodes]
8-
10.0.0.[1:3] kafkaBrokerRackId=1
9+
192.168.56.10[1:3] kafkaBrokerRackId=1
910

1011
[clusterAddNodes]
1112

1213
[clusterRemoveNodes]
13-
10.0.0.[1:3]
14+
192.168.56.10[1:3]
1415

1516
[kafka-manager]
16-
10.0.0.1
17+
192.168.56.101
1718

1819
[kafka-mirror-maker]
19-
10.0.0.[1:3]
2020

2121
[kafka-mirror-maker-remove-nodes]
22-
10.0.0.[1:3]
22+
192.168.56.10[1:3]

inventory/development/group_vars/all.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,37 @@ kafkaInstallDir: /kafka
1414
kafkaDataDir: "{{ kafkaInstallDir }}/kafka-data"
1515
kafkaLogDir: "{{ kafkaInstallDir }}/kafka-logs"
1616

17+
kafkaGcLogs: true
18+
kafkaGcLogsLocation: "{{ kafkaLogDir }}"
19+
kafkaGcLogFileCount: 5
20+
kafkaGcLogFileSize: 10M # with optional K, M or G suffix
21+
1722
# JVM Settings
1823
# total memory * 0.25 or 25% of total memory only
1924
# Rest 75% will be used for Caching
20-
kafkaXms: 6G # 6GB is max recommended for production kafka
25+
kafkaXms: "256m" # 6GB is max recommended for production kafka
2126
kafkaXmx: "{{ kafkaXms }}"
2227
kafkaPort: 9092
2328
kafkaJmxPort: 9999
2429
kafkaVmMaxMapCount: 100000
2530

2631
# zookeeper string should comma separate value
2732
# 192.168.56.100:2181,192.168.56.101:2181,192.168.56.102:2181
28-
kafkaZookeeperAddressString: 35.172.235.154:2181
33+
kafkaZookeeperAddressString: 192.168.56.101:2181
2934
kafkaZookeeperConnectionTimeoutMs: 10000
3035

3136
# please use name like <environment>-kafka, so it get distinct name in NewRelic
3237
kafkaClusterName: development-kafka
3338

34-
kafkaVersion: 2.8.0
39+
kafkaVersion: 3.2.1
3540
kafkaScalaVersion: 2.13
36-
kafkaTarLocation: "/home/dpal/Downloads/kafka_{{ kafkaScalaVersion }}-{{ kafkaVersion }}.tgz"
41+
kafkaTarLocation: "~/projects/kafka-cluster-ansible/kafka_{{ kafkaScalaVersion }}-{{ kafkaVersion }}.tgz"
3742

3843
# below will be used while decommission/downgrade only
39-
kafkaOldVersion: 2.7.0
44+
kafkaOldVersion: 3.0.0
4045
kafkaOldScalaVersion: 2.13
4146

42-
### Production Optimization Parameters
47+
### Production Optimized Parameters
4348
### if nothing is set then it will use default values.
4449
kafkaDefaultReplicationFactor: 3
4550
kafkaMinInsyncReplicas: "{{ kafkaDefaultReplicationFactor | int - 1 }}"
@@ -61,13 +66,16 @@ kafkaTransactionStateLogMinIsr: "{{ kafkaOffsetsTopicReplicationFactor }}"
6166
kafkaLogFlushIntervalMessages: 10000
6267
kafkaLogFlushIntervalMs: 1000
6368
kafkaLogRetentionHours: 168
64-
kafkaLogSegmentBytes: 2073741824 # need to ask expert kafka, should we use default 1GB here or 2GB or more
69+
kafkaLogSegmentBytes: 2073741824 # need to ask kafka expert, should we use default 1GB here or 2GB or more
6570
kafkalogRetentionCheckIntervalMs: 300000
6671
kafkaGroupInitRebalanceDelayMs: 3
6772

6873

6974
# Only for AWS Based Cluster
7075
aws_kafka_ec2_region: "us-east-1"
7176
aws_kafka_ebs_device: "/dev/nvme1n1"
72-
aws_kafka_ebs_device_fs: "xfs" # currently tested with xfs only.
73-
aws_kafka_ebs_device_mount_location: "{{ kafkaInstallDir }}"
77+
aws_kafka_ebs_device_fs: "xfs" # currently tested with xfs only.
78+
aws_kafka_ebs_device_mount_location: "{{ kafkaInstallDir }}"
79+
80+
# Only AWS Cloudwatch Agent
81+
aws_kafka_cloudwatch_log_group: "kafka-{{ kafkaClusterName }}-logs"

inventory/development/group_vars/kafka-manager.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22

33
kafkaManagerInstallDir: /opt
4-
kafkaManagerVersion: 3.0.0.5
4+
kafkaManagerVersion: 3.0.0.6
55
kafkaManagerDownloadLink: "https://github.com/yahoo/CMAK/releases/download/{{ kafkaManagerVersion }}/cmak-{{ kafkaManagerVersion }}.zip"
66
# if you don't want to download with ansible
77
kafkaManagerRemoteDownload: true

roles/cloudwatch/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
buffer_duration = 5000
1818
log_stream_name = {instance_id}
1919
initial_position = start_of_file
20-
log_group_name = kafka-{{ kafkaClusterName }}-logs
20+
log_group_name = {{ aws_kafka_cloudwatch_log_group }}
2121
2222
- name: update aws region of clouwatch agent
2323
ansible.builtin.lineinfile:

0 commit comments

Comments
 (0)