ラベル ApacheCassandra の投稿を表示しています。 すべての投稿を表示
ラベル ApacheCassandra の投稿を表示しています。 すべての投稿を表示

2019年8月22日木曜日

VagrantでCassandraをインストールした仮想マシン(CentOS7.6)を構築する

Cassandraはオープンソースの分散データベースです。

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

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/centos-7.6"
  config.vm.hostname = "co76cassandra"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "co76cassandra"
     vbox.gui = true
     vbox.cpus = 2
     vbox.memory = 2048
  end
config.vm.network "public_network", ip: "192.168.1.104", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
localectl set-locale LANG=ja_JP.UTF-8
yum install -y epel-release
yum check-update
yum -y update
timedatectl set-timezone Asia/Tokyo
yum -y install unzip

# install cassandra
cat << EOF > /etc/yum.repos.d/cassandra.repo
[cassandra]
name=Apache Cassandra
baseurl=https://www.apache.org/dist/cassandra/redhat/311x/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.apache.org/dist/cassandra/KEYS
EOF
yum install -y cassandra

# configure authentication
sed -i -e 's/authenticator: AllowAllAuthenticator/authenticator: PasswordAuthenticator/' /etc/cassandra/default.conf/cassandra.yaml
systemctl enable cassandra.service
systemctl start cassandra.service

# execute sample sql.
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

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に関する他の記事はこちらを参照してください。

2019年7月25日木曜日

VagrantでCassandraをインストールした仮想マシン(Ubuntu18.04)を構築する

Cassandraはオープンソースの分散データベースです。

以下の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

2019年5月18日土曜日

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

Cassandraはオープンソースの分散データベースです。

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

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.6"
  config.vm.hostname = "db96cassandra"
config.vm.network :public_network, ip:"192.168.1.107"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db96cassandra"
     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

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


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

2018年6月19日火曜日

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

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

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.4"
  config.vm.hostname = "db94cassandra"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db94cassandra"
     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

# 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


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

2018年6月3日日曜日

LXDでApache Cassandraをインストールしたコンテナ(Ubuntu18.04)を構築する

Apache Cassandraはjava製の分散データベースです。

〇構築方法
以下のコマンドを実行して1ノード構成のCassandraを構築することができます。
インストールと合わせて認証の設定とテストテーブルの作成・選択も実行します。
lxc init ubuntu:18.04 ub1804cassandra
lxc config set ub1804cassandra user.user-data - < config.yml
lxc start ub1804cassandra

config.yml
#cloud-config

package_upgrade: true

hostname: ub1804cassandra
manage_etc_hosts: true

write_files:
  - path: /tmp/sample.cql
    content: |
      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;

runcmd:
  - "apt-get update"
  - "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"
  - "while netstat -lnt | awk '$4 ~ /:9042$/ {exit 1}'; do sleep 10; done"
  - "sleep 10"
  - "cqlsh -u cassandra -p cassandra -f /tmp/sample.cql >> /tmp/output.log"

final_message: "completed."

〇コンテナのIPを調べる
コンテナのIPは以下のコマンドで調べることができます。
lxc list

〇ホストマシンの外部からコンテナにアクセスしたい場合
以下のコマンドを実行します。
PORT=9042 PUBLIC_IP=<ホストのIP> CONTAINER_IP=<コンテナのIP> sudo -E bash -c 'iptables -t nat -I PREROUTING -i eth0 -p TCP -d $PUBLIC_IP --dport $PORT -j DNAT --to-destination $CONTAINER_IP:$PORT -m comment --comment "container"'

〇コンテナに入る
lxc exec ub1804cassandra /bin/bash

〇コンテナの停止
lxc stop ub1804cassandra

〇コンテナの削除
lxc delete ub1804cassandra


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

2018年5月24日木曜日

VagrantでJupyter LabとApache Cassandraをインストールした仮想マシン(Ubuntu18.04)を構築する

Jupyter Labでインタラクティブなコンピューティング環境を提供する事ができます。

○Jupyter Labの画面


構築方法

以下のVagrantfileで、Jupyter LabとApache Cassandraをインストールした仮想マシン(Ubuntu18.04)を構築する事ができます。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/ubuntu-18.04"
  config.vm.hostname = "ub1804jupyterlabcassandra"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "ub1804jupyterlabcassandra"
     vbox.cpus = 2
     vbox.memory = 4096
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.101", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.101", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
# update packages
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
locale-gen ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8


# install 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

# execute statements 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 starts to listen 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

# install anaconda & jupyterlab
wget https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
chmod +x Anaconda3-5.1.0-Linux-x86_64.sh
./Anaconda3-5.1.0-Linux-x86_64.sh -b -p /opt/anaconda
source /opt/anaconda/bin/activate
pip install --upgrade pip
pip install jupyterlab

