diff options
author | Kirill Morozov <kirill_morozov@epam.com> | 2016-09-09 11:47:31 +0100 |
---|---|---|
committer | Konstantin Boudnik <konstantin_boudnik@epam.com> | 2016-10-07 14:15:16 -0700 |
commit | 81f583456f1bdc5ebc578a97391dba8303ab6461 (patch) | |
tree | db45eeb0072741bc8eba064c064d4af017fce5b8 | |
parent | 81529d1b407d0619675787b41b0cae536f4ef6c8 (diff) |
BIGTOP-2531. Create Greenplum deployment scripts
Signed-off-by: Konstantin Boudnik <cos@apache.org>
16 files changed, 482 insertions, 2 deletions
diff --git a/bigtop-deploy/puppet/hieradata/bigtop/cluster.yaml b/bigtop-deploy/puppet/hieradata/bigtop/cluster.yaml index 60c59b1d..c747b4e7 100644 --- a/bigtop-deploy/puppet/hieradata/bigtop/cluster.yaml +++ b/bigtop-deploy/puppet/hieradata/bigtop/cluster.yaml @@ -203,3 +203,9 @@ flink::common::jobmanager_port: "6123" flink::common::ui_port: "8081" flink::common::storage_dirs: "%{hiera('hadoop::hadoop_storage_dirs')}" + +gpdb::common::nodes: ["master_node_fqdn", "segment_node_fqdn"] +gpdb::common::gp_home: "/usr/lib/gpdb" +gpdb::common::db_base_dir: "/data_gp" +gpdb::common::master_db_port: "5432" +gpdb::common::segment_db_port_prefix: "4000" diff --git a/bigtop-deploy/puppet/hieradata/site.yaml b/bigtop-deploy/puppet/hieradata/site.yaml index b9ed6f98..7ee434d7 100644 --- a/bigtop-deploy/puppet/hieradata/site.yaml +++ b/bigtop-deploy/puppet/hieradata/site.yaml @@ -37,6 +37,7 @@ hadoop::hadoop_storage_dirs: # - yarn # - zookeeper # - ycsb +# - gpdb #bigtop::roles_enabled: false diff --git a/bigtop-deploy/puppet/manifests/cluster.pp b/bigtop-deploy/puppet/manifests/cluster.pp index 12e04248..7144f02b 100644 --- a/bigtop-deploy/puppet/manifests/cluster.pp +++ b/bigtop-deploy/puppet/manifests/cluster.pp @@ -117,6 +117,10 @@ $roles_map = { worker => ["qfs-chunkserver"], client => ["qfs-client"], }, + gpdb => { + master => ["gpdb-master"], + worker => ["gpdb-segment"], + }, kafka => { master => ["kafka-server"], } @@ -189,7 +193,8 @@ class node_with_roles ($roles = hiera("bigtop::roles")) inherits hadoop_cluster_ "ycsb", "kerberos", "zeppelin", - "kafka" + "kafka", + "gpdb" ] deploy_module { $modules: diff --git a/bigtop-deploy/puppet/modules/gpdb/README.md b/bigtop-deploy/puppet/modules/gpdb/README.md new file mode 100644 index 00000000..bc0cfcf3 --- /dev/null +++ b/bigtop-deploy/puppet/modules/gpdb/README.md @@ -0,0 +1,19 @@ +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +# Package instalation notes + +Greenplum scripts need the following python libs: psutil, paramiko. +And they need python-pip package, which in its turn needs libffi-dev, python-lockfile. diff --git a/bigtop-deploy/puppet/modules/gpdb/manifests/init.pp b/bigtop-deploy/puppet/modules/gpdb/manifests/init.pp new file mode 100644 index 00000000..98475a38 --- /dev/null +++ b/bigtop-deploy/puppet/modules/gpdb/manifests/init.pp @@ -0,0 +1,396 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class gpdb { + + class deploy($roles) { + if ("gpdb-master" in $roles or "gpdb-segment" in $roles) { + include gpdb::common + } + } + + class common($nodes, $gp_home, $db_base_dir, $master_db_port, $segment_db_port_prefix) { + + include stdlib + + class { 'gpdb::common::install_packages': } + + class { 'gpdb::common::gpadmin_user':} + + class { 'gpdb::common::prepare_file_structure': + base_dir => "$db_base_dir", + require => Class['gpdb::common::gpadmin_user'] + } + + class { 'gpdb::common::prepare_db_dirs': + base_dir => "$db_base_dir", + nodes => $nodes, + gp_home => $gp_home, + master_port => $master_db_port, + segment_port_prefix => $segment_db_port_prefix, + require => [Class['gpdb::common::prepare_file_structure'], Package["gpdb"]] + } + + gpdb::server{"stop_if_running": + nodes => $gpdb::common::nodes, + gp_home => $gpdb::common::gp_home, + db_base_dir => $gpdb::common::db_base_dir, + master_db_port => $gpdb::common::master_db_port, + segment_db_port_prefix => $gpdb::common::segment_db_port_prefix, + require => Class['gpdb::common::prepare_db_dirs'], + start_or_stop => stopped, + } + + class { 'gpdb::common::configure_master_node': + base_dir => "$db_base_dir", + nodes => $nodes, + gp_home => $gp_home, + master_port => $master_db_port, + segment_port_prefix => $segment_db_port_prefix, + require => Class['gpdb::common::prepare_db_dirs'] + } + + class { 'gpdb::common::stop_master_in_admin_mode': + base_dir => "$db_base_dir", + gp_home => $gp_home, + master_port => $master_db_port, + require => Class['gpdb::common::configure_master_node'] + } + + gpdb::server{"start": + nodes => $gpdb::common::nodes, + gp_home => $gpdb::common::gp_home, + db_base_dir => $gpdb::common::db_base_dir, + master_db_port => $gpdb::common::master_db_port, + segment_db_port_prefix => $gpdb::common::segment_db_port_prefix, + require => Class['gpdb::common::stop_master_in_admin_mode'], + start_or_stop => running, + } + + class gpadmin_user{ + group { 'gpadmin': + ensure => 'present', + } + user { 'gpadmin': + ensure => 'present', + system => false, + managehome => true, + groups => 'gpadmin', + shell => '/bin/bash', + } + } + + class install_packages{ + case $operatingsystem{ + /(?i:(centos|fedora))/: { + yumrepo { "epel": + baseurl => "http://download.fedoraproject.org/pub/epel/7/\$basearch", + descr => "epel packages", + enabled => 1, + gpgcheck => 0, + } + package { ["libffi-devel"]: + ensure => latest, + } + package { ["python-lockfile"]: + ensure => latest, + } + package { ["psutil"]: + ensure => latest, + provider => pip, + require => Package["python-pip"], + } + package { ["paramiko"]: + ensure => latest, + provider => pip, + require => Package["python-pip"], + } + package { ["python-pip"]: + ensure => latest, + require => [ + Yumrepo["epel"], + Package["libffi-devel"], + Package["python-lockfile"], + ], + } + } + /(?i:(SLES|opensuse))/: { + } + Amazon: { } + /(Ubuntu|Debian)/: { + package { ["libffi-dev"]: + ensure => latest, + } + package { ["python-lockfile"]: + ensure => latest, + } + package { ["psutil"]: + ensure => latest, + provider => pip, + require => Package["python-pip"], + } + package { ["paramiko"]: + ensure => latest, + provider => pip, + require => Package["python-pip"], + } + package { ["python-pip"]: + ensure => latest, + require => [ + Package["libffi-dev"], + Package["python-lockfile"], + ], + } + } + } + package { ["gpdb"]: + ensure => latest, + } + } + + class prepare_file_structure($base_dir = undef){ + file { "$base_dir": + ensure => 'directory', + owner => 'gpadmin', + group => 'gpadmin', + } + file { "$base_dir/master": + ensure => 'directory', + owner => 'gpadmin', + group => 'gpadmin', + } + file { "$base_dir/primary": + ensure => 'directory', + owner => 'gpadmin', + group => 'gpadmin', + } + } + + class prepare_db_dirs($nodes = undef, $base_dir = undef, $gp_home = undef, $master_port = undef, $segment_port_prefix = undef){ + file { '/home/gpadmin/init-db.sh': + content => template('gpdb/init-db.sh'), + require => [ + File["$base_dir/primary"], + File["$base_dir/master"]], + owner => 'gpadmin', + group => 'gpadmin', + mode => '0700', + } + file { '/home/gpadmin/stop-db.sh': + content => template('gpdb/stop-db.sh'), + owner => 'gpadmin', + group => 'gpadmin', + mode => '0700', + } + each($nodes) |$index, $value| { + notice($value) + if ($::fqdn == $value) { + $dbid = $index+1 + $content = $index-1 + $hostname = $value + $segment_nodes_count=size($nodes)-1 + if ($dbid == 1){ + $port = $master_port + $db_sub_dir = "master" + $m_options = "master" + $x_options = "-x 0 -E" + $z_options = "$segment_nodes_count" + } else{ + $port = "$segment_port_prefix${content}" + $db_sub_dir = "primary" + $m_options = "mirrorless" + $x_options = "" + $z_options = "$segment_nodes_count" + } + $db_dir = "$base_dir/${db_sub_dir}/gpseg${content}" + exec { "create_master_db${db_dir}": + command => "init-db.sh $db_dir", + require => [File["/home/gpadmin/init-db.sh"]], + path => '/home/gpadmin', + user => 'gpadmin', + } + file_line { "allow all host connection${db_dir}": + path => "${db_dir}/pg_hba.conf", + line => 'host all all 0.0.0.0/0 trust', + require => [Exec["create_master_db${db_dir}"]], + } + file_line { "add 1 conf${db_dir}": + path => "${db_dir}/postgresql.conf", + line => 'log_statement=all', + require => [Exec["create_master_db${db_dir}"]], + } + file_line { "add 2 conf${db_dir}": + path => "${db_dir}/postgresql.conf", + line => 'checkpoint_segments=8', + require => [Exec["create_master_db${db_dir}"]], + } + file_line { "add 3 conf${db_dir}": + path => "${db_dir}/postgresql.conf", + line => "port=${port}", + require => [Exec["create_master_db${db_dir}"]], + } + file { "${db_dir}/gp_dbid": + content => template('gpdb/gp_dbid'), + require => [Exec["create_master_db${db_dir}"]], + owner => 'gpadmin', + group => 'gpadmin', + mode => '0700', + } + file { "${db_dir}/gpssh.conf": + content => template('gpdb/gpssh.conf'), + require => [Exec["create_master_db${db_dir}"]], + owner => 'gpadmin', + group => 'gpadmin', + mode => '0700', + } + file { "${db_dir}/postmaster.opts": + content => template('gpdb/postmaster.opts'), + require => [Exec["create_master_db${db_dir}"]], + owner => 'gpadmin', + group => 'gpadmin', + mode => '0700', + } + file { "${db_dir}/run.opts": + source => "${db_dir}/postmaster.opts", + ensure => present, + require => [File["${db_dir}/postmaster.opts"]], + owner => 'gpadmin', + group => 'gpadmin', + mode => '0700', + } + } + } + } + + class stop_master_in_admin_mode($base_dir = undef, $gp_home = undef, $master_port = undef){ + exec { 'stop-master-db-in-admin-mode': + command => "stop-db.sh $base_dir/master/gpseg-1 $master_port", + path => '/home/gpadmin', + user => 'gpadmin', + require => [ + Exec["create_master_db$base_dir/master/gpseg-1"], + File['/home/gpadmin/stop-db.sh'] + ], + } + } + + class configure_master_node($nodes = undef, $base_dir = undef, $gp_home = undef, $master_port = undef, $segment_port_prefix = undef){ + if ($::fqdn == $nodes[0]) { + notice("must make admin") + file { '/home/gpadmin/start-master-db-in-admin-mode.sh': + content => template('gpdb/start-master-db-in-admin-mode.sh'), + require => [Exec["create_master_db$base_dir/master/gpseg-1"]], + owner => 'gpadmin', + group => 'gpadmin', + mode => '0700', + } + file { '/home/gpadmin/test-master-db.sh': + content => template('gpdb/test-master-db.sh'), + require => [Exec["create_master_db$base_dir/master/gpseg-1"]], + owner => 'gpadmin', + group => 'gpadmin', + mode => '0700', + } + exec { 'start-master-db-in-admin-mode': + command => "start-master-db-in-admin-mode.sh $base_dir/master/gpseg-1", + path => '/home/gpadmin', + user => 'gpadmin', + require => [ + Exec["create_master_db$base_dir/master/gpseg-1"], + File['/home/gpadmin/start-master-db-in-admin-mode.sh'] + ], + } + file { '/home/gpadmin/insert-to-segmentConfig-table.sh': + content => template('gpdb/insert-to-segmentConfig-table.sh'), + require => [Exec["start-master-db-in-admin-mode"]], + owner => 'gpadmin', + group => 'gpadmin', + mode => '0700', + } + file { '/home/gpadmin/insert-to-faultStrategy-table.sh': + content => template('gpdb/insert-to-faultStrategy-table.sh'), + require => [Exec["start-master-db-in-admin-mode"]], + owner => 'gpadmin', + group => 'gpadmin', + mode => '0700', + } + exec { "insert-to-faultStrategy-table": + environment => ["PGOPTIONS=-c gp_session_role=utility"], + command => "insert-to-faultStrategy-table.sh", + path => '/home/gpadmin', + user => 'gpadmin', + require => [ + File["/home/gpadmin/insert-to-faultStrategy-table.sh"], + Exec['start-master-db-in-admin-mode'], + ], + } + each($nodes) |$index, $value| { + $dbid = $index+1 + $content = $index-1 + $hostname = $value + if ($dbid == 1){ + $port = $master_port + $db_sub_dir = "master" + $m_options = "master" + $x_options = "\"-x\" \"0\" \"-c\" \"gp_role=utility\"" + $z_options = "0" + } else{ + $port = "$segment_port_prefix${content}" + $db_sub_dir = "primary" + $m_options = "mirrorless" + $x_options = "" + $z_options = "3" + } + $db_dir = "$base_dir/${db_sub_dir}/gpseg${content}" + notice("${dbid} - ${content} - ${port} - ${hostname} - ${db_dir}") + exec { "insert-to-segmentConfig-table${dbid}": + environment => ["PGOPTIONS=-c gp_session_role=utility"], + command => "insert-to-segmentConfig-table.sh ${dbid} ${content} ${port} ${value} ${db_dir}", + path => '/home/gpadmin', + user => 'gpadmin', + require => [ + File["/home/gpadmin/insert-to-segmentConfig-table.sh"], + Exec['start-master-db-in-admin-mode'], + ], + } + } + } + } + } + + define server($nodes, $gp_home, $db_base_dir, $master_db_port, $segment_db_port_prefix, $start_or_stop){ + each($nodes) |$index, $value| { + $content = $index-1 + if ($::fqdn == $value) { + if ($index == 0){ + $db_sub_dir = "master" + $port = $master_db_port + }else{ + $db_sub_dir = "primary" + $port = "$segment_db_port_prefix${content}" + } + $db_dir = "$db_base_dir/${db_sub_dir}/gpseg${content}" + service { "gpdb${content}${start_or_stop}": + provider => base, + ensure => $start_or_stop, + start => "su -l gpadmin -m $db_dir/run.opts", + stop => "su -l gpadmin -m /home/gpadmin/stop-db.sh $db_dir $port", + hasstatus => false, + pattern => "${db_dir}", + } + } + } + } +} diff --git a/bigtop-deploy/puppet/modules/gpdb/templates/gp_dbid b/bigtop-deploy/puppet/modules/gpdb/templates/gp_dbid new file mode 100755 index 00000000..2066b204 --- /dev/null +++ b/bigtop-deploy/puppet/modules/gpdb/templates/gp_dbid @@ -0,0 +1,3 @@ +# Greenplum Database identifier for this master/segment. +# Do not change the contents of this file. +dbid = <%= dbid %> diff --git a/bigtop-deploy/puppet/modules/gpdb/templates/gpssh.conf b/bigtop-deploy/puppet/modules/gpdb/templates/gpssh.conf new file mode 100755 index 00000000..640747f5 --- /dev/null +++ b/bigtop-deploy/puppet/modules/gpdb/templates/gpssh.conf @@ -0,0 +1,12 @@ +[gpssh] +# delaybeforesend specifies the time in seconds to wait at the +# beginning of an ssh interaction before doing anything. +# Increasing this value can have a big runtime impact at the +# beginning of gpssh. +delaybeforesend = 0.05 + +# prompt_validation_timeout specifies a timeout multiplier that +# will be used in validating the ssh prompt. Increasing this +# value will have a small runtime impact at the beginning of +# gpssh. +prompt_validation_timeout = 1.0 diff --git a/bigtop-deploy/puppet/modules/gpdb/templates/init-db.sh b/bigtop-deploy/puppet/modules/gpdb/templates/init-db.sh new file mode 100755 index 00000000..b1945267 --- /dev/null +++ b/bigtop-deploy/puppet/modules/gpdb/templates/init-db.sh @@ -0,0 +1,4 @@ +#!/bin/sh +if [ ! -d $1 ]; then + export LD_LIBRARY_PATH=<%= gp_home%>/lib:/lib;<%= gp_home%>/bin/initdb -E UNICODE -D $1 --locale=en_US.utf8 --max_connections=750 --shared_buffers=128000kB --is_filerep_mirrored=no --backend_output=$1.initdb +fi diff --git a/bigtop-deploy/puppet/modules/gpdb/templates/insert-to-faultStrategy-table.sh b/bigtop-deploy/puppet/modules/gpdb/templates/insert-to-faultStrategy-table.sh new file mode 100755 index 00000000..aeff9329 --- /dev/null +++ b/bigtop-deploy/puppet/modules/gpdb/templates/insert-to-faultStrategy-table.sh @@ -0,0 +1,2 @@ +#!/bin/sh +<%= gp_home%>/bin/psql -p <%= master_port%> -d "template1" -c "insert into gp_fault_strategy(fault_strategy) values ('n');" || true diff --git a/bigtop-deploy/puppet/modules/gpdb/templates/insert-to-segmentConfig-table.sh b/bigtop-deploy/puppet/modules/gpdb/templates/insert-to-segmentConfig-table.sh new file mode 100755 index 00000000..9bde3059 --- /dev/null +++ b/bigtop-deploy/puppet/modules/gpdb/templates/insert-to-segmentConfig-table.sh @@ -0,0 +1,2 @@ +#!/bin/sh +<%= gp_home%>/bin/psql -p <%= master_port%> -d "template1" -c "INSERT INTO gp_segment_configuration (dbid, content, role, preferred_role, mode, status, hostname, address, port, replication_port) VALUES ($1, $2, 'p', 'p', 's', 'u', '$4', '$4', $3, null);insert into pg_filespace_entry (fsefsoid, fsedbid, fselocation) values (3052, $1, '$5');" || true
\ No newline at end of file diff --git a/bigtop-deploy/puppet/modules/gpdb/templates/postmaster.opts b/bigtop-deploy/puppet/modules/gpdb/templates/postmaster.opts new file mode 100755 index 00000000..96e2212a --- /dev/null +++ b/bigtop-deploy/puppet/modules/gpdb/templates/postmaster.opts @@ -0,0 +1 @@ +<%= gp_home%>/bin/postgres "-D" "<%= db_dir %>" "-p" "<%= port %>" "-b" "<%= dbid %>" "-z" "<%= z_options %>" "--silent-mode=true" "-i" "-M" "<%= m_options %>" "-C" "<%= content %>" <%= x_options %> diff --git a/bigtop-deploy/puppet/modules/gpdb/templates/start-master-db-in-admin-mode.sh b/bigtop-deploy/puppet/modules/gpdb/templates/start-master-db-in-admin-mode.sh new file mode 100755 index 00000000..3966e417 --- /dev/null +++ b/bigtop-deploy/puppet/modules/gpdb/templates/start-master-db-in-admin-mode.sh @@ -0,0 +1,2 @@ +#!/bin/bash +export PGPORT=<%= master_port%>;<%= gp_home%>/bin/pg_ctl -w -l $1/pg_log/startup.log -D $1 -o "-i -p <%= master_port%> -c gp_role=utility -M master -b 1 -C -1 -z 0 -m" start
\ No newline at end of file diff --git a/bigtop-deploy/puppet/modules/gpdb/templates/stop-db.sh b/bigtop-deploy/puppet/modules/gpdb/templates/stop-db.sh new file mode 100644 index 00000000..5394b8a2 --- /dev/null +++ b/bigtop-deploy/puppet/modules/gpdb/templates/stop-db.sh @@ -0,0 +1,2 @@ +#!/bin/sh +<%= gp_home%>/bin/pg_ctl -p $2 -D $1 stop
\ No newline at end of file diff --git a/bigtop-deploy/puppet/modules/gpdb/templates/test-master-db.sh b/bigtop-deploy/puppet/modules/gpdb/templates/test-master-db.sh new file mode 100644 index 00000000..141cd3da --- /dev/null +++ b/bigtop-deploy/puppet/modules/gpdb/templates/test-master-db.sh @@ -0,0 +1,2 @@ +#!/bin/sh +<%= gp_home%>/bin/psql -p <%= master_port%> -d "template1" -c "select count(*) from gp_segment_configuration;"
\ No newline at end of file diff --git a/bigtop-deploy/puppet/modules/gpdb/tests/init.pp b/bigtop-deploy/puppet/modules/gpdb/tests/init.pp new file mode 100644 index 00000000..4a328a37 --- /dev/null +++ b/bigtop-deploy/puppet/modules/gpdb/tests/init.pp @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +gpdb::server{"start": + nodes => ["master_node_fqdn", "segment_node_fqdn"], + gp_home => "/usr/lib/gpdb", + db_base_dir => "/data_gp", + master_db_port => "5432", + segment_db_port_prefix => "4000", + start_or_stop => running, +} diff --git a/provisioner/docker/docker-hadoop.sh b/provisioner/docker/docker-hadoop.sh index 5e8e09df..9a74162e 100755 --- a/provisioner/docker/docker-hadoop.sh +++ b/provisioner/docker/docker-hadoop.sh @@ -131,7 +131,7 @@ destroy() { } bigtop-puppet() { - docker exec $1 bash -c 'puppet apply --modulepath=/bigtop-home/bigtop-deploy/puppet/modules:/etc/puppet/modules /bigtop-home/bigtop-deploy/puppet/manifests/site.pp' + docker exec $1 bash -c 'puppet apply --modulepath=/bigtop-home/bigtop-deploy/puppet/modules:/etc/puppet/modules /bigtop-home/bigtop-deploy/puppet/manifests' } get-yaml-config() { |