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集羣,也算是給自己一個交代。
另外,回頭再看時,中間將容器保存爲鏡像,似乎並沒有什麼用處。。。

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