暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

实验二

原创 Adiot 2023-02-15
137

一、环境准备

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@localhost ~]# free -g
              total        used        free      shared  buff/cache   available
Mem:             11           7           0           0           4           3
Swap:             4           0           4


将admin赋予sudo权限

[root@localhost ~]# chmod u+w /etc/sudoers
[root@localhost ~]#
[root@localhost ~]# vi /etc/sudoers


二、安装OBSERVER

手动部署,需要安装 OceanBase 的 OBSERVER 软件 。

[admin@localhost ~]$ sudo rpm -ivh /tmp/oceanbase-ce-*.rpm

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for admin:
Preparing...                          ################################# [100%]
Updating / installing...
   1:oceanbase-ce-libs-3.1.4-100000920################################# [ 50%]
   2:oceanbase-ce-3.1.4-10000092022071################################# [100%]


初始化数据目录

OceanBase 节点上的相关目录都需要手动创建。

[admin@localhost ~]$ sudo mkdir -p /data
[admin@localhost ~]$ sudo mkdir -p /redo
[admin@localhost ~]$ sudo chown -R admin:admin /data
[admin@localhost ~]$ sudo chown -R admin:admin /redo

mkdir -p ~/oceanbase/store/obdemo /data/obdemo/{sstable,etc3} /redo/obdemo/{clog,ilog,slog,etc2} for f in {clog,ilog,slog,etc2}; do ln -s /redo/obdemo/$f ~/oceanbase/store/obdemo/$f ; done for f in {sstable,etc3}; do ln -s /data/obdemo/$f ~/oceanbase/store/obdemo/$f; done


启动 OBSERVER 进程

安装客户端
yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo
yum install -y obclient mariadb mariadb-libs mariadb-devel
配置环境变量
export OB_HOME=/data/oceanbase
export PATH=$PATH:$OB_HOME/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OB_HOME/lib

[admin@localhost oceanbase]$ cd ~/oceanbase && bin/observer -i enp0s3 -p 2881 -P 2882 -z zone1 -d ~/oceanbase/store/obdemo -r '10.0.2.4: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=16,net_thread_count=4,datafile_size=50G,stack_size=1536K,config_additional_dir=/data/obdemo/etc3;/redo/obdemo/etc2" -d ~/oceanbase/store/obdemo
bin/observer -i enp0s3 -p 2881 -P 2882 -z zone1 -d /home/admin/oceanbase/store/obdemo -r 10.0.2.4: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=16,net_thread_count=4,datafile_size=50G,stack_size=1536K,config_additional_dir=/data/obdemo/etc3;/redo/obdemo/etc2 -d /home/admin/oceanbase/store/obdemo
devname: enp0s3
mysql port: 2881
rpc port: 2882
zone: zone1
data_dir: /home/admin/oceanbase/store/obdemo
rs list: 10.0.2.4: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=16,net_thread_count=4,datafile_size=50G,stack_size=1536K,config_additional_dir=/data/obdemo/etc3;/redo/obdemo/etc2
data_dir: /home/admin/oceanbase/store/obdemo


集群自举(初始化)

[admin@localhost oceanbase]$ mysql -h127.1 -uroot -P2881 -p -c -A
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221225472
Server version: 5.7.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:33:14)

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)]> set session ob_query_timeout=1000000000; alter system bootstrap ZONE 'zone1' SERVER '10.0.2.4:2882';
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (34.73 sec)


三、安装OBPROXY

使用sys@root登陆数据库

  • 集群管理员(root@sys)密码默认集群管理员(root@sys)的密码是空的,这里需要设置一个密码。

alter user root identified by '4S9wDbSr' ;


[admin@localhost oceanbase]$ mysql -h 127.1 -u root@sys -P 2881 -p -c -A
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221487690
Server version: 5.7.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:33:14)

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)]> grant select on oceanbase.* to proxyro identified by 'SWoLCQRH' ;
Query OK, 0 rows affected (0.08 sec)


安装obproxy软件包

[admin@localhost oceanbase]$ sudo rpm -ivh /tmp/obproxy-3.2.0-1.el7.x86_64.rpm
[sudo] password for admin:
Preparing...                          ################################# [100%]
Updating / installing...
   1:obproxy-3.2.0-1.el7              ################################# [100%]


启动 OBPROXY 进程

启动 OBPROXY 进程也推荐在软件安装目录,进程 pbproxy 会在该目录下生成目录 etc 保存 OBPROXY 的运行参数,以及目录 log 保存运行日志。

