以下のVagrantfileを使用して1ノード構成のCassandraを構築することができます。
インストールと合わせて認証の設定とテストテーブルの作成・選択も実行します。
Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/ubuntu-18.04"
config.vm.hostname = "ub1804cassandra"
config.vm.network :public_network, ip:"192.168.1.103"
config.vm.provider :virtualbox do |vbox|
vbox.name = "ub1804cassandra"
vbox.cpus = 2
vbox.memory = 2048
end
config.vm.provision "shell", inline: <<-SHELL
apt-get update
export DEBIAN_FRONTEND=noninteractive
apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get -y install language-pack-ja
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
apt-get update
# install apache cassandra
apt-get -y install curl
echo "deb http://www.apache.org/dist/cassandra/debian 311x main" >> /etc/apt/sources.list.d/cassandra.sources.list
curl https://www.apache.org/dist/cassandra/KEYS | apt-key add -
apt-get update
apt-get -y install cassandra
# configure authentication.
sed -i -e 's/authenticator: AllowAllAuthenticator/authenticator: PasswordAuthenticator/' /etc/cassandra/cassandra.yaml
systemctl enable cassandra.service
systemctl start cassandra.service
# CQL for test
cat << EOF > /home/vagrant/sample.cql
create keyspace mykeyspace with replication = {'class':'SimpleStrategy', 'replication_factor':1};
use mykeyspace;
create table mytable (
name text PRIMARY KEY,
value text
);
insert into mytable (name, value) values ('test1', 'cassandra');
select * from mytable;
EOF
# wait until it listens on 9042 port.
while netstat -lnt | awk '$4 ~ /:9042$/ {exit 1}'; do sleep 10; done
sleep 10
cqlsh -u cassandra -p cassandra -f /home/vagrant/sample.cql
SHELL
end
0 件のコメント:
コメントを投稿