实验要求
练习目的
本次练习目的掌握 OceanBase 集群的手动部署技能,理解进程的相关目录、集群初始化、OBProxy和 OB 集群关系等。
练习条件
有笔记本或服务器,内存至少12G 。
练习内容
请记录并分享下列内容:
(必选)手动部署一个 OB 单副本集群,包括一个 OBProxy 节点。
(必选)创建一个业务租户、一个业务数据库,以及一些表等。
(可选)如果单台服务器内存有32G,或者有三台服务器,改为部署一个 OB 三副本集群,包括一个 OBProxy 节点。
(可选)如果有三台服务器并且服务器内存有 32 G,可以单服务器内启动 2 个节点,实现 1-1-1 扩容到 2-2-2 。
参考资料
社区版官网-文档-学习中心-入门教程:如何手动部署 OceanBase 集群
社区版官网-博客-入门实战:如何手动部署 OceanBase 集群
练习要求
请用文章记录实践练习的环境、过程和问题(可选)、总结等,图文并茂。如果企业内部有安全限制,可以对 IP 、 密码等打码或者修改。如果不允许截图,可以用文字适当补充说明。
分享的文章行文语句通顺,有条理,字数不少于 500 字。
发布:OceanBase 社区版官网问答区或社区版博客(准备word 版本稿件给运营 @Hope,钉钉:hopelee21@dingtalk.com),也可以在CSDN、开源中国、Itpub、知乎等技术社区发布,在问答区附上作业链接及简要说明。
评分
OBCP考试券获取说明
OceanBase 入门到实战教程总共有 6 个练习,完成必选的 4 个练习,表示你掌握教程分享的学习技能,可以结业,并赠送全额 OBCP 考试券。本次练习为必选练习,请同学们积极参与哦~
其他说明
后期运营会针对同学的分享进行优秀评选,符合作业奖励规则的同学会给予积分奖励。
优秀作品 OceanBase 会在官方渠道实名推广。
我们欢迎同学们通过提 Issue、提交Pull Request 等方式参与 OceanBase github 社区 贡献。
实践过程如下
实验环境
笔记本基本信息: MacBook Pro 10.15.7/ Intel i7 3.1 GHz/16G/500G VMware Fusion 12.1.2 Guest OS:centos 7.9 12G内存 40G磁盘空间
初始化虚拟机环境(这里的步骤同修改内核参数,修改安全参数限制,生产环境需要按这个修改)
建议生产环境调整参数参考oceanbase官方文档
或者使用obd工具进行生产环境部署
[admin@localhost ~]$ cat /etc/sysctl.conf # sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). # 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 = 129 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_slow_start_after_idle=0 vm.swappiness = 0 vm.min_free_kbytes = 2097152 vm.max_map_count=655360 fs.aio-max-nr=1048576 [admin@localhost ~]$
修改会话变量设置,更改完后需要退出后重新登陆会话,检查是否生效
[admin@localhost ~]$ cat /etc/security/limits.conf * soft nofile 655360 * hard nofile 655360 * soft nproc 655360 * hard nproc 655360 * soft core unlimited * hard core unlimited * soft stack unlimited * hard stack unlimited
检查并关闭防火墙
[root@localhost ~]# systemctl disable firewalld [root@localhost ~]# systemctl stop firewalld [root@localhost ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1)
关闭SELinux
更改配置文件后重启生效,或者用setenforce 0命令可立即生效。
[root@localhost ~]# vi /etc/selinux/config [root@localhost ~]# cat /etc/selinux/config SELINUX=disabled SELINUXTYPE=targeted
创建用户,由于OceanBase rpm安装包默认将软件安装在/home/admin目录下,创建名为admin的用户可以简化部署过程,这里顺便给用户增加了sudo权限。
[root@38c7642a747b /]# useradd admin [root@38c7642a747b /]# passwd admin [root@38c7642a747b /]# usermod admin -G wheel [root@38c7642a747b /]# id admin uid=1000(admin) gid=1000(admin) groups=1000(admin),10(wheel)
下载并安装软件包
手动部署需要下载observer、obproxy软件包,另外也下载了obclient用户连接集群,还需要下载libobclient(obclient库),oceanbase-ce-libs库两个包,我这里下载在root用户的home目录下
https://mirrors.aliyun.com/oceanbase/community/stable/el/7/x86_64/ [root@localhost ~]# ll total 321948 -rw-r--r-- 1 root root 864276 Apr 7 12:01 libobclient-2.0.1-3.el7.x86_64.rpm -rw-r--r-- 1 root root 181499124 Apr 7 11:58 obclient-2.0.1-2.el7.x86_64.rpm -rw-r--r-- 1 root root 33460800 Apr 26 14:44 ob-deploy-1.3.3-11.el7.x86_64.rpm -rw-r--r-- 1 root root 9911060 Mar 30 20:37 obproxy-ce-3.2.3-2.el7.x86_64.rpm -rw-r--r-- 1 root root 49391004 Apr 15 17:04 oceanbase-ce-3.1.3-10100032022041510.el7.x86_64.rpm -rw-r--r-- 1 root root 158952 Apr 15 17:04 oceanbase-ce-libs-3.1.3-10100032022041510.el7.x86_64.rpm -rw-r--r-- 1 root root 49357724 Apr 15 17:04 oceanbase-ce-utils-3.1.3-10100032022041510.el7.x86_64.rpm
下载的rpm进行安装后如下
[root@localhost ~]# rpm -qa|egrep 'oceanbase|ob-|obclient|libob' libobclient-2.0.1-3.el7.x86_64 oceanbase-ce-libs-3.1.3-10100032022041510.el7.x86_64 oceanbase-ce-utils-3.1.3-10100032022041510.el7.x86_64 obclient-2.0.1-2.el7.x86_64 oceanbase-ce-3.1.3-10100032022041510.el7.x86_64 ob-deploy-1.3.3-11.el7.x86_64
安装目录是下面这个样子,oceanbase和obproxy各有自己的安装目录,都处于/home/admin目录下
[root@localhost ~]# tree /home/admin/oceanbase/ /home/admin/oceanbase/ ├── bin │ ├── import_time_zone_info.py │ └── observer ├── etc │ ├── observer.config.bin │ ├── observer.config.bin.history │ ├── oceanbase_upgrade_dep.yml │ ├── priv_checker.py │ ├── timezone_V1.log │ ├── upgrade_checker.py │ ├── upgrade_cluster_health_checker.py │ ├── upgrade_post_checker.py │ ├── upgrade_post.py │ ├── upgrade_pre.py │ ├── upgrade_rolling_post.py │ └── upgrade_rolling_pre.py ├── etc2 │ ├── observer.conf.bin │ └── observer.conf.bin.history ├── etc3 │ ├── observer.conf.bin │ └── observer.conf.bin.history ├── lib │ ├── libaio.so -> libaio.so.1.0.1 │ ├── libaio.so.1 -> libaio.so.1.0.1 │ ├── libaio.so.1.0.1 │ ├── libmariadb.so -> libmariadb.so.3 │ └── libmariadb.so.3 ├── log │ ├── election.log │ ├── election.log.wf │ ├── observer.log │ ├── observer.log.20220429181936 │ ├── observer.log.20220429184753 │ ├── observer.log.20220429193736 │ ├── observer.log.20220430110543 │ ├── observer.log.20220430115046 │ ├── observer.log.20220430131545 │ ├── observer.log.20220430151607 │ ├── observer.log.20220430160504 │ ├── observer.log.20220430161552 │ ├── observer.log.wf │ ├── observer.log.wf.20220429181936 │ ├── observer.log.wf.20220429184753 │ ├── observer.log.wf.20220429193736 │ ├── observer.log.wf.20220430110543 │ ├── observer.log.wf.20220430115046 │ ├── observer.log.wf.20220430131545 │ ├── observer.log.wf.20220430151607 │ ├── observer.log.wf.20220430160504 │ ├── observer.log.wf.20220430161552 │ ├── rootservice.log │ └── rootservice.log.wf └── run ├── mysql.sock └── observer.pid 7 directories, 49 files
初始化数据目录
在虚拟机添加第二个磁盘,这里就把数据目录直接放到了/oceanbase下,创建目录的命令做了一些调整
# 格式化分区进行挂载 parted /dev/sdb mklabel gpt parted /dev/sdb mkpart primary 500m 100% parted /dev/sdb print mkfs.xfs -f /dev/sdb blkid /dev/sdb [root@localhost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 6.3G 0 6.3G 0% /dev tmpfs tmpfs 6.3G 0 6.3G 0% /dev/shm tmpfs tmpfs 6.3G 12M 6.3G 1% /run tmpfs tmpfs 6.3G 0 6.3G 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 17G 9.8G 7.3G 58% / /dev/sdb xfs 20G 19G 1.8G 92% /oceanbase /dev/sda1 xfs 1014M 151M 864M 15% /boot tmpfs tmpfs 1.3G 0 1.3G 0% /run/user/0 [root@localhost ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Thu Apr 28 19:58:01 2022 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/centos-root / xfs defaults 0 0 UUID=5c628f9c-13de-4856-9353-53ee2971eb42 /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID="1c3bfe1c-354b-4ce7-b4e8-d67713a364ae" /oceanbase xfs defaults 0 0 /oceanbase/swapfile swap swap no 0 0 [root@localhost ~]# ll /oceanbase/store/obdemo/ total 0 drwxr-xr-x 2 admin admin 16 Apr 30 18:31 clog drwxr-xr-x 2 admin admin 6 Apr 29 17:25 etc2 drwxr-xr-x 2 admin admin 6 Apr 29 17:25 etc3 drwxr-xr-x 2 admin admin 15 May 1 12:25 ilog drwxr-xr-x 2 admin admin 15 Apr 29 18:26 slog drwxr-xr-x 2 admin admin 24 Apr 29 18:03 sstable
启动observer进程
由于上面更改了目录结构,相应的启动命令也需要调整一下,去掉关于/data, /redo路径的设置
[admin@localhost ~]$ echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/oceanbase/lib' >> ~/.bash_profile [admin@localhost ~]$ . ~/.bash_profile [admin@localhost ~]$ cd ~/oceanbase && bin/observer -i lo -p 2881 -P 2882 -z zone1 -d /oceanbase/store/obdemo -r '127.0.0.1:2882:2881' -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=8,net_thread_count=2,datafile_size=10G,stack_size=1536K" -d /oceanbase/store/obdemo bin/observer -i lo -p 2881 -P 2882 -z zone1 -d /oceanbase/store/obdemo -r 127.0.0.1:2882:2881 -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=8,net_thread_count=2,datafile_size=10G,stack_size=1536K -d /oceanbase/store/obdemo devname: lo mysql port: 2881 rpc port: 2882 zone: zone1 data_dir: /oceanbase/store/obdemo rs list: 127.0.0.1:2882:2881 cluster id: 20210912 appname: obdemo optstr: memory_limit=8G,cache_wash_threshold=1G,__min_full_resource_pool_memory=268435456,system_memory=3G,memory_chunk_cache_size=128M,cpu_count=8,net_thread_count=2,datafile_size=10G,stack_size=1536K data_dir: /oceanbase/store/obdemo [admin@localhost oceanbase]$ ps -efa|grep oceanbase admin 6425 1 99 15:09 ? 00:00:06 bin/observer -i lo -p 2881 -P 2882 -z zone1 -d /oceanbase/store/obdemo -r 127.0.0.1:2882:2881 -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=8,net_thread_count=2,datafile_size=10G,stack_size=1536K -d /oceanbase/store/obdemo admin 6662 6401 0 15:09 pts/4 00:00:00 grep --color=auto oceanbase
observer进程已经启动了,开始集群自举,先连接至集群(初始密码为空)
[admin@localhost oceanbase]$ mysql -h127.0.0.1 -u root -P2881 -p -c -A Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3221487635 Server version: 5.7.25 OceanBase 3.1.3 (r10100032022041510-a09d3134c10665f03fd56d7f8bdd413b2b771977) (Built Apr 15 2022 02:16:22) Copyright (c) 2009-2021 Percona LLC and/or its affiliates Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> mysql> mysql> mysql> mysql> show databases; +--------------------+ | Database | +--------------------+ | oceanbase | | information_schema | | mysql | | SYS | | LBACSYS | | ORAAUDITOR | | test | +--------------------+
启动集群自举,自举花了接近两分钟时间。
mysql> set session ob_query_timeout=1000000000; mysql> alter system bootstrap ZONE 'zone1' SERVER '127.0.0.1:2882'; Query OK, 0 rows affected (1 min 57.52 sec)
登陆集群系统租户,设置root密码,创建obproxy连接用户,授予必要权限
$ mysql -h127.0.0.1 -u root@sys -P2881 -p -c -A Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. mysql> grant select on oceanbase.* to proxyro identified by 'root123'; 创建代理用户 Query OK, 0 rows affected (0.20 sec) mysql> alter user root identified by 'root123'; 更改root密码 Query OK, 0 rows affected (0.07 sec)
启动obproxy进程
[admin@localhost oceanbase]$ cd ~/obproxy-3.2.3/ && bin/obproxy -r "127.0.0.1:2881" -p 2883 -o "enable_strict_kernel_release=false, enable_cluster_checkout=false,enable_metadb_used=false" -c obdemo bin/obproxy -r 127.0.0.1:2881 -p 2883 -o enable_strict_kernel_release=false, enable_cluster_checkout=false,enable_metadb_used=false -c obdemo rs list: 127.0.0.1:2881 listen port: 2883 optstr: enable_strict_kernel_release=false, enable_cluster_checkout=false,enable_metadb_used=false cluster_name: obdemo [admin@localhost obproxy-3.2.3]$ ps -efa|grep obproxy admin 7009 1 2 15:14 ? 00:00:00 bin/obproxy -r 127.0.0.1:2881 -p 2883 -o enable_strict_kernel_release=false, enable_cluster_checkout=false,enable_metadb_used=false -c obdemo
observer启动正常,监听2883端口,集群内有一台服务器。下面登陆obproxy,修改密码,登陆初始密码为空
[admin]$ obclient -h127.0.0.1 -u root@proxysys -P 2883 -p ##登陆代理,初始密码为空 Enter password: Welcome to the OceanBase. Commands end with ; or \g. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. ## 修改obproxy sys用户密码 MySQL [(none)]> alter proxyconfig set obproxy_sys_password='root123'; Query OK, 0 rows affected (0.003 sec) ## 修改OBPROXY连接OceanBase集群用户proxyro密码,密码和前面创建用户proxyro的密码相同。 MySQL [(none)]> alter proxyconfig set observer_sys_password='root123'; Query OK, 0 rows affected (0.002 sec)
退出后,通过obproxy登陆oceanbase系统库,检验登陆是否成功
[admin@localhost ~]$ obclient -h127.0.0.1 -uroot@sys -P2881 -p -c -A Enter password: Welcome to the OceanBase. Commands end with ; or \g. Your MySQL connection id is 3221487683 Server version: 5.7.25 OceanBase 3.1.3 (r10100032022041510-a09d3134c10665f03fd56d7f8bdd413b2b771977) (Built Apr 15 2022 02:16:22) Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [(none)]> show databases; +--------------------+ | Database | +--------------------+ | oceanbase | | information_schema | | mysql | | SYS | | LBACSYS | | ORAAUDITOR | | test | +--------------------+ 7 rows in set (0.003 sec) MySQL [(none)]> use oceanbase Database changed MySQL [oceanbase]> show full processlist; +------------+------+--------+-----------------+-----------+---------+------+--------+-----------------------+-----------+------+--------------+ | Id | User | Tenant | Host | db | Command | Time | State | Info | Ip | Port | Proxy_sessid | +------------+------+--------+-----------------+-----------+---------+------+--------+-----------------------+-----------+------+--------------+ | 3221487683 | root | sys | 127.0.0.1:32524 | oceanbase | Query | 0 | ACTIVE | show full processlist | 127.0.0.1 | 2881 | NULL | +------------+------+--------+-----------------+-----------+---------+------+--------+-----------------------+-----------+------+--------------+ 1 row in set (0.003 sec)
成功登陆系统租户,show full processlist命令显示正常。
创建租户、数据库、表
连接系统租户
[admin@38c7642a747b ~]$ obclient -h127.0.0.1 -u root@proxysys -P 2883 -p ##登陆代理,初始密码为空 Enter password: Welcome to the OceanBase. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 5.6.25 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
查看已经配置的资源单元规格,和集群内资源使用情况
MySQL [(none)]> use oceanbase Database changed MySQL [oceanbase]> select name, -> min_cpu, -> min_memory/1024/1024/1024 min_mem_GB, -> max_cpu, -> max_memory/1024/1024/1024 max_mem_GB, -> max_disk_size/1024/1024/1024 max_disk_size_gb -> from __all_unit_config; +-----------------+---------+----------------+---------+----------------+------------------+ | name | min_cpu | min_mem_GB | max_cpu | max_mem_GB | max_disk_size_gb | +-----------------+---------+----------------+---------+----------------+------------------+ | sys_unit_config | 1 | 1.250000000000 | 2 | 1.500000000000 | 10.000000000000 | | myunit1 | 1 | 2.000000000000 | 1 | 2.000000000000 | 6.000000000000 | +-----------------+---------+----------------+---------+----------------+------------------+ MySQL [oceanbase]> alter resource unit sys_unit_config min_cpu 1,max_cpu 2,max_disk_size '10G'; Query OK, 0 rows affected (0.014 sec) 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, -> disk_total/1024/1024/1024 total_disk_gb, -> (disk_total-disk_assigned)/1024/1024/1024 disk_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; +-------+----------------+-----------+--------------+----------+----------------+----------------+----------------+-----------------+-----------------+ | zone | observer | cpu_total | cpu_assigned | cpu_free | mem_total_gb | mem_assign_gb | mem_free_gb | total_disk_gb | disk_free_gb | +-------+----------------+-----------+--------------+----------+----------------+----------------+----------------+-----------------+-----------------+ | zone1 | 127.0.0.1:2882 | 6 | 2 | 4 | 5.000000000000 | 3.250000000000 | 1.750000000000 | 10.000000000000 | -6.000000000000 | +-------+----------------+-----------+--------------+----------+----------------+----------------+----------------+-----------------+-----------------+ 1 row in set (0.042 sec)
系统资源单元规格占用硬盘较大,占用了整个虚拟机的硬盘,需要调小一点
创建资源单元规格,资源池和租户
create resource unit myunit1 max_cpu=1,max_memory='2G',max_iops=2000,max_disk_size='6G', max_session_num=1000; Query OK, 0 rows affected (0.03 sec) create resource pool my_pool unit='myunit1', unit_num=1; Query OK, 0 rows affected (0.13 sec) select unit_count,unit_config_id,zone_list,name from __all_resource_pool; +------------+----------------+-----------+----------+ | unit_count | unit_config_id | zone_list | name | +------------+----------------+-----------+----------+ | 1 | 1 | zone1 | sys_pool | | 1 | 1001 | zone1 | my_pool | +------------+----------------+-----------+----------+ create tenant my_tenant resource_pool_list('my_pool'),primary_zone="RANDOM",charset='utf8' set ob_tcp_invited_nodes='%';
连接租户,创建数据库及表
[admin@localhost ~]$ obclient -h127.0.0.1 -uroot@my_tenant -P2881 -p -c -A Enter password: Welcome to the OceanBase. Commands end with ; or \g. Your MySQL connection id is 3221487752 Server version: 5.7.25 OceanBase 3.1.3 (r10100032022041510-a09d3134c10665f03fd56d7f8bdd413b2b771977) (Built Apr 15 2022 02:16:22) Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [(none)]> MySQL [(none)]> create database mydb; Query OK, 1 row affected (0.047 sec) MySQL [(none)]> use mydb Database changed MySQL [mydb]> create table t1 (id int,name varchar(30)); Query OK, 0 rows affected (0.109 sec) MySQL [mydb]> insert into t1 values(1,'kevin'); Query OK, 1 row affected (0.022 sec) MySQL [mydb]> select * from t1; +------+-------+ | id | name | +------+-------+ | 1 | kevin | +------+-------+ 1 row in set (0.002 sec)
连接自定义租户时遇到了问题,总是卡在登陆界面,重启了一下就ok了。另外的可能是创建的租户资源太小导致。