服务器配置
12核48G,操作系统为centos 7.9系统。
本次测试使用单台服务器,创建单节点三副本的1-1-1集群。
Observer
zone1 172.27.17.82 2881 2882
zone2 172.27.17.82 3881 3882
zone3 172.27.17.82 4881 4882
OBProxy
172.27.17.82 2883 2884
1、服务器环境初始化
参考:DBA入门入门教程2.4节https://www.oceanbase.com/docs/community-tutorials-cn-10000000000012296
包括修改配置文件、关闭防火墙、关闭SELinux、配置时间同步服务、配置安装用户、磁盘文件系统划分等。
2、安装OceanBase包
1)使用root用户安装软件包:rpm -ivh oceanbase-ce-libs-3.1.1-4.el7.x86_64.rpm、rpm -ivh oceanbase-ce-3.1.1-4.el7.x86_64.rpm、rpm -ivh obproxy-3.2.0-1.el7.x86_64.rpm。
安装Obclient:rpm -ivh libobclient-2.0.0-2.el7.x86_64.rpm、rpm -ivh obclient-2.0.0-2.el7.x86_64.rpm。
2)查看目录结构
3)配置lib路径
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/oceanbase/lib' >> ~/.bash_profile
. ~/.bash_profile
4)初始化数据目录
mkdir -p /data/{observer01,observer02,observer03,obproxy}
mkdir -p /data/observer{01,02,03}/store/{sort_dir,sstable,clog,ilog,slog}
/data归属于admin:admin。
3、启动OBServer进程
1)启动Observer
cd /data/observer01/ && /home/admin/oceanbase/bin/observer -r "172.27.17.82:2882:2881;172.27.17.82:3882:3881;172.27.17.82:4882:4881" -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,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_size=8G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone1 -p 2881 -P 2882 -c 1 -d /data/observer01/store -i eth0 -l INFO
cd /data/observer02/ && /home/admin/oceanbase/bin/observer -r "172.27.17.82:2882:2881;172.27.17.82:3882:3881;172.27.17.82:4882:4881" -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,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_size=8G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone2 -p 3881 -P 3882 -c 1 -d /data/observer02/store -i eth0 -l INFO
cd /data/observer03/ && /home/admin/oceanbase/bin/observer -r "172.27.17.82:2882:2881;172.27.17.82:3882:3881;172.27.17.82:4882:4881" -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,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_size=8G,enable_syslog_recycle=True,max_syslog_file_count=10 -z zone3 -p 4881 -P 4882 -c 1 -d /data/observer03/store -i eth0 -l INFO
2)初始化集群
obclient -h172.27.17.82 -uroot -P2881 -p -c -A # 默认空密码
set session ob_query_timeout=1000000000;
alter system bootstrap ZONE 'zone1' SERVER '172.27.17.82:2882' , ZONE 'zone2' SERVER '172.27.17.82:3882' , ZONE 'zone3' SERVER '172.27.17.82:4882';
3)查看集群状态
SELECT * FROM __all_server;
SELECT svr_ip,svr_port, cpu_total, mem_total/1024/1024/1024,disk_total/1024/1024/1024, zone FROM __all_virtual_server_stat;
4)修改密码
alter user root identified by 'rootPWD123';
4、启动OBProxy
1)创建 OBProxy内部账户
obclient -h172.27.17.82 -uroot@sys -P2881 -prootPWD123 -c -A oceanbase。
create user proxyro identified by 'proxyroPWD123';
grant select on oceanbase.* to proxyro;
2)启动OBProxy
cd /data/obproxy
/home/admin/obproxy-3.2.0/bin/obproxy -p2883 -c obcluster -r "172.27.17.82:2881;172.27.17.82:3881;172.27.17.82:4881" -o "enable_cluster_checkout=false,enable_strict_kernel_release=false,enable_metadb_used=false"
3)修改OBProxy连接OceanBase集群用户proxyro的密码
obclient -h 172.27.17.82 -u root@proxysys -P 2883 -p #密码为空
alter proxyconfig set observer_sys_password = 'proxyroPWD123' ; #密码与前述proxyro用户一致
obclient -h172.27.17.82 -uroot@sys#obcluster -P2883 -prootPWD123 -c -A oceanbase #登录测试
5、创建业务租户
1)登录
obclient -h172.27.17.82 -uroot@sys#obcluster -P2883 -prootPWD123 -c -A oceanbase
2)查询系统资源总计资源
SELECT svr_ip,svr_port, cpu_total, mem_total/1024/1024/1024, disk_total/1024/1024/1024, zone FROM __all_virtual_server_stat;
3)查询租户已分配资源:
SELECT sum(c.max_cpu), sum(c.max_memory)/1024/1024/1024 FROM __all_resource_pool as a, __all_unit_config AS c WHERE a.unit_config_id=c.unit_config_id;
4)创建资源规格
create resource unit unit_wang max_cpu=2, min_cpu=2, max_memory='1g', min_memory='1g', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='50g';
select * from __all_unit_config;
5)创建资源池
create resource pool my_pool unit = 'unit_wang', unit_num = 1;
select * from oceanbase.gv$unit;
6)创建租户
create tenant tenant_henry resource_pool_list=('my_pool'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
select * from oceanbase.gv$tenant;
6、创建业务数据库和表
1)登录刚刚创建的业务租户tenant_henry
obclient -h 172.27.17.82 -uroot@tenant_henry#obcluster -P2883 -p -c -A。
2)创建数据库
create database mydb;
创建用户:
create user henry identified by "mydb";
grant all privileges on mydb.* to henry;
3)使用业务用户登录租户tenant_henry并创建业务表:
业务用户登录
obclient -h 172.27.17.82 -uhenry@tenant_henry#obcluster -P2883 -p -c -A。
创建业务表
CREATE TABLE `accountmoremenuinfo` (
`id` INT DEFAULT NULL,
`labelid` INT DEFAULT NULL,
`customname` VARCHAR(1000) DEFAULT NULL,
`icon` VARCHAR(1000) DEFAULT NULL,
`isshow` CHAR(1) DEFAULT NULL,
`url` VARCHAR(1000) DEFAULT NULL,
`linkmode` CHAR(1) DEFAULT NULL,
`type` VARCHAR(10) DEFAULT NULL,
`shoposition` CHAR(1) DEFAULT NULL,
`sortnum` INT DEFAULT NULL,
`sType` VARCHAR(255) DEFAULT NULL,
`iconType` VARCHAR(100) DEFAULT NULL,
`iconFrom` VARCHAR(100) DEFAULT NULL,
`iconImgSrc` VARCHAR(300) DEFAULT NULL
);
CREATE TABLE `actionexecutelog` (
`id` INT NOT NULL AUTO_INCREMENT,
`ACTIONID` TEXT,
`ACTIONTYPE` INT DEFAULT NULL,
`DATASHOWCOUNT` INT DEFAULT NULL,
`CREATEDATE` VARCHAR(80) DEFAULT NULL,
`CREATETIME` VARCHAR(64) DEFAULT NULL,
`ModifyDate` VARCHAR(80) DEFAULT NULL,
`ModifyTime` VARCHAR(64) DEFAULT NULL,
`clientip` VARCHAR(256) DEFAULT NULL,
`execresult` INT DEFAULT NULL,
`actiondbid` VARCHAR(1000) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_0826_actiondbid` (`actiondbid`),
KEY `idx_0826_createDate` (`CREATEDATE`)
) ;
CREATE TABLE `actionsetting` (
`id` INT NOT NULL AUTO_INCREMENT,
`ACTIONNAME` VARCHAR(1000) DEFAULT NULL,
`ACTIONCLASS` TEXT,
`TYPENAME` VARCHAR(160) DEFAULT NULL,
`ACTIONSHOWNAME` VARCHAR(1000) DEFAULT NULL,
`CREATEDATE` VARCHAR(80) DEFAULT NULL,
`CREATETIME` VARCHAR(64) DEFAULT NULL,
`MODIFYDATE` VARCHAR(80) DEFAULT NULL,
`MODIFYTIME` VARCHAR(64) DEFAULT NULL,
`javacode` TEXT,
`uuid` VARCHAR(50) DEFAULT '0',
`subcompanyid` INT DEFAULT NULL,
PRIMARY KEY (`id`)
) AUTO_INCREMENT=152 ;
查询业务表
7、遇到的问题
在配置OBProxy登录时,一定要注意proxyro的密码与配置的连接密码一致,即第5节提到的这两个命令:
create user proxyro identified by 'proxyroPWD123';
alter proxyconfig set observer_sys_password = 'proxyroPWD123' ;
因为proxyconfig里observer_sys_password配置的密码写错,导到初次使用OBProxy登录时失败,我排查了好半天。