Created
February 28, 2016 07:17
-
-
Save InfinitiesLoop/38b06d62020c345554d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
kafka_version=0.9.0.1 | |
kafka_version_scala=2.11 | |
kafka_version_full=${kafka_version_scala}-${kafka_version} | |
elasticsearch_version=2.2.0 | |
elasticsearch_clustername=bnet-es | |
elasticsearch_nodename=bnet-es-node01 | |
java_version=java-1.8.0-openjdk.x86_64 | |
cd /tmp | |
# ensure some tools are here... | |
sudo yum install tar | |
sudo yum install wget | |
# install java | |
echo Installing Java... | |
sudo yum install --quiet --assumeyes ${java_version} | |
# install elasticsearch | |
# This results in Elasticsearch being installed in: | |
# binaries : /usr/share/elasticsearch/ | |
# config : /etc/elasticsearch | |
# init script: /etc/init.d/elasticsearch | |
echo Downloading ElasticSearch... | |
wget -q https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/${elasticsearch_version}/elasticsearch-${elasticsearch_version}.rpm | |
echo Installing ElasticSearch v${elasticsearch_version}... | |
sudo rpm -ivh elasticsearch-${elasticsearch_version}.rpm | |
# configure elasticsearch by prepending our settings | |
echo -e "node.name: ${elasticsearch_nodename}\ncluster.name: ${elasticsearch_clustername}\nnetwork.bind_host: 0\n" > /tmp/tmpfile.$$ | |
# why bind_host:0? ==> http://stackoverflow.com/questions/33412549/how-to-bind-elasticsearch-2-0-on-both-loopback-and-non-loopback-interfaces | |
sudo cat /etc/elasticsearch/elasticsearch.yml >> /tmp/tmpfile.$$ | |
sudo mv /tmp/tmpfile.$$ /etc/elasticsearch/elasticsearch.yml | |
# turn elasticsearch on | |
sudo systemctl daemon-reload | |
sudo systemctl start elasticsearch.service | |
echo ElasticSearch installed and enabled on port 9200. | |
echo | |
echo | |
# Kafka's turn | |
# it will be in /usr/share/kafka_${kafka_version} | |
echo Downloading Kafka ${kafka_version}... | |
cd /usr/share | |
sudo wget -q http://apache.mivzakim.net/kafka/${kafka_version}/kafka_${kafka_version_full}.tgz | |
sudo tar -zxvf kafka_${kafka_version_full}.tgz | |
sudo rm kafka_${kafka_version_full}.tgz | |
# create scripts to start ZK/Kafka | |
echo Creating Kafka start scripts... | |
sudo touch /usr/bin/start-{zookeeper,kafka} | |
sudo chmod 755 /usr/bin/start-{zookeeper,kafka} | |
cat <<EOH | sudo tee /usr/bin/start-zookeeper >/dev/null | |
/usr/share/kafka_${kafka_version_full}/bin/zookeeper-server-start.sh \ | |
/usr/share/kafka_${kafka_version_full}/config/zookeeper.properties & | |
EOH | |
cat <<EOH | sudo tee /usr/bin/start-kafka >/dev/null | |
start-zookeeper | |
sleep 3 | |
/usr/share/kafka_${kafka_version_full}/bin/kafka-server-start.sh \ | |
/usr/share/kafka_${kafka_version_full}/config/server.properties & | |
EOH | |
echo Use sudo start-kafka to start Kafka. Starting the first time for you now. | |
sudo start-kafka |
You should use mktemp
instead of creating your own temp file.
tempfile=$(sudo mktemp) # sudo so the file will be owned by root, otherwise you'd have to `chown` it
echo -e "node.name: ${elasticsearch_nodename}\ncluster.name: ${elasticsearch_clustername}\nnetwork.bind_host: 0\n" | sudo tee ${tempfile} >/dev/null
cat /etc/elasticsearch/elasticsearch.yml | sudo tee --append ${tempfile} >/dev/null
sudo mv ${tempfile} /etc/elasticsearch/elasticsearch.yml
Better still would be to edit the YAML file in-place, with sed -i
most likely (assuming the file already has node.name
and friends already in there, but commented out or something).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can save a bit of time by combining your
yum install
s (so you don't have to repeatedly check mirrors and such):sudo yum install --quiet --assumeyes tar wget ${java_version}
You can pass the url for ES's RPM directly to
rpm
and it'll download it for you, so you don't have to worry about being in/tmp
or leaving a file behind:You can also combine the download and extraction of kafka, so you can avoid
cd
-ing, avoid the temp file, and avoid runningwget
as root:Also, consider installing kafka to
/opt
or/usr/local
instead of/usr/share
./usr/share
is typically for data, not programs. You can also flatten out the tarball a bit when you extract like so:wget
options:tar
options: