diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..ee5839968a2bf86c93283efc09d40fd050b7cfa2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,127 @@ + 木兰宽松许可证, 第2版 + + 木兰宽松许可证, 第2版 + 2020年1月 http://license.coscl.org.cn/MulanPSL2 + + + 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: + + 0. 定义 + + “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 + + “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 + + “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 + + “法人实体”是指提交贡献的机构及其“关联实体”。 + + “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 + + 1. 授予版权许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 + + 2. 授予专利许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 + + 3. 无商标许可 + + “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 + + 4. 分发限制 + + 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 + + 5. 免责声明与责任限制 + + “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 + + 6. 语言 + “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 + + 条款结束 + + 如何将木兰宽松许可证,第2版,应用到您的软件 + + 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: + + 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; + + 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; + + 3, 请将如下声明文本放入每个源文件的头部注释中。 + + Copyright (c) [Year] [name of copyright holder] + [Software Name] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. + + + Mulan Permissive Software License,Version 2 + + Mulan Permissive Software License,Version 2 (Mulan PSL v2) + January 2020 http://license.coscl.org.cn/MulanPSL2 + + Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: + + 0. Definition + + Software means the program and related documents which are licensed under this License and comprise all Contribution(s). + + Contribution means the copyrightable work licensed by a particular Contributor under this License. + + Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. + + Legal Entity means the entity making a Contribution and all its Affiliates. + + Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. + + 1. Grant of Copyright License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. + + 2. Grant of Patent License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. + + 3. No Trademark License + + No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4. + + 4. Distribution Restriction + + You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. + + 5. Disclaimer of Warranty and Limitation of Liability + + THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + 6. Language + + THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. + + END OF THE TERMS AND CONDITIONS + + How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software + + To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: + + i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; + + ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; + + iii Attach the statement to the appropriate annotated syntax at the beginning of each source file. + + + Copyright (c) [Year] [name of copyright holder] + [Software Name] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. diff --git "a/\346\267\261\345\205\245" "b/\346\267\261\345\205\245" new file mode 100644 index 0000000000000000000000000000000000000000..d89a8b9522aa5ef05268109915f908d6298ec323 --- /dev/null +++ "b/\346\267\261\345\205\245" @@ -0,0 +1,1154 @@ +# 深入 OceanBase 社区版体验 CentOS7 使用 OBD 自动部暑三节点集群 + +上一篇测试文章介绍如何用docker部署OceanBase社区版,本次测试:使用OBD自动部署一个三副本集群,包括OBproxy,创建业务租户、业务数据库、测试表 + + + +> **作者:马顺华** + +> 从事运维管理工作多年,目前就职于某科技有限公司,熟悉运维自动化、OceanBase部署运维、MySQL 运维以及各种云平台技术和产品。并已获得OceanBase认证OBCA、OBCP证书。 + + + +### **前言** + +OceanBase 是一个分布式集群产品,在生产环境至少是三台机器。学习环境可以部署单机版本。OceanBase 的部署跟传统数据库的部署有很多共同的地方,对操作系统硬件、软件设置、文件系统等会有一些最佳实践建议。那些是 OceanBase 发挥高性能稳定运行的基础。社区版也提供了工具能实现一定程度的自动化。OceanBase部署的方法比传统数据库简单许多,新手觉得难的主要原因在于还不太了解OB的步骤原理。当机器资源和环境都初始化正确后,大概5分钟左右即可重新部署一个OceanBase集群。很多人喜欢自动化脚本部署,觉得省事。但弊端也很明显。如果部署成功了,不知道为什么成功;部署报错了,也不知道为什么报错。除非你研究自动化部署脚本的程序 。所以在测试完ODB自动部署OceanBase集群后,可以再测试一下手动部署OceanBase集群。 + +![image-20220611142406567](../AppData/Roaming/Typora/typora-user-images/image-20220611142406567.png) + +## 部署准备 + +**OceanBase**是一个集群数据库,生产环境最小规模是 3 台服务器(节点)至少要三个节点。通常三个节点是要在三台机器上,整个集群里,业务数据会有三份,所以也叫三副本。学习测试的时候,可以部署 单副本单节点 OceanBase 集群。本文介绍使用 OBD 自动化部署 OceanBase 集群的方法,OBDeploy 简称 OBD 是 OceanBase 集群部署的工具,当机器资源和环境都初始化正确后,通过一些简单的命令就能非常快速的完成 OceanBase 部署。使用该方法需要通过中控机直接远程登录到 OceanBase 节点上部署启动 OBServer 进程,并在中控机上部署 OBProxy 进程。`obproxy` 进程部署位置没有要求。可以部署在应用服务器上,也可以部署在独立的机器上,或者部署在 OceanBase 机器上。`obproxy` 可以部署多个,生产环境建议至少部署两个。 + +OceanBase机器里关键资源是内存。就目前而言,OS剩余可用空间大于4C10G的环境将OB跑起来是没问题的。如果条件允许,尽可能用更大资源的机器。 + +**部署资源要求** + +OceanBase 数据库运行的时候会对主机资源有一些要求,主要是 CPU、内存和磁盘空间。安装 OceanBase 的目的不一样,对资源的要求也不一样。 + +![image-20220611105412789](../AppData/Roaming/Typora/typora-user-images/image-20220611105412789.png) + +**注意:**上面性能测试环境和生产环境的资源要求是建议。在社区版后续版本,会进一步降低对内存的要求。 + +OceanBase 对操作系统也有一些要求,目前支持下面这些系统: + +- Redhat / CentOS 7.x/8.x +- SUSE / OpenSUSE 15.x +- Anlios 7.x/8.x +- Debian 9.x +- Ubuntu 20.x + +#### 测试环镜资源信息 + +| 机器类型 | 主机配置 | 备注 | +| ------------------ | ------------ | ----------------------- | +| OS | Centos 7.4 | | +| 中控机 /OBD | CPU:8C | 内存:16G | +| 目标机器 /OBserver | CPU:8C | 内存:32G | +| 系统盘 / | dev/vda 100G | LVS分区、文件系统:EXT4 | +| 数据盘 /data | dev/vdb 200G | GPT分区、文件系统:xfs | +| 事务日志盘 /redo | dev/vdc 100G | GPT分区、文件系统:xfs | + +![image-20211231154309608](../AppData/Roaming/Typora/typora-user-images/image-20211231154309608.png) + +#### 资源规划 + +| 角色 | 机器IP | 备注 | +| -------- | ------------- | -------------------------------- | +| OBD | 112.127.2.131 | 中控机 | +| OBserver | 112.127.2.120 | {2881,2882}, {3881,3882} zone1 | +| | 112.127.2.121 | {2881,2882}, {3881,3882} zone2 | +| | 112.127.2.122 | {2881,2882}, {3881,3882} zone3 | +| OBproxy | 112.127.2.120 | {2883,2884} 反向代理 | +| | 112.127.2.121 | {2883,2884} 反向代理 | +| | 112.127.2.122 | {2883,2884} 反向代理 | +| OBAgent | 112.127.2.120 | 监控采集框架 默认端口 8088、8089 | +| | 112.127.2.121 | 监控采集框架 默认端口 8088、8089 | +| | 112.127.2.122 | 监控采集框架 默认端口 8088、8089 | +| OBclient | 112.127.2.131 | OB命令行客户端 | + +#### 目录规划: + +如果是安装 OceanBase 的 RPM 包,则需要提前创建好用户 `admin` ,软件包默认安装目录是 : `/home/admin/oceanbase` + +目录结构如下: + +| 目录路径(相对于工作目录) | 备注 | +| -------------------------- | ------------------------------ | +| etc、etc2、etc3 | 配置文件所在目录。 | +| log | 运行日志目录。 | +| run | 运行输出目录,输出 pid 文件。 | +| store | 数据(包括日志)所在总目录。 | +| store/clog | commit log 所在目录。 | +| store/ilog | ilog 所在目录。 | +| store/slog | slog 所在目录。 | +| store/sstable | 数据文件 block file 所在目录。 | + +自动化部署过程简单来说分为几步: + +- 初始化 OceanBase 各个节点环境。包括参数配置、文件系统目录设置等。 +- (可选)初始化中控机到OceanBase 各个节点的 SSH 免密登录。 +- 准备 OBD 自动化部署配置文件。 +- 使用 OBD 部署集群节点目录。 +- 使用 OBD 启动并初始化集群。 + +### 一、学习如何使用 OBD 自动化部署多节点集群 + +#### 1、OceanBase 社区版教程入门指引 + +链接:https://open.oceanbase.com/blog/10900159?currentPage=undefined + +![image-20220611141346053](../AppData/Roaming/Typora/typora-user-images/image-20220611141346053.png) + +#### 2、官方文档学习 + +链接:https://open.oceanbase.com/docs/tutorials-cn/V1.0.0/10000000000012299 + +![image-20220607152320870](../AppData/Roaming/Typora/typora-user-images/image-20220607152320870.png) + +#### 3、官方视频学习 + +为您介绍使用 OBD 自动部署 OceanBase 三副本集群。 + +链接: https://open.oceanbase.com/docs/videoCenter/4700025 + +![image-20220611104602095](../AppData/Roaming/Typora/typora-user-images/image-20220611104602095.png) + +#### 4、官方书籍学习 + +数据库博大精深,需要**系统学习**数据库**理论**知识,如果你想**从零开始学习数据库**,**不用先学习Mysql和Oracle**,这本书直接带你**从零开始学习数据库**,你会发现再学习Mysql和Oracle等数据库时,已经**自通Mysql和Oracle数据库**啦。 + +推荐学习 OceanBase 开源社区的《**OceanBase原生分布式数据库实战教程**》**实体书**,**OceanBase原生分布式数据库实战教程\****电子书**在 OceanBase** 社区版博客**和**阿里云**都有发布。这本与开源社区用户共创的书籍共八章,从 OceanBase 数据库概述开始,到安装部署,到使用,到迁移、再到运维、测试、性能诊断,最后是 OceanBase 生态工具的使用,可以带你全面掌握 OceanBase 实战使用技能! + +电子文档 + +链接: https://open.oceanbase.com/docs/tutorials-cn/V1.0.0/10000000000012249 + +![img](https://oss-emcsprod-public.modb.pro/image/editor/20220609-ebaf61cc-605f-4637-828f-c81dc6f6891f.png) + +##### 1)电子书 + +链接:https://developer.aliyun.com/ebook/7541 + +![img](https://oss-emcsprod-public.modb.pro/image/editor/20220611-198a7ca1-1121-443c-98ef-27c5aaf27505.png) + +##### 2)实体书 + +![img](https://oss-emcsprod-public.modb.pro/image/editor/20220609-59646fd5-7d02-45ae-b1b8-cb1a67d03d2a.png) + +### 二、**磁盘文件系统划分** + +(所有目标节点都要设置) + +#### 1、查看原磁盘df -Th + +![image-20220213152223376](../AppData/Roaming/Typora/typora-user-images/image-20220213152223376.png) + +#### 2、查看待增加磁盘fdisk-l + +![image-20220213152303408](../AppData/Roaming/Typora/typora-user-images/image-20220213152303408.png) + +#### 3、磁盘划分(GPT)分区 + +使用 parted 技术对 `/dev/vdb` 进行划分。GPT分区大小请根据实际磁盘大小调整参数。需要登录到每个节点上手动初始化。 + +yum -y install gdisk cloud-utils-growpart parted e2fsprogs + +![image-20220213152629075](../AppData/Roaming/Typora/typora-user-images/image-20220213152629075.png) + +~~~ +[root@CAIP120 ~]# parted /dev/sdb +# 将设备转换成GPT分区格式。 +(parted) mklabel gpt +#划分一个主分区,并设置分区的开始位置和结束位置 +#使用全部空间创建一个主分区(请根据实际创建)。通常于前面留出1M的空余空间。 +(parted) mkpart primary 1 100% +# 检查分区是否对齐(如有多个分区,均需检查),此处显示“1 aligned”表示已对齐。 +(parted) align-check optimal 1 +#查看分区表 +(parted) print +#退出 +(parted) quit +~~~ + +![image-20220213152551680](../AppData/Roaming/Typora/typora-user-images/image-20220213152551680.png) + +#### 4、查看到分区 + +此时使用`fdisk -l`应能查看到分区/dev/sdb1(根据实际显示分区名)。 + +![image-20220213152712367](../AppData/Roaming/Typora/typora-user-images/image-20220213152712367.png) + +~~~ +[root@CAIP120 ~]# fdisk -l +#格式化文件系统(请使用实际的分区名和文件系统类型) +mkfs.xfs /dev/sdb1 --xfs分区格式化 +mkfs.ext4 /dev/sdb1 --ext4分区格式化 +#创建挂载点目录 +[root@CAIP120 /]# mkdir data +#使用blkid查看UUID +[root@CAIP120 ~]# blkid +#备份/etc/fstab,并新增加UUID +vim /etc/fstab +#使用`mount -a`验证fstab配置是否正确。 +[root@CAIP120 ~]# mount -a +~~~ + +![image-20220213153101198](../AppData/Roaming/Typora/typora-user-images/image-20220213153101198.png) + +![image-20220213153325133](../AppData/Roaming/Typora/typora-user-images/image-20220213153325133.png) + +#### 5、挂载磁盘 + +重复上面操作、同上、依次挂载好对应磁盘和目录 + +~~~ +(/data、/redo、) + +mkdir -p /data (/dev/sdb) + +mkdir -p /redo (/dev/sdc) +~~~ + +![image-20220213154413084](../AppData/Roaming/Typora/typora-user-images/image-20220213154413084.png) + +#### 6、检查磁盘 + +检查划分好的磁盘df -h #检查 + +![image-20211231153558521](../AppData/Roaming/Typora/typora-user-images/image-20211231153558521.png) + +### 三、配置安装用户 + +OceanBase 本质上是一个软件,可以运行在任意用户下。OceanBase 软件包默认解压目录是在 `/home/admin/` 下,生产环境默认也是安装在用户 `admin` 下。社区版的软件 RPM 包也是这个特点,支持部署在任意用户的任意目录下。 + +根据官方介绍,不建议在 `root` 用户下直接部署。建议安装部署在普通用户下,此次测试均以用户 `admin` 为例。 + +**注意** 为 `admin` 用户赋与 `sudo` 权限不是必须的,只是为了某些时候方便操作。您可以结合企业安全规范决定是否执行。 + +#### 1、创建admin用户并设置密码: + +(所有节点都要设置) + +``` +[root@CAIP120 /]# useradd -U admin -d /home/admin -s /bin/bash && echo "Sixlens2881" |passwd --stdin admin +``` + +![image-20220213154453771](../AppData/Roaming/Typora/typora-user-images/image-20220213154453771.png) + +#### 2、更改目录**属主属组**权限: + +(所有节点都要设置) + +``` +[root@CAIP120 /]# chown -R admin.admin /data && chown -R admin.admin /redo && chown -R admin.admin /home/admin +``` + +![image-20220213154543228](../AppData/Roaming/Typora/typora-user-images/image-20220213154543228.png) + +**注意**:先创建admin用户,后mount挂载/home/admin/ocaeabase 否则创建用户提示家目录存在 + +#### 3、用户 `admin` 授予 `sudo` 权限配置: + +(所有节点都要设置) + +``` +[root@CAIP120 /]# vim /etc/sudoers +## Allow root to run any commands anywhere +admin ALL=(ALL) ALL +``` + +![image-20220213154720447](../AppData/Roaming/Typora/typora-user-images/image-20220213154720447.png) + +**注意**: sudoers拒绝所有用户读写,root用户也无权限,需增加权限后更改 #chmod u+w /etc/sudoers + +### 四、初始化服务器环境 + +OceanBase 数据库是单进程软件,需要访问网络,需要打开多个文件以及开启很多 TCP 连接,所以需要修改内核参数和用户会话设置。 + +**注意** 您如果在独立服务器上部署 OBProxy,也需按本文要求初始化服务器环境。 + +#### 1、配置 SSH 免密登录 + +手动部署 OceanBase 集群,相应节点上安装软件包,并启动 `observer` 或 `obproxy` 进程,不需要配置 SSH 免密登录。如果您是使用自动化技术部署 OceanBase 集群,则需要一台中控机,中控机的用户 `admin` 到 OBSERVER 节点的用户 `admin` 的免密登录: + +此次测试为 OBD 自动部署 OceanBase 集群,需要配置 SSH 免密登录 + +- 在中控机生成 RSA 或 DSA 公钥和私钥 + +``` +[admin@CAIP131 ~]$ ssh-keygen -t rsa #在中控机执行 +[admin@CAIP131 ~]$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys +[admin@CAIP131 ~]$ mkdir ~/.ssh #在Observer3个节点建立隐藏ssh目录 +[admin@CAIP131 ~]$ scp ~/.ssh/authorized_keys admin@112.127.2.120-122:~/.ssh/authorized_keys #中控机复制到目标机器 +``` + +![image-20211231165737696](../AppData/Roaming/Typora/typora-user-images/image-20211231165737696.png) + +![image-20220613100455199](../AppData/Roaming/Typora/typora-user-images/image-20220613100455199.png) + +目标机器授权(所有目标节点) + +~~~ +[admin@CAIP120 ~]$ chmod 700 .ssh --目标机器执行 +[admin@CAIP120 ~]$ chmod 600 .ssh/authorized_keys --目标机器执行 +~~~ + +![image-20220213161916554](../AppData/Roaming/Typora/typora-user-images/image-20220213161916554.png) + +Note:root用户配置免密可直接登录,普通用户需更改目录和文件权限,否则无法登陆 + +``` +[admin@CAIP131 ~]$ for i in 120 121 122;do ssh 172.20.2.$i date;done --中控机执行免密连接测试 +``` + +![image-20220213162041256](../AppData/Roaming/Typora/typora-user-images/image-20220213162041256.png) + +#### 2、配置时间同步服务 + +OceanBase 数据库是分布式数据库产品,是一个集群软件,对各个节点之间的时间同步性有要求。技术上要求所有节点之间的时间误差需控制在 50ms 以内。实际生产环境中为了稳定性和性能考虑,建议时间误差控制在 10ms 以内。 + +(中控节点作为时间服务器,以root身份配置): + +##### 1)判断是否使用 `ntpd`同步时间 + +~~~ +[root@CAIP131 ~]# systemctl status ntpd +Unit ntpd.service could not be found. #未安装 +~~~ + +![image-20220213184441861](../AppData/Roaming/Typora/typora-user-images/image-20220213184441861.png) + +出现上述提示,表示没有使用 `ntpd`,需要安装 chrony 服务 + +##### 2)安装 `chrony`配置时间同步服务 + +CentOS 或 RedHat 7.x 版本推荐使用 `chrony` 服务做时间源 + +``` +# yum remove ntp -y +# yum -y install chrony +# vim /etc/chrony.conf +server ntp1.aliyun.com iburst +driftfile /var/lib/chrony/drift +makestep 1.0 3 +rtcsync +logdir /var/log/chrony +allow all +stratumweight 0 +local stratum 10 +``` + +![image-20220213184547823](../AppData/Roaming/Typora/typora-user-images/image-20220213184547823.png) + +##### 3)配置时间同步服务器 + +`chrony` 服务守护进程名为 `chronyd`,`chronyc` 是用来监控 `chronyd` 性能和配置参数的命令行工具。`chrony` 的主配置文件为 `/etc/chrony.conf`。配置方法如下: + +~~~ +[root@CAIP131 ~]# vim /etc/chrony.conf +~~~ + +![image-20220213184705084](../AppData/Roaming/Typora/typora-user-images/image-20220213184705084.png) + +##### 4)配置时间同步服务器开机自启 + +~~~ +[root@CAIP131 ~]# systemctl start chronyd && systemctl enable chronyd && systemctl status chronyd #设置开机自启 +~~~ + +![image-20220213184810901](../AppData/Roaming/Typora/typora-user-images/image-20220213184810901.png) + +##### 5)客户端配置(所有目标节点): + +``` +[root@CAIP120 /]# echo "* * * * * /sbin/ntpdate -u 112.127.2.131 2>&1 1>>/tmp/ntpdate.log" >> /var/spool/cron/root + +[root@CAIP121 /]# echo "* * * * * /sbin/ntpdate -u 112.127.2.131 2>&1 1>>/tmp/ntpdate.log" >> /var/spool/cron/root + +[root@CAIP122 /]# echo "* * * * * /sbin/ntpdate -u 112.127.2.131 2>&1 1>>/tmp/ntpdate.log" >> /var/spool/cron/root +``` + +##### 6)中控机检查时间同步(中控机执行) + +~~~ +# for i in 120 121 122 ;do clockdiff 172.20.2.$i;done +检查和目标节点时间误差常用命令是: clockdiff +~~~ + +![image-20220613102744780](../AppData/Roaming/Typora/typora-user-images/image-20220613102744780.png) + +##### 7)客户端检查时间同步 + +(所有目标节点)目标机到中控机之间时间同步检查 + +~~~ +[root@CAIP120 /]# clockdiff 112.127.2.131 +~~~ + +如果有机子clockdiff报错,使用tsandaddr + +``` +[admin@CAIP120 oceanbase]$ ping -T tsandaddr 112.127.2.131 -c 2 +``` + +![image-20220613100345449](../AppData/Roaming/Typora/typora-user-images/image-20220613100345449.png) + +#### 3、修改会话变量设置 + +(所有目标节点) + +您可以通过配置 `limits.conf` 修改会话限制。OceanBase 数据库的进程涉及的限制包括:线程最大栈空间大小(Stack)、最大文件句柄数(Open Files)和 core 文件大小(Core File Size)。 + +您可以使用以下两种方法修改资源限制: + +- 通过启动时在会话级别修改。如:`ulimit -c unlimited`,通过此方法修改只影响当前会话。如果会话断开之后重连,则又会是默认配置。 + +- 通过配置文件 `/etc/security/limits.conf` 在全局级别修改。 + + > **注意** 修改后,已经登录的会话需要退出后重新登录才生效。 + +全局修改配置limits.conf(所有目标节点)最大文件句柄数设置为 655350,Core 文件大小设置为 `unlimited` 。 + +``` +[root@CAIP120 /]# vim /etc/security/limits.conf +root soft nofile 655350 +root hard nofile 655350 +* soft nofile 655350 +* hard nofile 655350 +* soft stack 20480 +* hard stack 20480 +* soft nproc 655360 +* hard nproc 655360 +* soft core unlimited +* hard core unlimited +``` + +![image-20220612174624189](../AppData/Roaming/Typora/typora-user-images/image-20220612174624189.png) + +出当前会话,重新登录。执行 # ulimit -a,查看配置是否生效: + +```text +[root@CAIP120 /]# ulimit -a +``` + +![image-20220612174750661](../AppData/Roaming/Typora/typora-user-images/image-20220612174750661.png) + +#### 4、内核参数修改 + +修改(所有目标节点)配置文件 /etc/sysctl.conf + +``` +[root@CAIP120 /]# vim /etc/sysctl.conf + +fs.aio-max-nr=1048576 +net.core.somaxconn = 2048 +net.core.netdev_max_backlog = 10000 +net.core.rmem_default = 16777216 +net.core.wmem_default = 16777216 +net.core.rmem_max = 16777216 +net.core.wmem_max = 16777216 +net.ipv4.ip_local_port_range = 3500 65535 +net.ipv4.ip_forward = 0 +net.ipv4.conf.default.rp_filter = 1 +net.ipv4.conf.default.accept_source_route = 0 +net.ipv4.tcp_syncookies = 0 +net.ipv4.tcp_rmem = 4096 87380 16777216 +net.ipv4.tcp_wmem = 4096 65536 16777216 +net.ipv4.tcp_max_syn_backlog = 16384 +net.ipv4.tcp_fin_timeout = 15 +net.ipv4.tcp_max_syn_backlog = 16384 +net.ipv4.tcp_tw_reuse = 1 +net.ipv4.tcp_tw_recycle = 1 +net.ipv4.tcp_slow_start_after_idle=0 +vm.swappiness = 0 +vm.min_free_kbytes = 2097152 +``` + +![image-20220612175050656](../AppData/Roaming/Typora/typora-user-images/image-20220612175050656.png) + +加载配置,使配置生效 + +~~~~ +[root@CAIP120 /]# sysctl -p +~~~~ + +![image-20220612174924118](../AppData/Roaming/Typora/typora-user-images/image-20220612174924118.png) + +#### 5、关闭防火墙和 SELinux + +(所有目标节点) + +不同操作系统的防火墙设置可能会有不同,本次是以 CentOS 7 系统为例进行测试。 + +查看防火墙状态 + +~~~ +[root@CAIP120 /]# systemctl status firewalld +~~~ + +![image-20220213191029699](../AppData/Roaming/Typora/typora-user-images/image-20220213191029699.png) + +如果是 `inactive` 那就不用管。如果是 `active`,那就永久关闭 + +~~~ +[root@CAIP120 /]# systemctl stop firewalld +[root@CAIP120 /]# systemctl disable firewalld +[root@CAIP120 /]# systemctl status firewalld +~~~ + +关闭 SELinux + +修改 SELinux 配置文件中的 `SELINUX` 选项。 + +~~~ +[root@CAIP120 /]# vim /etc/selinux/config + +# This file controls the state of SELinux on the system. +# SELINUX= can take one of these three values: +# enforcing - SELinux security policy is enforced. +# permissive - SELinux prints warnings instead of enforcing. +# disabled - No SELinux policy is loaded. +SELINUX=disabled +~~~ + +![image-20220213191059206](../AppData/Roaming/Typora/typora-user-images/image-20220213191059206.png) + +配置文件修改后只会重启主机后生效,还需要使用下面命令立即生效。 + +~~~ +[root@CAIP120 /]# setenforce 0 +~~~ + +#### 6、安装相关依赖工具软件 + +(所有目标节点) + +未安装工具后面相关命令无法执行 + +~~~ +[root@CAIP120 /]# yum install epel-release -y +[root@CAIP120 /]# yum install -y net-tools lrzsz tree htop dstat sysvinit-tools + +查看 OBSERVER 进程特点 +[root@CAIP120 /]# yum -y install sysvinit-tools +[root@CAIP120 /]# ps -ef|grep observer + +查看进程监听端口 +[root@CAIP120 /]# yum install -y net-tools +[root@CAIP120 /]# netstat -ntlp + +查看 OceanBase 工作目录结构 +[root@CAIP120 /]# yum -y install tree +[root@CAIP120 /]# tree /root/ob +[root@CAIP120 /]# tree /root/obce/ +~~~ + +![image-20220213191924818](../AppData/Roaming/Typora/typora-user-images/image-20220213191924818.png) + +### 五、安装部署OBD + +OceanBase 本质上是一个单进程的软件,可执行文件名叫 `observer` 。可以通过 RPM 包安装,也可以通过源码直接编译安装。本次测试都是通过OBD自动安装。切换到 `admin` 用户下,执行 + +#### 1、在线安装依赖软件 + +(中控节点) + +~~~ +[admin@CAIP131 ~]$ sudo yum install -y yum-utils +~~~ + +![image-20220213200849774](../AppData/Roaming/Typora/typora-user-images/image-20220213200849774.png) + +#### 2、在线安装ob-deploy + +~~~ +[admin@CAIP131 ~]$ sudo yum install -y ob-deploy +~~~ + +![image-20220213201637563](../AppData/Roaming/Typora/typora-user-images/image-20220213201637563.png) + +~~~ +[admin@CAIP131 ~]$ sudo yum install -y libobclient +~~~ + +![image-20220213201847161](../AppData/Roaming/Typora/typora-user-images/image-20220213201847161.png) + +#### 3、在线安装obclient客户端工具 + +~~~ +[admin@CAIP131 ~]$ sudo yum install -y obclient +~~~ + +![image-20220213202036729](../AppData/Roaming/Typora/typora-user-images/image-20220213202036729.png) + +### 六、使用 OBD 自动化部署三节点集群 + +本次测试介绍 OceanBase 集群三节点部署方法,需要通过中控机直接远程登录到 OceanBase 节点上部署启动 `observer` 和 `obproxy` 进程。 + +#### 1、编辑 OBD yaml配置文件 + +OBD 针对不同的部署场景提供不同的配置文件。这些配置文件示例均放在 OceanBase 开源项目地址中,您可访问链接查看:https://github.com/oceanbase/obdeploy/tree/master/example 。 + +如果您是部署单节点版本,只需下载其中两个配置文件: + +- 部署三节点 `observer` 进程: + + https://github.com/oceanbase/obdeploy/blob/master/example/mini-distributed-example.yaml + +- 部署三节点 `observer` 和 `obproxy` 进程: + + https://github.com/oceanbase/obdeploy/blob/master/example/mini-distributed-with-obproxy-example.yaml + + 这里是部署三节点 `observer` 进程,所以下载第二个配置文件。 + **注意:**后续版本的配置文件格式可能会有些变化,请参考 OBD 工具具体使用说明。用户信息已脱敏。 + +~~~ +oceanbase-ce: + servers: + - name: z1 + ip: 112.127.2.120 + - name: z2 + ip: 172.20.2.121 + - name: z3 + ip: 172.20.2.122 + global: + devname: ens192 + cluster_id: 1 + memory_limit: 24G + system_memory: 4G + stack_size: 512K + cpu_count: 16 + cache_wash_threshold: 1G + __min_full_resource_pool_memory: 268435456 + workers_per_cpu_quota: 10 + schema_history_expire_time: 1d + net_thread_count: 4 + major_freeze_duty_time: Disable + minor_freeze_times: 10 + enable_separate_sys_clog: 0 + enable_merge_by_turn: FALSE + datafile_disk_percentage: 90 + #datafile_size: 50G + syslog_level: WARN + enable_syslog_wf: false + enable_syslog_recycle: true + max_syslog_file_count: 10 + appname: obce-demo + root_password: Pwd2012# + z1: + mysql_port: 2881 + rpc_port: 2882 + home_path: /home/admin/oceanbase/ob + data_dir: /data/ob + clog_dir: /redo/clog + ilog_dir: /redo/ilog + slog_dir: /redo/slog + zone: zone1 + enable_syslog_wf: true + cpu_count: 16 + z2: + mysql_port: 2881 + rpc_port: 2882 + home_path: /home/admin/oceanbase/ob + data_dir: /data/ob + clog_dir: /redo/clog + ilog_dir: /redo/ilog + slog_dir: /redo/slog + zone: zone2 + enable_syslog_wf: true + cpu_count: 16 + z3: + mysql_port: 2881 + rpc_port: 2882 + home_path: /home/admin/oceanbase/ob + data_dir: /data/ob + clog_dir: /redo/clog + ilog_dir: /redo/ilog + slog_dir: /redo/slog + zone: zone3 + enable_syslog_wf: true + cpu_count: 16 +obproxy: + servers: + - 112.127.2.120 + - 112.127.2.121 + - 112.127.2.122 + depends: + - oceanbase-ce + global: + listen_port: 2883 + prometheus_listen_port: 2884 + home_path: /home/admin/obproxy + rs_list: 112.127.2.120:2881;112.127.2.121:2881;112.127.2.122:2881 + enable_cluster_checkout: false + cluster_name: ob_cluster + enable_compression_protocol: false + automatic_match_work_thread: True + work_thread_num: 16 + net_accept_threads: 2 + proxy_mem_limited: 16G + obproxy_sys_password: Pwd123# +obagent: + servers: + - name: z1 + ip: 112.127.2.120 + - name: z2 + ip: 112.127.2.121 + - name: z3 + ip: 112.127.2.122 + depends: + - oceanbase-ce + global: + home_path: /home/admin/oceanbase/obagent + server_port: 8088 + pprof_port: 8089 + log_level: INFO + log_path: log/monagent.log + crypto_method: plain + log_size: 30 + log_expire_day: 7 + log_file_count: 10 + http_basic_auth_user: admin + http_basic_auth_password: root + pprof_basic_auth_user: admin + pprof_basic_auth_password: root + ob_monitor_status: active + host_monitor_status: active + disable_http_basic_auth: false + disable_pprof_basic_auth: false +~~~ + +![image-20220613103045369](../AppData/Roaming/Typora/typora-user-images/image-20220613103045369.png) + +当上面部署成功后,OBD 会把配置文件 `config.yaml` 复制到自己的工作目录里(`~/.obd/cluster/obce-3zones/config.yaml` ),后面如果想修改外面这个 `config.yaml` 文件,是不生效的。 + +#### 2、 部署 OceanBase 集群: + +配置文件准备好后,就可以在(中控机)部署这个配置文件对应的集群了,部署内容主要包含: + +- 复制软件到所有目标节点,并安装软件。 +- 在所有目标节点创建相关目录。 + +这个集群名只是这个配置文件在 OBD 里的唯一标识,可以跟配置文件中的集群名一样,也可以跟文件名一样,这个不强要求。 + +``` +[admin@CAIP131 ~]$ obd cluster deploy obce-3zones -c obce-3zones.yaml +``` + +![image-20220301101357694](C:\Users\dell\AppData\Roaming\Typora\typora-user-images\image-20220301101357694.png) + +**注意:** + +obd cluster autodeploy使用该命令可传入一个简易的配置文件,OBD 会根据目标机器资源自动生成最大规格的完整配置并部署启动集群。 + +obd cluster deploy使用该命令可以根据配置部署集群。 + +查看部署后的运行状态 + +~~~ +[admin@CAIP131 ~]$ obd cluster list ++----------------------------------------------------------------------+ +| Cluster List | ++-------------+--------------------------------------+-----------------+ +| Name | Configuration Path | Status (Cached) | ++-------------+--------------------------------------+-----------------+ +| obce-3zones | /home/admin/.obd/cluster/obce-3zones | deployed | ++-------------+--------------------------------------+-----------------+ +~~~ + +![image-20220612192633225](../AppData/Roaming/Typora/typora-user-images/image-20220612192633225.png) + +#### 3、OBD 启动和初始化集群 + +上面 `deploy` 操作只是安装了软件和准备初始化目录,您还需使用命令 `obd cluster start` 启动集群节点并初始化集群。 + +~~~ +[admin@CAIP131 ~]$ obd cluster start obce-3zones +~~~ + +![image-20220613103135816](../AppData/Roaming/Typora/typora-user-images/image-20220613103135816.png) + +配置有误,可以修改配置 + +~~~ +[admin@CAIP131 ~]$ obd cluster edit-config obce-3zones +Search param plugin and load ok +Search param plugin and load ok +Parameter check ok +Save deploy "obce-3zones" configuration +Use `obd cluster restart obce-3zones --wp` to make changes take effect. +~~~ + +![image-20220612201852746](../AppData/Roaming/Typora/typora-user-images/image-20220612201852746.png) + +参数 obce-3zones 为部署集群名,可以根据实际配置修改文件的别名。 + +修改完重启配置 + +~~~ +[admin@CAIP131 ~]$ obd cluster restart obce-3zones +Get local repositories and plugins ok +Load cluster param plugin ok +Open ssh connection ok +Cluster status check ok +Connect to observer ok +Server check ok +Observer rotation restart ok +Wait for observer init ok +~~~ + +![image-20220612201948996](../AppData/Roaming/Typora/typora-user-images/image-20220612201948996.png) + +#### 4、连接 OceanBase 集群: + +传统的 mysql 客户端可以连接 OceanBase 社区版,前提是 mysql 的版本是 5.5/5.6/5.7 。OceanBase 也提供自己的客户端工具 `obclient` 需要安装使用。 + +跟传统MySQL 不一样的地方是 OBSERVER 连接端口是 2881 , 连接用户名是 :`root@sys` ,密码是前面 OBD 配置文件里指定的。 + +~~~ +[admin@CAIP131 ~]$ obclient -h112.127.2.120 -uroot@sys#obce-3zones -p -P2883 -A -c oceanbase +~~~ + +![image-20220613103316196](../AppData/Roaming/Typora/typora-user-images/image-20220613103316196.png) + +使用sys系统租户查看所有节点是否正常: + +~~~ +MySQL [oceanbase]> select svr_ip,status,with_rootserver,usec_to_time(start_service_time),usec_to_time(stop_time) from __all_server; +~~~ + +![image-20220613103420293](../AppData/Roaming/Typora/typora-user-images/image-20220613103420293.png) + +1)、status 表示节点状态。inactive, 表示节点已经掉线或者进程退出了。节点掉线常见原因是节点时钟偏差过大、网络延时过大、clog空间盘满(use大于等于95%)。如果进程刚刚启动,则是进程在跟 rootserver 通信沟通。正常情况下启动几秒就能变 active,异常宕机后的再启动可能需要几十秒变 acitve,最长不超过2分钟。 + +2)、start_service_time 表示节点开始提供服务时间。如果是默认值 1970-1-1 ,则表示进程还在应用clog、刷新schema等。通常如果要应用的clog不多的时候,这个几秒钟就好了。如果是此前内存中大量数据还没有合并落盘就宕机了,这个恢复时间就长一些,可能会要十几分钟。 + +3)、stop_service_time 表示停止服务时间。如果是默认值 1970-1-1 ,表示没有停止服务。如果时间大于默认值(在当前时间附近),表示手动发起过 stop server 或 stop zone 命令。则需要手动发起 start server 或者 start zone 命令恢复服务。 + +4)、只有这三个列都正常了,节点才是正常的,集群才是正常的 + +#### 5、登录obproxy账户 + +OBProxy 作为 OceanBase 数据库专用的反向代理软件,其核心功能是路由,将客户端发起的数据访问请求转发到正确的 OBServer 上,并将 OBServer 的响应结果转发给客户端。 + +~~~ +[admin@CAIP131 ~]$ obclient -h112.127.2.120 -uroot@proxysys -P2883 -pPwd123# +~~~ + +![image-20220613103510278](../AppData/Roaming/Typora/typora-user-images/image-20220613103510278.png) + +~~~ +MySQL [(none)]> show processlist; ++------+----------+------+--------------------+------+-------------+-------------------+-------------------+-------+-------+ +| Id | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid | ++------+----------+------+--------------------+------+-------------+-------------------+-------------------+-------+-------+ +| 7 | proxysys | root | 112.127.2.131:59024 | NULL | 0 | 0 | MCS_ACTIVE_READER | 58963 | 58963 | ++------+----------+------+--------------------+------+-------------+-------------------+-------------------+-------+-------+ +1 row in set (0.001 sec) +~~~ + +![image-20220214150329732](../AppData/Roaming/Typora/typora-user-images/image-20220214150329732.png) + +### 七、创建资源池和租户 + +#### 1、查询系统资源总计资源 + +~~~ +[admin@CAIP131 ~]$ obclient -h112.127.2.120 -uroot@sys#obce-3zones -pPwd2012# -P2883 -A -c oceanbase + +MySQL [oceanbase]> SELECT svr_ip,svr_port, cpu_total, mem_total/1024/1024/1024, disk_total/1024/1024/1024, zone FROM __all_virtual_server_stat; +~~~ + +![image-20220613103615412](../AppData/Roaming/Typora/typora-user-images/image-20220613103615412.png) + +查询租户已分配资源: + +~~~ +MySQL [oceanbase]> SELECT sum(c.max_cpu), sum(c.max_memory)/1024/1024/1024 FROM __all_resource_pool as a, __all_unit_config AS c WHERE a.unit_config_id=c.unit_config_id; +~~~ + +![image-20220214172145283](../AppData/Roaming/Typora/typora-user-images/image-20220214172145283.png) + +Note:资源池cpu共14c/13g/79G 租户已用 5c/4G 新建租户最大可用为 9c/9g(超分会报错) + +#### 2、创建资源单元: + +在创建租户前,需要先确定租户的资源单元配置和资源使用范围。租户使用的资源被限制在资源单元的范围内,如果当前存在的资源单元配置无法满足新租户的需要,可以新建资源单元配置。 + +~~~ +MySQL [oceanbase]> CREATE RESOURCE UNIT unitcaip max_cpu = 4, max_memory = '4G', min_memory = '4G', max_iops = 100000, min_iops = 100000, max_session_num = 30000, max_disk_size = '20G'; +~~~ + +![image-20220613091648389](../AppData/Roaming/Typora/typora-user-images/image-20220613091648389.png) + +查看新创建的资源单元 + +~~~ +MySQL [oceanbase]> SELECT unit_config_id,name,max_cpu,min_cpu,max_memory,min_memory,max_disk_size FROM __all_unit_config; ++----------------+-----------------+---------+---------+------------+------------+---------------+ +| unit_config_id | name | max_cpu | min_cpu | max_memory | min_memory | max_disk_size | ++----------------+-----------------+---------+---------+------------+------------+---------------+ +| 1 | sys_unit_config | 5 | 2.5 | 5153960755 | 4294967296 | 53687091200 | +| 1001 | unitcaip | 4 | 4 | 4294967296 | 4294967296 | 21474836480 | ++----------------+-----------------+---------+---------+------------+------------+---------------+ +2 rows in set (0.010 sec) +~~~ + +![image-20220613091733200](../AppData/Roaming/Typora/typora-user-images/image-20220613091733200.png) + +#### 3、创建资源池: + +在使用 SQL 语句创建资源池前,请确认已创建了待使用的资源单元配置 + +~~~ +MySQL [oceanbase]> CREATE RESOURCE POOL poolcaip UNIT = 'unitcaip', UNIT_NUM = 1,ZONE_LIST = ('zone1', 'zone2', 'zone3'); +Query OK, 0 rows affected (0.025 sec) +~~~ + +![image-20220613091845759](../AppData/Roaming/Typora/typora-user-images/image-20220613091845759.png) + +- 参数 `UNIT_NUM` 表示在集群的一个 Zone 里面包含的资源单元个数。该值小于等于一个 Zone 中的 OBServer 的个数。 +- 参数 `ZONE_LIST` 表示资源池的 Zone 列表,显示该资源池的资源在哪些 Zone 中被使用。 + +#### 4、创建租户tenantobd: + +新建租户后默认密码为空,需修改租户密码,以保证数据安全。 + +~~~ +MySQL [oceanbase]> create tenant tenantobd resource_pool_list=('poolcaip'), charset=utf8mb4, replica_num=3, zone_list('zone1', 'zone2', 'zone3'), primary_zone=RANDOM, locality='F@zone1,F@zone2,F@zone3' set variables ob_compatibility_mode='mysql', ob_tcp_invited_nodes='%'; +Query OK, 0 rows affected (1.601 sec) +~~~ + +![image-20220613093903825](../AppData/Roaming/Typora/typora-user-images/image-20220613093903825.png) + +查看创建成功的租户: + +创建租户后,您可以通过查询 `tenant` 相关视图来确认租户是否创建成功。 + +~~~ +MySQL [oceanbase]> select tenant_id,tenant_name,primary_zone from __all_tenant; ++-----------+-------------+-------------------+ +| tenant_id | tenant_name | primary_zone | ++-----------+-------------+-------------------+ +| 1 | sys | zone1;zone2,zone3 | +| 1002 | tenantobd | RANDOM | ++-----------+-------------+-------------------+ +2 rows in set (0.002 sec) +~~~ + +![image-20220613093938285](../AppData/Roaming/Typora/typora-user-images/image-20220613093938285.png) + +#### 5、登录新创建的租户: + +您可尝试通过 OBProxy 连接 OceanBase 集群,obproxy 默认会监听2个端口:2883 和 2884。登录用户名:`root@proxysys`,端口:`2883`,初始密码:空。 + +~~~ +[admin@CAIP131 ~]$ obclient -h112.127.2.120 -uroot@tenantobd#obce-3zones -P2883 -c -A oceanbase +~~~ + +![image-20220613094402876](../AppData/Roaming/Typora/typora-user-images/image-20220613094402876.png) + +设置租户tenantobd的root密码 + +~~~ +MySQL [oceanbase]> alter user root identified by 'Pwd123#'; +Query OK, 0 rows affected (0.026 sec) +~~~ + +![image-20220613094138811](../AppData/Roaming/Typora/typora-user-images/image-20220613094138811.png) + +### 八、创建测试用户 + +#### 1、创建测试用户 + +##### 1)登录新创建的tenantobd租户 + +~~~ +[admin@CAIP131 ~]$ obclient -h112.127.2.120 -uroot@tenantobd#obce-3zones -P2883 -p -c -A oceanbase +Enter password: +~~~ + +![image-20220613094329406](../AppData/Roaming/Typora/typora-user-images/image-20220613094329406.png) + +##### 2)创建用户userobd + +创建用户并设置密码 + +~~~ +MySQL [oceanbase]> CREATE USER 'userobd' IDENTIFIED BY '#####'; +Query OK, 0 rows affected (0.033 sec) +~~~ + +![image-20220613094646890](../AppData/Roaming/Typora/typora-user-images/image-20220613094646890.png) + +##### 3)查看创建成功的用户 + +~~~ +MySQL [oceanbase]> SELECT user FROM mysql.user; ++------------+ +| user | ++------------+ +| root | +| ORAAUDITOR | +| userobd | ++------------+ +3 rows in set (0.063 sec) +~~~ + +![image-20220613094715003](../AppData/Roaming/Typora/typora-user-images/image-20220613094715003.png) + +#### 2、授权用户GRANT + +##### 1)授权userobd用户 + +该语句用于系统管理员授予用户某些权限。用户授权后,该用户只有重新连接 OceanBase 数据库,权限才能生效。 + +~~~ +MySQL [oceanbase]> grant all on *.* to 'userobd' WITH GRANT OPTION; +Query OK, 0 rows affected (0.051 sec) +~~~ + +![image-20220613094807517](../AppData/Roaming/Typora/typora-user-images/image-20220613094807517.png) + +##### 2)查看用户授权 + +通过 `SHOW GRANTS` 语句查看某个用户被授予的权限。 + +~~~ +MySQL [oceanbase]> show grants for userobd; ++------------------------------------------------------------+ +| Grants for userobd@% | ++------------------------------------------------------------+ +| GRANT ALL PRIVILEGES ON *.* TO 'userobd' WITH GRANT OPTION | ++------------------------------------------------------------+ +1 row in set (0.026 sec) +~~~ + +![image-20220613094841114](../AppData/Roaming/Typora/typora-user-images/image-20220613094841114.png) + +##### 3)用于登录测试 + +~~~ +[admin@CAIP131 ~]$ obclient -h112.127.2.120 -uuserobd@tenantobd#obce-3zones -p -P2883 -c -A oceanbase +~~~ + +![image-20220613095029530](../AppData/Roaming/Typora/typora-user-images/image-20220613095029530.png) + +#### 3、连接白名单设置 + +##### 1)登录租户 + +##### 您可以通过租户白名单功能来设置允许哪些客户端访问当前租户。(否则只能127登录)sys租户登录 + +~~~ +[admin@CAIP131 ~]$ obclient -h112.127.2.120 -uroot@sys#obce-3zones -p -P2883 -A -c oceanbase +Enter password: +~~~ + +![image-20220613095229593](../AppData/Roaming/Typora/typora-user-images/image-20220613095229593.png) + +##### 2)设置租户tenantobd白名单 + +~~~ +MySQL [oceanbase]> ALTER TENANT tenantobd SET VARIABLES ob_tcp_invited_nodes='%'; +Query OK, 0 rows affected (0.005 sec) +~~~ + +![image-20220613095314699](../AppData/Roaming/Typora/typora-user-images/image-20220613095314699.png) + +白名单看来是设置成功了 + +### 九、创建业务数据库 + +设置好白名单后,再来创建业务数据库 + +#### 1、用户登录 + +使用租户下的用户登录OB集群测试建库建表: + +~~~ +[admin@CAIP131 ~]$ obclient -h112.127.2.120 -uuserobd@tenantobd#obce-3zones -p -P2883 -c -A oceanbase +Enter password: +~~~ + +![image-20220613100102265](../AppData/Roaming/Typora/typora-user-images/image-20220613100102265.png) + +#### 2、创建测试表 + +~~~ +MySQL [oceanbase]> create database testobd; +Query OK, 1 row affected (0.020 sec) + +MySQL [oceanbase]> show databases; ++--------------------+ +| Database | ++--------------------+ +| oceanbase | +| information_schema | +| mysql | +| test | +| testobd | ++--------------------+ +5 rows in set (0.021 sec) + +MySQL [oceanbase]> use testobd; +Database changed +MySQL [testobd]> CREATE TABLE testobd (id int,name varchar(20)); +Query OK, 0 rows affected (0.095 sec) + +MySQL [testobd]> insert into testobd(id,name) values(20211212,"obobd"); +Query OK, 1 row affected (0.026 sec) + +MySQL [testobd]> select * from testobd; ++----------+-------+ +| id | name | ++----------+-------+ +| 20211212 | obobd | ++----------+-------+ +1 row in set (0.003 sec) +~~~ + +![image-20220613095916831](../AppData/Roaming/Typora/typora-user-images/image-20220613095916831.png) + +### 十、寻求帮助 + +#### 1、官方社区问答板块寻求帮助 + +OB开源团队老师和同学非常乐于跟用户交流OB技术。在检查的最后,会将所有存在的问题一并列出,并且给出解决建议。 可以参照建议解决问题,并再次运行环境检查。或者你可以在OceanBase 社区问答板块提问、分享、查找之前别人遇到过的问题?在寻求帮助的过程中, 也不断的锻炼自己, 让自己的知识越来越丰富。 + +问答链接:https://ask.oceanbase.com/ + +![image-20220611135940709](../AppData/Roaming/Typora/typora-user-images/image-20220611135940709.png) + +#### 2、官方钉钉群寻求帮助 + +OB开源团队老师和同学非常乐于跟用户交流OB技术。加入钉钉社群,提问、分享、查找之前别人遇到过的问题? 在寻求帮助的过程中, 也不断的锻炼自己, 让自己的知识越来越丰富。 + +钉钉群号 33254054 + +![image-20220611140154294](../AppData/Roaming/Typora/typora-user-images/image-20220611140154294.png) + + + +**结语:** + +使用OBD自动化安装部署OceanBase整体还是比较简单的,但还是要比docker安装复杂一些,细心一点多检查在执行。在检查的最后,会将所有存在的问题一并列出,并且在OB官网找出解决建议,参照建议解决问题,并再次运行环境检查。OB官方网站文档中心提供了比较详细的资料,obd配置文件的各参数是否设置正确。但是在实验环境中安装还是会遇到各种问题,大家如果有机会可以自己搭建起来,对于理解OB的架构有些帮助。 + +1. 有一种无缝使用MySQL的感觉,如果有mysql数据库经验,使用 OceanBase 的还是比较容易的。 +2. OBD 对 OceanBase 的管理权限很高,所以 OBD 要部署在数据库服务器的中控机上,需要 DBA 有完全的控制权限。 +3. 如果部署遇到报错,找你看得懂的ERROR日志。或者根据错误号到官网问答区查看别人发布过的问题,参考是如何解决的,可以参照建议解决问题,或在钉钉群提问。总会找到有用的线索,并再次运行环境检查。 +4. 只要按照官方文档步骤部署是一定能成功的,如果报错可能是某一个细节没做好。 +5. 不管是官方文档部署还是网络方法部署,只是测试。在测试OB之前至少得先确保熟悉原理,在根据实际环境部署。 + + + + + + + + + + + +