一、安装前准备:
1.服务器规划:
角色 | 机器 | 备注 | 规格 |
Obd、Obproxy、Obclient | 192.168.64.101 | 中控机,访问反向代理、 命令行客户端 | 8C4G centos7.2 |
Observer | 192.168.64.102 | Oceanbase数据库 zone1 | 8C 12G centos7.2 |
Observer | 192.168.64.103 | Oceanbase数据库 zone2 | 8C 12G centos7.2 |
Observer | 192.168.64.104 | Oceanbase数据库 zone3 | 8C 12G centos7.2 |
2.Host配置:
[root@localhost ~]# vim /etc/hosts
192.168.64.101 obproxy
192.168.64.102 observer01
192.168.64.103 observer02
192.168.64.104 observer03
3.内核参数修改
[root@localhost ~]# vim /etc/sysctl.conf
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 = 1
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
#配置生效
[root@localhost ~]# sysctl -p
4.修改会话变量设置
[root@localhost ~]# vim /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 ~]# ulimit -a
5.关闭防火墙和selinux
[root@localhost ~]# systemctl disable --now firewalld.service
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
[root@localhost ~]# setenforce 0
6.配置时间同步服务
[root@localhost ~]# systemctl status chronyd.service
注:系统自带chronyd服务
#服务端调整chrony配置(选用obd这台虚拟机)
[root@localhost ~]# vim /etc/chrony.conf
server 192.168.64.101
allow 192.168.64.0/24
local stratum 10
[root@localhost ~]# systemctl enable --now chronyd.service
#客户端配置(三节点执行)
[root@localhost ~]# vim /etc/chrony.conf
pool 192.168.64.101 iburst
[root@localhost ~]# systemctl restart chronyd.service
[root@localhost ~]# chronyc sources -v
210 Number of sources = 1
7.创建安装用户
[root@localhost ~]# useradd admin
[root@localhost ~]# echo 'admin' | passwd --stdin admin
#将用户admin增加sudo权限(admin 加到用户组 wheel 里)
[root@localhost ~]# usermod admin -G wheel
[root@localhost ~]# id admin
uid=1000(admin) gid=1000(admin) groups=1000(admin),10(wheel)
8.磁盘目录划分
[root@localhost ~]# mkdir /data #需要使用单独的逻辑卷datalv挂载
[root@localhost ~]# mkdir /redo #需要使用单独的逻辑卷redolv挂载
[root@localhost ~]# chown -R admin:admin /data/
[root@localhost ~]# chown -R admin:admin /redo/
二、安装部署oceanbase
1.安装oceanbase软件包(所有server节点)
[admin@localhost ~]$ mkdir soft
[admin@localhost soft]$ sudo rpm -ivh /home/admin/soft/oceanbase-ce-*.rpm
默认安装在/home/admin/oceanbase目录
#配置环境变量
[admin@localhost ~]$ vim .bash_profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/oceanbase/lib
[admin@localhost ~]$ source .bash_profile
2.初始化数据目录(所有server节点)
#手动部署时,oceanbase节点上的相关目录都需要手动创建
[root@localhost ~]# chown -R admin:admin /home/admin/oceanbase/
[root@localhost ~]# su – admin
[admin@localhost ~]$ mkdir -p ~/oceanbase/store/myob
[admin@localhost ~]$ mkdir -p /data/myob/{sstable,etc3} #注意文件所属权限
[admin@localhost ~]$ mkdir -p /redo/myob/{clog,ilog,slog,etc2}
[admin@localhost ~]$ for f in {clog,ilog,slog,etc2}; do ln -s /redo/myob/$f ~/oceanbase/store/myob/$f ; done
[admin@localhost ~]$ for f in {sstable,etc3}; do ln -s /data/myob/$f ~/oceanbase/store/myob/$f; done
3.启动observer进程(所有server节点)
server节点1:
[admin@localhost ~]$ cd ~/oceanbase/store && ~/oceanbase/bin/observer -i eno16777728 -p 2881 -P 2882 -z zone1 -d ~/oceanbase/store/myob -r '192.168.64.102:2882:2881;192.168.64.103:2882:2881;192.168.64.104:2882:2881' -c 20220120 -n myob -o "memory_limit=8G,cache_wash_threshold=1G,__min_full_resource_pool_memory=1073741824,system_memory=3G,memory_chunk_cache_size=128M,cpu_count=8,net_thread_count=4,datafile_size=5G,stack_size=1536K,enable_separate_sys_clog=0,enable_merge_by_turn=False,enable_syslog_wf=False,enable_syslog_recycle=True,max_syslog_file_count=4,config_additional_dir=/data/myob/etc3;/data/myob/etc2" -d ~/oceanbase/store/myob -l ERROR
server节点2:
[admin@localhost ~]$ cd ~/oceanbase/store && ~/oceanbase/bin/observer -i eno16777728 -p 2881 -P 2882 -z zone2 -d ~/oceanbase/store/myob -r '192.168.64.102:2882:2881;192.168.64.103:2882:2881;192.168.64.104:2882:2881' -c 20220120 -n myob -o "memory_limit=8G,cache_wash_threshold=1G,__min_full_resource_pool_memory=1073741824,system_memory=3G,memory_chunk_cache_size=128M,cpu_count=8,net_thread_count=4,datafile_size=5G,stack_size=1536K,enable_separate_sys_clog=0,enable_merge_by_turn=False,enable_syslog_wf=False,enable_syslog_recycle=True,max_syslog_file_count=4,config_additional_dir=/data/myob/etc3;/data/myob/etc2" -d ~/oceanbase/store/myob -l ERROR
server节点3:
[admin@localhost ~]$ cd ~/oceanbase/store && ~/oceanbase/bin/observer -i eno16777728 -p 2881 -P 2882 -z zone3 -d ~/oceanbase/store/myob -r '192.168.64.102:2882:2881;192.168.64.103:2882:2881;192.168.64.104:2882:2881' -c 20220120 -n myob -o "memory_limit=8G,cache_wash_threshold=1G,__min_full_resource_pool_memory=1073741824,system_memory=3G,memory_chunk_cache_size=128M,cpu_count=8,net_thread_count=4,datafile_size=5G,stack_size=1536K,enable_separate_sys_clog=0,enable_merge_by_turn=False,enable_syslog_wf=False,enable_syslog_recycle=True,max_syslog_file_count=4,config_additional_dir=/data/myob/etc3;/data/myob/etc2" -d ~/oceanbase/store/myob -l ERROR
4.集群初始化(bootstrap)
当 OceanBase 集群三个节点都正常启动,并且监听正常时,连接到任一节点(通过 2881 端口直连),进行自举(bootstrap 集群初始化)操作。 初始密码是空。
1.中控机安装Obclient
[root@localhost ~]# rpm -ivh libobclient-2.2.3-1.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh obclient-2.2.3-1.el7.x86_64.rpm
2.中控机使用ob客户端连接server1
[admin@localhost ~]$ obclient -h 192.168.64.102 -u root -P 2881 -p -c -A
Enter password: 初始无密码
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 3221225472
Server version: OceanBase_CE 4.2.1.0 (r100000102023092807-7b0f43693565654bb1d7343f728bc2013dfff959) (Built Sep 28 2023 07:25:28)
Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
obclient [(none)]> set session ob_query_timeout=1000000000;
obclient [(none)]> alter system bootstrap ZONE 'zone1' SERVER '192.168.64.102:2882',ZONE 'zone2' SERVER '192.168.64.103:2882',ZONE 'zone3' SERVER '192.168.64.104:2882';
Query OK, 0 rows affected (59.671 sec)
[admin@obproxy ~]$ obclient -h 192.168.64.102 -u root@sys -P 2881 -p -c -A
obclient [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| LBACSYS |
| mysql |
| oceanbase |
| ORAAUDITOR |
| SYS |
| test |
+--------------------+
7 rows in set (0.003 sec)
#默认集群管理员(root@sys)的密码为空,这里需要设置一个密码。
obclient [(none)]> alter user root identified by 'system' ;
#默认 OBPROXY 连接 OceanBase 集群时使用用户 proxyro 。该用户不存在,需要手动创建。
obclient [(none)]> create user proxyro identified by 'proxyro';
obclient [(none)]> grant select on oceanbase.* to proxyro;
3.中控机安装obproxy
[admin@obproxy ~]$ sudo rpm -ivh obproxy-ce-4.2.1.0-11.el7.x86_64.rpm
4.启动obproxy
#obproxy默认会监听2个端口:2883 和 2884
[admin@obproxy bin]$ cd ~/obproxy-4.2.1.0/ && bin/obproxy -r "192.168.64.102:2881;192.168.64.103:2881;192.168.64.104:2881" -p 2883 -o "enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false" -c myob
[admin@obproxy ~]$ ps -ef|grep obproxy
admin 3157 1 4 19:44 ? 00:00:01 bin/obproxy -r 192.168.64.102:2881;192.168.64.103:2881;192.168.64.104:2881 -p 2883 -o enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false -c myob
#登录obproxy修改密码(root@proxysys初始密码为空)
[admin@obproxy ~]$ obclient -h 192.168.64.101 -u root@proxysys -P 2883 -p
Enter password:
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 1
Server version: 5.6.25
Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
obclient [(none)]>
obclient [(none)]> alter proxyconfig set obproxy_sys_password='proxysys';
obclient [(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 | e3fd448c516073714189b57233c9cf428ccb1bed | password for obproxy sys user | false | SYS |
+------------------------+------------------------------------------+--------------------------------+-------------+---------------+
3 rows in set (0.002 sec)
#修改 OBPROXY 连接 OceanBase 集群用户 proxyro 的密码
obclient [(none)]> alter proxyconfig set observer_sys_password='proxyro';
#检查部署情况
通过 OBPROXY 连接 OceanBase 集群进行检查确认
[admin@obproxy ~]$ obclient -h192.168.64.101 -uroot@sys#myob -P2883 -p -c -A oceanbase
obclient [oceanbase]> select * from oceanbase.__all_server;
+----------------------------+----------------------------+----------------+----------+----+-------+------------+-----------------+--------+-----------------------+-------------------------------------------------------------------------------------------+-----------+--------------------+--------------+----------------+-------------------+
| gmt_create | gmt_modified | svr_ip | svr_port | id | zone | inner_port | with_rootserver | status | block_migrate_in_time | build_version | stop_time | start_service_time | first_sessid | with_partition | last_offline_time |
+----------------------------+----------------------------+----------------+----------+----+-------+------------+-----------------+--------+-----------------------+-------------------------------------------------------------------------------------------+-----------+--------------------+--------------+----------------+-------------------+
| 2024-03-09 01:45:20.310782 | 2024-03-09 01:45:21.537255 | 192.168.64.102 | 2882 | 1 | zone1 | 2881 | 1 | ACTIVE | 0 | 4.2.1.0_100000102023092807-7b0f43693565654bb1d7343f728bc2013dfff959(Sep 28 2023 07:25:28) | 0 | 1709919910048886 | 0 | 1 | 0 |
| 2024-03-09 01:45:20.338990 | 2024-03-09 01:45:25.548403 | 192.168.64.103 | 2882 | 2 | zone2 | 2881 | 0 | ACTIVE | 0 | 4.2.1.0_100000102023092807-7b0f43693565654bb1d7343f728bc2013dfff959(Sep 28 2023 07:25:28) | 0 | 1709919924449561 | 0 | 1 | 0 |
| 2024-03-09 01:45:20.364113 | 2024-03-09 01:45:23.543956 | 192.168.64.104 | 2882 | 3 | zone3 | 2881 | 0 | ACTIVE | 0 | 4.2.1.0_100000102023092807-7b0f43693565654bb1d7343f728bc2013dfff959(Sep 28 2023 07:25:28) | 0 | 1709919923091850 | 0 | 1 | 0 |
三、登录ob数据库并创建用户
[admin@obproxy ~]$ obclient -h192.168.64.101 -uroot@sys#myob -P2883 -psystem -c -A oceanbase
obclient [oceanbase]> CREATE RESOURCE UNIT S2C1G MAX_CPU 1, MIN_CPU 1, MEMORY_SIZE '2G', MAX_IOPS 1024, MIN_IOPS 1024, IOPS_WEIGHT 0, LOG_DISK_SIZE '2G';
obclient [oceanbase]> CREATE resource pool my_pool unit = 'S2C1G', unit_num = 1;
obclient [oceanbase]> create tenant myoadb resource_pool_list=('my_pool'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
四、登录myoadb 租户并创建数据库及表
[admin@obproxy ~]$ obclient -h192.168.64.101 -uroot@myoadb#myob -P2883 -p -c -A test
obclient [test]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| oceanbase |
| test |
+--------------------+
4 rows in set (0.007 sec)
obclient [test]> create database oadb;
obclient [test]> use oadb;
obclient [oadb]> create table test (id int(10),name varchar(100));
obclient [oadb]> insert into test values(1,'张三');
obclient [oadb]> commit;
Query OK, 1 row affected (0.110 sec)
obclient [oadb]> select * from test;
+------+--------+
| id | name |
+------+--------+
| 1 | 张三 |
+------+--------+
1 row in set (0.004 sec)




