OceanBase社区版手动部署单副本集群及OBProxy

OceanBase社区版手动部署单副本集群及OBProxy

文章目录

一、环境准备

oceanbase社区版部署单副本集群,要求内存不小于10G。本机操作系统为redhat7.9,资源配置为4c16G,磁盘空间100G。

新建admin用户

bash 复制代码
useradd admin -G wheel
echo 'admin:admin' | chpasswd

设置admin用户环境变量

bash 复制代码
su - admin
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/oceanbase/lib' >> ~/.bash_profile
. ~/.bash_profile

创建相关目录

bash 复制代码
mkdir -p /home/admin/oceanbase/store/obcluster /data/obcluster/{sstable,etc3} /redo/obcluster/{clog,ilog,slog,etc2}
chown -R admin:admin /home/admin /data /redo
su - admin
for f in {clog,ilog,slog,etc2}; do ln -s /redo/obcluster/$f ~/oceanbase/store/obcluster/$f ; done
for f in {sstable,etc3}; do ln -s /data/obcluster/$f ~/oceanbase/store/obcluster/$f; done

配置内核参数

bash 复制代码
vi /etc/sysctl.conf

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
vm.max_map_count=655360
fs.aio-max-nr=1048576
bash 复制代码
[root@rac04 software]# sysctl -p
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
vm.max_map_count = 655360
fs.aio-max-nr = 1048576

配置用户资源限制

bash 复制代码
vi /etc/security/limits.conf

admin soft nofile 655360
admin hard nofile 655360
admin soft nproc 655360
admin hard nproc 655360
admin soft core unlimited
admin hard core unlimited
admin soft stack unlimited
admin hard stack unlimited
bash 复制代码
[root@rac04 software]# su - admin
上一次登录:四 3月  7 17:21:22 CST 2024pts/0 上
[admin@rac04 ~]$ ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 63334
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 655360
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) unlimited
cpu time               (seconds, -t) unlimited
max user processes              (-u) 655360
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

禁用防火墙

bash 复制代码
systemctl disable firewalld 
systemctl stop firewalld
systemctl status firewalld

禁用selinux

bash 复制代码
vi /etc/selinux/config

SELINUX=disabled
bash 复制代码
[root@rac04 software]# setenforce 0

二、部署observer

下载ob软件

bash 复制代码
wget https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/libobclient-2.0.0-2.el7.x86_64.rpm  
wget https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/oceanbase-ce-3.1.0-1.el7.x86_64.rpm
wget https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/obclient-2.0.0-1.el7.x86_64.rpm     
wget https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/obproxy-3.1.0-1.el7.x86_64.rpm    
wget https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/oceanbase-ce-libs-3.1.0-1.el7.x86_64.rpm

安装ob软件包

bash 复制代码
rpm -ivh oceanbase-ce-libs-3.1.0-1.el7.x86_64.rpm oceanbase-ce-3.1.0-1.el7.x86_64.rpm
rpm -ivh libobclient-2.0.0-2.el7.x86_64.rpm obclient-2.0.0-1.el7.x86_64.rpm

启动observer

bash 复制代码
su - admin
# 通常仅在第一次启动时,需要添加启动参数,其他时候启动时,可直接使用 observer 命令启动 observer 进程。
cd ~/oceanbase #这一步不能少,因为启动时会生成一些文件在当前目录
/home/admin/oceanbase/bin/observer -i ens33 -p 2881 -P 2882 -z zone1 -d /home/admin/oceanbase/store/obcluster -r '11.11.11.14:2882:2881' -c 10001 -n obcluster -l WARN  -o "memory_limit=8G,__min_full_resource_pool_memory=268435456,system_memory=2G,cpu_count=16,datafile_size=4G,config_additional_dir=/data/obcluster/etc3;/redo/obcluster/etc2"

