페이지

2024년 8월 17일 토요일

Hands On:Single Machine Setup

1. SSH into our machine

2. Install some necessary (java) and helpful packages on the machine

3. Disable RAM Swap

4. Add hosts mapping from hostname to public ips to /etc/hosts

5. Download & Configure Zookeeper on the machine

6. Launch Zookeeper on the machine to test

7. Setup Zookeeper as a service on the machine


sudo apt-get update && \
sudo apt-get -y install wget ca-certificates zip net-tools vim nano tar netcat
sudo apt-get -y install openjdk-8-jdk
java -version
sudo sysctl vm.swappiness=1
echo 'vm.swappiness=1' | sudo tee --append /etc/sysctl.conf
cat /etc/hosts
echo "172.31.9.1 kafka1
172.31.9.1 zookeeper1
172.31.19.230 kafka2
172.31.19.230 zookeeper2
172.31.35.20 kafka3
172.31.35.20 zookeeper3" | sudo tee --append /etc/hosts
ping kafka1
ping kafka2
wget https://archive.apache.org/dist/kafka/0.10.2.1/kafka_2.12-0.10.2.1.tgz
tar -xvzf kafka_2.12-0.10.2.1.tgz
rm kafka_2.12-0.10.2.1.tgz
mv kafka_2.12-0.10.2.1 kafka
cd kafka/
cat config/zookeeper.properties
bin/zookeeper-server-start.sh config/zookeeper.properties
# Testing Zookeeper install
# Start Zookeeper in the background
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
bin/zookeeper-shell.sh localhost:2181
ls /
# demonstrate the use of a 4 letter word
echo "ruok" | nc localhost 2181 ; echo


sudo nano /etc/init.d/zookeeper
#!/bin/sh
#
# zookeeper Start/Stop zookeeper
#
# chkconfig: - 99 10
# description: Standard script to start and stop zookeeper

DAEMON_PATH=/home/ubuntu/kafka/bin
DAEMON_NAME=zookeeper

PATH=$PATH:$DAEMON_PATH

# See how we were called.
case "$1" in
start)
# Start daemon.
pid=`ps ax | grep -i 'org.apache.zookeeper' | grep -v grep | awk '{print $1}'`
if [ -n "$pid" ]
then
echo "Zookeeper is already running";
else
echo "Starting $DAEMON_NAME";
$DAEMON_PATH/zookeeper-server-start.sh -daemon /home/ubuntu/kafka/config/zookeeper.properties
fi
;;
stop)
echo "Shutting down $DAEMON_NAME";
$DAEMON_PATH/zookeeper-server-stop.sh
;;
restart)
$0 stop
sleep 2
$0 start
;;
status)
pid=`ps ax | grep -i 'org.apache.zookeeper' | grep -v grep | awk '{print $1}'`
if [ -n "$pid" ]
then
echo "Zookeeper is Running as PID: $pid"
else
echo "Zookeeper is not Running"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac

exit 0
sudo chmod +x /etc/init.d/zookeeper
sudo chown root:root /etc/init.d/zookeeper
sudo update-rc.d zookeeper defaults
sudo service zookeeper stop
nc -vz localhost 2181
sudo service zookeeper start
sudo service zookeeper status
nc -vz localhost 2181
echo "ruok" | nc localhost 2181 ; echo
cat logs/zookeeper.out

2024년 8월 16일 금요일

How to SSH into our machine

1. Windows: Install Putty

https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

2. Mac/Linux: You have OpenSSH






Hands On:AWS Setup

1. Create an AWS Account
2. Setup network security to allow Zookeeper ports (2181, 2888, 3888)
3. Setup network security to allow myu IP only
4. Create I EC2 machines Ubuntu image t2.medium (4 GB RAM)
5. Reserve 3 private IPs for our machines










Zookeeper configuration

1. Zookeeper configuration can be very tricky to optimize and really depends on how your Kafka cluster is formed, as well as your network environment


2. We are going to set the most common settings for Zookeeper and discuss some more advance settings

# the location to store the in-memory database snapshots and, unless specified otherwise, the transaction log of updates to the database.
dataDir=/data/zookeeper
# the port at which the clients will connect
clientPort=2181
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
# the basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime.
tickTime=2000
# The number of ticks that the initial synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# zoo servers
# these hostnames such as `zookeeper-1` come from the /etc/hosts file
server.1=zookeeper1:2888:3888
server.2=zookeeper2:2888:3888
server.3=zookeeper3:2888:3888

Zookeeper Architecture Quorum sizing

1. Zookeeper needs to have a strict majority of servers up to form a strict majority when votes happen

2. Therefore Zookeepr quorums have 1,3,5,7,9,(2N+1) servers

3. This allows for 0,1,2,3,4,N server to go down

















Role of Zookeeper in Kafka

1. Brokers registration, with heartbeats mechanism to keep the list current

2. Maintaining a list of topics alongside

    - Their configuration (partitions, replication factor, additional configurations..)

    - The list of ISRs (in sync replicas) for partitions

3.  Performing leader elections in case some brokers go down

4. Storing the Kafka cluster id(randomly generated at 1st startup of cluster)

5. Storing ACLs (Access Control Lists) if security is enabled

    - Topics

    - Consumer Groups

    - Users

6. Quatas configuration if enabled

7. (deprecated) Used by old consumer API to store consumer offserts



2024년 8월 14일 수요일

What is Zookeeper

 1. Zookeeper provides multiple features for distributed applications:

    - Distributed configuration management

    - Self election / consensus building

    - Coordination and locks.

    - Key value store

2. Zookeeper is used in many distributed systems, such as Hadoop, Kafka, etc...

3. It's an Apache Project that's proven to be very stable and hasn't had major release in many years

4. 3.4.x is the stable channel

    3.5.x has been in development for manyu years, and it is still in beta


5. Zookeeper internal data structure is like a tree

- Each node is called a zNode

- Each zNode has a path

- zNode can be persistent or ephemeral

- Each zNode can store data

- No renaming of zNode

- Each zNode can be WATCHed for changes