部署社区版单节点OB(未使用obshell)

57 阅读4分钟

说明:

  • 没有使用obshell进行运维管理
  • 所需安装包

1. 硬件准备

1.1. 配置:

系统:Alibaba Cloud Linux release 3 (OpenAnolis Edition)

内核版本:5.10.134-19.1.al8.x86_64

CPU:4C

内存:32G

挂载盘:500G

1.2. 规划配置:

/data 200G --根据实际数据量

/home/admin/oceanbase 200G ---安装需求至少 200 G 空间以保存 7 天及以上的日志。

/redo 80G ----事务日志文件大小 = 增量数据内存上限的 3~4 倍。

2. 安装前准备:

2.1. 检查硬件:

  • 查看操作系统:cat /etc/redhat-release。需满足
  • 查看内核:uname -r 。OceanBase 数据库要求操作系统为 3.10.0 及以上。
  • 查看内存:free -g。确保可用内存小于配置文件中的 memory_limit 值。

清理内存:sudo sysctl -w vm.drop_caches=3或sudo echo 3 > /proc/sys/vm/drop_caches

2.2. 创建用户:

创建用户:useradd -U admin -d /home/admin -s /bin/bash

设置密码:passwd admin

授权:chown -R admin:admin /redo

chown -R admin:admin /data/

chown -R admin:admin /home/admin

添加sudo权限:vim /etc/sudoers

Same thing without a password

%wheel ALL=(ALL) NOPASSWD: ALL

admin ALL=(ALL) NOPASSWD: ALL

2.3. 磁盘做LVM:

pvcreate /dev/nvme1n1

pvscan

vgcreate、vgscan

lvcreate、lvscan

格式化、挂载

mkfs -t ext4 /dev/vbirdvg/data

mkfs -t ext4 /dev/vbirdvg/build

mkfs -t ext4 /dev/vbirdvg/redo

mkdir /data

mkdir /redo

mkdir -p /home/admin/oceanbase

mount /dev/vbirdvg/data /data

mount /dev/vbirdvg/build /home/admin/oceanbase

mount /dev/vbirdvg/redo /redo/

修改配置文件:

limits.conf

在 /etc/security/limits.conf 配置文件中添加以下内容:

root soft nofile 655350 
root hard nofile 655350
* soft nofile 655350
* hard nofile 655350
* soft stack unlimited
* hard stack unlimited
* soft nproc 655360
* hard nproc 655360
* soft core unlimited
* hard core unlimited

退出重新登录后ulimit -a生效

sysctl.conf

#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_forward = 0

net.ipv4.conf.default.rp_filter = 1

net.ipv4.conf.default.accept_source_route = 0

net.ipv4.tcp_syncookies = 1

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_slow_start_after_idle=0

vm.swappiness = 0

vm.min_free_kbytes = 2097152

vm.overcommit_memory = 0

fs.file-max = 6573688

fs.pipe-user-pages-soft = 0

#修改进程可以拥有的虚拟内存区域数量

vm.max_map_count = 655360

#此处为 OceanBase 数据库的 data 目录

kernel.core_pattern = /data/core-%e-%p-%t

2.4. 关闭防火墙

systemctl stop firewalld

systemctl status firewalld

2.5. 关闭selinux

vi /etc/selinux/config

修改:SELINUX=disabled

2.6. 配置时钟同步

单节点部署不需要

2.7. 互信

admin用户可登录自己

#ssh-keygen -t rsa

#ssh-copy-id -i id_rsa.pub admin@172.16.79.89

验证:admin用户执行ssh 'admin@172.16.79.89' --不需要输入密码表示成功

注意

1、不要更改/etc/hosts文件。

2、其中172.16.79.89为本主机的内网IP。

3. 安装

3.1. 安装OBD:

rpm -ivh ob-deploy-3.5.0-5.el8.x86_64.rpm

source /etc/profile.d/obd.sh

3.2. 配置OBD:

  1. 禁用远程仓库:obd mirror disable remote
  2. 将安装包添加至本地镜像库:obd mirror clone *.rpm
  3. 查看本地镜像库:obd mirror list local
  4. 修改参数文件

user:

username: admin

key_file: /home/admin/.ssh/authorized_keys

servers:

# Please don't use hostname, only IP can be supported

- 172.16.79.89

global:

# The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.

home_path: /home/admin/oceanbase/observer

# The directory for data storage. The default value is $home_path/store.

data_dir: /data

# The directory for clog, ilog, and slog. The default value is the same as the data_dir value.

redo_dir: /redo

# Starting from observer version 4.2, the network selection for the observer is based on the 'local_ip' parameter, and the 'devname' parameter is no longer mandatory.

# If the 'local_ip' parameter is set, the observer will first use this parameter for the configuration, regardless of the 'devname' parameter.

