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

軟件介質清單

官網介質下載地址

image-20210828112420024

共6個rpm包,下載后上傳至安裝主機soft目錄。

  • OBD: OceanBase Database Deployer社區版部署工具
  • oceanbase-ce: OceanBase數據庫社區版
  • OceanBase libs: oceanbase運行時所依賴的部分三方動態庫
  • Obproxy : oceanbase數據庫專用的代理服務器
  • OBClient:obclient交互式和批量處理查詢工具
  • LibOBClient:obclient的依賴包

下載社區版軟件

yum源上rpm包信息

image-20210828113257031

下載軟件
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

image-20210828203151827

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

image-20210828204514514

配置本地oceanbase鏡像[oceanbase用戶]

當前主機不能連接公網,將之前OceanBase數據庫的rpm離線軟件包鏡像到本地。

檢查離線包
ls ./*.rpm

image-20210828204555714

將OceanBase數離線軟件包加入本地鏡像

將OceanBase數據庫的離線軟件包加入本地鏡像:

which obd
obd mirror clone *.rpm

image-20210828205316677

clone命令執行后,將本地上rpm包復制到~/.obd/mirror目錄上

image-20210828210517441

image-20210828210625193

yaml配置文件准備[oceanbase用戶]

yaml說明

yaml是批量安裝調用的內容,當前OceanBase提供多種類型配置文件,分別為mini-local-example.yaml、mini-single-example.yaml、mini-distributed-example.yaml。

image-20210828115951250

根據您的資源條件選擇正確的配置文件:

小規格開發模式

適用於個人設備(內存不低於 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

image-20210828210310114

說明:obd安裝首先默認使用remote官方的鏡像進行安裝,remote失敗時,OBD才會嘗試使用local鏡像,當前部署集群成功。

image-20210828211342307

建議官方添加參數,增加obd mirror delete選項,刪除remote鏡像路徑,或者增加disable選項,禁用remote鏡像路徑,或者增加其它參數,優先使用本地mirror。

使用本地local倉庫安裝
mv ~/.obd/mirror/remote ~/.obd/mirror/remote_bak

如果要本地安裝需刪除或者重命名remote目錄

image-20210828211052768

image-20210828211507572

啟動集群
obd cluster start <deploy_name>

如:

[oceanbase@oceanbase ~]$ obd cluster start biu

注:WARN是當前主機僅8G內存,低於建議的最低配置16G,測試環境不影響使用。

image-20210828221656650

查看集群狀態
#查看obd管理的集群列表
obd cluster list


#查看集群狀態
obd cluster display biu

image-20210828221726001

image-20210828222123948

修改配置

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

image-20210828204720550

連接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

image-20210828222317690

連接數據庫

注意:社區版沒有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

image-20210828222550545

查看數據庫

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
;

image-20210828224321265

創建租戶

-- 資源單位
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

處理

image-20210828221927949


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM