当前位置:   article > 正文

OBD搭建OceanBase三副本集群(1-1-1)docker版

OBD搭建OceanBase三副本集群(1-1-1)docker版

1. 目的

        本次使用OBD方式搭建一个OceanBase三副本集群,由于服务器资源有限,选择较为轻量级的docker,运行三个容器来实现OceanBase(1-1-1)+OBProxy集群架构的搭建,ODC开发工具客户端远程连接做简单查询。

2. 环境规划

IP服务器资源规格软件及版本宿主机:容器端口映射宿主机:容器目录映射
10.0.0.11docker0120C15g512GOceanBase(4.2.1)

1881:2881

1882:2882

1883:2883

/mnt/db/oceanbase/ob01:/opt

/sys/fs/cgroup:/sys/fs/cgroup

10.0.0.12docker0220C15g512G

OceanBase(4.2.1)

OBProxy(4.2.1)

OBD(2.5.0)

2881:2881

2882:2882

2883:2883

2884:2884

/mnt/db/oceanbase/ob02:/opt

/sys/fs/cgroup:/sys/fs/cgroup

10.0.0.11docker0320C15g512GOceanBase(4.2.1)

3881:2881

3882:2882

3883:2883

/mnt/db/oceanbase/ob03:/opt

/sys/fs/cgroup:/sys/fs/cgroup

192.168.0.113

Ubantu

(宿主机)

20C64g512Gdocker//
192.168.0.21

Windows

(客户端)

8C16g512G

ODC(4.2.2)

等开发工具

//

3.  搭建步骤

3.1. 初始化服务器

1)docker运行三个CentOS7.6容器:

  1. ## docker拉取一个基础镜像:
  2. root@system:~# docker pull vitotp/centos7.6
  3. ## 基于基础镜像构建一个自己的基础镜像:
  4. root@system:~# vim Dockerfile
  5. root@system:~# cat Dockerfile
  6. FROM vitotp/centos7.6
  7. RUN echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf && yum -y update && yum -y install openssh-server openssh-clients lrzsz sudo && yum -y clean all && echo "root:qwerty"|chpasswd && echo "root ALL=(ALL) ALL" >> /etc/sudoers && mkdir /var/run/sshd
  8. EXPOSE 22
  9. CMD ["systemctl","start","sshd.server"]
  10. root@system:~# docker build -t myos-el7:1.0 .
  11. root@system:~# docker images
  12. REPOSITORY TAG IMAGE ID CREATED SIZE
  13. myos-el7 1.0 6510f68c38d4 3 weeks ago 771MB
  14. vitotp/centos7.6 latest 0429a3daccd0 4 years ago 433MB
  15. ## 创建ob01容器:
  16. root@system:~# docker run -d -m 15g -p 122:22 -p 1881:2881 -p 1882:2882 -p 1883:2883 -v /mnt/db/oceanbase/ob01:/opt -v /mnt/hub/obadmin01:/home -h OBSERVER01 --name=ob01 --privileged=true 6510f68c38d4 /usr/sbin/init
  17. ## 创建ob02容器:
  18. root@system:~# docker run -d -m 15g -p 222:22 -p 2881:2881 -p 2882:2882 -p 2883:2883 -p 2884:2884 -p 8080:8080 -v /mnt/db/oceanbase/ob02:/opt -v /mnt/hub/obadmin02:/home -h OBSERVER02 --name=ob02 --privileged=true 6510f68c38d4 /usr/sbin/init
  19. ## 创建ob03容器:
  20. root@system:~# docker run -d -m 15g -p 322:22 -p 3881:2881 -p 3882:2882 -p 3883:2883 -v /mnt/db/oceanbase/ob03:/opt -v /mnt/hub/obadmin03:/home -h OBSERVER03 --name=ob03 --privileged=true 6510f68c38d4 /usr/sbin/init

2)创建容器桥接网络:

  1. ## 创建桥接网卡:
  2. root@system:~# docker network create --subnet 10.0.0.0/24 --gateway 10.0.0.1 innet
  3. ## 设置固定IP追加到各个容器:
  4. root@system:~# docker network create --subnet 10.0.0.0/24 --gateway 10.0.0.1 innet
  5. root@system:~# docker network connect innet --ip "10.0.0.11" ob01
  6. root@system:~# docker network connect innet --ip "10.0.0.12" ob02
  7. root@system:~# docker network connect innet --ip "10.0.0.13" ob03

docker基础命令可浏览博客:

