docker使用greenplum6.0源码搭建调试环境

ubuntu下docker搭建greenplum调试环境

工作原因,需要经常进行greenplum的调试,趁着无聊,打算搭建一套调试环境以方便经常使用,之前写了一片vmware搭建的笔记,这一篇是docker版本,刚好借此机会也了解一下docker。

系统环境

ubuntu18.04 LTS

zhengshibin@zhengshibin-ubuntu:~$ cat /proc/version
Linux version 4.15.0-23-generic (buildd@lgw01-amd64-055) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #25-Ubuntu SMP Wed May 23 18:02:16 UTC 2018

前期准备

docker

对于有网络的情况下,docker的安装还算是比较方便的,这里有一些前辈的资料可以参考。

Ubuntu18.04安装Docker
免sudo使用docker命令

没有征得作者同意,这里仅留下链接,而不是直接拷贝或者转载。

centos image

默认下载最新版本的镜像,避免版本太过陈旧带来的各种依赖问题。

zhengshibin@zhengshibin-ubuntu:~$ docker pull hub.c.163.com/public/centos
Using default tag: latest
latest: Pulling from public/centos
96057de2d572: Pull complete 
a3ed95caeb02: Pull complete 
8a1dcc3f76c2: Pull complete 
8fe56c90e86a: Pull complete 
43fc3558431f: Pull complete 
5881bc109689: Pull complete 
Digest: sha256:75a27ccbfdef28456d98134cf04f2f41f76b435d9e62c678c6791af467d6b1b0
Status: Downloaded newer image for hub.c.163.com/public/centos:latest

查看已经准备好的镜像。

zhengshibin@zhengshibin-ubuntu:~$ docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
hub.c.163.com/public/centos   latest              997f0ed97903        2 years ago         442MB

添加tag,并以此作为master的模板 。

zhengshibin@zhengshibin-ubuntu:~$ docker tag hub.c.163.com/public/centos:latest greenplum:master
zhengshibin@zhengshibin-ubuntu:~$ docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
greenplum                     master              997f0ed97903        2 years ago         442MB
hub.c.163.com/public/centos   latest              997f0ed97903        2 years ago         442MB

创建并启动容器,开始准备安装greenplum依赖环境及greenplum

zhengshibin@zhengshibin-ubuntu:~$ docker create -v /media/sf_ShareFolders/docker_gpdb:/ -it --security-opt seccomp=unconfined --cap-add sys_ptrace greenplum:master
87209baa5bbc60af7962e6e4d0a509c31f0925ed9468f570afd82dae4b427ac2
zhengshibin@zhengshibin-ubuntu:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS                        PORTS               NAMES
87209baa5bbc        greenplum:master    "/usr/sbin/sshd -D"   2 minutes ago       Exited (255) 27 seconds ago                       lucid_liskov
zhengshibin@zhengshibin-ubuntu:~$ docker start 87209baa5bbc
87209baa5bbc
zhengshibin@zhengshibin-ubuntu:~$ docker exec -it 87209baa5bbc /bin/bash
[root@87209baa5bbc /]# 

注:--security-opt seccomp=unconfined --cap-add sys_ptrace的作用是为了gdb的调试支持。

接下来的操作就是在容器中,而不是宿主机中了,greenplum的代码在github上有备份,我们需要先安装git来下载源码。

yum install -y git

下载源码前记得注册github账号,然后生成ssh key不然git clone的时候会没有权限。

[root@87209baa5bbc /]# git config --global user.name "binresist"
[root@87209baa5bbc /]# git config --global user.email "[email protected]"
[root@87209baa5bbc /]# ssh-keygen -t rsa -b 4096 -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Passphrases do not match.  Try again.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
70:6e:14:a3:c5:01:9b:4c:7b:a0:e5:cf:1d:53:54:db [email protected]
The key's randomart image is:
+--[ RSA 4096]----+
|      =o=. .o..  |
|     * B.o .   o |
|    . O + o   . E|
|       O . o     |
|        S .      |
|       .         |
|                 |
|                 |
|                 |
+-----------------+

此时生成的公钥在/root/.ssh/id_rsa.pub下,拷贝之后粘贴到github用户ssh keys里面。

greenplum源码

下载源码,并切换到对应的tag上,用法类似于branch,git chekcout xxxx

