install_cluster.sh 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/sh
  2. set -ex
  3. TOXIPROXY_VERSION=2.1.4
  4. mkdir -p ${KAFKA_INSTALL_ROOT}
  5. if [ ! -f ${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_VERSION}.tgz ]; then
  6. wget --quiet https://archive.apache.org/dist/kafka/${KAFKA_VERSION}/kafka_${KAFKA_SCALA_VERSION}-${KAFKA_VERSION}.tgz -O ${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_VERSION}.tgz
  7. fi
  8. if [ ! -f ${KAFKA_INSTALL_ROOT}/toxiproxy-${TOXIPROXY_VERSION} ]; then
  9. wget --quiet https://github.com/Shopify/toxiproxy/releases/download/v${TOXIPROXY_VERSION}/toxiproxy-server-linux-amd64 -O ${KAFKA_INSTALL_ROOT}/toxiproxy-${TOXIPROXY_VERSION}
  10. chmod +x ${KAFKA_INSTALL_ROOT}/toxiproxy-${TOXIPROXY_VERSION}
  11. fi
  12. rm -f ${KAFKA_INSTALL_ROOT}/toxiproxy
  13. ln -s ${KAFKA_INSTALL_ROOT}/toxiproxy-${TOXIPROXY_VERSION} ${KAFKA_INSTALL_ROOT}/toxiproxy
  14. for i in 1 2 3 4 5; do
  15. ZK_PORT=$((i + 2180))
  16. ZK_PORT_REAL=$((i + 21800))
  17. KAFKA_PORT=$((i + 9090))
  18. KAFKA_PORT_REAL=$((i + 29090))
  19. # unpack kafka
  20. mkdir -p ${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_PORT}
  21. tar xzf ${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_VERSION}.tgz -C ${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_PORT} --strip-components 1
  22. # broker configuration
  23. mkdir -p "${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_PORT}/data"
  24. # Append to default server.properties with a small number of customisations
  25. printf "\n\n" >> "${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_PORT}/config/server.properties"
  26. cat << EOF >> "${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_PORT}/config/server.properties"
  27. ############################# Sarama Test Cluster #############################
  28. broker.id=${KAFKA_PORT}
  29. broker.rack=${i}
  30. # Listen on "real" port
  31. listeners=PLAINTEXT://:${KAFKA_PORT_REAL}
  32. # Advertise Toxiproxy port
  33. advertised.listeners=PLAINTEXT://${KAFKA_HOSTNAME}:${KAFKA_PORT}
  34. # Connect to Zookeeper via Toxiproxy port
  35. zookeeper.connect=127.0.0.1:${ZK_PORT}
  36. # Data directory
  37. log.dirs="${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_PORT}/data"
  38. # Create new topics with a replication factor of 2 so failover can be tested
  39. # more easily.
  40. default.replication.factor=2
  41. # Turn on log.retention.bytes to avoid filling up the VM's disk
  42. log.retention.bytes=268435456
  43. log.segment.bytes=268435456
  44. # Enable topic deletion and disable auto-creation
  45. delete.topic.enable=true
  46. auto.create.topics.enable=false
  47. # Lower the zookeeper timeouts so we don't have to wait forever for a node
  48. # to die when we use toxiproxy to kill its zookeeper connection
  49. zookeeper.session.timeout.ms=3000
  50. zookeeper.connection.timeout.ms=3000
  51. # Disable broker ID length constraint
  52. reserved.broker.max.id=10000
  53. # Permit follower fetching (KIP-392)
  54. replica.selector.class=org.apache.kafka.common.replica.RackAwareReplicaSelector
  55. ###############################################################################
  56. EOF
  57. # zookeeper configuration
  58. cp ${REPOSITORY_ROOT}/vagrant/zookeeper.properties ${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_PORT}/config/
  59. sed -i s/KAFKAID/${KAFKA_PORT}/g ${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_PORT}/config/zookeeper.properties
  60. sed -i s/ZK_PORT/${ZK_PORT_REAL}/g ${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_PORT}/config/zookeeper.properties
  61. ZK_DATADIR="${KAFKA_INSTALL_ROOT}/zookeeper-${ZK_PORT}"
  62. mkdir -p ${ZK_DATADIR}
  63. sed -i s#ZK_DATADIR#${ZK_DATADIR}#g ${KAFKA_INSTALL_ROOT}/kafka-${KAFKA_PORT}/config/zookeeper.properties
  64. echo $i > ${KAFKA_INSTALL_ROOT}/zookeeper-${ZK_PORT}/myid
  65. done