记录在 MacOS 上编译、安装、运行 Greenplum 的步骤。

下载代码

git clone https://github.com/greenplum-db/gpdb.git
cd gpdb

安装依赖

./README.macOS.bash
source ~/.bashrc

## 如果遇到 Error: unable to import module: No module named 'pgdb' 报错安装 PyGreSQL,而非 pgdb
pip3 install PyGreSQL
pip3 install psutil

配置 ssh

mkdir -p "$HOME/.ssh"

cat >> ~/.bash_profile << EOF

# Allow ssh to use the version of python in path, not the system python
# BEGIN SSH agent
# from http://stackoverflow.com/questions/18880024/start-ssh-agent-on-login/18915067#18915067
SSH_ENV="\$HOME/.ssh/environment"
# Refresh the PATH per new session
sed -i .bak '/^PATH/d' \${SSH_ENV}
echo "PATH=\$PATH" >> \${SSH_ENV}

function start_agent {
    echo "Initialising new SSH agent..."
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "\${SSH_ENV}"
    echo succeeded
    chmod 600 "\${SSH_ENV}"
    source "\${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add;
}

# Source SSH settings, if applicable
if [ -f "\${SSH_ENV}" ]; then
    . "\${SSH_ENV}" > /dev/null
    ps -ef | grep \${SSH_AGENT_PID} 2>/dev/null | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi

[ -f ~/.bashrc ] && source ~/.bashrc
# END SSH agent
EOF

source ~/.bash_profile
sudo tee -a /etc/ssh/sshd_config << EOF
# Allow ssh to use the version of python in path, not the system python
PermitUserEnvironment yes
EOF

确保能够从本机免密登录:

ssh `hostname`

编译安装

./configure --with-perl --with-python --with-libxml --with-gssapi --enable-debug --disable-gpfdist
make -j8
sudo make install

# Bring in greenplum environment into your running shell
source /usr/local/gpdb/greenplum_path.sh

启动 demo 集群

# 查看端口号是否被占用
sudo lsof -PiTCP -sTCP:LISTEN

# 选择一个端口号启动集群
cd gpAux/gpdemo
WITH_MIRRORS=false WITH_STANDBY=false PORT_BASE=5555 make cluster

# 设置环境变量
source gpdemo-env.sh

在需要调试集群的时候,segemnts 的个数越少越方便定位问题,因此可以指定只启动一个 segement:

WITH_MIRRORS=false WITH_STANDBY=false PORT_BASE=5555 NUM_PRIMARY_MIRROR_PAIRS=1 make cluster

删除 demo 集群

make clean

启停集群

在使用集群的过程中,并不需要频繁地创建或是删除集群,应该使用 gpdb 提供的工具来启停集群:

# 停止集群
gpstop -a

# 启动集群
gpstart -a

# 查看集群状态
gpstate -s

Troubleshooting

Problem 1:

.bashrc 中使用 ulimit -n 65536 65536 设置了文件描述符的个数和文件的大小,但在集群启动的时候遇到了 Child process was terminated by signal 25, File size limit exceeded 的错误,改为 ulimit -n 65536 unlimited 后解决问题。另外在解决问题的过程中还进行了如下设置:

launchctl limit maxfiles
sudo launchctl limit maxfiles 65536 1048576

但不确定是否跟问题的解决相关。

Problem 2:

gpfdist 依赖 apr-1-config,在 mac 上安装 apr 未创建 apr-1-config 的软链接导致如下报错:

configure: error: apr-1-config is required for gpfdist, unable to find binary

通过安装 apr/apr-util 并创建 apr-1-config 的软链接解决:

brew install apr
brew install apr-util
ln -s /usr/local/Cellar/apr/1.7.0_2/bin/apr-1-config /usr/local/bin/apr-1-config