/home/admin/oceanbase/bin/observer -i ens33 -p 2881 -P 2882 -z zone1 -d /home/admin/oceanbase/store/obcluster -r 11.11.11.14:2882:2881 -c 10001 -n obcluster -l WARN -o memory_limit=8G,__min_full_resource_pool_memory=268435456,system_memory=2G,cpu_count=16,datafile_size=4G,config_additional_dir=/data/obcluster/etc3;/redo/obcluster/etc2
devname: ens33
mysql port: 2881
rpc port: 2882
zone: zone1
data_dir: /home/admin/oceanbase/store/obcluster
rs list: 11.11.11.14:2882:2881
cluster id: 10001
appname: obcluster
log level: WARN
optstr: memory_limit=8G,__min_full_resource_pool_memory=268435456,system_memory=2G,cpu_count=16,datafile_size=4G,config_additional_dir=/data/obcluster/etc3;/redo/obcluster/etc2
[2024-03-07 18:55:54.082318] ERROR [LIB] pidfile_test (utility.cpp:1153) [76370][0][Y0-0000000000000000] [lt=0] fid file doesn't exist(pidfile="run/observer.pid") BACKTRACE:0x90a107e 0x90008fb 0x24c152f 0x251bb2d 0x90a6215 0x24be1a8 0x2b781995e555 0x24bd4e9

该报错似乎是内部bug,不用在意。等待一会之后,observer进程会起来。

bash 复制代码
参数	说明
-i	指定网卡名,可通过 ifconfig 命令查看。
-p	指定服务端口号,一般指定为 2881。
-P	指定 RPC 端口号,一般指定为 2882。
-n	指定集群名称。可自定义,不同集群名称不要重复即可。
-z	指定启动的 observer 进程所属的 Zone。
-d	指定集群主目录,除集群名字 obdemo 外,其他不要变动。
-c	指定集群 ID。为一组数字,可以自定义,不同集群不要重复即可。
-l	指定日志级别。
-r	指定 RS 列表,格式是 ip:2882:2881 ,分号分割,表示 RootService 信息。三台机器参数一致。
-o	指定集群启动参数,需要根据实际情况设置。system_memory 指定 
   OceanBase 内部保留内存,默认是 30G ,机器内存比较少的情况下把
   这个调小,影响就是可能在性能测试时有内存不足问题。 
   datafile_size 指定 OceanBase 数据文件 sstable 的大小
   (一次性初始化)

检查进程状态

bash 复制代码
[admin@rac04 oceanbase]$ ps -ef|grep observer
admin     75358      1 43 18:25 ?        00:02:23 /home/ad
min/oceanbase/bin/observer -i ens33 -p 2881 -P 2882 -z zo
ne1 -d /home/admin/oceanbase/store/obcluster -r 11.11.11.
14:2882:2881 -c 10001 -n obcluster -l WARN -o memory_limi
t=8G,__min_full_resource_pool_memory=268435456,system_mem
ory=2G,memory_chunk_cache_size=128M,cpu_count=16,net_thre
ad_count=4,datafile_size=2G,stack_size=1536K,config_addi
tional_dir=/data/obcluster/etc3;/redo/obcluster/etc2

#检查端口,如果监听到了 2881 与 2882 端口,则说明进程启动成功。
netstat -ntlp|grep observer

tcp        0      0 0.0.0.0:2881            0.0.0.0:*               LISTEN      75358/observer      
tcp        0      0 0.0.0.0:2882            0.0.0.0:*               LISTEN      75358/observer    

三、集群初始化

登录集群时,不要加上@租户名,否则报错。

bash 复制代码
[admin@rac04 etc2]$ obclient -h11.11.11.14 -P2881 -uroot@sys -p -c -A
Enter password: 
ERROR 8001 (08004): Server is initializing

obclient -h11.11.11.14 -P2881 -uroot -p -c -A
sql 复制代码
MySQL [(none)]> set session ob_query_timeout=1000000000;
Query OK, 0 rows affected (0.001 sec)

MySQL [(none)]> alter system bootstrap ZONE 'zone1' SERVER '11.11.11.14:2882';
Query OK, 0 rows affected (10.725 sec)

bootstrap之后,就可以登录sys租户了。

sql 复制代码
obclient -h11.11.11.14 -P2881 -uroot@sys -p -c -A

