裸机部署单副本 oceanbase-3.2.4.1 企业版(for ORACLE)集群
OceanBase 也支持单副本部署,并且单副本 OceanBase 集群还可以扩容(增加节点),所以也称为集群。
裸机准备
配置:4cpu,12G内存,100G磁盘
[root@c7 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@c7 ~]# uname -r
3.10.0-1160.el7.x86_64
[root@c7 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 5.8G 0 5.8G 0% /dev
tmpfs tmpfs 5.8G 0 5.8G 0% /dev/shm
tmpfs tmpfs 5.8G 8.9M 5.8G 1% /run
tmpfs tmpfs 5.8G 0 5.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 99G 1.3G 98G 2% /
/dev/sda1 xfs 1014M 150M 865M 15% /boot
tmpfs tmpfs 1.2G 0 1.2G 0% /run/user/0
sudo yum install -y yum-utils wget net-tools tree
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo
创建用户
useradd -U admin -d /home/admin -s /bin/bash
mkdir -p /home/admin
chown -R admin:admin /home/admin
mkdir -p /data
chown -R admin:admin /data
安装 oceanbase-3.2.4.1 企业版软件
https://www.oceanbase.com/softwarecenter-enterprise
填写相关信息,进行下载,安装
[root@c7 ~]# rpm -ivh oceanbase-3.2.4.1-101000052023010822.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:oceanbase-3.2.4.1-101000052023010################################# [100%]
初始化 OceanBase 目录
su - admin
export cluster_name=obdemo
echo $cluster_name
mkdir -p /data/1/$cluster_name/{etc3,sort_dir,sstable}
mkdir -p /data/log1/$cluster_name/{clog,etc2,ilog,slog,oob_clog}
mkdir -p /home/admin/oceanbase/store/$cluster_name
for t in {etc3,sort_dir,sstable};do ln -s /data/1/$cluster_name/$t /home/admin/oceanbase/store/$cluster_name/$t; done
for t in {clog,etc2,ilog,slog,oob_clog};do ln -s /data/log1/$cluster_name/$t /home/admin/oceanbase/store/$cluster_name/$t; done
目录验证:
cd /home/admin/oceanbase
tree store
[admin@c7 ~]$ cd /home/admin/oceanbase
[admin@c7 oceanbase]$ tree store
store
└── obdemo
├── clog -> /data/log1/obdemo/clog
├── etc2 -> /data/log1/obdemo/etc2
├── etc3 -> /data/1/obdemo/etc3
├── ilog -> /data/log1/obdemo/ilog
├── oob_clog -> /data/log1/obdemo/oob_clog
├── slog -> /data/log1/obdemo/slog
├── sort_dir -> /data/1/obdemo/sort_dir
└── sstable -> /data/1/obdemo/sstable
安装 OceanBase 客户端
sudo yum install -y obclient
初始化 OceanBase 集群
启动 observer 进程
su - admin
cd /home/admin/oceanbase && /home/admin/oceanbase/bin/observer -i ens192 -P 2882 -p 2881 -z zone1 -d /home/admin/oceanbase/store/obdemo -r '172.17.10.82:2882:2881' -c 10001 -n obdemo -o "__min_full_resource_pool_memory=268435456,system_memory=1G,datafile_size=50G,config_additional_dir=/data/1/obdemo/etc3;/data/log1/obdemo/etc2"
可通过 netstat -ntlp 命令查看 observer 进程是否启动成功。
如果监听到了 2881 与 2882 端口,则说明进程启动成功。
[admin@c7 ~]$ netstat -ntlp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:2881 0.0.0.0:* LISTEN 17339/observer
tcp 0 0 0.0.0.0:2882 0.0.0.0:* LISTEN 17339/observer
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 ::1:25 :::* LISTEN -
集群 bootstrap 操作
通过 obclient 命令连接已启动的 observer 进程,密码为空。
obclient -h127.0.0.1 -uroot -P2881 -p
SET SESSION ob_query_timeout=1000000000;
ALTER SYSTEM BOOTSTRAP ZONE 'zone1' SERVER '172.17.10.82:2882'; # 耗时63s
SHOW DATABASES;
ALTER USER root IDENTIFIED BY '1'; # 修改密码
创建 OceanBase 租户
降低sys租户的资源
alter resource unit sys_unit_config min_cpu=1,max_cpu=1;
alter resource unit sys_unit_config min_memory='1G',max_memory='1G';
创建资源单元规格
资源单元仅仅是规格定义,不实际分配资源。
CREATE RESOURCE UNIT unit001
MAX_CPU 0.1,MAX_MEMORY '256M',MAX_IOPS 128,MAX_DISK_SIZE '512M',MAX_SESSION_NUM 64,
MIN_CPU 0.1,MIN_MEMORY '256M',MIN_IOPS 128;
创建资源池
资源池会实际创建 unit,按规格定义分配资源。
CREATE RESOURCE POOL pool001
UNIT='unit001',UNIT_NUM=1,ZONE_LIST=('zone1');
创建租户
将资源池分配给对应的租户
创建 Oracle 兼容模式租户
CREATE TENANT IF NOT EXISTS oracle001
CHARSET='utf8mb4',
PRIMARY_ZONE='zone1',
RESOURCE_POOL_LIST=('pool001')
SET ob_tcp_invited_nodes='%',ob_compatibility_mode='oracle';
设置管理员用户密码
使用 SQL 语句创建的租户,租户管理员用户密码为空。使用前请先设置密码。
– 登录sys用户,oracle001租户
obclient -h127.0.0.1 -P2881 -usys@oracle001 -p -A
SET PASSWORD = PASSWORD(1);
开始体验
SELECT to_char(SYSDATE,'yyyy.mm.dd HH24:mi:ss') FROM DUAL;
– 查看所有数据库用户
SELECT * FROM all_users;
+------------+------------------+-----------+
| USERNAME | USERID | CREATED |
+------------+------------------+-----------+
| LBACSYS | 1100611139403783 | 18-JUN-24 |
| ORAAUDITOR | 1100611139403784 | 18-JUN-24 |
| PUBLIC | 1100611139403781 | 18-JUN-24 |
| SYS | 1100611139403782 | 18-JUN-24 |
+------------+------------------+-----------+
– 查看当前连接数据库用户
SHOW PROCESSLIST;
– 通过 SQL 修改用户密码
ALTER USER SYS IDENTIFIED BY "1";