2018年5月28日月曜日

VagrantでAmbari(HDP2.6)/HDFS/HBase/Phoenixをインストールした仮想マシン(CentOS7.4)を構築する

Apache PhoenixはHBase上に構築されるRDBレイヤーです。

〇Ambariの画面

ブラウザでhttp://192.168.1.117:8080/にアクセスします。ユーザ/パスワードはadmin/adminです。

〇構築方法
以下のVagrantfileを使用して、Ambari/HDFS/HBase/Phoenixをインストールした仮想マシン(CentOS7.4)を構築する事ができます。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/centos-7.4"
  config.vm.hostname = "co74phoenix.vm.internal"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "co74phoenix.vm.internal"
     vbox.cpus = 4
     vbox.memory = 10240 
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
  # private network
  config.vm.network "private_network", ip: "192.168.55.117", :netmask => "255.255.255.0"
  # bridge netwrok
  config.vm.network "public_network", ip: "192.168.1.117", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
localectl set-locale LANG=ja_JP.UTF-8
echo "192.168.55.117 co74phoenix" >> /etc/hosts

cd /root
mkdir ./.ssh
ssh-keygen -f ./.ssh/id_rsa -t rsa -N ''

# copy private key
cp -f ./.ssh/id_rsa /vagrant
cat ./.ssh/id_rsa.pub >> ./.ssh/authorized_keys
chmod 600 ./.ssh/authorized_keys

# install and configure ambari server
cd /etc/yum.repos.d/
wget http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.6.2.0/ambari.repo
yum -y install ambari-server ambari-agent
ambari-server setup --silent
ambari-server start

# create hive database and hive user
echo "host    all         all         127.0.0.1/32          password" >> /var/lib/pgsql/data/pg_hba.conf
echo "host    all         all         192.168.1.0/24          password" >> /var/lib/pgsql/data/pg_hba.conf
echo "host    all         all         192.168.55.0/24          password" >> /var/lib/pgsql/data/pg_hba.conf
service postgresql restart

yum -y install postgresql-jdbc*
chmod 644 /usr/share/java/postgresql-jdbc.jar

ambari-server setup -s --database=postgres --databasehost=localhost --databaseport=5432 --databasename=hive --databaseusername=hive --databasepassword=hive --jdbc-db=postgres --jdbc-driver=/usr/share/java/postgresql-jdbc.jar
ambari-agent start


cat << EOF > /home/vagrant/cluster_configuration.json
{
  "configurations" : [
    {
      "hbase-env" : {
        "properties_attributes" : { },
        "properties" : {
          "phoenix_sql_enabled" : "true"
        }
      }
    },
    {
      "core-site": {
        "properties" : {
          "hadoop.proxyuser.root.groups" : "*",
          "hadoop.proxyuser.root.hosts" : "*"
        }
      }
    }
  ],
  "host_groups" : [
    {
      "name" : "host_group_1",
      "components" : [
        {
          "name" : "NAMENODE"
        },
        {
          "name" : "SECONDARY_NAMENODE"
        },
        {
          "name" : "DATANODE"
        },
        {
          "name" : "HDFS_CLIENT"
        },
        {
          "name" : "RESOURCEMANAGER"
        },
        {
          "name" : "NODEMANAGER"
        },
        {
          "name" : "YARN_CLIENT"
        },
        {
          "name" : "HISTORYSERVER"
        },
        {
          "name" : "APP_TIMELINE_SERVER"
        },
        {
          "name" : "ZOOKEEPER_SERVER"
        },
        {
          "name" : "ZOOKEEPER_CLIENT"
        },
        {
          "name" : "METRICS_MONITOR"
        },
        {
          "name" : "METRICS_COLLECTOR"
        },
        {
          "name" : "HBASE_CLIENT"
        },
        {
          "name" : "HBASE_MASTER"
        },
        {
          "name" : "HBASE_REGIONSERVER"
        }
      ],
      "cardinality" : "1"
    }
  ],
  "settings" : [{
     "recovery_settings" : [{
       "recovery_enabled" : "true"
    }]
  }],
  "Blueprints" : {
    "blueprint_name" : "hdp26-minimal-phoenix",
    "stack_name" : "HDP",
    "stack_version" : "2.6"
  }
}
EOF

curl -H "X-Requested-By: ambari" -X POST -u admin:admin http://localhost:8080/api/v1/blueprints/hdp26-minimal-phoenix -d @/home/vagrant/cluster_configuration.json

cat << EOF > /home/vagrant/hostmapping.json
{
  "blueprint" : "hdp26-minimal-phoenix",
  "default_password" : "admin",
  "provision_action" : "INSTALL_AND_START",
  "host_groups" :[
    {
      "name" : "host_group_1",
      "hosts" : [
        {
          "fqdn" : "co74phoenix.vm.internal"
        }
      ]
    }
  ]
}
EOF

curl -H "X-Requested-By: ambari" -X POST -u admin:admin http://localhost:8080/api/v1/clusters/hdp26-minimal-phoenix -d @/home/vagrant/hostmapping.json
sleep 30


# wait until the cluster is ready.
ProgressPercent=`curl -s --user admin:admin -X GET http://localhost:8080/api/v1/clusters/hdp26-minimal-phoenix/requests/1 | grep progress_percent | awk '{print $3}' | cut -d . -f 1`
while [[ `echo $ProgressPercent | grep -v 100` ]]; do
  ProgressPercent=`curl -s --user admin:admin -X GET http://localhost:8080/api/v1/clusters/hdp26-minimal-phoenix/requests/1 | grep progress_percent | awk '{print $3}' | cut -d . -f 1`
  echo " Progress: $ProgressPercent %"
  sleep 10
done


cat << EOF > /home/vagrant/shutdown_components.sh
#!/bin/bash
#stop all services
curl -u admin:admin -i -H 'X-Requested-By: ambari' -X PUT \
   -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"hdp26-minnimal-hbase"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' \
   http://localhost:8080/api/v1/clusters/hdp26-minimal-phoenix/services
EOF
chmod +x /home/vagrant/shutdown_components.sh


# execute sql commands for test...
cat << EOF > test1.txt
create table test1 (message_id integer not null primary key, message varchar(100));
upsert into test1 values (100, 'hello world.');
select * from test1;
!quit
EOF
/usr/hdp/2.6.5.0-292/phoenix/bin/sqlline.py test1.txt


echo 'access -> http://192.168.1.117:8080'
echo 'user/password -> admin/admin'
SHELL
end

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

0 件のコメント:

コメントを投稿