Docker基础(小白篇)-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/weixin_61894388/article/details/130708198?spm=1001.2014.3001.5501 3)初始化操作系统环境:三个OB容器均执行;

  1. ## 添加一个初始化操作系统脚本:
  2. root@system:~# cd /mnt/db/oceanbase
  3. root@system:oceanbase# cat initos.sh
  4. echo ' _
  5. _ _|_| ___
  6. _|_|_|_|_ \ \___
  7. _|_|_|_|_|_|___ \ __\
  8. /===============\___/ /
  9. ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~~/~~ ~~~
  10. \_____o ___/
  11. \ \ __/
  12. \__\________/
  13. docker - centos7.6' > /root/logo.txt
  14. echo '#!/bin/bash
  15. echo -e "\033[1;36m$(cat /root/logo.txt)\033[0m\n登录主机: [\033[1;35m$(hostname -I)\033[0m],时间: [\033[1;33m$(date +%F_%T)\033[0m]"
  16. pg(){
  17. ps -ef | grep "$1" | grep -v grep
  18. }
  19. ns(){
  20. netstat -unlpt | grep "$1"
  21. }
  22. clockdiff 10.0.0.11
  23. clockdiff 10.0.0.12
  24. clockdiff 10.0.0.13
  25. ' > /root/cmd
  26. chmod 775 /root/cmd
  27. echo 'source /root/cmd' >> /root/.bash_profile
  28. source /root/.bash_profile
  29. ## 关闭透明大页:
  30. echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
  31. cat /sys/kernel/mm/transparent_hugepage/enabled
  32. ## 修改可用最小内存值,小于该值则清理缓存:
  33. echo 3 > /proc/sys/vm/drop_caches
  34. ## 设置资源限制大小:
  35. echo '
  36. root soft nofile 655350
  37. root hard nofile 655350
  38. * soft nofile 655350
  39. * hard nofile 655350
  40. * soft nproc 655360
  41. * hard nproc 655360
  42. * soft stack unlimited
  43. * hard stack unlimited
  44. * soft core unlimited
  45. * hard core unlimited
  46. ' >> /etc/security/limits.conf
  47. ulimit -a
  48. ## 修改操作系统内核参数:
  49. echo 'fs.aio-max-nr=1048576
  50. net.core.somaxconn = 2048
  51. net.core.netdev_max_backlog = 10000
  52. net.core.rmem_default = 16777216
  53. net.core.wmem_default = 16777216
  54. net.core.rmem_max = 16777216
  55. net.core.wmem_max = 16777216
  56. net.ipv4.ip_local_port_range = 3500 65535
  57. net.ipv4.conf.default.rp_filter = 1
  58. net.ipv4.conf.default.accept_source_route = 0
  59. net.ipv4.tcp_syncookies = 0
  60. net.ipv4.tcp_rmem = 4096 87380 16777216
  61. net.ipv4.tcp_wmem = 4096 65536 16777216
  62. net.ipv4.tcp_max_syn_backlog = 16384
  63. net.ipv4.tcp_fin_timeout = 15
  64. net.ipv4.tcp_max_syn_backlog = 16384
  65. net.ipv4.tcp_tw_reuse = 1
  66. net.ipv4.tcp_tw_recycle = 1
  67. net.ipv4.tcp_slow_start_after_idle=0
  68. vm.swappiness = 0
  69. vm.min_free_kbytes = 2097152
  70. fs.file-max = 6573688
  71. vm.max_map_count = 655360
  72. kernel.core_pattern = /opt/core-%e-%p-%t
  73. ' >> /etc/sysctl.conf
  74. sysctl -p
  75. ## 创建操作系统用户:
  76. useradd -g root -m -d /home/admin -s /bin/bash admin
  77. echo 'Admin123' | passwd --stdin admin
  78. id admin
  79. ## 配置sodu权限:
  80. echo "admin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
  81. ## 目录规划:
  82. mkdir -p /opt/{data,redolog}
  83. ## 配置服务域名:
  84. echo '
  85. 10.0.0.11 OBSVR01
  86. 10.0.0.12 OBSVR02
  87. 10.0.0.13 OBSVR03
  88. ' >> /etc/hosts
  89. ## 时钟校正:
  90. clockdiff OBSVR01
  91. clockdiff OBSVR02
  92. clockdiff OBSVR03
  93. ## 修改环变量:
  94. echo 'export OB_HOME=/home/admin/oceanbase
  95. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OB_HOME/lib
  96. export PATH=$PATH:$OB_HOME/bin
  97. ' >> /home/admin/.bash_profile
  98. ## 设置免密登陆:
  99. su - admin -c "ssh-keygen -t rsa -N ''"
  100. ## 各个容器执行初始化:
  101. root@system:oceanbase# docker exec -it ob01 /bin/bash -c "/opt/initos.sh"
  102. root@system:oceanbase# docker exec -it ob02 /bin/bash -c "/opt/initos.sh"
  103. root@system:oceanbase# docker exec -it ob03 /bin/bash -c "/opt/initos.sh"

4)docker集群管理脚本:

  1. ## 简化docker命令集:
  2. root@system:~# cd /var/lib/docker/dockercmd
  3. #!/bin/bash
  4. dls(){
  5. docker images
  6. }
  7. dps(){
  8. docker ps -a
  9. }
  10. dexec(){
  11. docker exec -it "$1" /bin/bash -c "sudo -i"
  12. }
  13. drm(){
  14. docker rm -f "$1"
  15. }
  16. drmi(){
  17. docker rmi -f "$1"
  18. }
  19. OBCService(){
  20. OBSVRLIST=(ob01 ob02 ob03)
  21. mode="${1:-stats}"
  22. for svr in ${OBSVRLIST[@]};do echo "正在${mode}容器${svr}..."&&echo -e "[\033[1;32mOK\033[0m]: $(docker ${mode} ${svr})容器${mode}成功.";done
  23. }
  24. complete -W "start stop restart stats" OBCService
  25. root@system:~# source /var/lib/docker/dockercmd
  26. ## 一键重启OceanBase集群:
  27. root@system:~# OBCService restart
  28. 正在restart容器ob01...
  29. [OK]: ob01容器restart成功.
  30. 正在restart容器ob02...
  31. [OK]: ob02容器restart成功.
  32. 正在restart容器ob03...
  33. [OK]: ob03容器restart成功.
  34. ## 进入ob1容器:
  35. root@system:~# dexec ob01
  36. _
  37. _ _|_| ___
  38. _|_|_|_|_ \ \___
  39. _|_|_|_|_|_|___ \ __\
  40. /===============\___/ /
  41. ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~~/~~ ~~~
  42. \_____o ___/
  43. \ \ __/
  44. \__\________/
  45. docker - centos7.6
  46. 登录主机: [128.128.0.3 10.0.0.11 ],时间: [2024-01-20_13:18:54]
  47. .
  48. host=10.0.0.11 rtt=750(187)ms/0ms delta=0ms/0ms Sat Jan 20 13:18:54 2024
  49. .
  50. host=10.0.0.12 rtt=750(187)ms/0ms delta=0ms/0ms Sat Jan 20 13:18:54 2024
  51. .
  52. host=10.0.0.13 rtt=750(187)ms/0ms delta=0ms/0ms Sat Jan 20 13:18:54 2024
  53. [root@OBSERVER01 ~]# vim /etc/security/limits.d/20-nproc.conf
  54. [root@OBSERVER01 ~]# su - admin
  55. Last login: Sat Jan 20 12:25:28 CST 2024 on pts/2
  56. [admin@OBSERVER01 ~]$