# install cassandra driver
pip install cassandra-driver


useradd py
mkdir -p /home/py
chown -R py:py /home/py
sudo -u py bash -c "mkdir /home/py/.jupyter"
sudo -u py bash -c "cat << EOF > /home/py/.jupyter/jupyter_notebook_config.py
conf = get_config()
conf.NotebookApp.ip = '*'
conf.NotebookApp.open_browser = False
conf.NotebookApp.port = 8080
conf.NotebookApp.token = 'jupyter'
EOF"

cat << EOF > /etc/systemd/system/jupyter.service
[Unit]
Description=Jupyter notebook
[Service]
Type=simple
EnvironmentFile=/opt/anaconda/bin/activate
ExecStart=/opt/anaconda/bin/jupyter lab
User=py
Group=py
WorkingDirectory=/home/py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable jupyter
sudo systemctl start jupyter


echo 'access -> http://192.168.55.101:8080/?token=jupyter'

SHELL
end

〇動作確認用コード
from cassandra.cluster import Cluster

cluster = Cluster(['127.0.0.1'])
session = cluster.connect('mykeyspace')

rows = session.execute('SELECT name, value FROM mytable')
for row in rows:
  print(row)


関連情報

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

2018年5月16日水曜日

VagrantでApache Nifi 1.6.0とApache Cassandraがインストールされた仮想マシン(Debian Stretch/9.4)を構築する。

Apache Nifiは様々なデータを処理・分配するためのソフトウェアです。

〇Apache Nifiの画面


〇構築方法
1.以下のVagrantfileを使用して、Apache Nifi 1.6.0とApache Cassandraがインストールされた仮想マシン(Debian Stretch/9.4)を構築します。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.4"
  config.vm.hostname = "db94nifi160cassandra"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db94nifi160cassandra"
     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

# 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


# maximum file handles & maximum forked processes
echo '*  hard  nofile  50000' >> /etc/security/limits.conf
echo '*  soft  nofile  50000' >> /etc/security/limits.conf
echo '*  hard  nproc  10000' >> /etc/security/limits.conf
echo '*  soft  nproc  10000' >> /etc/security/limits.conf

echo '*  soft  nproc  10000' >> /etc/security/limits.d/90-nproc

# download and install Apache Nifi
wget http://ftp.riken.jp/net/apache/nifi/1.6.0/nifi-1.6.0-bin.tar.gz
tar xvfz nifi-1.6.0-bin.tar.gz
mv nifi-1.6.0 /opt

cat << EOF > /etc/systemd/system/nifi.service
[Unit]
Description=Apache Nifi
After=syslog.target network.target

[Service]
Type=forking
ExecStart=/opt/nifi-1.6.0/bin/nifi.sh start
ExecStop=/opt/nifi-1.6.0/bin/nifi.sh stop
KillMode=none

[Install]
WantedBy=multi-user.target
EOF
systemctl enable nifi.service
systemctl start nifi.service

echo 'access url -> http://192.168.1.105:8080/nifi/'

SHELL
end

2.Query Cassandra Processorで、以下のようにパラメータを設定してローカルのCassandraにアクセスします。
Cassandra Constact Points : localhost:9042
Keyspace : mykeyspace
Username : cassandra
Password : cassandra
CQL select query : select name, value from mytable


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

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

2018年5月10日木曜日

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

Jupyter Labでインタラクティブなコンピューティング環境を提供する事ができます。

〇Jupyter Labの画面


構築方法

以下のVagrantfileで、Jupyter LabとApache Cassandraをインストールした仮想マシンを構築する事ができます。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/ubuntu-16.04"
  config.vm.hostname = "ub1604jupyterlabcassandra"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "ub1604jupyterlabcassandra"
     vbox.cpus = 2
     vbox.memory = 4096
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.101", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.101", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
# update packages
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
locale-gen ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8


# install 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

# 認証の構成
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

# install anaconda & jupyterlab
wget https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
chmod +x Anaconda3-5.1.0-Linux-x86_64.sh
./Anaconda3-5.1.0-Linux-x86_64.sh -b -p /opt/anaconda
source /opt/anaconda/bin/activate
pip install --upgrade pip
pip install jupyterlab

# install cassandra driver
pip install cassandra-driver


useradd py
mkdir -p /home/py
chown -R py:py /home/py
sudo -u py bash -c "mkdir /home/py/.jupyter"
sudo -u py bash -c "cat << EOF > /home/py/.jupyter/jupyter_notebook_config.py
conf = get_config()
conf.NotebookApp.ip = '*'
conf.NotebookApp.open_browser = False
conf.NotebookApp.port = 8080
conf.NotebookApp.token = 'jupyter'
EOF"