[root@87209baa5bbc /]# cd /tmp/
[root@87209baa5bbc tmp]# ls
[root@87209baa5bbc tmp]# git clone [email protected]:greenplum-db/gpdb.git gpdb_src
Initialized empty Git repository in /tmp/gpdb_src/.git/
The authenticity of host 'github.com (13.229.188.59)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.229.188.59' (RSA) to the list of known hosts.
Enter passphrase for key '/root/.ssh/id_rsa': 
remote: Counting objects: 508402, done.
remote: Compressing objects: 100% (50/50), done.
remote: Total 508402 (delta 32), reused 25 (delta 21), pack-reused 508331
Receiving objects: 100% (508402/508402), 273.45 MiB | 1.88 MiB/s, done.
Resolving deltas: 100% (414242/414242), done.
[root@bd675377db24 tmp]# cd gpdb_src/
[root@bd675377db24 gpdb_src]# ls
COPYRIGHT            README.linux.md     doc
Dockerfile           README.macOS.bash   getversion
GNUmakefile.in       README.macOS.md     gpAux
LICENSE              README.md           gpMgmt
Makefile             README.ubuntu.bash  gpdb-doc
NOTICE               aclocal.m4          hooks
README.CentOS.bash   concourse           putversion
README.PostgreSQL    config              python-dependencies.txt
README.amazon_linux  configure           python-developer-dependencies.txt
README.conda.md      configure.in        src
README.docker.md     contrib
README.git           depends
[root@bd675377db24 gpdb_src]# git tag
5.0.0
5.0.0-alpha.0
5.0.0-alpha.1
5.0.0-alpha.2
5.0.0-alpha.3
5.0.0-alpha.4
5.0.0-alpha.5
5.0.0-alpha.6
5.0.0-alpha.7
5.0.0-alpha.8
5.0.0-beta.1
5.0.0-beta.10
5.0.0-beta.2
5.0.0-beta.3
5.0.0-beta.4
5.0.0-beta.5
5.0.0-beta.6
5.0.0-beta.7
5.0.0-beta.8
5.0.0-beta.9
5.1.0
5.2.0
5.3.0
5.4.0
5.4.1
5.5.0
5.6.0
5.6.1
5.7.0
5.7.1
5.8.0
5.8.1
5.9.0
6.0.0-alpha.0
[root@bd675377db24 gpdb_src]# git checkout 6.0.0-alpha.0 
Note: checking out '6.0.0-alpha.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at d413c0d... bumped default version to 6.0.0-alpha.0

安装准备工作

首先安装sudo,默认镜像中没有,我们需要手动安装

yum install -y sudo

开始安装

准备安装所需的依赖库,依赖库可能有先后顺序,执行时可能有部分软件由于依赖关系不完整安装失败,再次执行即可。

先查看安装说明,之前一直不习惯看这个,吃亏很多啊。

[root@bd675377db24 gpdb_src]# cat README.CentOS.md
### CentOS Build Setup Instructions

These setup instructions only apply to builds without Orca.

### Install Dependencies

```bash
./README.CentOS.bash
```

### Get an Updated GCC on CentOS 6

Install [devtoolset-6][devtoolset-6], which contains gcc 6.3.

[devtoolset-6]: https://www.softwarecollections.org/en/scls/rhscl/devtoolset-6/

First, enable the repository:

```bash
#CentOS 6:
sudo yum install centos-release-scl
#RHEL on AWS:
sudo yum-config-manager --enable rhui-REGION-rhel-server-rhscl
```

Then install devtoolset-6:

```bash
sudo yum install devtoolset-6-toolchain
```

Now running `scl enable devtoolset-6 bash` starts a bash session that puts gcc
6.3 in `$PATH`. To enable devtoolset-6 in all your login shells:

```bash
echo 'source scl_source enable devtoolset-6' >> ~/.bashrc
```

接下来按照步骤操作就行了。

为了方便后续操作,需要配置ssh免密登陆(集群部署的时候需要),此时ssh服务端尚未安装,需要安装ssh服务。

sudo yum install openssh*

设置开机启动
chkconfig --add sshd

启动ssh服务
service sshd start

设置免密登陆

cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

检验方式是ssh < hostname of your machine>,不需要输入密码即表示成功,这里需要将hostname of our machine替换为真实主机名,可以通过hostname来进行查看主机名。

安装openssl-devel

yum install openssl-devel

开始编译代码。

./configure --enable-debug --disable-orca --with-perl --with-python --with-libxml --prefix=/usr/local/gpdb

make

make install

接下来配置系统参数,由于greenplum是多进程的,且表一般对应单独的文件,因此需要配置的参数比较多,然而并不麻烦,执行官方文档中的语句基本就可以完成任务。