执行初始化OS脚本后,注意观察clockdiff时间延时情况,由于我这里是同在一个宿主机里的三个docker容器,所以这三个容器时间是一致的,延时为零;如果是三台物理机,各个节点是需要配置时钟源来让各节点时间保持延时最小,具体配置时钟源方法可查看OceanBase官网文档:

(可选)配置时钟源-OceanBase 数据库 -OceanBase文档中心-分布式数据库使用文档icon-default.png?t=N7T8https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000000220840

3.2. OBD下载安装rpm包

1)下载OB安装包:(在容器ob02执行即可)

        服务器如果不能连外网,可在官网下载,上传到服务器进行安装,官网链接:

OceanBase 社区版下载 - 开源数据库下载 - OceanBase 数据库下载中心icon-default.png?t=N7T8https://www.oceanbase.com/softwarecenter        服务器如果可以连外网,可以直接下载:

  1. ## 进入ob02容器交互:
  2. root@system:~# docker exec -it ob02 /bin/bash
  3. [root@OBSERVER02 ~]$ cd /opt/obinstall
  4. [root@OBSERVER02 obinstall]$ wget https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/download-center/opensource/observer/4.2.1_CE_BP2/oceanbase-ce-4.2.1.2-102000042023120514.el7.x86_64.rpm
  5. [root@OBSERVER02 obinstall]$ wget https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/download-center/opensource/observer/4.2.1_CE_BP2/oceanbase-ce-libs-4.2.1.2-102000042023120514.el7.x86_64.rpm
  6. [root@OBSERVER02 obinstall]$ wget https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/download-center/opensource/obdeploy/2.5.0/ob-deploy-2.5.0-2.el7.x86_64.rpm
  7. [root@OBSERVER02 obinstall]$ wget https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/download-center/opensource/obproxy/v4.2.1_CE/obproxy-ce-4.2.1.0-11.el7.x86_64.rpm
  8. [root@OBSERVER02 obinstall]$ ll
  9. total 285096
  10. -rw-r--r-- 1 root root 11936672 Jan 3 18:36 obclient-2.2.3-1.el7.x86_64.rpm
  11. -rw-r--r-- 1 root root 65033488 Jan 3 18:36 ob-deploy-2.5.0-2.el7.x86_64.rpm
  12. -rw-r--r-- 1 root root 123411192 Jan 2 16:14 obproxy-ce-4.2.1.0-11.el7.x86_64.rpm
  13. -rw-r--r-- 1 root root 91384448 Jan 2 16:14 oceanbase-ce-4.2.1.2-102000042023120514.el7.x86_64.rpm
  14. -rw-r--r-- 1 root root 158316 Jan 2 16:14 oceanbase-ce-libs-4.2.1.2-102000042023120514.el7.x86_64.rpm
  15. [root@OBSERVER02 obinstall]$ chown -R admin:root /opt/obinstall

2)安装OBD:

  1. ## 安装OBD:
  2. [admin@OBSERVER02 obinstall]$ sudo rpm -ivh ob-deploy-2.4.1-2.el7.x86_64.rpm
  3. Preparing... ################################# [100%]
  4. Updating / installing...
  5. 1:ob-deploy-2.4.1-2.el7 ################################# [100%]
  6. Installation of obd finished successfully
  7. Please source /etc/profile.d/obd.sh to enable it
  8. [admin@OBSERVER02 obinstall]$ source /etc/profile.d/obd.sh
  9. [admin@OBSERVER02 obinstall]$ obd --help
  10. Usage: obd <command> [options]
  11. Available commands:
  12. cluster Deploy and manage a cluster.
  13. demo Quickly start
  14. display-trace display trace_id log.
  15. mirror Manage a component repository for OBD.
  16. obdiag Oceanbase Diagnostic Tool
  17. repo Manage local repository for OBD.
  18. test Run test for a running deployment.
  19. update Update OBD.
  20. web Start obd deploy application as web.
  21. Options:
  22. --version show program's version number and exit
  23. -h, --help Show help and exit.
  24. -v, --verbose Activate verbose output.

 

 3)禁用远程仓库:(建议OBD离线方式安装rpm包,速度比OBD在线下载安装步骤要快一些)

  1. ## (可选)删除或移走远程yum源包:
  2. [admin@OBSERVER02 ~]$ rm -rf ~/.obd/mirror/remote/OceanBase.repo
  3. [admin@OBSERVER02 ~]$ obd mirror list
  4. Update OceanBase-community-stable-el7 ok
  5. Update OceanBase-development-kit-el7 ok
  6. +-----------------------------------------------------------------------------+
  7. | Mirror Repository List |
  8. +----------------------------+--------+---------+----------+------------------+
  9. | SectionName | Type | Enabled | Avaiable | Update Time |
  10. +----------------------------+--------+---------+----------+------------------+
  11. | oceanbase.community.stable | remote | True | True | 2024-01-03 10:31 |
  12. | oceanbase.development-kit | remote | True | True | 2024-01-03 10:31 |
  13. | local | local | - | True | 2024-01-03 10:37 |
  14. +----------------------------+--------+---------+----------+------------------+
  15. Use `obd mirror list <section name>` for more details
  16. Trace ID: 083bc7ec-a9e1-11ee-8b6b-0242ac110003
  17. If you want to view detailed obd logs, please run: obd display-trace 083bc7ec-a9e1-11ee-8b6b-0242ac110003
  18. ## OBD禁用远程仓库:
  19. [admin@OBSERVER02 ~]$ obd mirror disable remote
  20. Disable remote ok
  21. Trace ID: 14b436b2-a9e1-11ee-bd85-0242ac110003
  22. If you want to view detailed obd logs, please run: obd display-trace 14b436b2-a9e1-11ee-bd85-0242ac110003
  23. [admin@OBSERVER02 ~]$ obd mirror list
  24. +-----------------------------------------------------------------------------+
  25. | Mirror Repository List |
  26. +----------------------------+--------+---------+----------+------------------+
  27. | SectionName | Type | Enabled | Avaiable | Update Time |
  28. +----------------------------+--------+---------+----------+------------------+
  29. | oceanbase.community.stable | remote | False | False | 2024-01-03 10:37 |
  30. | oceanbase.development-kit | remote | False | False | 2024-01-03 10:37 |
  31. | local | local | - | True | 2024-01-03 10:39 |
  32. +----------------------------+--------+---------+----------+------------------+
  33. Use `obd mirror list <section name>` for more details
  34. Trace ID: 50f681a2-a9e1-11ee-9248-0242ac110003
  35. If you want to view detailed obd logs, please run: obd display-trace 50f681a2-a9e1-11ee-9248-0242ac110003

