以下のVagrantfileを使用して、Apache Igniteがインストールされた3ノードクラスタを構築する事ができます。
Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "ignode1" do |server|
server.vm.box = "bento/ubuntu-16.04"
server.vm.hostname = "ignode1"
server.vm.network :public_network, ip:"192.168.1.91"
server.vm.network "private_network", ip: "192.168.55.91", :netmask => "255.255.255.0"
server.vm.provider :virtualbox do |vbox|
vbox.name = "ignode1"
vbox.cpus = 2
vbox.memory = 2048
vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
end
server.vm.provision "shell", inline: <<-SHELL
# add host entries...
sed -i -e 's/^.*ignode1$//' /etc/hosts
cat << EOF >> /etc/hosts
192.168.55.91 ignode1
192.168.55.92 ignode2
192.168.55.93 ignode3
EOF
# 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
apt-get -y install unzip
# install java
apt-get -y install openjdk-8-jdk
# download and install zookeeper
wget http://ftp.riken.jp/net/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
tar xvfz zookeeper-3.4.11.tar.gz
mv zookeeper-3.4.11 /opt/zookeeper
# create configuration file.
cat << EOF > /opt/zookeeper/conf/zoo.cfg
tickTime=2000
dataDir=/var/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=ignode1:2888:3888
server.2=ignode2:2888:3888
server.3=ignode3:2888:3888
EOF
mkdir -p /var/zookeeper
echo '1' >> /var/zookeeper/myid
# register as a service.
cat << EOF > /etc/systemd/system/zookeeper.service
[Unit]
Description=Apache Zookeeper
Requires=network.target
After=network.target
[Service]
Type=forking
ExecStart=/opt/zookeeper/bin/zkServer.sh start /opt/zookeeper/conf/zoo.cfg
ExecStop=/opt/zookeeper/bin/zkServer.sh stop
WorkingDirectory=/opt/zookeeper
[Install]
WantedBy=multi-user.target
EOF
systemctl enable zookeeper.service
systemctl start zookeeper.service
# 2181ポートでlistenするまで待つ.
while netstat -lnt | awk '$4 ~ /:2181$/ {exit 1}'; do sleep 10; done
sleep 10
# Apache Igniteのインストール
wget http://www-us.apache.org/dist//ignite/2.4.0/apache-ignite-fabric-2.4.0-bin.zip
unzip apache-ignite-fabric-2.4.0-bin.zip
mv apache-ignite-fabric-2.4.0-bin /opt/ignite
cat << EOF > /etc/systemd/system/ignite.service
[Unit]
Description=Apache Ignite
[Service]
ExecStart=/opt/ignite/bin/ignite.sh
WorkingDirectory=/opt/ignite
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl enable ignite.service
systemctl start ignite.service
# 11211ポートでlistenするまで待つ.
while netstat -lnt | awk '$4 ~ /:11211$/ {exit 1}'; do sleep 10; done
sleep 10
SHELL
end
#----------------------------------------------------------------------------------------
config.vm.define "ignode2" do |server|
server.vm.box = "bento/ubuntu-16.04"
server.vm.hostname = "ignode2"
server.vm.network :public_network, ip:"192.168.1.92"
server.vm.network "private_network", ip: "192.168.55.92", :netmask => "255.255.255.0"
server.vm.provider :virtualbox do |vbox|
vbox.name = "ignode2"
vbox.cpus = 2
vbox.memory = 2048
vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
end
server.vm.provision "shell", inline: <<-SHELL
# add host entries...
sed -i -e 's/^.*ignode2$//' /etc/hosts
cat << EOF >> /etc/hosts
192.168.55.91 ignode1
192.168.55.92 ignode2
192.168.55.93 ignode3
EOF
# 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
apt-get -y install unzip
# install java
apt-get -y install openjdk-8-jdk
# download and install zookeeper
wget http://ftp.riken.jp/net/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
tar xvfz zookeeper-3.4.11.tar.gz
mv zookeeper-3.4.11 /opt/zookeeper
# create configuration file.
cat << EOF > /opt/zookeeper/conf/zoo.cfg
tickTime=2000
dataDir=/var/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=ignode1:2888:3888
server.2=ignode2:2888:3888
server.3=ignode3:2888:3888
EOF
mkdir -p /var/zookeeper
echo '2' >> /var/zookeeper/myid
# register as a service.
cat << EOF > /etc/systemd/system/zookeeper.service
[Unit]
Description=Apache Zookeeper
Requires=network.target
After=network.target
[Service]
Type=forking
ExecStart=/opt/zookeeper/bin/zkServer.sh start /opt/zookeeper/conf/zoo.cfg
ExecStop=/opt/zookeeper/bin/zkServer.sh stop
WorkingDirectory=/opt/zookeeper
[Install]
WantedBy=multi-user.target
EOF
systemctl enable zookeeper.service
systemctl start zookeeper.service
# 2181ポートでlistenするまで待つ.
while netstat -lnt | awk '$4 ~ /:2181$/ {exit 1}'; do sleep 10; done
sleep 10
# Apache Igniteのインストール
wget http://www-us.apache.org/dist//ignite/2.4.0/apache-ignite-fabric-2.4.0-bin.zip
unzip apache-ignite-fabric-2.4.0-bin.zip
mv apache-ignite-fabric-2.4.0-bin /opt/ignite
cat << EOF > /etc/systemd/system/ignite.service
[Unit]
Description=Apache Ignite
[Service]
ExecStart=/opt/ignite/bin/ignite.sh
WorkingDirectory=/opt/ignite
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl enable ignite.service
systemctl start ignite.service
# 11211ポートでlistenするまで待つ.
while netstat -lnt | awk '$4 ~ /:11211$/ {exit 1}'; do sleep 10; done
sleep 10
SHELL
end
#----------------------------------------------------------------------------------------
config.vm.define "ignode3" do |server|
server.vm.box = "bento/ubuntu-16.04"
server.vm.hostname = "ignode3"
server.vm.network :public_network, ip:"192.168.1.93"
server.vm.network "private_network", ip: "192.168.55.93", :netmask => "255.255.255.0"
server.vm.provider :virtualbox do |vbox|
vbox.name = "ignode3"
vbox.cpus = 2
vbox.memory = 2048
vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
end
server.vm.provision "shell", inline: <<-SHELL
# add host entries...
sed -i -e 's/^.*ignode3$//' /etc/hosts
cat << EOF >> /etc/hosts
192.168.55.91 ignode1
192.168.55.92 ignode2
192.168.55.93 ignode3
EOF
# 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
apt-get -y install unzip
# install java
apt-get -y install openjdk-8-jdk
# download and install zookeeper
wget http://ftp.riken.jp/net/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
tar xvfz zookeeper-3.4.11.tar.gz
mv zookeeper-3.4.11 /opt/zookeeper
# create configuration file.
cat << EOF > /opt/zookeeper/conf/zoo.cfg
tickTime=2000
dataDir=/var/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=ignode1:2888:3888
server.2=ignode2:2888:3888
server.3=ignode3:2888:3888
EOF
mkdir -p /var/zookeeper
echo '3' >> /var/zookeeper/myid
# register as a service.
cat << EOF > /etc/systemd/system/zookeeper.service
[Unit]
Description=Apache Zookeeper
Requires=network.target
After=network.target
[Service]
Type=forking
ExecStart=/opt/zookeeper/bin/zkServer.sh start /opt/zookeeper/conf/zoo.cfg
ExecStop=/opt/zookeeper/bin/zkServer.sh stop
WorkingDirectory=/opt/zookeeper
[Install]
WantedBy=multi-user.target
EOF
systemctl enable zookeeper.service
systemctl start zookeeper.service
# 2181ポートでlistenするまで待つ.
while netstat -lnt | awk '$4 ~ /:2181$/ {exit 1}'; do sleep 10; done
sleep 10
# Apache Igniteのインストール
wget http://www-us.apache.org/dist//ignite/2.4.0/apache-ignite-fabric-2.4.0-bin.zip
unzip apache-ignite-fabric-2.4.0-bin.zip
mv apache-ignite-fabric-2.4.0-bin /opt/ignite
cat << EOF > /etc/systemd/system/ignite.service
[Unit]
Description=Apache Ignite
[Service]
ExecStart=/opt/ignite/bin/ignite.sh
WorkingDirectory=/opt/ignite
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl enable ignite.service
systemctl start ignite.service
# 11211ポートでlistenするまで待つ.
while netstat -lnt | awk '$4 ~ /:11211$/ {exit 1}'; do sleep 10; done
sleep 10
# サンプルSQLの実行
wget http://wiki.metawerx.net/attach/SJSQL/sjsql.java
wget http://wiki.metawerx.net/attach/SJSQL/sjsql.class
cat << EOF >> /home/vagrant/test1.sql
create table test1 (test_id integer primary key, test_desc varchar(100));
insert into test1 (test_id, test_desc) values (1, 'test_id_001');
EOF
java -cp .:/opt/ignite/libs/ignite-core-2.4.0.jar sjsql org.apache.ignite.IgniteJdbcThinDriver jdbc:ignite:thin://ignode1/ test test /home/vagrant/test1.sql
cat << EOF >> /home/vagrant/test2.sql
insert into test1 (test_id, test_desc) values (2, 'test_id_002');
EOF
java -cp .:/opt/ignite/libs/ignite-core-2.4.0.jar sjsql org.apache.ignite.IgniteJdbcThinDriver jdbc:ignite:thin://ignode2/ test test /home/vagrant/test2.sql
cat << EOF >> /home/vagrant/test3.sql
insert into test1 (test_id, test_desc) values (3, 'test_id_003');
select * from test1;
EOF
java -cp .:/opt/ignite/libs/ignite-core-2.4.0.jar sjsql org.apache.ignite.IgniteJdbcThinDriver jdbc:ignite:thin://ignode3/ test test /home/vagrant/test3.sql
SHELL
end
#----------------------------------------------------------------------------------------
end
○関連情報
・Apache Igniteに関する他の記事はこちらを参照してください。
0 件のコメント:
コメントを投稿