[gpadmin@87209baa5bbc tmp]$ sudo bash -c 'cat >> /etc/sysctl.conf <<-EOF
> kernel.shmmax = 500000000
> kernel.shmmni = 4096
> kernel.shmall = 4000000000
> kernel.sem = 250 512000 100 2048
> kernel.sysrq = 1
> kernel.core_uses_pid = 1
> kernel.msgmnb = 65536
> kernel.msgmax = 65536
> kernel.msgmni = 2048
> net.ipv4.tcp_syncookies = 1
> net.ipv4.ip_forward = 0
> net.ipv4.conf.default.accept_source_route = 0
> net.ipv4.tcp_tw_recycle = 1
> net.ipv4.tcp_max_syn_backlog = 4096
> net.ipv4.conf.all.arp_filter = 1
> net.ipv4.ip_local_port_range = 1025 65535
> net.core.netdev_max_backlog = 10000
> net.core.rmem_max = 2097152
> net.core.wmem_max = 2097152
> vm.overcommit_memory = 2
> 
> EOF'
[sudo] password for gpadmin: 
[gpadmin@87209baa5bbc tmp]$ sudo bash -c 'cat >> /etc/security/limits.conf <<-EOF
> * soft nofile 65536
> * hard nofile 65536
> * soft nproc 131072
> * hard nproc 131072
> 
> EOF'
[gpadmin@87209baa5bbc tmp]$ sudo bash -c 'cat >> /etc/ld.so.conf <<-EOF
> /usr/local/lib
> 
> EOF'

至此,一个安装了greenplum的docker容器已经准备好了,退出容器。

exit

查看刚刚退出的容器id。

zhengshibin@zhengshibin-ubuntu:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
5298af188708        greenplum:0.1       "/bin/bash"         About an hour ago   Exited (0) 29 seconds ago                       tender_poincare

保存到新的镜像中。

docker commit 5298af188708 greenplum:0.2

查看刚刚保存的镜像。

zhengshibin@zhengshibin-ubuntu:~$ docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
greenplum                     0.2                 cdca5e6e7bf5        16 seconds ago      2.24GB
greenplum                     0.1                 997f0ed97903        2 years ago         442MB
hub.c.163.com/public/centos   latest              997f0ed97903        2 years ago         442MB

好吧,继续的时候已经是几个月以后了。。。
现在开始:

开始部署

greenplum的部署可能稍显复杂,而且这里可能也只是个人调试,因此这里还是选择单机配置,对于这种情况,greenplum给出了相应的方案,照做即可。

配置环境变量

. /opt/gpdb/greenplum_path.sh
which gpssh–检验环境变量是否正确设置

注:不要漏掉’.’

配置mpp所需的信息

cp $GPHOME/docs/cli_help/gpconfigs/gpinitsystem_singlenode .–拷贝greenplum准备的模板。

vi gpinitsystem_singlenode–修改配置信息
注:需要根据自己的主机名,路径等配置详细信息,路径需要手动创建,保证存在且有权限。

vi hostlist_singlenode–创建该文件,并写入自己的主机名

gpssh-exchkeys -f hostlist_singlenode–配置节点互信等操作

gpinitsystem -c gpinitsystem_singlenode–初始化

createdb demo–创建demo库

psql demo–连接数据库

另外,为了方便起见,可以将一些信息放到~/.bashrc中,以保证每次连接后,都可以执行gpstart/gpstop等,并且MASTER的主文件夹也已知。

. /usr/local/gpdb/greenplum_path.sh
MASTER_DATA_DIRECTORY=/home/gp6/master/segment-1
export MASTER_DATA_DIRECTORY

注意:segment-1是由于gpinitsystem_singlenode中将前缀修改为segment导致的,也就是说,MASTER_DATA_DIRECTORY的路径是gpinitsystem_singlenode中配置的+前缀+’-1’,配置错误可能导致启动失败。

最终版本保存

docker commit 5298af188708 greenplum:mpp

之后,就可以基于这个镜像创建一个新的容器,然后删除之前的容器和镜像。

docker stop container_id–关闭容器

docker rm container_id–删除容器

docker rmi image_id–删除镜像

另外,新创建的容器可能会有主机名不正确的问题,因为之前是用别的容器搭建的greenplum,而保存之后,在创建的新容器,主机名和原来的不同,因此容器主机名和greenplum集群配置的主机名不同,会导致无法启动。

这里附上当时找到的一个链接,希望之后再遇到问题时能快速解决。

修改主机名

至此,终于配置完成一套可以正确执行、调试的greenplum集群,也算是给自己一个交代。
另外,回头再看时,中间将容器保存为镜像,似乎并没有什么用处。。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章