Apache Cassandra 2019 Version in Docker
ApacheCassandra2019VersioninDocker
Ithinktheconf/cassandra.yamlshouldbefromthesample
ImportantMakefilewillbeasfollow:
IMAGE=sillycat/public
TAG=ubuntu-cassandra
NAME=ubuntu-cassandra
prepare:
wgethttp://apache.osuosl.org/cassandra/3.11.4/apache-cassandra-3.11.4-bin.tar.gz-Pinstall/
mkdirlogs
mkdirdata
docker-context:
build:docker-context
#dockerbuild--no-cache-t$(IMAGE):$(TAG).
dockerbuild-t$(IMAGE):$(TAG).
run:
dockerrun-d-p127.0.0.1:7000-7001:7000-7001-p127.0.0.1:7199:7199-p127.0.0.1:9042:9042-p127.0.0.1:9160:9160-v$(shellpwd)/data:/tool/cassandra/data-v$(shellpwd)/logs:/tool/cassandra/logs--name$(NAME)$(IMAGE):$(TAG)
debug:
dockerrun-ti-p7000-7001:7000-7001-p7199:7199-p9042:9042-p9160:9160-v$(shellpwd)/data:/tool/cassandra/data-v$(shellpwd)/logs:/tool/cassandra/logs--name$(NAME)$(IMAGE):$(TAG)/bin/bash
clean:
dockerstop${NAME}
dockerrm${NAME}
logs:
dockerlogs${NAME}
publish:
dockerpush${IMAGE}:${TAG}
fetch:
dockerpull${IMAGE}:${TAG}
Thestart.shwilldetecttheIPforrunningmachine.
#!/bin/sh-ex
#prepareconfig
INTERNAL_IP="$(hostname--ip-address)"
sed-ri's/(listen_address:).*/\1"'"$INTERNAL_IP"'"/'"/tool/cassandra/conf/cassandra.yaml"
#startthecassandra
/tool/cassandra/bin/cassandra-Dcassandra.config=file:///tool/cassandra/conf/cassandra.yaml-R-f
tail-f/tool/cassandra/logs/debug.log
HereistheDockerfileshowsallthesteps
#SetupCassandrainDocker
#PreparetheOS
FROMubuntu:16.04
MAINTAINERRachelKang<[email protected]>
ENVDEBIAN_FRONTENDnoninteractive
ENVJAVA_HOME/usr/lib/jvm/java-8-oracle
ENVLANGen_US.UTF-8
ENVLC_ALLen_US.UTF-8
RUNapt-get-qqupdate
RUNapt-get-qqydist-upgrade
#Preparethedenpendencies
RUNapt-getinstall-qywgetunzipvim
RUNapt-getinstall-qyiputils-ping
#InstallSUNJAVA
RUNapt-getupdate&&\
apt-getinstall-y--no-install-recommendslocales&&\
locale-genen_US.UTF-8&&\
apt-getdist-upgrade-y&&\
apt-get--purgeremoveopenjdk*&&\
echo"oracle-java8-installershared/accepted-oracle-license-v1-1selecttrue"|debconf-set-selections&&\
echo"debhttp://ppa.launchpad.net/webupd8team/java/ubuntuxenialmain">/etc/apt/sources.list.d/webupd8team-java-trusty.list&&\
apt-keyadv--keyserverkeyserver.ubuntu.com--recv-keysEEA14886&&\
apt-getupdate&&\
apt-getinstall-y--no-install-recommendsoracle-java8-installeroracle-java8-set-default&&\
apt-getcleanall
#Installtheapplication
WORKDIR/tool/
ADDinstall/apache-cassandra-3.11.4-bin.tar.gz/tool/
RUNln-s/tool/apache-cassandra-3.11.4/tool/cassandra
RUNmkdir/tool/cassandra/logs
RUNmkdir/tool/cassandra/data
ADDconf/cassandra.yaml/tool/cassandra/conf/
#StarttheApplication
#7000:intra-nodecommunication
#7001:TLSintra-nodecommunication
#7199:JMX
#9042:CQL
#9160:thriftservice
EXPOSE70007001719990429160
RUNmkdir-p/app/
ADDstart.sh/app/
WORKDIR/app
CMD["./start.sh”]
Putthecommandtoolinclasspath
sudoln-s/Users/hluo/tool/apache-cassandra-3.11.4/opt/cassandra-3.11.4
CheckVersion
>cqlsh--version
cqlsh5.0.1
Connecttolocalhost
>cqlshlocalhost9042
Verifywithaneasysample
CreateDatabase
cqlsh>createkeyspacemykeyspacewithreplication={'class':'SimpleStrategy','replication_factor':1};
cqlsh>usemykeyspace;
CreateTable
>cqlsh:mykeyspace>createtableusers(user_idintprimarykey,firstnametext,lastnametext);
InsertSomeData
cqlsh:mykeyspace>insertintousers(user_id,firstname,lastname)values(1,'carl','luo');
cqlsh:mykeyspace>insertintousers(user_id,firstname,lastname)values(2,'ray','luo');
cqlsh:mykeyspace>insertintousers(user_id,firstname,lastname)values(3,'kiko','kang');
Search
select*fromusers;
user_id|firstname|lastname
---------+-----------+----------
1|carl|luo
2|ray|luo
3|kiko|kang
CreateIndex
cqlsh:mykeyspace>createindexonusers(lastname);
SearchonIndex
select*fromuserswherelastname='luo';
user_id|firstname|lastname
---------+-----------+----------
1|carl|luo
2|ray|luo
Searchwithprimarykey
select*fromuserswhereuser_id=1;
user_id|firstname|lastname
---------+-----------+----------
1|carl|luo
References:
http://cassandra.apache.org/download/