天天看点

Greenplum 安装方法

1.  下载文件  greenplum-db-4.3.10.0-build-1-rhel5-x86_64.bin

2.  执行命令 ./greenplum-db-4.3.10.0-build-1-rhel5-x86_64.bin 查看/usr/local目录下必须有greenplum_db目录

3. 编辑   gpinitsystem_config   installgpdb.sh

gpinitsystem_config

ARRAY_NAME="Bruce Greenplum DW"
SEG_PREFIX=bruce_seg
PORT_BASE=40000
MASTER_PORT=15432
TRUSTED_SHELL=ssh
CHECK_POINT_SEGMENTS=64
ENCODING=UNICODE
MASTER_MAX_CONNECT=150
MASTER_HOSTNAME=brucevm
MASTER_DIRECTORY=/data2/gpdb0217//GreenPlum//db/gpmaster
declare -a DATA_DIRECTORY=( /data2/gpdb0217//GreenPlum//db/gpsegdata /data2/gpdb0217//GreenPlum//db/gpsegdata /data2/gpdb0217//GreenPlum//db/gpsegdata)
DATABASE_NAME=brucedb 
           

 createdb.sql

CREATE ROLE bruce WITH LOGIN ENCRYPTED PASSWORD '11111111' SUPERUSER INHERIT CREATEDB CREATEROLE RESOURCE QUEUE pg_default;
CREATE SCHEMA bruce;
ALTER ROLE bruce SET SEARCH_PATH TO bruce,public,pg_catalog;
--CREATE DATABASE brucedb WITH OWNER = bruce ENCODING = 'UTF8' TABLESPACE = pg_default CONNECTION LIMIT = -1;
ALTER DATABASE brucedb OWNER TO bruce;
ALTER DATABASE brucedb WITH CONNECTION LIMIT -1;
ALTER DATABASE brucedb SET search_path TO bruce,public, pg_catalog; 


           

 installgpdb.sh

#!/bin/bash  
# os type  
#set -x   
script_path=$(dirname $0);  
export script_abs_path=$(cd ${script_path}/; pwd);  
MAX_SEGMENT_NUM=30 #max segment in this hosts  
HIGH_CONCURRENCY=1 # 1 means many user access gp; 0 means 1 or 2 user access gp  
echo "work dir:" ${script_abs_path}  
  
  
SYSTEM_SHAREBUFFER_MEM_PERCENT=0.6  
SYSTEM_WORKBUFFER_MEM_PERCENT=0.2  
  
  
CheckExistsGPProcess(){  
    PORTCHECK=$(lsof -i:15432 |wc -l)  
    if (("$PORTCHECK" > 0)); then  
        echo "tcpip port 15432 is in used, please release it !!!"  
        exit 2  
    fi  
    PROCESSCHECK=$(ps -ef|grep  postgres |grep  -v grep |wc -l)  
     if (("$PROCESSCHECK" > 0)); then  
       echo "greenplum or postgresql is running, please stop it!!!"  
       exit 3  
    fi 
    rm /tmp/.s.PGSQL.15432*    -f 
}  
  
  
  
CheckDBAUser(){  
    # ---------------------------------------------------  
    # create user  
    # ---------------------------------------------------  
    echo "Begin Init User Info: "${dba_user}  
    if [[ $(cat /etc/group|grep -c ${dba_group}) -lt 1 ]]; then  
        groupadd $dba_group  
    fi  
  
    if [[ $(id -nu $dba_user) = $dba_user ]]; then  
        echo "user '$dba_user' already exists,need  delete this user, first backup /home/$dba_user,then execute command: "  
        echo " userdel  -r  -f  $dba_user"        
        exit 1  
        #usermod -g $dba_group -G $dba_group $dba_user  
        #id -a $dba_user  
    else  
        echo "to add user '$dba_user'"  
        useradd -g $dba_group -G $dba_group -m -d /home/$dba_user $dba_user  
    fi  
    echo "$dba_user:$dba_user"|chpasswd  
    echo "Sunccess Init User Info: "${dba_user}  
   
}   
CheckHardWare(){  
    echo "Begin Check HardWare Info"  
    #CPU_CORE=$(cat /proc/cpuinfo | grep processor | uniq | wc -l)  
    CPU_COREEACH=$(cat /proc/cpuinfo| grep "cpu cores"| uniq| awk '{print $4}')  
    CPU_NUM=$(cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l )  
    if [[ $CPU_NUM -eq 0 ]]; then  
        CPU_NUM=1  
    fi  
    CPU_CORE=$(( ${CPU_COREEACH:=1} * $CPU_NUM ))  
    MEMORY=$(free -m |grep "Mem" | awk '{print $2}')  
  
    mkdir -p  $install_dir  
    HDLine=$(df -hl $install_dir | wc -l|bc)    
    if [[ $HDLine -eq 3 ]]; then  
        echo "HDLine = 3"  
        HD=$(df -hl $install_dir | grep '%' | tail -n 1 | awk '{print $3}')    
    elif [[ $HDLine -eq 2 ]]; then  
        echo "HDLine = 2"  
        HD=$(df -hl $install_dir | grep '%' | tail -n 1 | awk '{print $4}')    
    fi  
  
    SWAP=$(cat /proc/meminfo | grep SwapTotal | sed -r "s#\s+# #" |cut -d" " -f2 | bc)  
  
    echo ""  
    echo "*******************************"  
    echo "********* system info *********"  
    echo "*******************************"  
    echo "Physical CPU core number: $CPU_CORE"  
    echo "System memory size: $MEMORY MB"  
    echo "free space of $install_dir: " $HD  
    echo "swap size: $SWAP KB"  
    echo "*******************************"  
  
    UNIT=$(echo ${HD:0-1:1})  
    if [ "$UNIT" = "G" ]; then  
        FREE_DISK=$(echo ${HD%G*} | bc)  
        if [ $(echo "$FREE_DISK < 3"|bc) -eq 1 ]  
        then  
            echo "error! free disk is too small, it must >= 5G"  
            sys_check=3;  
        fi  
    elif [ "$UNIT" = "M" ]; then  
        echo "error! free DISK is too small, it must >= 5G"  
        sys_check=3;  
    fi  
  
    if (($SWAP < 1000000)); then  
        echo "error! Swap size is too small to install sybase iq, it must >= 1G!"  
        sys_check=4;  
    elif (($SWAP < 8000000)); then  
        echo "warning!Swap size is too small to running bruce, it need >= 16G";  
    fi  
  
    if ((sys_check > 0)); then  
        exit $sys_check  
    fi  
  
    if (($CPU_CORE < 4)); then  
        echo "warning!number of cpu core is too little to running bruce, it need >= 4"  
    fi  
  
    if (($MEMORY < 8000)); then  
        echo "warning!memory size is too small to running bruce, it need >= 8G"  
    fi  
      
    SetmentNum=$(echo $CPU_CORE/2+1|bc)  
    if (($HIGH_CONCURRENCY < 1)); then  
        SetmentNum=$(echo $CPU_CORE|bc)  
    fi    
      
      
    if (($SetmentNum > $MAX_SEGMENT_NUM)); then  
        SetmentNum=$MAX_SEGMENT_NUM  
    fi  
  
    SYSTEMSHMMEM=$(echo $MEMORY*$SYSTEM_SHAREBUFFER_MEM_PERCENT*100/100|bc)  
    SYSTEMWORKMEM=$(echo $MEMORY* 0.2 *100/100|bc)     
      
   
    KERNEL_SHMMAX=$(echo $SYSTEMSHMMEM*1024*1024|bc)  
    KERNEL_SHMALL=$(echo $KERNEL_SHMMAX/4096|bc)  
   
    Temp_SegmentNumber=$(echo $SetmentNum + 2|bc)  
    Master_ShareBufferPercent=$(echo 200/$Temp_SegmentNumber|bc)     
    ALLSetment_ShareBufferPercent=$(echo $SetmentNum*100/$Temp_SegmentNumber|bc)  
    SingleSetment_ShareBufferPercent=$(echo $ALLSetment_ShareBufferPercent/$SetmentNum|bc)     
   
   
    echo "Master_ShareBufferPercent: $Master_ShareBufferPercent"  
    echo "ALLSetment_ShareBufferPercent: $ALLSetment_ShareBufferPercent"  
    echo "SingleSetment_ShareBufferPercent: $SingleSetment_ShareBufferPercent"  
  
    
    GP_MASTER_WORKBUFFER=$(echo $MEMORY*$SYSTEM_WORKBUFFER_MEM_PERCENT*$Master_ShareBufferPercent/100|bc)  
    GP_SEGMENT_WORKBUFFER=$(echo $MEMORY*$SYSTEM_WORKBUFFER_MEM_PERCENT*$SingleSetment_ShareBufferPercent/100|bc)      
    
    echo ""  
    echo "*******************************"  
    echo "********* greenplum info *********"  
    echo "*******************************"      
    echo "kernel.shmmax=$KERNEL_SHMMAX"   
    echo "kernel.shmall=$KERNEL_SHMALL"    
    echo "GP SetmentNum: $SetmentNum"  
    echo "SYSTEMSHMMEM: $SYSTEMSHMMEM MB"     
    echo "GP MASTER WORKBUFFER: $GP_MASTER_WORKBUFFER MB"  
    echo "GP SEGMENT WORKBUFFER: $GP_SEGMENT_WORKBUFFER MB"        
      
    echo "Finish Check HardWare Info"      
   
    echo "*******************************"    
    read -t 100 -p "Do you want to continue install greenplum.[N/Y]:" CONTINUE_INSTALL  
    if [ "$CONTINUE_INSTALL" == "N" ] || [ "$CONTINUE_INSTALL" == "n" ]  
    then  
        echo "Terminal INSTALL"     
        exit 2          
    fi  
  
}  
CheckOperationSystem()  
{  
    echo "Begin Check Operation System Info"  
    if [ $(uname) != "Linux" ]; then  
        echo "error! This is a linux script"  
        exit 1  
    fi  
  
    if [ -f /etc/redhat-release ]; then  
        VERSION=$(cat  /etc/redhat-release | awk '{print $7}' | bc)  
          
        if [ $(echo "$VERSION < 6.1"|bc) -eq 1 ]  
        then  
            echo "error! Operating system version is too low, Need version above Red Hat Enterprise Linux v6.1"  
            exit 2;  
        fi  
        echo "This is a Redhat " ${VERSION};  
    else   
        echo "error! This is a Redhat script"  
        exit 1  
    fi  
       
      
  
    # ---------------------------------------------------  
    #only root can run this script  
    # ---------------------------------------------------  
    if [ "$USER" != "root" ]  
    then  
       echo "Must be root to run the script!"  
       exit 1   
    fi  
      
      
    HostName=`hostname`  
    if [[ $(hostname|grep -c localhost) -ge 1 ]]; then  
        echo "hostname should rename,not be localhost,  execute hostname newhostname; edit /etc/hosts and /etc/sysconfig/network"  
        exit 1  
    fi  
    if [[ $(cat /etc/hosts |grep  127.0.0.1|grep  -c  localhost) -lt 1 ]]; then  
        echo "add  '127.0.0.1  localhost'  to   /etc/hosts"  
        echo "127.0.0.1  localhost" >> /etc/hosts           
    fi      
    if [[ $(cat /etc/hosts|grep -c $HostName) -lt 1 ]]; then  
        echo "hostname should be in  /etc/hosts"  
        exit 1  
    fi  
    echo " Sucess Check Operation System Info"  
}  
CheckInstallDir(){  
    echo "Begin Init install_dir,Dir is:" ${install_dir}  
  
    if [ -d $install_dir ]; then  
        rm  -rf $install_dir  
    fi  
  
    mkdir -p $install_dir  
    chown -R $dba_user:$dba_group $install_dir  
    chmod -R 755 $install_dir  
  
    echo "Sunccess Init install_dir,Dir is:" ${install_dir}  
}  
   
  
CheckSystemParameters(){  
    if [ -f /etc/systemd/logind.conf ]; then
       echo "RemoveIPC=no" >> /etc/systemd/logind.conf
       service systemd-logind restart
    fi  
    # ---------------------------------------------------  
    # Set Parameter for Linux  
    # ---------------------------------------------------  
    echo "Begin Check  /etc/sysctl.conf"    
    sed -i "/net.ipv4.ip_forward/d"   /etc/sysctl.conf  
    sed -i "/net.ipv4.conf.default.accept_source_route/d"   /etc/sysctl.conf  
    sed -i "/kernel.sysrq/d"   /etc/sysctl.conf  
    sed -i "/kernel.core_uses_pid/d"   /etc/sysctl.conf  
    sed -i "/net.ipv4.tcp_syncookies/d"   /etc/sysctl.conf  
    sed -i "/kernel.msgmnb/d"   /etc/sysctl.conf  
    sed -i "/kernel.msgmax/d"   /etc/sysctl.conf  
    sed -i "/kernel.sem/d"   /etc/sysctl.conf  
    sed -i "/kernel.shmmax/d"   /etc/sysctl.conf  
    sed -i "/kernel.shmmni/d"   /etc/sysctl.conf  
    sed -i "/kernel.shmall/d"   /etc/sysctl.conf  
    sed -i "/net.ipv4.tcp_tw_recycle/d"   /etc/sysctl.conf  
    sed -i "/net.ipv4.tcp_max_syn_backlog/d"   /etc/sysctl.conf  
    sed -i "/net.core.netdev_max_backlog/d"   /etc/sysctl.conf  
    sed -i "/vm.overcommit_memory/d"   /etc/sysctl.conf  
    sed -i "/vm.overcommit_ratio/d"   /etc/sysctl.conf      
    sed -i "/net.ipv4.conf.all.arp_filter/d"   /etc/sysctl.conf  
      
      
      
    echo "net.ipv4.ip_forward = 0" >>   /etc/sysctl.conf  
    echo "net.ipv4.conf.default.accept_source_route = 0" >>   /etc/sysctl.conf  
    echo "kernel.sysrq = 1" >>   /etc/sysctl.conf  
    echo "kernel.core_uses_pid = 1" >>   /etc/sysctl.conf  
    echo "net.ipv4.tcp_syncookies = 1" >>   /etc/sysctl.conf  
    echo "kernel.msgmnb = 65536" >>   /etc/sysctl.conf  
    echo "kernel.msgmax = 65536" >>   /etc/sysctl.conf  
      
    echo "kernel.sem = 50100 64128000 50100 1280" >>   /etc/sysctl.conf  
    echo "kernel.shmmax = $KERNEL_SHMMAX" >>   /etc/sysctl.conf  
    echo "kernel.shmmni = 4096" >>   /etc/sysctl.conf  
    echo "kernel.shmall = $KERNEL_SHMALL" >>   /etc/sysctl.conf  
      
    echo "net.ipv4.tcp_tw_recycle=1" >>   /etc/sysctl.conf  
    echo "net.ipv4.tcp_max_syn_backlog=4096" >>   /etc/sysctl.conf  
    echo "net.core.netdev_max_backlog=10000" >>   /etc/sysctl.conf  
    echo "vm.overcommit_memory=0" >>   /etc/sysctl.conf  
    echo "vm.overcommit_ratio=90" >>   /etc/sysctl.conf  
      
    echo "net.ipv4.conf.all.arp_filter = 1" >>   /etc/sysctl.conf  
    echo "Finish Check  /etc/sysctl.conf"    
      
    echo "Begin Check  /etc/security/limits.conf"    
    sed -i "/* soft nproc/d" /etc/security/limits.conf  
    sed -i "/* hard nproc/d" /etc/security/limits.conf  
    sed -i "/* soft nofile/d" /etc/security/limits.conf  
    sed -i "/* hard nofile/d" /etc/security/limits.conf  
          
    echo " * soft nproc   131072  " > /etc/security/limits.d/90-nproc.conf  
    echo " * hard nproc   131072  " >> /etc/security/limits.d/90-nproc.conf  
          
    echo "* soft nproc   131072" >> /etc/security/limits.conf  
    echo "* hard nproc   131072" >> /etc/security/limits.conf  
    echo "* soft nofile  65535" >> /etc/security/limits.conf  
    echo "* hard nofile  65535" >> /etc/security/limits.conf  
    echo "Finish Check  /etc/security/limits.conf"    
    sysctl -p   1>/dev/null   
}  
  
  
dba_user=gpadmin;  
dba_group=gpadmin;  
sys_check=0;  
if [ "$1" = "" ]; then  
    echo "usage:  install.sh install_dir"  
    exit 1  
else  
    chown gpadmin:gpadmin  $install_dir
    install_dir=$1/GreenPlum/  
fi  
  
if [ ! -f ./gpinitsystem_config ]; then  
    echo "miss  file gpinitsystem_config"  
    exit 1  
fi  
  
CheckHardWare  
CheckOperationSystem  
CheckExistsGPProcess  
CheckDBAUser  
CheckInstallDir  
CheckSystemParameters  
   
PrepareInstallPackages(){  
    echo "Begin Install  Packages"    
   
    GPHOME="${script_abs_path}/../compile/gpdb/"  
    dba_bash_profile=/home/${dba_user}/.bash_profile  
    sed -i "/greenplum_path.sh/d"  $dba_bash_profile  
    sed -i "/MASTER_DATA_DIRECTORY/d"  $dba_bash_profile  
    sed -i "/PGPORT/d"  $dba_bash_profile  
    sed -i "/PGUSER/d"  $dba_bash_profile  
    sed -i "/PGDATABASE/d" $dba_bash_profile  
    echo "source ${GPHOME}/greenplum_path.sh" >> $dba_bash_profile  
    echo "export MASTER_DATA_DIRECTORY=${install_dir}/db/gpmaster/bruce_seg-1" >> $dba_bash_profile        
    echo "export PGPORT=15432" >>  $dba_bash_profile  
    echo "export PGUSER=gpadmin" >>  $dba_bash_profile  
    echo "export PGDATABASE=brucedb" >>  $dba_bash_profile  
      
    HostName=`hostname`  
    hostname > ssh_hosts_file  
    sed -i "/MASTER_HOSTNAME/d"  gpinitsystem_config  
    echo "MASTER_HOSTNAME=${HostName}" >>gpinitsystem_config  
    sed -i "/MASTER_DIRECTORY/d"  gpinitsystem_config  
    echo "MASTER_DIRECTORY=${install_dir}/db/gpmaster" >>gpinitsystem_config      
      
  
    SUBDATADIRSTRING="${install_dir}/db/gpsegdata"  
    DATA_DIRECTORYSTRING="declare -a DATA_DIRECTORY=("  
   
    for i in $(seq $SetmentNum)  
    do   
        DATA_DIRECTORYSTRING="${DATA_DIRECTORYSTRING}  ${SUBDATADIRSTRING}"  
    done  
      
   
    DATA_DIRECTORYSTRING="${DATA_DIRECTORYSTRING})"  
    echo $DATA_DIRECTORYSTRING          
    sed -i "/DATA_DIRECTORY/d"  gpinitsystem_config  
    echo  ${DATA_DIRECTORYSTRING} >>gpinitsystem_config      
      
    sed -i "/DATABASE_NAME/d"  gpinitsystem_config  
    echo  "DATABASE_NAME=brucedb" >>gpinitsystem_config         
      
   
    cp ./ssh_hosts_file   ${install_dir}  
    cp ./gpinitsystem_config  ${install_dir}  
    mkdir -p ${install_dir}/db/gpmaster  
    mkdir -p ${install_dir}/db/gpsegdata  
    chgrp -R $dba_group $install_dir  
    chown -R $dba_user $install_dir  
    echo  "(  
        gpssh-exkeys -f ${install_dir}/ssh_hosts_file;    
        gpinitsystem   -a  -c  ${install_dir}/gpinitsystem_config -h  ${install_dir}/ssh_hosts_file;  
    )";  
    su - $dba_user -c "(  
        gpssh-exkeys -f ${install_dir}/ssh_hosts_file;    
        gpinitsystem   -a  -c ${install_dir}/gpinitsystem_config -h  ${install_dir}/ssh_hosts_file;  
    )";  
    echo  "host       all       bruce 0.0.0.0/0    trust"   >>${install_dir}/db/gpmaster/bruce_seg-1/pg_hba.conf   
    echo  "host       all       gpadmin  0.0.0.0/0    trust"   >>${install_dir}/db/gpmaster/bruce_seg-1/pg_hba.conf  
      
   
    
    su - $dba_user -c "(  
      cd ${script_abs_path}; psql -f createdb.sql;  
       gpstop  -a -M fast;    
        gpstart -a;  
    )";  
    echo "Finish Install  Packages"    
}  
PrepareInstallPackages 
           

4. 执行命令 ./installgpdb.sh /greenplumdir  完成数据库安装。

继续阅读