# If only the 'devname' parameter is set, the observer will use the 'devname' parameter for the configuration.

# If neither the 'devname' nor the 'local_ip' parameters are set, the 'local_ip' parameter will be automatically assigned the IP address configured above.

# devname: eth0

mysql_port: 2881 # External port for OceanBase Database. The default value is 2881. DO NOT change this value after the cluster is started.

rpc_port: 2882 # Internal port for OceanBase Database. The default value is 2882. DO NOT change this value after the cluster is started.

obshell_port: 2886 # Operation and maintenance port for Oceanbase Database. The default value is 2886. This parameter is valid only when the version of oceanbase-ce is 4.2.2.0 or later.

zone: zone1

# if current hardware's memory capacity is smaller than 50G, please use the setting of "mini-single-example.yaml" and do a small adjustment.

memory_limit: 0 # The maximum running memory for an observer

memory_limit_percentage: 70

# The reserved system memory. system_memory is reserved for general tenants. The default value is 30G.

system_memory: 0MB

datafile_size: 140GB # Size of the data file.

#cpu_count: 16

log_disk_size: 55GB # The size of disk space used by the clog files.

ob_sql_work_area_percentage: 10

#enable_syslog_wf: false # Print system logs whose levels are higher than WARNING to a separate log file. The default value is true.

max_syslog_file_count: 0 # The maximum number of reserved log files before enabling auto recycling. The default value is 0.

enable_syslog_recycle: true

# root_password: # root user password, can be empty

connect_timeout: 10000

ob_query_timeout: 300000000

ob_trx_timeout: 300000000
  1. 部署集群: obd cluster deploy obtest -c test-local.yaml
  2. 启动集群: obd cluster start obtest
  3. 查看集群列表:obd cluster list
  4. 查看集群及root初始密码:obd cluster display obtest

3.3. 连接集群:

命令行连接:(使用obclient或mysql命令都可以)

obclient -h127.1 -uroot@sys -p -A -C

查看数据库可用资源

select a.zone, a.SVR_IP,a.SVR_PORT, b.status,

cpu_capacity,cpu_assigned_max,cpu_capacity-cpu_assigned_max as cpu_free,

round(memory_limit/1024/1024/1024,2) as memory_total_gb,

round((memory_limit-mem_capacity)/1024/1024/1024,2) as system_memory_gb,

round(mem_assigned/1024/1024/1024,2) as mem_assigned_gb,

round((mem_capacity-mem_assigned)/1024/1024/1024,2) as memory_free_gb,

round(log_disk_capacity/1024/1024/1024,2) as log_disk_capacity_gb,

round(log_disk_assigned/1024/1024/1024,2) as log_disk_assigned_gb,

round((log_disk_capacity-log_disk_assigned)/1024/1024/1024,2) as log_disk_free_gb,

round((data_disk_capacity/1024/1024/1024),2) as data_disk_gb,

round((data_disk_in_use/1024/1024/1024),2) as data_disk_used_gb,

round((data_disk_capacity-data_disk_in_use)/1024/1024/1024,2) as data_disk_free_gb

from gv$ob_servers a join oceanbase.DBA_OB_SERVERS b on a.zone=b.zone\G;

租户可用资源:

CPU:3 C,内存:13GB,日志磁盘空间51GB, 数据磁盘空间139.99GB。

4. 数据库管理

4.1. 建议:

OceanBase 创建资源池默认只允许大于 5G(包括 5G)内存规格,如果创建小规格的unit需要手动修改下参数__min_full_resource_pool_memory为1G:

alter system set __min_full_resource_pool_memory=1073741824;

验证:

select * from __all_virtual_sys_parameter_stat where name='__min_full_resource_pool_memory';

4.2. 创建租户:

1、创建unit规格:

create resource unit if not exists sp_trans_test MAX_CPU=1, MEMORY_SIZE='2G';

---可修改unit规格:

alter RESOURCE UNIT sp_trans_test MAX_CPU=1, MEMORY_SIZE='2G' MAX_IOPS=128000000, MIN_IOPS=128000000, LOG_DISK_SIZE='5G';

---查看unit

select * from __all_unit;

2、创建资源池:

create resource pool if not exists sp_trans_test unit='sp_trans_test', unit_num=1;

--查看资源池

select * from __all_resource_pool\G;

3、创建租户:

create tenant if not exists sp_trans_test RESOURCE_POOL_LIST=('sp_trans_test') set ob_tcp_invited_nodes='%';

--查看租户:select * from __all_tenant\G;

5. 主机重启后:

需要admin用户手动启动,命令:

/home/admin/oceanbase/bin/obshell admin start --takeover 0 --ob

obd cluster start obtest

网页访问:http://39.97.32.230:2886/ 可以白屏管理租户。