当前位置:   article > 正文

如何手动部署OceanBase的单节点集群

如何手动部署OceanBase的单节点集群

本文介绍了手动部署OceanBase单节点集群,到创建MySQL租户的实操步骤,供大家参考。

一、环境准备

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

因为docker安装经常会出现警告的提示,需要修改资源限制文件 vi /etc/security/limits.conf,添加以下内容

  1. * soft nofile 655360
  2. * hard nofile 655360
  3. * soft nproc 655360
  4. * hard nproc 655360
  5. * soft core unlimited
  6. * hard core unlimited
  7. * soft stack unlimited
  8. * hard stack unlimited

修改[/etc/sysctl.conf

  1. net.core.somaxconn = 2048
  2. net.core.netdev_max_backlog = 10000
  3. net.core.rmem_default = 16777216
  4. net.core.wmem_default = 16777216
  5. net.core.rmem_max = 16777216
  6. net.core.wmem_max = 16777216
  7. net.ipv4.ip_local_port_range = 3500 65535
  8. net.ipv4.ip_forward = 0
  9. net.ipv4.conf.default.rp_filter = 1
  10. net.ipv4.conf.default.accept_source_route = 0
  11. net.ipv4.tcp_syncookies = 0
  12. net.ipv4.tcp_rmem = 4096 87380 16777216
  13. net.ipv4.tcp_wmem = 4096 65536 16777216
  14. net.ipv4.tcp_max_syn_backlog = 16384
  15. net.ipv4.tcp_fin_timeout = 15
  16. net.ipv4.tcp_max_syn_backlog = 16384
  17. net.ipv4.tcp_tw_reuse = 1
  18. net.ipv4.tcp_tw_recycle = 1
  19. net.ipv4.tcp_slow_start_after_idle=0
  20. vm.swappiness = 0
  21. vm.min_free_kbytes = 2097152
  22. vm.max_map_count=655360
  23. fs.aio-max-nr=1048576

授权admin用户拥有sudo权限

  1. [root@10 ~]# chmod u+w /etc/sudoers
  2. [root@10 ~]#
  3. [root@10 ~]# vi /etc/sudoers

二、安装OBSERVER

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

  1. [admin@10 ~]$ sudo rpm -ivh /tmp/oceanbase-ce-*.rpm
  2. We trust you have received the usual lecture from the local System
  3. Administrator. It usually boils down to these three things:
  4. #1) Respect the privacy of others.
  5. #2) Think before you type.
  6. #3) With great power comes great responsibility.
  7. [sudo] password for admin:
  8. Preparing... ################################# [100%]
  9. Updating / installing...
  10. 1:oceanbase-ce-libs-3.1.4-100000920################################# [ 50%]
  11. 2:oceanbase-ce-3.1.4-10000092022071################################# [100%]

初始化数据目录

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

  1. [admin@10 ~]$ sudo mkdir -p /data
  2. [admin@10 ~]$ sudo mkdir -p /redo
  3. [admin@10 ~]$ sudo chown -R admin:admin /data
  4. [admin@10 ~]$ sudo chown -R admin:admin /redo
  1. mkdir -p ~/oceanbase/store/obdemo /data/obdemo/{sstable,etc3} /redo/obdemo/{clog,ilog,slog,etc2}
  2. for f in {clog,ilog,slog,etc2}; do ln -s /redo/obdemo/$f ~/oceanbase/store/obdemo/$f ; done
  3. for f in {sstable,etc3}; do ln -s /data/obdemo/$f ~/oceanbase/store/obdemo/$f; done

启动 OBSERVER 进程

  1. 安装客户端
  2. yum install -y yum-utils
  3. yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo
  4. yum install -y obclient mariadb mariadb-libs mariadb-devel
  1. 配置环境变量
  2. export OB_HOME=/data/oceanbase
  3. export PATH=$PATH:$OB_HOME/bin
  4. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OB_HOME/lib
  5. [admin@10 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
  6. 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
  7. devname: enp0s3
  8. mysql port: 2881
  9. rpc port: 2882
  10. zone: zone1
  11. data_dir: /home/admin/oceanbase/store/obdemo
  12. rs list: 10.0.2.4:2882:2881
  13. cluster id: 20210912
  14. appname: obdemo
  15. 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
  16. data_dir: /home/admin/oceanbase/store/obdemo

集群自举(初始化)

  1. [admin@10 oceanbase]$ mysql -h127.1 -uroot -P2881 -p -c -A
  2. Enter password:
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 3221225472
  5. Server version: 5.7.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:33:14)
  6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8. MySQL [(none)]>
  9. MySQL [(none)]> set session ob_query_timeout=1000000000; alter system bootstrap ZONE 'zone1' SERVER '10.0.2.4:2882';
  10. Query OK, 0 rows affected (0.00 sec)
  11. Query OK, 0 rows affected (34.73 sec)

三、安装OBPROXY

使用sys@root登陆数据库

  • 集群管理员(root@sys)密码默认集群管理员(root@sys)的密码是空的,这里需要设置一个密码。
 
alter user root identified by '4S9wDbSr' ;

  1. [admin@10 oceanbase]$ mysql -h 127.1 -u root@sys -P 2881 -p -c -A
  2. Enter password:
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 3221487690
  5. Server version: 5.7.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:33:14)
  6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8. MySQL [(none)]> grant select on oceanbase.* to proxyro identified by 'SWoLCQRH' ;
  9. Query OK, 0 rows affected (0.08 sec)

安装obproxy软件包

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

启动 OBPROXY 进程

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

  1. [admin@10 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
  2. 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
  3. rs list: 10.0.2.4:2881
  4. listen port: 2883
  5. optstr: enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false
  6. cluster_name: obdemo
[admin@10 obproxy-3.2.0]$ ps -ef|grep obproxyadmin 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 obdemoadmin 29535 27728 0 02:13 pts/2 00:00:00 grep --color=auto obproxy

  • 登录 OBPROXY 修改密码

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

  1. [admin@10 obproxy-3.2.0]$ mysql -h 10.0.2.4 -u root@proxysys -P 2883 -p
  2. Enter password:
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 1
  5. Server version: 5.6.25
  6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8. MySQL [(none)]> show proxyconfig like '%sys_password%';
  9. +------------------------+-------+--------------------------------+-------------+---------------+
  10. | name | value | info | need_reboot | visible_level |
  11. +------------------------+-------+--------------------------------+-------------+---------------+
  12. | observer_sys_password1 | | password for observer sys user | false | SYS |
  13. | observer_sys_password | | password for observer sys user | false | SYS |
  14. | obproxy_sys_password | | password for obproxy sys user | false | SYS |
  15. +------------------------+-------+--------------------------------+-------------+---------------+
  16. 3 rows in set (0.00 sec)
  17. MySQL [(none)]> alter proxyconfig set obproxy_sys_password = 'wPhGddup' ;
  18. Query OK, 0 rows affected (0.01 sec)
  19. MySQL [(none)]> alter proxyconfig set observer_sys_password = 'SWoLCQRH' ;
  20. Query OK, 0 rows affected (0.00 sec)

退出,通过 OBPROXY 连接 OceanBase 集群看看, 如果能查看所有会话,则说明 OBPROXY 部署成功。

  1. [admin@10 obproxy-3.2.0]$ mysql -h10.0.2.4 -uroot@sys#obdemo -P2883 -p4S9wDbSr -c -A oceanbase
  2. Welcome to the MariaDB monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 8
  4. Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:33:14)
  5. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  7. MySQL [oceanbase]> show processlist;
  8. +------+--------+------+----------------+-----------+-------------+-------------------+-------------------+-------+-------+
  9. | Id | Tenant | User | Host | db | trans_count | svr_session_count | state | tid | pid |
  10. +------+--------+------+----------------+-----------+-------------+-------------------+-------------------+-------+-------+
  11. | 8 | sys | root | 10.0.2.4:37142 | oceanbase | 0 | 1 | MCS_ACTIVE_READER | 29503 | 29503 |
  12. +------+--------+------+----------------+-----------+-------------+-------------------+-------------------+-------+-------+
  13. 1 row in set (0.00 sec)

四、创建租户并导入数据

登录ob数据库并创建租户

  1. [admin@10 obproxy-3.2.0]$ mysql -h 127.1 -u root@sys -P 2881 -p4S9wDbSr -c -A
  2. Welcome to the MariaDB monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 3221487862
  4. Server version: 5.7.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:33:14)
  5. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  7. 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';
  8. CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1;
  9. 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)
  10. MySQL [(none)]> CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1;
  11. Query OK, 0 rows affected (0.04 sec)
  12. 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';
  13. Query OK, 0 rows affected (2.22 sec)

登录OB MySQL租户

  1. [admin@1cb6a05746e9 ~]$ obclient -h 127.1 -uroot@obmysql#obce-single -P2883 -p -c -A test
  2. Enter password:
  3. Welcome to the OceanBase. Commands end with ; or \g.
  4. Your MySQL connection id is 6
  5. Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05)
  6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8. MySQL [test]> show databases;
  9. +--------------------+
  10. | Database |
  11. +--------------------+
  12. | oceanbase |
  13. | information_schema |
  14. | mysql |
  15. | test |
  16. +--------------------+
  17. 4 rows in set (0.146 sec)

创建数据库和表等:

  1. [admin@1cb6a05746e9 ~]$ obclient -h 127.1 -uroot@obmysql#obce-single -P2883 -p -c -A test
  2. Enter password:
  3. Welcome to the OceanBase. Commands end with ; or \g.
  4. Your MySQL connection id is 11
  5. Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05)
  6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8. MySQL [test]> source /tmp/test_db-master/employees.sql;
  9. MySQL [employees]> show databases;
  10. +--------------------+
  11. | Database |
  12. +--------------------+
  13. | oceanbase |
  14. | information_schema |
  15. | mysql |
  16. | test |
  17. | royce |
  18. | world |
  19. | employees |
  20. +--------------------+
  21. 7 rows in set (0.014 sec)
  22. MySQL [employees]> show tables;
  23. +----------------------+
  24. | Tables_in_employees |
  25. +----------------------+
  26. | current_dept_emp |
  27. | departments |
  28. | dept_emp |
  29. | dept_emp_latest_date |
  30. | dept_manager |
  31. | employees |
  32. | salaries |
  33. | titles |
  34. +----------------------+
  35. 8 rows in set (0.008 sec)
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/1018637
推荐阅读
相关标签
  

闽ICP备14008679号