cat << EOF > /etc/systemd/system/jupyter.service
[Unit]
Description=Jupyter notebook
[Service]
Type=simple
ExecStartPre=source /opt/anaconda/bin/activate
ExecStart=/opt/anaconda/bin/jupyter lab
User=py
Group=py
WorkingDirectory=/home/py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable jupyter
sudo systemctl start jupyter


echo 'access -> http://192.168.55.101:8080/?token=jupyter'

SHELL
end

〇動作確認用コード
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider

ap = PlainTextAuthProvider(username='cassandra', password='cassandra')
cluster = Cluster(['127.0.0.1'], auth_provider=ap)
session = cluster.connect('mykeyspace')

rows = session.execute('SELECT name, value FROM mytable')
for row in rows:
  print(row)

関連情報

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

2018年4月12日木曜日

VagrantでCassandraをインストールした仮想マシン(Ubuntu16.04)を構築する

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

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/ubuntu-16.04"
  config.vm.hostname = "ub1604cassandra"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "ub1604cassandra"
     vbox.cpus = 2
     vbox.memory = 2048
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.117", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.117", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
sed -i.bak -e "s#http://archive.ubuntu.com/ubuntu/#http://ftp.riken.jp/pub/Linux/ubuntu/#g" /etc/apt/sources.list
apt-get update
apt-get -y install language-pack-ja
localectl set-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja"
localectl set-keymap jp106
#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/default.conf/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に関する他の記事はこちらを参照してください。

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に関する他の記事はこちらを参照してください。

2018年3月30日金曜日

VagrantでJupyter LabとApache Cassandraをインストールした仮想マシン(Ubuntu16.04)を構築する

Jupyter Labでインタラクティブなコンピューティング環境を提供する事ができます。
以下のVagrantfileで、Jupyter LabとApache Cassandraをインストールした仮想マシンを構築する事ができます。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/ubuntu-16.04"
  config.vm.hostname = "ub1604jupyterlabcassandra"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "ub1604jupyterlabcassandra"
     vbox.cpus = 2
     vbox.memory = 4096
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.101", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.101", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
# update packages
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
locale-gen ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8


# install 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

# 認証の構成
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

# install anaconda & jupyterlab
wget https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
chmod +x Anaconda3-5.1.0-Linux-x86_64.sh
./Anaconda3-5.1.0-Linux-x86_64.sh -b -p /opt/anaconda
source /opt/anaconda/bin/activate
pip install --upgrade pip
pip install jupyterlab

# install cassandra driver
pip install cassandra-driver


useradd py
mkdir -p /home/py
chown -R py:py /home/py
sudo -u py bash -c "mkdir /home/py/.jupyter"
sudo -u py bash -c "cat << EOF > /home/py/.jupyter/jupyter_notebook_config.py
conf = get_config()
conf.NotebookApp.ip = '*'
conf.NotebookApp.open_browser = False
conf.NotebookApp.port = 8080
conf.NotebookApp.token = 'jupyter'
EOF"

cat << EOF > /etc/systemd/system/jupyter.service
[Unit]
Description=Jupyter notebook
[Service]
Type=simple
ExecStartPre=source /opt/anaconda/bin/activate
ExecStart=/opt/anaconda/bin/jupyter lab
User=py
Group=py
WorkingDirectory=/home/py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable jupyter
sudo systemctl start jupyter


echo 'access -> http://192.168.55.101:8080/?token=jupyter'

SHELL
end

〇動作確認用コード
from cassandra.cluster import Cluster

cluster = Cluster(['127.0.0.1'])
session = cluster.connect('mykeyspace')

rows = session.execute('SELECT name, value FROM mytable')
for row in rows:
  print(row)

〇Jupyter Labの画面


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

2017年10月15日日曜日

VagrantでCassandraをインストールした仮想マシン(CentOS7.4)を構築する

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

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/centos-7.4"
  config.vm.hostname = "co74cassandra"
  config.vm.network :public_network, ip:"192.168.1.116"
  config.vm.network "private_network", ip: "192.168.55.116", :netmask => "255.255.255.0"
  config.vm.provider :virtualbox do |vbox|
    vbox.name = "co74cassandra"
    vbox.cpus = 4
    vbox.memory = 4096
    vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
  config.vm.provision "shell", inline: <<-SHELL
# cassandraのインストール
cat << EOF > /etc/yum.repos.d/cassandra.repo
[cassandra]
name=Apache Cassandra
baseurl=https://www.apache.org/dist/cassandra/redhat/311x/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.apache.org/dist/cassandra/KEYS
EOF
yum install -y cassandra

# 認証の構成
sed -i -e 's/authenticator: AllowAllAuthenticator/authenticator: PasswordAuthenticator/' /etc/cassandra/default.conf/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に関する他の記事はこちらを参照してください。