4)将本地rpm包加入OBD:

  1. [admin@OBSERVER02 obinstall]$ obd mirror clone ./*.rpm
  2. name: obproxy-ce
  3. version: 4.2.1.0
  4. release:11.el7
  5. arch: x86_64
  6. md5: 0aed4b782120e4248b749f67be3d2cc82cdcb70d
  7. add ./obproxy-ce-4.2.1.0-11.el7.x86_64.rpm to local mirror
  8. name: oceanbase-ce
  9. version: 4.2.1.2
  10. release:102000042023120514.el7
  11. arch: x86_64
  12. md5: bf178e82c99ca1324a3df9e1a21cbbb8f8c4d46c
  13. add ./oceanbase-ce-4.2.0.0-102000042023120514.el7.x86_64.rpm to local mirror
  14. name: oceanbase-ce-libs
  15. version: 4.2.1.2
  16. release:102000042023120514.el7
  17. arch: x86_64
  18. md5: f77ba7e678acf0645889967391c847ca9cf684b6
  19. add ./oceanbase-ce-libs-4.2.0.0-102000042023120514.el7.x86_64.rpm to local mirror
  20. Trace ID: 03fa748c-a3bd-11ee-acb3-0242ac110003
  21. If you want to view detailed obd logs, please run: obd display-trace 03fa748c-a3bd-11ee-acb3-0242ac110003
  22. ## 查看本地仓库:
  23. [admin@OBSERVER02 ~]$ obd mirror list local
  24. +----------------------------------------------------------------------------------------------------------+
  25. | local Package List |
  26. +-------------------+---------+------------------------+--------+------------------------------------------+
  27. | name | version | release | arch | md5 |
  28. +-------------------+---------+------------------------+--------+------------------------------------------+
  29. | obproxy-ce | 4.2.1.0 | 11.el7 | x86_64 | 0aed4b782120e4248b749f67be3d2cc82cdcb70d |
  30. | oceanbase-ce | 4.2.1.2 | 102000042023120514.el7 | x86_64 | b2ccb524f200a9ef0fad2cddf59d309ddaa2e3e4 |
  31. | oceanbase-ce-libs | 4.2.1.2 | 102000042023120514.el7 | x86_64 | b4ae00ee729404557fa858d4cdd87250bca1aa63 |
  32. +-------------------+---------+------------------------+--------+------------------------------------------+
  33. Trace ID: ccbaf870-ac77-11ee-8848-0242ac110003
  34. If you want to view detailed obd logs, please run: obd display-trace ccbaf870-ac77-11ee-8848-0242ac110003
  35. [admin@OBSERVER02 ~]$

3.3. 搭建OceaBase集群

1)配置yaml文件:

  1. [admin@OBSERVER02 obinstall]$ cat myobc.yaml
  2. user:
  3. username: admin
  4. password: Admin123
  5. oceanbase-ce:
  6. servers:
  7. - name: obsvr01
  8. ip: 10.0.0.11
  9. - name: obsvr02
  10. ip: 10.0.0.12
  11. - name: obsvr03
  12. ip: 10.0.0.13
  13. global:
  14. devname: eth1
  15. mysql_port: 2881
  16. rpc_port: 2882
  17. home_path: /home/admin/oceanbase
  18. data_dir: /opt/data
  19. redo_dir: /opt/redolog
  20. cluster_id: 202401
  21. production_mode: false
  22. memory_limit: 8G
  23. system_memory: 2G
  24. stack_size: 512K
  25. cpu_count: 16
  26. datafile_size: 15G
  27. log_disk_size: 5G
  28. cache_wash_threshold: 1G
  29. __min_full_resource_pool_memory: 2147483648
  30. workers_per_cpu_quota: 10
  31. schema_history_expire_time: 1d
  32. net_thread_count: 4
  33. major_freeze_duty_time: Disable
  34. minor_freeze_times: 10
  35. enable_separate_sys_clog: 0
  36. enable_merge_by_turn: false
  37. syslog_level: WARN
  38. enable_syslog_wf: false
  39. enable_syslog_recycle: true
  40. enable_rich_error_msg: true
  41. max_syslog_file_count: 4
  42. appname: myobc
  43. root_password: 1qazxsw2
  44. proxyro_password:
  45. obsvr01:
  46. zone: zone1
  47. obsvr02:
  48. zone: zone2
  49. obsvr03:
  50. zone: zone3
  51. [admin@OBSERVER02 obinstall]$

2)OBD自动搭建OB集群: 

  1. [admin@OBSERVER02 ~]$ obd cluster deploy myobc -c /opt/obinstall/myobc.yaml -f
  2. Package oceanbase-ce-4.2.1.2-102000042023120514.el7 is available.
  3. install oceanbase-ce-4.2.1.2 for local ok
  4. +--------------------------------------------------------------------------------------------+
  5. | Packages |
  6. +--------------+---------+------------------------+------------------------------------------+
  7. | Repository | Version | Release | Md5 |
  8. +--------------+---------+------------------------+------------------------------------------+
  9. | oceanbase-ce | 4.2.1.2 | 102000042023120514.el7 | b2ccb524f200a9ef0fad2cddf59d309ddaa2e3e4 |
  10. +--------------+---------+------------------------+------------------------------------------+
  11. Repository integrity check ok
  12. Parameter check ok
  13. Initializes observer work home ok
  14. Remote oceanbase-ce-4.2.1.2-102000042023120514.el7-b2ccb524f200a9ef0fad2cddf59d309ddaa2e3e4 repository install ok
  15. Remote oceanbase-ce-4.2.1.2-102000042023120514.el7-b2ccb524f200a9ef0fad2cddf59d309ddaa2e3e4 repository lib check !!
  16. Try to get lib-repository
  17. Package oceanbase-ce-libs-4.2.1.2-102000042023120514.el7 is available.
  18. install oceanbase-ce-libs-4.2.1.2 for local ok
  19. Remote oceanbase-ce-libs-4.2.1.2-102000042023120514.el7-29557bf57e13a46975c28ca5ce222ee3d776a8a9 repository install ok
  20. Remote oceanbase-ce-4.2.1.2-102000042023120514.el7-b2ccb524f200a9ef0fad2cddf59d309ddaa2e3e4 repository lib check ok
  21. myobc deployed
  22. Please execute ` obd cluster start myobc ` to start
  23. Trace ID: 76232158-b74a-11ee-99a2-024280800002
  24. If you want to view detailed obd logs, please run: obd display-trace 76232158-b74a-11ee-99a2-024280800002

-f 参数可以强制覆盖原有的安装目录文件,避免安装过程出现安装目录不为空产生的报错;如果是第一次安装搭建,可以不加-f。 

3)启动集群: 

  1. [admin@OBSERVER02 ~]$ obd cluster start myobc
  2. Get local repositories ok
  3. Search plugins ok
  4. Load cluster param plugin ok
  5. Open ssh connection ok
  6. Check before start observer ok
  7. [WARN] OBD-1012: (10.0.0.11) clog and data use the same disk (/opt)
  8. [WARN] OBD-1012: (10.0.0.12) clog and data use the same disk (/opt)
  9. [WARN] OBD-1012: (10.0.0.13) clog and data use the same disk (/opt)
  10. Start observer ok
  11. observer program health check ok
  12. Connect to observer 10.0.0.11:2881 ok
  13. Initialize oceanbase-ce ok
  14. Wait for observer init ok
  15. +---------------------------------------------+
  16. | observer |
  17. +-----------+---------+------+-------+--------+
  18. | ip | version | port | zone | status |
  19. +-----------+---------+------+-------+--------+
  20. | 10.0.0.11 | 4.2.1.2 | 2881 | zone1 | ACTIVE |
  21. | 10.0.0.12 | 4.2.1.2 | 2881 | zone2 | ACTIVE |
  22. | 10.0.0.13 | 4.2.1.2 | 2881 | zone3 | ACTIVE |
  23. +-----------+---------+------+-------+--------+
  24. obclient -h10.0.0.11 -P2881 -uroot -p'1qazxsw2' -Doceanbase -A
  25. myobc running
  26. Trace ID: ffe97290-aaa5-11ee-86dc-0242ac110003
  27. If you want to view detailed obd logs, please run: obd display-trace ffe97290-aaa5-11ee-86dc-0242ac110003

4)安装obclient客户端工具:

  1. [admin@OBSERVER02 opt]$ sudo rpm -ivh obclient-2.2.3-1.el7.x86_64.rpm
  2. Preparing... ################################# [100%]
  3. Updating / installing...
  4. 1:obclient-2.2.3-1.el7 ################################# [100%]
  5. [admin@OBSERVER02 opt]$

3.4. 安装运行OBProxy

        OBD方式也可以在安装配置文件myobc.yaml上添加OBProxy的配置项,由OBD一键执行下载安装并启停服务,但这一步在本次的搭建试验中老是存在问题,问题详情可看第5章节《问题处理》会讲到,为了绕开问题,采用手动完成OBProxy的搭建,并写到脚本将OBProxy与OBD合并一处一键启停。

1)安装OBProxy并拉起服务:

  1. [admin@OBSERVER02 obinstall]$ sudo rpm -ivh obproxy-ce-4.2.1.0-11.el7.x86_64.rpm
  2. Preparing... ################################# [100%]
  3. Updating / installing...
  4. 1:obproxy-ce-4.2.1.0-11.el7 ################################# [100%]
  5. [admin@OBSERVER02 obinstall]$ cd ~/obproxy
  6. [admin@OBSERVER02 obproxy]$ /home/admin/obproxy/bin/obproxy -o 'enable_strict_kernel_release=false,enable_cluster_checkout=false,skip_proxy_sys_private_check=true,enable_metadb_used=false' --listen_port 2883 --prometheus_listen_port 2884 --rs_list '10.0.0.11:2881;10.0.0.12:2881;10.0.0.13:2881' --cluster_name myobc
  7. /home/admin/obproxy/bin/obproxy -o enable_strict_kernel_release=false,enable_cluster_checkout=false,skip_proxy_sys_private_check=true,enable_metadb_used=false --listen_port 2883 --prometheus_listen_port 2884 --rs_list 10.0.0.11:2881;10.0.0.12:2881;10.0.0.13:2881 --cluster_name myobc
  8. optstr: enable_strict_kernel_release=false,enable_cluster_checkout=false,skip_proxy_sys_private_check=true,enable_metadb_used=false
  9. listen port: 2883
  10. prometheus listen port: 2884
  11. [admin@OBSERVER02 obproxy]$ ps -ef|grep obproxy
  12. admin 855 1 3 18:14 ? 00:00:23 /home/admin/obproxy/bin/obproxy -o enable_strict_kernel_release=false,enable_cluster_checkout=false,skip_proxy_sys_private_check=true,enable_metadb_used=false --listen_port 2883 --prometheus_listen_port 2884 --rs_list 10.0.0.11:2881;10.0.0.12:2881;10.0.0.13:2881 --cluster_name myobc
  13. [admin@OBSERVER02 obproxy]$ ss -unlpt|grep 2883
  14. tcp LISTEN 0 1024 *:2883 *:* users:(("obproxy",pid=2062,fd=92))

2)设置OBProxy进程系统密码: 

  1. [admin@OBSERVER02 ~]$ obclient -h10.0.0.12 -P2883 -uroot@proxysys -p -c -A
  2. Enter password:
  3. Welcome to the OceanBase. Commands end with ; or \g.
  4. Your OceanBase connection id is 5
  5. Server version: 5.6.25
  6. Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8. obclient [(none)]> show processlist;
  9. +------+----------+------+-----------------+------+-------------+-------------------+-------------------+------+------+
  10. | Id | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid |
  11. +------+----------+------+-----------------+------+-------------+-------------------+-------------------+------+------+
  12. | 5 | proxysys | root | 10.0.0.12:52932 | NULL | 0 | 0 | MCS_ACTIVE_READER | 2062 | 2062 |
  13. +------+----------+------+-----------------+------+-------------+-------------------+-------------------+------+------+
  14. 1 row in set (0.002 sec)
  15. obclient [(none)]> show proxyconfig like '%sys_password%';
  16. +------------------------+-------+--------------------------------+-------------+---------------+
  17. | name | value | info | need_reboot | visible_level |
  18. +------------------------+-------+--------------------------------+-------------+---------------+
  19. | observer_sys_password1 | | password for observer sys user | false | SYS |
  20. | observer_sys_password | | password for observer sys user | false | SYS |
  21. | obproxy_sys_password | | password for obproxy sys user | false | SYS |
  22. +------------------------+-------+--------------------------------+-------------+---------------+
  23. 3 rows in set (0.002 sec)
  24. obclient [(none)]> alter proxyconfig set observer_sys_password='1QAZXSW2';
  25. Query OK, 0 rows affected (0.017 sec)
  26. obclient [(none)]> alter proxyconfig set obproxy_sys_password='1QAZXSW2';
  27. Query OK, 0 rows affected (0.016 sec)
  28. obclient [(none)]> show proxyconfig like '%sys_password%';
  29. +------------------------+------------------------------------------+--------------------------------+-------------+---------------+
  30. | name | value | info | need_reboot | visible_level |
  31. +------------------------+------------------------------------------+--------------------------------+-------------+---------------+
  32. | observer_sys_password1 | | password for observer sys user | false | SYS |
  33. | observer_sys_password | 51045cddb1a4447ece609d181d80833cbcd361c6 | password for observer sys user | false | SYS |
  34. | obproxy_sys_password | 51045cddb1a4447ece609d181d80833cbcd361c6 | password for obproxy sys user | false | SYS |
  35. +------------------------+------------------------------------------+--------------------------------+-------------+---------------+
  36. 3 rows in set (0.003 sec)
  37. obclient [(none)]> exit
  38. Bye

3)创建OBProxy与OBServer的通信用户(proxyro):设置proxyro用户密码要与observer_sys_password值一致。

  1. ## 进入sys租户修改proxyro用户密码:
  2. [admin@OBSERVER02 ~]$ obclient -h10.0.0.12 -P2881 -uroot@sys -p'1qazxsw2' -c -A oceanbase
  3. Welcome to the OceanBase. Commands end with ; or \g.
  4. Your OceanBase connection id is 3221780363
  5. Server version: OceanBase_CE 4.2.1.2 (r102000042023120514-ccdde7d34de421336c5362483d64bf2b73348bd4) (Built Dec 5 2023 14:34:01)
  6. Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8. obclient [oceanbase]> show tenant;
  9. +---------------------+
  10. | Current_tenant_name |
  11. +---------------------+
  12. | sys |
  13. +---------------------+
  14. 1 row in set (0.003 sec)
  15. obclient [oceanbase]> select user,host,password from mysql.user;
  16. +---------+------+-------------------------------------------+
  17. | user | host | password |
  18. +---------+------+-------------------------------------------+
  19. | root | % | *79b36e3d5f430af5b15934d61d71c031b6502834 |
  20. | proxyro | % | |
  21. +---------+------+-------------------------------------------+
  22. 2 rows in set (0.009 sec)
  23. obclient [oceanbase]> grant select on oceanbase.* to proxyro identified by '1QAZXSW2';
  24. Query OK, 0 rows affected (0.097 sec)
  25. obclient [oceanbase]> grant usage on *.* to proxyro;
  26. Query OK, 0 rows affected (0.095 sec)
  27. obclient [oceanbase]> select user,host,password from mysql.user;
  28. +---------+------+-------------------------------------------+
  29. | user | host | password |
  30. +---------+------+-------------------------------------------+
  31. | root | % | *79b36e3d5f430af5b15934d61d71c031b6502834 |
  32. | proxyro | % | *64ac39155222d296839dc451f38bba28b5a33a12 |
  33. +---------+------+-------------------------------------------+
  34. 2 rows in set (0.000 sec)
  35. obclient [oceanbase]> show full processlist;
  36. +------------+---------+--------+-----------------+-----------+---------+------+--------+-----------------------+-----------+------+----------------------+
  37. | Id | User | Tenant | Host | db | Command | Time | State | Info | Ip | Port | Proxy_sessid |
  38. +------------+---------+--------+-----------------+-----------+---------+------+--------+-----------------------+-----------+------+----------------------+
  39. | 3221780363 | root | sys | 10.0.0.12:43370 | oceanbase | Query | 0 | ACTIVE | show full processlist | 10.0.0.12 | 2881 | NULL |
  40. | 3221687230 | proxyro | sys | 10.0.0.12:57964 | oceanbase | Sleep | 1 | SLEEP | NULL | 10.0.0.11 | 2881 | 12398691262201528324 |
  41. | 3221661587 | proxyro | sys | 10.0.0.12:47908 | oceanbase | Sleep | 1463 | SLEEP | NULL | 10.0.0.11 | 2881 | 12398691262201528323 |
  42. +------------+---------+--------+-----------------+-----------+---------+------+--------+-----------------------+-----------+------+----------------------+
  43. 3 rows in set (0.011 sec)
  44. obclient [oceanbase]> quit
  45. Bye

4)连接2883端口登录数据库:

  1. [admin@OBSERVER02 ~]$ obclient -h10.0.0.12 -P2883 -uroot@sys#myobc -p'1qazxsw2' -Doceanbase -c -A
  2. Welcome to the OceanBase. Commands end with ; or \g.
  3. Your OceanBase connection id is 10
  4. Server version: OceanBase_CE 4.2.1.2 (r102000042023120514-ccdde7d34de421336c5362483d64bf2b73348bd4) (Built Dec 5 2023 14:34:01)
  5. Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  7. obclient [oceanbase]> select svr_ip,svr_port,zone,inner_port,with_rootserver,status,stop_time,start_service_time,last_offline_time from __all_server;
  8. +-----------+----------+-------+------------+-----------------+--------+-----------+--------------------+-------------------+
  9. | svr_ip | svr_port | zone | inner_port | with_rootserver | status | stop_time | start_service_time | last_offline_time |
  10. +-----------+----------+-------+------------+-----------------+--------+-----------+--------------------+-------------------+
  11. | 10.0.0.11 | 2882 | zone1 | 2881 | 1 | ACTIVE | 0 | 1704536095795754 | 0 |
  12. | 10.0.0.12 | 2882 | zone2 | 2881 | 0 | ACTIVE | 0 | 1704536100355839 | 0 |
  13. | 10.0.0.13 | 2882 | zone3 | 2881 | 0 | ACTIVE | 0 | 1704536096955836 | 0 |
  14. +-----------+----------+-------+------------+-----------------+--------+-----------+--------------------+-------------------+
  15. 3 rows in set (0.004 sec)
  16. obclient [oceanbase]> quit
  17. Bye

 大功告成!!

5)启停数据库集群脚本:

  1. [admin@OBSERVER02 bin]$ cat OBService
  2. #!/bin/bash
  3. OPTMODE="${1:-status}"
  4. OBCLU_NAME=myobc
  5. OB_HOME=/home/admin/oceanbase
  6. ODP_HOME=/home/admin/obproxy
  7. ODP_PID=`ps -ef|grep -w $ODP_HOME|grep -v grep|awk '{print $2}'`
  8. LAB="\033[36m[$(date +%F_%T)]\033[0m"
  9. if [[ -n "$ODP_PID" ]];then RMD="obproxy服务已开启.";else RMD="obproxy服务已关闭.";fi
  10. if [[ "$OPTMODE" == "start" && -z "$ODP_PID" ]];then
  11. obd cluster start "$OBCLU_NAME"
  12. cd $ODP_HOME && $ODP_HOME/bin/obproxy
  13. LAB="[\033[1;32mOK\033[0m]";RMD="obproxy服务已开启."
  14. elif [[ "$OPTMODE" == "stop" && -n "$ODP_PID" ]];then
  15. obd cluster stop "$OBCLU_NAME"
  16. kill -9 "$ODP_PID"
  17. LAB="[\033[1;32mOK\033[0m]";RMD="obproxy服务已关闭."
  18. elif [[ "$OPTMODE" == "restart" ]];then
  19. obd cluster restart "$OBCLU_NAME"
  20. kill -9 "$ODP_PID"
  21. cd $ODP_HOME && $ODP_HOME/bin/obproxy
  22. LAB="[\033[1;32mOK\033[0m]";RMD="obproxy服务已重启."
  23. elif [[ "$OPTMODE" == "status" ]];then
  24. ps -ef|grep -w $ODP_HOME|grep -v grep
  25. ss -unlpt|grep -w 2883
  26. else
  27. LAB="[\033[1;31mERROR\033[0m]";RMD="参数选项有误,正确执行方法: $0 start/stop/restart/status."
  28. fi
  29. obd cluster list
  30. echo -e "${LAB}: ${RMD}"
  31. [admin@OBSERVER02 bin]$ chmod 775 OBService

一键启动OB集群及OBProxy:

一键关闭OB集群及OBProxy:

 4. ODC开发工具客户端连接

        ODC远程连接宿主机里docker的数据库,IP填写宿主机IP,端口填容器ob02与宿主机映射的2883端口既可以连接上OceanBase数据库,用图形化界面开心的玩耍了。

5. 报错处理 

5.1. 安装失败后卸载重装

        出现安装失败后,需要重新将环境回退到安装前,可参考以下做法:

  1. ## kill掉数据库进程:
  2. [admin@OBSERVER02 ~]$ pidof observer|xargs kill -9
  3. ## kill掉obproxy进程:
  4. [admin@OBSERVER02 ~]$ pidof observer|xargs kill -9
  5. ## 清空数据文件目录和日志文件目录:
  6. [admin@OBSERVER02 ~]$ rm -rf /home/admin/oceanbase /opt/data/* /opt/redolog/*
  7. ## 移除掉rpm包:
  8. [admin@OBSERVER02 ~]$ yum list installed|grep -iE 'oceanbase|obproxy'|awk '{print $1}'|xargs sudo yum remove -y
  9. ## obd重新安装部署集群:
  10. [admin@OBSERVER02 ~]$ obd cluster deploy myobc -c /opt/obinstall/myobc.yaml -f

5.2. 安装用户可使用线程数小于要求

1)现象:

2)排错过程:

  1. ## 先查看/etc/security/limits.conf配置:
  2. [admin@OBSERVER02 ~]$ tail -15 /etc/security/limits.conf
  3. #@student - maxlogins 4
  4. # End of file
  5. root soft nofile 655350
  6. root hard nofile 655350
  7. * soft nofile 655350
  8. * hard nofile 655350
  9. * soft nproc 655360
  10. * hard nproc 655360
  11. * soft stack unlimited
  12. * hard stack unlimited
  13. * soft core unlimited
  14. * hard core unlimited

发现在这个文件里是配置上了,但显然admin用户没有生效,检查admin用户的ulimit值:

  1. ## 查看admin用户ulimit值:
  2. [admin@OBSERVER02 ~]$ ulimit -u
  3. 4096
  4. ## 查看root用户ulimit值:
  5. [root@OBSERVER02 ~]# ulimit -u
  6. 655360

明显在root用户生效了,但admin用户没有生效;

3)解决办法:修改/etc/security/limits.d/20-nproc.conf文件,nproc.conf文件随OS发行版的不同命名会略有区别;

  1. ## 将普通用户soft nproc值改成655360;
  2. [root@OBSERVER02 ~]$ ll /etc/security/limits.d/*-nproc.conf
  3. -rw-r--r-- 1 root root 193 Jan 20 12:49 /etc/security/limits.d/20-nproc.conf
  4. [admin@OBSERVER02 ~]$ cat /etc/security/limits.d/20-nproc.conf
  5. # Default limit for number of user's processes to prevent
  6. # accidental fork bombs.
  7. # See rhbz #432903 for reasoning.
  8. * soft nproc 655360
  9. root soft nproc unlimited
  10. [root@OBSERVER02 ~]$
  11. [root@OBSERVER02 ~]# su - admin
  12. Last login: Sat Jan 20 12:33:47 CST 2024 on pts/0
  13. [admin@OBSERVER02 ~]$ ulimit -a
  14. core file size (blocks, -c) unlimited
  15. data seg size (kbytes, -d) unlimited
  16. scheduling priority (-e) 0
  17. file size (blocks, -f) unlimited
  18. pending signals (-i) 256628
  19. max locked memory (kbytes, -l) 64
  20. max memory size (kbytes, -m) unlimited
  21. open files (-n) 655350
  22. pipe size (512 bytes, -p) 8
  23. POSIX message queues (bytes, -q) 819200
  24. real-time priority (-r) 0
  25. stack size (kbytes, -s) unlimited
  26. cpu time (seconds, -t) unlimited
  27. max user processes (-u) 655360
  28. virtual memory (kbytes, -v) unlimited
  29. file locks (-x) unlimited

重新登录admin用户执行ulimit -a看到max user processes值变成655360了,同样的,在其他节点修改,后再重新执行启动集群的操作。

5.3. 空间资源不足产生的报错

1)现象:

 2)日志定位报错:

查看OBD跟踪日志:发现 数据库进程先是被OBD拉起来过,后面不知道啥原因数据库进程自动kill掉,导致OBD跟踪日志显示Failed to connect to oceanbase-ce;

挑其中一个数据库节点查看数据库服务日志,检索所有关键字error,发现报剩余的磁盘空间大小全给了日志空间占用,导致observer无空间可用,数据库服务自动退出;

3)解决办法:

        对日志使用空间上限进行限制,在OBD安装配置文件myobc.yaml里添加全局参数:log_disk_size: 5G,大小自定义,重新执行安装即可。

5.4. OBD拉起OBProxy服务失败

1)现象:

2)日志排错:

        查看OBD跟踪日志,也是未发现有效报错的信息,查看OBProxy日志,也未能找到有效的信息,后面是在OceanBase官网搜有关的帖子,发现这个问题与帖子里的几乎一样,给的解释是OBD存在BUG,在资源给得不是很大的情况下,OBD拉起OBProxy是会报错的,至于Why,我也不知道了;

OBD部署obproxy集群失败 - #14,来自 妙妙 - OceanBase - 社区问答- OceanBase社区-分布式数据库【 使用环境 】测试环境 【 OB or 其他组件 】OBD 2.0.1 【 使用版本 】 【问题描述】OBD集群部署异常: 期望按照此架构进行部署 测试机器*3:CPU 8core+ Memory 16GB + Disk …icon-default.png?t=N7T8https://ask.oceanbase.com/t/topic/35603305/143)解决办法:

        既然OBD方式没法拉起OBProxy,那就改手动启停服务,将原来myobc.yaml文件里有关obroxy-ce下的参数项全去掉,只留oceanbase-ce的参数再次使用OBD安装,安装OK后,手动拉起OBProxy服务即可,启停可自写脚本一键执行。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/168065?site
推荐阅读
相关标签
  

闽ICP备14008679号