1. 部署ob-deploy
sudo yum install -y yum-utils sudo yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/oceanbase.repo sudo yum install -y ob-deploy
2. 复制配置文件并修改
github地址:
根据部署计划选择相应的文件。
## only need to configure when remote login is required user: # username: your username username: root # password: your password if need password: '123456' # key_file: your ssh-key file path if need # port: your ssh port, default 22 # timeout: ssh connection timeout (second), default 30 oceanbase-ce: servers: # please don't use hostname, only ip can be supported - 192.168.32.131 global: # the working directory for oceanbase database. oceanbase database is started under this directory. this is a required field. home_path: /home/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 # 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: ens33 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. zone: zone1 cluster_id: 1 # please set memory limit to a suitable value which is matching resource. memory_limit: 8g # the maximum running memory for an observer system_memory: 4g # the reserved system memory. system_memory is reserved for general tenants. the default value is 30g. stack_size: 512k cpu_count: 10 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 major_freeze_duty_time: disable minor_freeze_times: 3 enable_separate_sys_clog: 0 enable_merge_by_turn: false datafile_disk_percentage: 20 # the percentage of the data_dir space to the total disk space. this value takes effect only when datafile_size is 0. the default value is 90. syslog_level: info # system log level. the default value is info. enable_syslog_wf: false # print system logs whose levels are higher than warning to a separate log file. the default value is true. enable_syslog_recycle: true # enable auto system log recycling or not. the default value is false. max_syslog_file_count: 4 # the maximum number of reserved log files before enabling auto recycling. the default value is 0. # observer cluster name, consistent with obproxy's cluster_name appname: obcluster # root_password: # root user password, can be empty root_password: admin # proxyro_password: # proxyro user pasword, consistent with obproxy's observer_sys_password, can be empty obproxy: # set dependent components for the component. # when the associated configurations are not done, obd will automatically get the these configurations from the dependent components. depends: - oceanbase-ce servers: - 192.168.32.131 global: listen_port: 2883 # external port. the default value is 2883. prometheus_listen_port: 2884 # the prometheus port. the default value is 2884. home_path: /root/obproxy # oceanbase root server list # format: ip:mysql_port;ip:mysql_port. when a depends exists, obd gets this value from the oceanbase-ce of the depends. rs_list: 192.168.32.131:2881 enable_cluster_checkout: false # observer cluster name, consistent with oceanbase-ce's appname. when a depends exists, obd gets this value from the oceanbase-ce of the depends. # cluster_name: obcluster skip_proxy_sys_private_check: true # obproxy_sys_password: # obproxy sys user password, can be empty. when a depends exists, obd gets this value from the oceanbase-ce of the depends. # observer_sys_password: # proxyro user pasword, consistent with oceanbase-ce's proxyro_password, can be empty. when a depends exists, obd gets this value from the oceanbase-ce of the depends.
3. 使用obd部署
echo "fs.aio-max-nr=1048576" >> /etc/sysctl.conf sysctl -p echo "* soft nofile 20480" >> /etc/security/limits.conf echo "* hard nofile 20480" >> /etc/security/limits.conf obd cluster deploy obcluster -c /etc/obdeploy.yaml obd cluster start obcluster
4. 连接ob
# 连接ob obclient -h127.0.0.1 -uroot@sys#obcluster -p2883 -p'your password' -doceanbase -a # 连接obproxy obclient -h 127.0.0.1 -p2883 -uroot@proxysys
5. 创建unit和资源池、租户
create resource unit lcxunit max_cpu=2,max_memory='2g',max_iops=10000,max_disk_size='2g',max_session_num=2000; create resource pool lcxpool unit='lcxunit',unit_num=1; create tenant if not exists test_tenant charset='utf8mb4', replica_num=1, zone_list=('zone1'), primary_zone='zone1', resource_pool_list=('lcxpool') set ob_tcp_invited_nodes='%'; drop tenant tenant_name [force]
示例 1:
下述语句展示了创建名为 test_tenant 的一个 3 副本的 mysql 租户(创建新租户默认是 mysql 租户)。
obclient> create tenant if not exists test_tenant charset='utf8mb4', replica_num=3, zone_list=('zone1','zone2','zone3'), primary_zone='zone1;zone2,zone3', resource_pool_list=('pool1')
示例 2:
下述语句展示了创建租户后,直接通过修改变量 ob_tcp_innvited_nodes 的值为 % 以便允许任何客户端 ip 连接该租户。
如果不调整,默认租户的连接方式为只允许本机的 ip 连接数据库。
obclient> create tenant if not exists test_tenant charset='utf8mb4', replica_num=3, zone_list=('zone1','zone2','zone3'), primary_zone='zone1;zone2,zone3', resource_pool_list=('pool1') set ob_tcp_invited_nodes='%'
示例说明如下:
- primary_zone 指该租户的表的分区 leader 所在的 zone ,例如,primary_ zone =’ zone1; zone2, zone3’ 表示该租户的表的分区 leader 在 zone1 上, 这时通过分号来分隔。
- zone2 和 zone3 通过逗号分割,表示 zone2 和 zone3 是同一优先级,但是比 zone1 优先级低。
- primary_zone 设置时,其值可以为 random(必须大写),表示随机。
普通租户的内存最小规格必须大于等于 5 gb,否则创建租户失败。
如果希望建立租户进行非常简单的功能测试,可以修改参数 alter system __min_full_resource_pool_memory 的值为 1073741824 来允许以最小 1 gb 内存的规格创建租户。
6. 常用运维语句(来自d88尊龙官网手机app官网)
查看服务器资源配置
可以通过以下 sql 查看当前的服务器资源配置。
其中,__all_server 表记录了了各 observer 的状态,__all_virtual_server_stat 记录了各 observer 的 cpu、内存与磁盘使用量。
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 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;
查看资源池配置
可以通过以下 sql 查看当前的资源池配置。
其中,__all_resource_pool 表记录了资源池的信息,__all_unit_config 记录了资源单元的配置,__all_unit 记录了资源单元的列表。
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;
查看 rootservice 执行的管理任务
可以通过以下 sql 查看 rootservice 最近执行的管理任务。
__all_rootservice_event_history 用于记录集群级的历史事件,如合并、server 上下线、负载均衡任务执行等。配置项 ob_event_history_recycle_interval 控制该表中记录历史事件的保留时间,默认为 7 天。
有关 ob_event_history_recycle_interval 配置项的详细信息,请参见《oceanbase 数据库 参考指南》中的 系统配置项 章节。
select date_format(gmt_create, '%b%d %h:%i:%s') gmt_create_ , module, event, name1, value1, name2, value2, rs_svr_ip from __all_rootservice_event_history where 1 = 1 order by gmt_create desc limit 20;
如何查看用户表
可以通过以下 sql 查看指定租户中所有用户表。
其中,gvtenant视图记录了租户信息 , gvtenant 视图记录了租户信息,gv tenant视图记录了租户信息,gvdatabase 记录了数据库信息,gvkatex parse error: expected group after '_' at position 14: table 记录了表信息,_̲_all_virtual_me…tenant_id 表示租户 id。
select t1.tenant_id,t1.tenant_name,t2.database_name,t3.table_id,t3.table_name,t3.tablegroup_id,t3.part_num,t4.partition_id,t4.zone,t4.svr_ip,t4.role, round(t4.data_size/1024/1024) data_size_mb from `gv$tenant` t1 join `gv$database` t2 on (t1.tenant_id = t2.tenant_id) join gv$table t3 on (t2.tenant_id = t3.tenant_id and t2.database_id = t3.database_id and t3.index_type = 0) left join `__all_virtual_meta_table` t4 on (t2.tenant_id = t4.tenant_id and ( t3.table_id = t4.table_id or t3.tablegroup_id = t4.table_id ) and t4.role in (1)) where t1.tenant_id = $tenant_id order by t3.tablegroup_id, t4.partition_id, t3.table_name ;
查看指定用户 sql 命令执行情况
可以通过以下 sql 查看指定用户执行的 sql 命令的执行情况。
其中 tenant_id 表示租户 id,user_name 表示用户名,ip_address 表示执行 sql 的节点的 ip 地址。
obclient> select /* read_consistency(weak) ob_querytimeout(100000000) */ substr(usec_to_time(request_time),1,19) request_time_, s.svr_ip, s.client_ip, s.sid,s.tenant_id, s.tenant_name, s.user_name, s.db_name, s.query_sql, s.affected_rows, s.return_rows, s.ret_code, s.event, s.elapsed_time, s.queue_time, s.execute_time, round(s.request_memory_used/1024/1024,2) req_mem_mb, plan_type, is_executor_rpc, is_inner_sql from gv$sql_audit s where s.tenant_id=and user_name=' ' and svr_ip in (' ') order by request_time desc limit 100;
查看物理机资源使用情况
可以通过以下 sql 查看指定租户在物理机上的资源使用情况。
其中 gvmemstore 视图记录了租户的内存使用情况 , memstore 视图记录了租户的内存使用情况, memstore视图记录了租户的内存使用情况,tenant_id 表示租户 id。
obclient> select tenant_id, ip, round(active/1024/1024) active_mb, round(total/1024/1024) total_mb, round(freeze_trigger/1024/1024) freeze_trg_mb, round(mem_limit/1024/1024) mem_limit_mb , freeze_cnt , round((active/freeze_trigger),2) freeze_pct, round(total/mem_limit, 2) mem_usage from `gv$memstore` where $tenant_id in (1001) order by tenant_id, ip;
查看合并进度
可以通过以下 sql 查看合并进度。
其中查询结果中的 merge_process 列表示当前合并进度的百分比。
select zone,svr_ip,major_version,min_version,ss_store_count,merged_ss_store_count,modified_ss_store_count,merge_start_time,merge_finish_time,merge_process from __all_virtual_partition_sstable_image_info;
查看分区信息
可以通过以下 sql 查询指定租户的分区信息。
其中 __all_virtual_partition_info 记录了分区信息,$tenant_id 表示租户 id。
select table_id, partition_idx, usec_to_time(min_log_service_ts), time_to_sec( now())-time_to_sec(usec_to_time(min_log_service_ts)) delta_time from __all_virtual_partition_info where tenant_id=$tenant_id;
7. 小脚本(持续更新)
关于 shell 变量取值:
#!/bin/bash function start_cluster() { obd cluster start obcluster } function user_conn() { dbname=$2 echo ${dbname:-oceanbase} obclient -h127.0.0.1 -uroot@$1\#obcluster -p2883 -p'your password' -d${dbname:-oceanbase} -a } function stop_cluster() { obd cluster stop obcluster } case "$1" in 'start') start_cluster ;; '-u') user_conn $2 $3 ;; 'stop') stop_cluster ;; *) echo "ob-manager start|-u|stop ..." esac
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。