2018年4月3日火曜日

VagrantでCassandraをインストールした仮想マシン(Debian Stretch/9.3)を構築する

以下のVagrantfileを使用して1ノード構成のCassandraを構築することができます。
インストールと合わせて認証の設定とテストテーブルの作成・選択も実行します。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.3"
  config.vm.hostname = "db93ignite240"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db93ignite240"
     vbox.cpus = 2
     vbox.memory = 2048
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.105", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.105", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
apt-get -y install task-japanese
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
update-locale LANG=ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

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

# 認証の構成
sed -i -e 's/authenticator: AllowAllAuthenticator/authenticator: PasswordAuthenticator/' /etc/cassandra/cassandra.yaml
systemctl enable cassandra.service
systemctl start cassandra.service

# テスト実行
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

# 9042ポートでlistenするまで待つ.
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


○関連情報
・Apache Cassandraに関する他の記事はこちらを参照してください。

0 件のコメント:

コメントを投稿