-- 验证集群初始化成功。
MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| SYS                |
| LBACSYS            |
| ORAAUDITOR         |
| test               |
+--------------------+
7 rows in set (0.002 sec)

-- 修改sys租户root密码
MySQL [(none)]> alter user root identified by 'root';
Query OK, 0 rows affected (0.015 sec)

四、部署obproxy

安装obproxy包

bash 复制代码
rpm -ivh obproxy-3.1.0-1.el7.x86_64.rpm

创建proxyro用户

sql 复制代码
MySQL [(none)]> grant select on oceanbase.* to proxyro identified by 'root';
Query OK, 0 rows affected (0.028 sec)

启动obproxy

bash 复制代码
/home/admin/obproxy-3.1.0/bin/obproxy -r "127.0.0.1:2881" -p 2883 -o "enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false" -c obcluster

/home/admin/obproxy-3.1.0/bin/obproxy -r 127.0.0.1:2881 -p 2883 -o enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false -c obcluster
rs list: 127.0.0.1:2881
listen port: 2883
optstr: enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false
cluster_name: obcluster

连接obproxy配置密码

bash 复制代码
-- 初始密码为空
obclient -h 127.0.0.1 -u root@proxysys -P 2883 -p

MySQL [(none)]> alter proxyconfig set observer_sys_password ='root';
Query OK, 0 rows affected (0.001 sec)

测试proxy

bash 复制代码
[admin@rac04 ~]$ obclient -h127.0.0.1 -P2883 -uroot@sys#obcluster -p -c -A -Doceanbase
Enter password: 
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.25 OceanBase 3.1.0 (r-) (Built May 30 2021 11:21:29)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [oceanbase]> 

五、创建租户、数据库、表

检查资源状况

sql 复制代码
select zone,
concat(svr_ip, ':', svr_port) observer,
cpu_capacity,
cpu_total,
cpu_assigned,
cpu_assigned_percent,
mem_capacity/1024/1024,
mem_total/1024/1024,
mem_assigned/1024/1024,
mem_assigned_percent,
disk_total/1024/1024,
disk_assigned/1024/1024,
disk_assigned_percent,
unit_Num,
round('load', 2) 'load',
round('cpu_weight', 2) 'cpu_weight',
round('memory_weight', 2) 'mem_weight',
leader_count
from __all_virtual_server_stat
order by zone, svr_ip\G

*************************** 1. row ***************************
                   zone: zone1
               observer: 11.11.11.14:2882
           cpu_capacity: 14
              cpu_total: 14
           cpu_assigned: 2.5
   cpu_assigned_percent: 17
 mem_capacity/1024/1024: 6144.00000000
    mem_total/1024/1024: 6144.00000000
 mem_assigned/1024/1024: 1536.00000000
   mem_assigned_percent: 25
   disk_total/1024/1024: 4096.00000000
disk_assigned/1024/1024: 4096.00000000
  disk_assigned_percent: 100
               unit_Num: 1
                   load: 0.00
             cpu_weight: 0.00
             mem_weight: 0.00
           leader_count: 1189
1 row in set, 3 warnings (0.008 sec)

剩余资源足够。

创建资源单元

sql 复制代码
CREATE resource unit u1 max_cpu=1, min_cpu=1, max_memory='1G',
min_memory='1G', max_iops=10000,min_iops=1000, 
max_session_num=1000000, max_disk_size='5G';

创建资源池

sql 复制代码
create resource pool pool1 unit='u1', unit_num=1, zone_list=('zone1') ;

创建mysql类型业务租户,允许所有连接,关闭回收站

sql 复制代码
create tenant yw charset='utf8mb4',zone_list=('zone1'),resource_pool_list=('pool1'),comment='业务租户1' 
set ob_compatibility_mode=mysql,ob_tcp_invited_nodes='%',recyclebin = off;

检查

sql 复制代码
MySQL [oceanbase]> select * from __all_tenant where tenant_name='yw'\G
*************************** 1. row ***************************
                 gmt_create: 2024-03-07 19:33:18.124137
               gmt_modified: 2024-03-07 19:33:18.124137
                  tenant_id: 1001
                tenant_name: yw
                replica_num: -1
                  zone_list: zone1
               primary_zone: RANDOM
                     locked: 0
             collation_type: 0
                       info: 业务租户1
                  read_only: 0
      rewrite_merge_version: 0
                   locality: FULL{1}@zone1
        logonly_replica_num: 0
          previous_locality: 
     storage_format_version: 0
