OB-本地单节点部署社区版3.1
作者:互联网
部署环境
序号 | 项目 | 内容 | 官方建议 |
---|---|---|---|
1 | CPU | 2C | CPU数量不低于2 |
2 | MEMOERY | 8G | 内存不低于16G |
3 | DISK | 200G(/ob) | N/A |
4 | IP | 192.168.10.181 | 可单机、分布式多种方式部署 |
5 | OS | rhel 7.6 | |
6 | oceanbase | 社区版3.1 | N/A |
7 |
软件介质清单
共6个rpm包,下载后上传至安装主机soft目录。
- OBD: OceanBase Database Deployer社区版部署工具
- oceanbase-ce: OceanBase数据库社区版
- OceanBase libs: oceanbase运行时所依赖的部分三方动态库
- Obproxy : oceanbase数据库专用的代理服务器
- OBClient:obclient交互式和批量处理查询工具
- LibOBClient:obclient的依赖包
下载社区版软件
yum源上rpm包信息
下载软件
yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo
# 创建一个目录用于下载
mkdir soft
cat > rpm_list <<EOF
oceanbase-ce-3.1.0-3.el7.x86_64.rpm
oceanbase-ce-libs-3.1.0-3.el7.x86_64.rpm
obproxy-3.1.0-1.el7.x86_64.rpm
obclient-2.0.0-2.el7.x86_64.rpm
ob-deploy-1.1.0-1.el7.x86_64.rpm
libobclient-2.0.0-2.el7.x86_64.rpm
oceanbase-ce-sql-parser-3.1.0-3.el7.x86_64.rpm
EOF
wget -B https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/ -i rpm_list -P soft
# or
yum install obclient libobclient obproxy oceanbase-ce oceanbase-ce-libs ob-deploy --downloadonly --downloaddir=soft
yaml配置文件
在页面https://gitee.com/oceanbase/obdeploy/blob/master/example/mini-local-example.yaml,拷贝mini-local-example.yaml内容并保存为mini-local-example.yaml,上传至安装服务器soft目录。
cat > mini-local-example.yaml <<-EOF
oceanbase-ce:
servers:
# Please don't use hostname, only IP can be supported
- 127.0.0.1
global:
home_path: /root/observer
# Please set devname as the network adaptor's name whose ip is in the setting of severs.
# if set severs as "127.0.0.1", please set devname as "lo"
# if current ip is 192.168.1.10, and the ip's network adaptor's name is "eth0", please use "eth0"
devname: lo
mysql_port: 2881
rpc_port: 2882
zone: zone1
cluster_id: 1
# please set memory limit to a suitable value which is matching resource.
memory_limit: 8G
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
# The value of net_thread_count had better be same as cpu's core number.
net_thread_count: 4
sys_bkgd_migration_retry_num: 3
minor_freeze_times: 10
enable_separate_sys_clog: 0
enable_merge_by_turn: FALSE
datafile_disk_percentage: 20
syslog_level: INFO
enable_syslog_recycle: true
max_syslog_file_count: 4
# root_password: # root user password, can be empty
EOF
操作系统配置
以下操作如无特别说明,均以root用户执行。
准备工作[root]
selinux关闭
#临时关闭
setenforce 0
getenforce
#开机不启动selinux,需重启生效。已临时关闭,本次不需要重启生效。
sed -i 's/=enforcing/=disabled/g' /etc/selinux/config
#查看配置已生效
cat /etc/selinux/config
firewalld关闭
#关闭防火墙
systemctl stop firewalld
#开机不启动防火墙
systemctl disable firewalld
修改主机名
#修改主机名为oceanbase,当前已生效,退出会话,再登录后显示新主机名
hostnamectl set-hostname oceanbase
配置hosts
#主机名解析添加主机信息
cat >> /etc/hosts << EOF
192.168.10.182 oceanbase
EOF
#查看主机名信息
cat /etc/hosts
添加oceanbase用户
oceanbase安装和维护均由oceanbase用户操作。[生产的OB默认运行在admin用户]
#添加oceanbase用户
useradd ober
#更改密码
echo "ober" | passwd --stdin ober
#运行oceanbase可运行任何命令,不需要密码
visudo #添加oceanbase一行内容
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
ober ALL=(ALL) NOPASSWD: ALL
创建SSH 互信
安装目录准备
以root用户安装时,默认安装在/root/observer目录下,这里以oceanbase用户安装在/ob/observer目录下。
查看默认安装路径
rpm -ql oceanbase-ce-3.1.0-3.el7.x86_64
for pkg in $(ls -tr ./*.rpm);do
echo $pkg; rpm -ql $pkg
done
自定义安装
# 查看安装目录大小
[root@progs oceanbase]# df -hT /ups
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/upsvg-upslv xfs 64G 44G 21G 69% /ups
[root@progs oceanbase]#
# 检查属主、属组
[root@progs oceanbase]# ls -ld /ups/app/oceanbase
drwxr-xr-x 2 ober ober 6 Aug 28 20:39 /ups/app/oceanbase
[root@progs oceanbase]#
sysctl.conf配置
#添加内容
echo "fs.aio-max-nr=1048576" >> /etc/sysctl.conf
#配置生效
sysctl -p
# for oceanbase ## 修改内核异步 I/O 限制 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 # 此处为 OceanBase 数据库的 data 目录 kernel.core_pattern = /data/core-%e-%p-%t
其中,kernel.core_pattern
中的 /data
为 OceanBase 数据库的 data
目录。如果您只是测试,您可以只设置 fs.aio-max-nr=1048576
。
打开文件数限制
#添加内容
cat >> /etc/security/limits.d/98-ober.conf << EOF
ober soft nofile 655350
ober hard nofile 655350
root soft nofile 655350
root hard nofile 655350
EOF
# 生产环境建议配置
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
#退出当前会话,重新登录,使配置生效。
#检查open files当前值,应为655350,否则后续启动集群会报错
ulimit -n
软件安装
下载并安装OBD[oceanbase用户]
获取OceanBase数据库最快的方式是使用数据库部署工具OceanBase Deployer(简称OBD),因此推荐使用此方式体验OceanBase数据库。
在线安装安装OBD
通过 YUM 软件源安装 OBD
sudo yum install -y ob-deploy
source /etc/profile.d/obd.sh
离线安装OBD(即RPM包)
安装OBD
# oceanbase用户安装
sudo yum install -y ob-deploy-1.1.0-1.el7.x86_64.rpm
# 用户使变量生效
source /etc/profile.d/obd.sh
配置本地oceanbase镜像[oceanbase用户]
当前主机不能连接公网,将之前OceanBase数据库的rpm离线软件包镜像到本地。
检查离线包
ls ./*.rpm
将OceanBase数离线软件包加入本地镜像
将OceanBase数据库的离线软件包加入本地镜像:
which obd
obd mirror clone *.rpm
clone命令执行后,将本地上rpm包复制到~/.obd/mirror目录上
yaml配置文件准备[oceanbase用户]
yaml说明
yaml是批量安装调用的内容,当前OceanBase提供多种类型配置文件,分别为mini-local-example.yaml、mini-single-example.yaml、mini-distributed-example.yaml。
根据您的资源条件选择正确的配置文件:
小规格开发模式
适用于个人设备(内存不低于 8G)。
专业开发模式
适用于高配置 ECS 或物理服务器(不低于 16 核 64G 内存)。
这里使用本地单节点配置:mini-local-example.yaml
修改配置文件
默认root用户安装可不做修改,本次将安装目录home_path由/root/observer更改为/ob/observer。
因以oceanbase用户安装,确保/ob目录存在,属主、属组均为oceanbase,observer安装目录不需要创建。
- 修改 home_path, 这是 OceanBase 数据库的工作目录
- 修改 mysql_port,这是 OceanBase 数据库 SQL 服务协议端口号。
- 修改 rpc_port,这是 OceanBase 数据库集群内部通信的端口号
[oceanbase@oceanbase ~]$ vi mini-local-example.yaml
oceanbase-ce:
version: 3.1.0
servers:
# Please don't use hostname, only IP can be supported
- 192.168.10.181
global:
home_path: /ups/app/oceanbase
# Please set devname as the network adaptor's name whose ip is in the setting of severs.
# if set severs as "127.0.0.1", please set devname as "lo"
# if current ip is 192.168.1.10, and the ip's network adaptor's name is "eth0", please use "eth0"
devname: ens32
mysql_port: 2881
rpc_port: 2882
zone: zone1
cluster_id: 1
# please set memory limit to a suitable value which is matching resource.
memory_limit: 8G
system_memory: 4G
stack_size: 512K
cpu_count: 2
cache_wash_threshold: 1G
__min_full_resource_pool_memory: 268435456
workers_per_cpu_quota: 10
schema_history_expire_time: 1d
# The value of net_thread_count had better be same as cpu's core number.
net_thread_count: 4
sys_bkgd_migration_retry_num: 3
minor_freeze_times: 10
enable_separate_sys_clog: 0
enable_merge_by_turn: FALSE
datafile_disk_percentage: 5
syslog_level: INFO
enable_syslog_recycle: true
max_syslog_file_count: 4
# root_password: # root user password, can be empty
安装部署oceanbase集群[oceanbase用户]
部署集群
obd cluster deploy <deploy_name> -c <deploy_config_path>
默认优先使用remote仓库安装
在oceanbase用户下,部署名为biu集群,使用配置文件/soft/mini-local-example.yaml
[oceanbase@oceanbase ~]$ obd cluster deploy biu -c soft/mini-local-example.yaml
说明:obd安装首先默认使用remote官方的镜像进行安装,remote失败时,OBD才会尝试使用local镜像,当前部署集群成功。
建议官方添加参数,增加obd mirror delete选项,删除remote镜像路径,或者增加disable选项,禁用remote镜像路径,或者增加其它参数,优先使用本地mirror。
使用本地local仓库安装
mv ~/.obd/mirror/remote ~/.obd/mirror/remote_bak
如果要本地安装需删除或者重命名remote目录
启动集群
obd cluster start <deploy_name>
如:
[oceanbase@oceanbase ~]$ obd cluster start biu
注:WARN是当前主机仅8G内存,低于建议的最低配置16G,测试环境不影响使用。
查看集群状态
#查看obd管理的集群列表
obd cluster list
#查看集群状态
obd cluster display biu
修改配置
OceanBase 数据库有数百个配置项,有些配置是耦合的,在您熟悉 OceanBase 数据库之前,不建议您修改示例配件文件中的配置。此处示例用来说明如何修改配置,并使之生效。
# 使用 edit-config 命令进入编辑模式,修改集群配置
obd cluster edit-config biu
# 修改 sys_bkgd_migration_retry_num 为 5
# 注意 sys_bkgd_migration_retry_num 值最小为 3
# 保存并退出后,obd 会告知您如何使得此次改动生效
# 此配置项仅需要 reload 即可生效
obd cluster reload biu
停止集群
stop
命令用于停止一个运行中的集群。如果 start
命令执行失败,但有进程没有退出,请使用 destroy
命令。
obd cluster stop biu
销毁集群
运行以下命令销毁集群:
# 启动集群时失败,可以能会有一些进程停留。
# 此时可用 -f 选项强制停止并销毁集群
obd cluster destroy biu
OBD其它命令参考
#查看帮助
obd -h
连接OceanBase数据库[oceanbase用户]
安装OceanBase数据库客户端 OBClient
1) 在线安装-本次不使用
如您的机器已添加OceanBase官方YUM源作为软件源,使用以下命令直接安装:
sudo yum install -y obclient
2) 离线安装-本次使用
前述已经下载了客户端离线包,分别安装OBClient库文件和软件包,采用本地安装:
sudo rpm -ivh libobclient-2.0.0-2.el7.x86_64.rpm obclient-2.0.0-2.el7.x86_64.rpm
连接数据库
注意:社区版没有oracle模式
obclient客户端工具连接
语法
obclient -u[用户名]@[租户名]#[集群名称] -P[端口号] -h[ip地址] -p[密码] -D[数据库名] -c
说明
- 连接语句中不带
-c
项的话,则连接至租户后 Hint 无法生效。 - 连接语句中不带
-D[数据库名]
项的话,则默认数据库同用户名一致
示例
运行以下命令,使用 OBClient 客户端连接 OceanBase 数据库:
obclient -h<your_ip> -P<observer_mysql_port> -uroot
如
进程第一次启动后,用mysql客户端登录(mysql版本5.5/5.6/5.7) ,root密码为空
obclient -h192.168.10.181 -P2881 -uroot
查看数据库
ob命令兼容部分mysql,查看数据库:
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| oceanbase |
| information_schema |
| mysql |
| SYS |
| LBACSYS |
| ORAAUDITOR |
| test |
+--------------------+
7 rows in set (0.006 sec)
创建租户(实例)
租户就是实例,是逻辑实例,没有单独的进程
获取集群可用资源信息
-- 查集群各个节点的剩余资源
select a.zone,concat(a.svr_ip,':',a.svr_port) observer, cpu_total, (cpu_total-cpu_assigned) cpu_free, round(mem_total/1024/1024/1024) mem_total_gb, round((mem_total-mem_assigned)/1024/1024/1024) mem_free_gb, usec_to_time(b.last_offline_time) last_offline_time, usec_to_time(b.start_service_time) start_service_time, b.status, b.build_version , usec_to_time(a.stop_time) stop_time
from __all_virtual_server_stat a join __all_server b on (a.svr_ip=b.svr_ip and a.svr_port=b.svr_port)
order by a.zone, a.svr_ip
;
-- 查询集群里当前资源使用细节
select t1.name resource_pool_name, t2.`name` unit_config_name, t2.max_cpu, t2.min_cpu, round(t2.max_memory/1024/1024/1024) max_mem_gb, round(t2.min_memory/1024/1024/1024) min_mem_gb, t3.unit_id, t3.zone, concat(t3.svr_ip,':',t3.`svr_port`) observer,t4.tenant_id, t4.tenant_name
from __all_resource_pool t1 join __all_unit_config t2 on (t1.unit_config_id=t2.unit_config_id)
join __all_unit t3 on (t1.`resource_pool_id` = t3.`resource_pool_id`)
left join __all_tenant t4 on (t1.tenant_id=t4.tenant_id)
order by t1.`resource_pool_id`, t2.`unit_config_id`, t3.unit_id
;
创建租户
-- 资源单位
CREATE resource unit my_unit_config max_cpu=4, min_cpu=4, max_memory='1G', min_memory='1G', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='10G';
-- 资源池
CREATE resource pool pool_mysql_01 unit = 'my_unit_config', unit_num = 1;
-- 租户
CREATE tenant mysql01 resource_pool_list=('pool_mysql_01'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
-- 查看
select * from __all_tenant\G
select t1.name resource_pool_name, t2.`name` unit_config_name, t2.max_cpu, t2.min_cpu, round(t2.max_memory/1024/1024/1024) max_mem_gb, round(t2.min_memory/1024/1024/1024) min_mem_gb, t3.unit_id, t3.zone, concat(t3.svr_ip,':',t3.`svr_port`) observer,t4.tenant_id, t4.tenant_name
from __all_resource_pool t1 join __all_unit_config t2 on (t1.unit_config_id=t2.unit_config_id)
join __all_unit t3 on (t1.`resource_pool_id` = t3.`resource_pool_id`)
left join __all_tenant t4 on (t1.tenant_id=t4.tenant_id)
order by t1.`resource_pool_id`, t2.`unit_config_id`, t3.unit_id
;
附录
参考文档
https://www.oceanbase.com/community/articles/1100213
https://open.oceanbase.com/quickStart
observer启动失败
启动过程
[ober@progs biu]$ obd cluster start biu
Get local repositories and plugins ok
Open ssh connection ok
Cluster param config check ok
Check before start observer ok
[WARN] (192.168.10.181) clog and data use the same disk (/ups)
Start observer ok
observer program health check ok
Connect to observer x
[ERROR] Failed to connect oceanbase-ce
[ober@progs biu]$ ps -ef|grep observer
ober 11004 10392 0 21:52 pts/0 00:00:00 grep --color=auto observer
[ober@progs biu]$
日志输出
[2021-08-28 21:50:41.106331] ERROR easy_client_dispatch (easy_client.c:30) [10651][8][YB42C0A80AB5-0005CA9EE244110E] [lt=5] [dc=0] easy_io_dispatch is failure: easy not started
[2021-08-28 21:50:46.120475] ERROR easy_client_dispatch (easy_client.c:30) [10651][8][YB42C0A80AB5-0005CA9EE244110F] [lt=12] [dc=0] easy_io_dispatch is failure: easy not started
[2021-08-28 21:50:46.708890] ERROR [SERVER.OMT] init (ob_multi_tenant.cpp:184) [10646][0][Y0-0000000000000000] [lt=6] [dc=0] node quota should greater than 1(node_quota_=0.000000000000000000e+00, ret=-4002) BACKTRACE:0x91613ee 0x912f6c1 0x21562ef 0x2155f3b 0x2155d02 0x4706f66 0x8ad6864 0x897e185 0x897382a 0x2117d91 0x7fc8137d03d5 0x2116ae9
[2021-08-28 21:50:46.709167] ERROR [SERVER] init_multi_tenant (ob_server.cpp:1163) [10646][0][Y0-0000000000000000] [lt=254] [dc=0] init multi tenant fail(ret=-4002) BACKTRACE:0x91613ee 0x912f6c1 0x211b3c4 0x211aeab 0x211ac11 0x2119ba8 0x897f0a2 0x897382a 0x2117d91 0x7fc8137d03d5 0x2116ae9
[2021-08-28 21:50:46.709346] ERROR [SERVER] init (ob_server.cpp:299) [10646][0][Y0-0000000000000000] [lt=120] [dc=0] init multi tenant fail(ret=-4002) BACKTRACE:0x91613ee 0x912f6c1 0x211b3c4 0x211aeab 0x211ac11 0x2119ba8 0x89755c0 0x2117d91 0x7fc8137d03d5 0x2116ae9
[2021-08-28 21:51:47.785700] ERROR [SERVER] main (main.cpp:488) [10646][0][Y0-0000000000000000] [lt=3] [dc=0] observer init fail(ret=-4002) BACKTRACE:0x91613ee 0x912f6c1 0x211b3c4 0x211aeab 0x211ac11 0x2119ba8 0x2118084 0x7fc8137d03d5 0x2116ae9
处理
标签:oceanbase,obd,OB,id,OceanBase,3.1,net,节点,unit 来源: https://www.cnblogs.com/binliubiao/p/15201453.html