[admin@localhost oceanbase]$ cd ~/obproxy-3.2.0/ && bin/obproxy -r "10.0.2.4:2881" -p 2883 -o "enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false" -c obdemo
bin/obproxy -r 10.0.2.4:2881 -p 2883 -o enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false -c obdemo
rs list: 10.0.2.4: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.0]$ ps -ef|grep obproxy
admin 29503 1 1 02:12 ? 00:00:00 bin/obproxy -r 10.0.2.4:2881 -p 2883 -o enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false -c obdemo
admin 29535 27728 0 02:13 pts/2 00:00:00 grep --color=auto obproxy


  • 登录 OBPROXY 修改密码

登录用户名:root@proxysys, 端口:2883 ,初始密码:空。

[admin@localhost obproxy-3.2.0]$ mysql -h 10.0.2.4 -u root@proxysys -P 2883 -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
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)]> show proxyconfig like '%sys_password%';
+------------------------+-------+--------------------------------+-------------+---------------+
| name                   | value | info                           | need_reboot | visible_level |
+------------------------+-------+--------------------------------+-------------+---------------+
| observer_sys_password1 |       | password for observer sys user | false       | SYS           |
| observer_sys_password  |       | password for observer sys user | false       | SYS           |
| obproxy_sys_password   |       | password for obproxy sys user  | false       | SYS           |
+------------------------+-------+--------------------------------+-------------+---------------+
3 rows in set (0.00 sec)

MySQL [(none)]> alter proxyconfig set obproxy_sys_password = 'wPhGddup' ;
Query OK, 0 rows affected (0.01 sec)

MySQL [(none)]> alter proxyconfig set observer_sys_password = 'SWoLCQRH' ;
Query OK, 0 rows affected (0.00 sec)


通过 OBPROXY 连接 OceanBase 集群, show processlist。

[admin@localhost obproxy-3.2.0]$ mysql -h10.0.2.4 -uroot@sys#obdemo -P2883 -p4S9wDbSr -c -A oceanbase
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:33:14)

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 [oceanbase]> show processlist;
+------+--------+------+----------------+-----------+-------------+-------------------+-------------------+-------+-------+
| Id   | Tenant | User | Host           | db        | trans_count | svr_session_count | state             | tid   | pid   |
+------+--------+------+----------------+-----------+-------------+-------------------+-------------------+-------+-------+
|    8 | sys    | root | 10.0.2.4:37142 | oceanbase |           0 |                 1 | MCS_ACTIVE_READER | 29503 | 29503 |
+------+--------+------+----------------+-----------+-------------+-------------------+-------------------+-------+-------+
1 row in set (0.00 sec)


四、创建租户并导入数据

登录ob数据库并创建租户

[admin@localhost obproxy-3.2.0]$ mysql -h 127.1 -u root@sys -P 2881 -p4S9wDbSr -c -A
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221487862
Server version: 5.7.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:33:14)

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)]> CREATE resource unit S4C1G 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='1024G';
CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1;
create tenant obmysql resource_pool_list=('my_pool'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';Query OK, 0 rows affected (0.02 sec)

MySQL [(none)]> CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1;
Query OK, 0 rows affected (0.04 sec)

MySQL [(none)]> create tenant obmysql resource_pool_list=('my_pool'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
Query OK, 0 rows affected (2.22 sec)


登录OB MySQL租户

[admin@1cb6a05746e9 ~]$ obclient -h 127.1 -uroot@obmysql#obce-single -P2883 -p -c -A test
Enter password:
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05)

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 [test]> show databases;
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.146 sec)


创建数据库和表等:

[admin@1cb6a05746e9 ~]$ obclient -h 127.1 -uroot@obmysql#obce-single -P2883 -p -c -A test
Enter password:
Welcome to the OceanBase.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05)

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 [test]> source /tmp/test_db-master/employees.sql;

MySQL [employees]> show databases;
+--------------------+
| Database           |
+--------------------+
| oceanbase          |
| information_schema |
| mysql              |
| test               |
| royce              |
| world              |
| employees          |
+--------------------+
7 rows in set (0.014 sec)

MySQL [employees]> show tables;
+----------------------+
| Tables_in_employees  |
+----------------------+
| current_dept_emp     |
| departments          |
| dept_emp             |
| dept_emp_latest_date |
| dept_manager         |
| employees            |
| salaries             |
| titles               |
+----------------------+
8 rows in set (0.008 sec)
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论