storage_format_work_version: 0
      default_tablegroup_id: -1
         compatibility_mode: 0
           drop_tenant_time: -1
                     status: TENANT_STATUS_NORMAL
              in_recyclebin: 0
1 row in set (0.004 sec)

连接业务租户yw

bash 复制代码
 obclient -h127.0.0.1 -P2881 -uroot@yw -p -c -A -Doceanbase
sql 复制代码
alter user root identified by 'root';

-- 创建业务数据库
MySQL [oceanbase]> create database ywdb charset='utf8mb4' read write;
Query OK, 1 row affected (0.013 sec)
sql 复制代码
-- 修改yw租户root密码
MySQL [oceanbase]> alter user root identified by 'root';
Query OK, 0 rows affected (0.015 sec)
-- 创建表
MySQL [oceanbase]> create database ywdb charset='utf8mb4' read write;
Query OK, 1 row affected (0.017 sec)

MySQL [oceanbase]> use ywdb
Database changed
MySQL [ywdb]> create table t1(name char(20));
Query OK, 0 rows affected (0.064 sec)

MySQL [ywdb]> create table t3(id int(10),t3name char(20)) partition by hash(id) partitions 5;
Query OK, 0 rows affected (0.041 sec)

MySQL [ywdb]> show tables;
+----------------+
| Tables_in_ywdb |
+----------------+
| t1             |
| t3             |
+----------------+
2 rows in set (0.011 sec)

六、避坑指导

  1. 启动observer进程之前,需要cd 到/home/admin/observer目录下,再调用observer命令启动。
  2. 启动observer进程之后,会报错fid file doesn't exist(pidfile="run/observer.pid,只要检查observer进程以及2881,2882端口正常,就可以忽略该错误。
  3. 在集群尚未bootstrap之前,不能连接sys租户,即-uroot@sys这种方式,只能使用-uroot不加租户和集群的方式连接。否则报错ERROR 8001 (08004): Server is initializing

七、参考链接

部署单副本 OceanBase 集群-OceanBase 数据库-OceanBase文档中心-分布式数据库使用文档

如何手动部署 OceanBase 集群(单节点)-数据库技术博客-OceanBase分布式数据库

2.11 (高级)如何手动部署 OceanBase 集群-DBA 入门教程-OceanBase文档中心-分布式数据库使用文档

相关推荐
老年DBA1 天前
【无标题】observer: error while loading shared libraries: libmariadb.so.3处理办法
数据库·oceanbase
@素素~2 天前
OceanBase—02(入门篇——对于单副本单节点,由1个observer扩容为3个observer集群)——之前的记录,当初有的问题未解决,目前新版未尝试
数据库·oceanbase
OceanBase数据库官方博客2 天前
快手:数据库升级实践,实现PB级数据的高效管理|OceanBase案例
oceanbase·分布式数据库·实践经验
好记忆不如烂笔头abc4 天前
测试部署单副本 oceanbase-3.2.4.1 企业版
oceanbase
OceanBase数据库官方博客4 天前
利用 Local Data 导入文件到 OceanBase 的方法
银行·oceanbase·分布式数据库·保险证券
OceanBase数据库官方博客4 天前
遇到慢SQL、SQL报错,应如何快速定位问题 | OceanBase优化实践
sql·oceanbase·分布式数据库·实践经验
救救孩子把4 天前
OceanBase企业级分布式关系数据库
数据库·分布式·oceanbase
OceanBase数据库官方博客5 天前
DDL 超时,应该如何解决 | OceanBase 用户问题集萃
oceanbase·分布式数据库·ddl
光锥智能5 天前
OceanBase云数据库战略实施两年,受零售、支付、制造行业青睐
数据库·oceanbase·零售
爬树的小蚂蚁5 天前
OceanBase 一级表分区记录
oceanbase