作者简介:李寅,软件测试工程师
1. 实验环境
Centos7.3;64G内存;16CPU; IP 10.137.32.175;
2. 服务器环境初始化
在开始实验前,需对系统环境进行初始化,初始化步骤参考OceanBase官方文档:https://open.oceanbase.com/blog/8600144 。
3. 软件下载
本次实验采取本地安装的方式,因此需要先从社区(https://www.oceanbase.com/softwareCenter/community)下载安装软件:obproxy-3.2.0-1.el7.x86_64.rpm、oceanbase-ce-3.1.1-4.el7.x86_64.rpm、oceanbase-ce-libs-3.1.1-4.el7.x86_64.rpm
4. 安装软件
[admin@admin lastest]$ sudo rpm -ivh oceanbase-ce-libs-3.1.1-4.el7.x86_64.rpm
[admin@admin lastest]$ sudo rpm -ivh oceanbase-ce-3.1.1-4.el7.x86_64.rpm
[admin@admin lastest]$ sudo rpm -ivh obproxy-3.2.0-1.el7.x86_64.rpm
5. 查看已安装软件包
[admin@admin ~]$ rpm -qa |grep ocean
[admin@admin ~]$ rpm -qa |grep obproxy
6. 初始化目录数据
这一步只用于第一次部署时执行。如果是重复部署,目录已经创建的情况下,不需要再执行这一步。手动部署时,OceanBase 节点上的相关目录都需要手动创建。
6.1创建data目录及redo目录
6.2创建三个节点的运行目录及目录链接关系
节点1:
节点2:
节点3:
7. 配置环境变量
7.1配置lib信息
[admin@admin ~]$ echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/oceanbase/lib' >> ~/.bash_profile
[admin@admin ~]$ . ~/.bash_profile
7.2启动Observer进程
节点1:
[admin@admin ~]$ cd /data/obdemo1/ && /home/admin/oceanbase/bin/observer -i eth0 -p 2881 -P 2882 -z zone1 -d ~/oceanbase/store/obdemo1 -r '10.137.32.175:2882:2881;10.137.32.175:3882:3881;10.137.32.175:4882:4881' -c 20210912 -n obdemo -o "memory_limit=8G,cache_wash_threshold=1G,__min_full_resource_pool_memory=268435456,system_memory=3G,memory_chunk_cache_size=128M,cpu_count=16,net_thread_count=4,datafile_size=20G,stack_size=1536K,config_additional_dir=/data/obdemo1/etc3;/redo/obdemo1/etc2" -d ~/oceanbase/store/obdemo1
7.3查看监听端口
检查OBserver节点进程启动正常,主要看端口监听是否正常。
8. bootstrap集群
当 OceanBase 集群节点正常启动,并且监听正常时,连接到该节点(通过 2881 端口直连),初始化集群。初始密码是空。
[admin@admin obdemo1]$ mysql -h 10.137.32.175 -u root -P 2881 -p -c -A MySQL [(none)]> set session ob_query_timeout=10000000000; alter system bootstrap ZONE 'zone1' SERVER '10.137.32.175:2882';
检查集群状态:
9. 添加另外两个节点
节点2:
[admin@admin obdemo2]$ cd /data/obdemo2/ && /home/admin/oceanbase/bin/observer -i eth0 -p 3881 -P 3882 -z zone2 -d ~/oceanbase/store/obdemo2 -r '10.137.32.175:3882:3881' -c 20210912 -n obdemo -o "memory_limit=16G,cache_wash_threshold=1G,__min_full_resource_pool_memory=268435456,system_memory=6G,memory_chunk_cache_size=128M,cpu_count=8,net_thread_count=4,datafile_size=12G,stack_size=1536K,config_additional_dir=/data/obdemo2/etc3;/redo/obdemo2/etc2" -d ~/oceanbase/store/obdemo2
节点3:
[admin@admin obdemo2]$ cd /data/obdemo3/ && /home/admin/oceanbase/bin/observer -i eth0 -p 4881 -P 4882 -z zone3 -d ~/oceanbase/store/obdemo3 -r '10.137.32.175:4882:4881' -c 20210912 -n obdemo -o "memory_limit=16G,cache_wash_threshold=1G,__min_full_resource_pool_memory=268435456,system_memory=6G,memory_chunk_cache_size=128M,cpu_count=8,net_thread_count=4,datafile_size=12G,stack_size=1536K,config_additional_dir=/data/obdemo3/etc3;/redo/obdemo3/etc2" -d ~/oceanbase/store/obdemo3
10. 添加observer
10.1添加zone2,zone3并启动
MySQL [(none)]>obclient -h 192.168.5.200 -u root -P 2881 -p -c -A oceanbase
MySQL [(none)]>alter system add zone 'zone2' region 'default_region';
MySQL [(none)]>alter system add zone 'zone3' region 'default_region';
MySQL [(none)]>alter system start zone 'zone2';alter system start zone 'zone3';
MySQL [(none)]> use oceanbase
MySQL [oceanbase]> select * from __all_zone where name in ('region','status','zone_type')
10.3添加oberver
MySQL [oceanbase]> alter system add server '192.168.5.200:3882' zone 'zone2'; MySQL [oceanbase]> alter system add server '192.168.5.200:4882' zone 'zone3'; MySQL [oceanbase]> SELECT svr_ip,svr_port, cpu_total, mem_total, disk_total, zone FROM __all_virtual_server_stat ;
MySQL [oceanbase]> select * from __all_server;
11. 部署obproxy
obproxy跟OB集群通信是使用sys租户内的一个内部账户proxyro。这个账户需要创建。
mysql -h127.1 -uroot@sys -P2881 -p -c -A oceanbase MySQL [oceanbase]> create user proxyro identified by 'proxyro123456'; MySQL [oceanbase]> grant select on oceanbase.* to proxyro;
启动obproxy
[admin@admin ~]$ mkdir -p /data/obproxy [admin@admin bin]$ cd /data/obproxy && /home/admin/obproxy-3.2.0/bin/obproxy -p2883 -c 20210912 -r "10.137.32.175:2881;10.137.32.175:3881;10.137.32.175:4881" -o "enable_cluster_checkout=false,enable_strict_kernel_release=false,enable_metadb_used=false"
[admin@admin obproxy]$ mysql -h127.1 -uroot@proxysys -P2883 -p MySQL [(none)]> alter proxyconfig set obproxy_sys_password='proxysys123456'; MySQL [(none)]> alter proxyconfig set observer_sys_password='proxyro123456'; MySQL [(none)]> show proxyconfig like '%sys_password%'; mysql -h127.1 -uroot@sys#obcluster -P2883 -p123456 -c -A oceanbase
12. 创建租户、数据库及表
12.1查看集群可用资源
mysql -h127.1 -uroot@sys#obdemo -P2883 -p123456 -c -A oceanbase
MySQL [oceanbase]> select a.zone,concat(a.svr_ip,':',a.svr_port) observer, cpu_total, cpu_assigned, (cpu_total-cpu_assigned) cpu_free, mem_total/1024/1024/1024 mem_total_gb, mem_assigned/1024/1024/1024 mem_assign_gb, (mem_total-mem_assigned)/1024/1024/1024 mem_free_gb 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;
12.2已分配资源池情况
MySQL [oceanbase]> select t1.name resource_pool_name, t2.`name` unit_config_name, t2.max_cpu, t2.min_cpu, t2.max_memory/1024/1024/1024 max_mem_gb, 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;
12.3 创建资源单元
MySQL [oceanbase]> create resource unit my1_unit_config max_cpu=1, min_cpu=1, max_memory='512M', min_memory='512M', max_iops=1000, min_iops=1000, max_session_num=100, max_disk_size='10G';
12.4创建资源池
create resource pool my_pool unit = 'my1_unit_config', unit_num = 1;
12.5 创建租户
create tenant pay_mysql_tat resource_pool_list=('my_pool'), primary_zone='RANDOM',comment 'mysql tenant/instance' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
12.6 创建数据库及表
登陆新建的租户
[admin@admin ~]$ mysql -h 127.1 -uroot@pay_mysql_tat#obdemo -P2883 -p -c -A oceanbase create database mytestdb; use mytestdb; create table test1(id int primary key,name varchar(256),age int,sex int); select * from test1; desc test1;
insert into test1 values(1,'ly3',1,0),(2,'ly2',2,0),(3,'ly',3,1);
13. 错误记录
13.1错误1:
因为本次实验是在一台服务器模拟三节点,在启动OBServer时,第一次本人是在同一路径下起多个OBServer进程,报错如下;后改为在起多个进程时每个进程指定不同的启动路径,解决此文图。
13.2 错误2:
因为本次实验是在一台服务器模拟三节点,在启动第二个OBServer进程时,未报错,但端口号并未监听,如下图:
查看错误日志后发现是磁盘空间不够,如下图。将datafile_size参数改小后解决。
结束语
OceanBase社区版入门到实战教程直播正在进行中~
快和小伙伴一起进群交流学习吧~
加入直播群方式一:
钉钉群号3255 4020
加入直播群方式二:
扫码下方二维码加入