当您熟悉了使用 OBD 部署 OceanBase 集群的方法原理后,就可以尝试手动部署一套 OceanBase 集群。学会手动部署 OceanBase 集群后,当 OBD 的功能不满足您的需求时,您可以自己写程序脚本部署 OceanBase 集群,或者在集群出现异常时,手动做一些应急处理。
本文介绍手动部署 OceanBase 集群三节点的方法,使用该方法需要通过中控机直接远程登录到 OceanBase 节点上部署启动 observer 进程,并在中控机上部署 obproxy 进程。
机器类型 | 云主机 ECS |
---|---|
IP | 172.20.249.50 |
网卡名 | eth0 |
OS | CentOS Linux release 8.4.2105 |
CPU | 4C |
内存 | 总内存 14G,可用内存 11G |
磁盘1 | 云盘 /dev/vda 100G |
磁盘2 | 云盘 /dev/vdb 100G |
角色 | 机器 | 备注 |
---|---|---|
OBD | 172.20.249.50 | 中控机,自动化部署软件 |
OBServer 节点 | 172.20.249.52 | OceanBase 数据库 zone1 |
OBServer 节点 | 172.20.249.49 | OceanBase 数据库 zone2 |
OBServer 节点 | 172.20.249.51 | OceanBase 数据库 zone3 |
ODP | 172.20.249.50 | OceanBase 访问反向代理 |
OBClient | 172.20.249.50 | OceanBase 命令行客户端 |
部署之前需要初始化服务器环境,详细操作请参考 2.4 如何初始化服务器环境。
检查本机和目标节点时间误差常用命令是: clockdiff
。
示例:
[admin@obce02 oceanbase]$ sudo clockdiff 172.20.249.52
[sudo] password for admin:
.
host=172.20.249.52 rtt=750(187)ms/0ms delta=0ms/0ms Sun Sep 12 14:52:24 2021
[admin@obce02 oceanbase]$ sudo clockdiff 172.20.249.51
.
host=172.20.249.51 rtt=750(187)ms/0ms delta=0ms/0ms Sun Sep 12 14:52:30 2021
有些机器使用 clockdiff
可能会报错。此时您可使用以下命令判断时间同步误差。
[admin@obce02 oceanbase]$ ping -T tsandaddr 172.20.249.52 -c 2
PING 172.20.249.52 (172.20.249.52) 56(124) bytes of data.
64 bytes from 172.20.249.52: icmp_seq=1 ttl=64 time=0.161 ms
TS: 172.20.249.49 24851014 absolute
172.20.249.52 -1
172.20.249.52 0
172.20.249.49 1
64 bytes from 172.20.249.52: icmp_seq=2 ttl=64 time=0.172 ms
TS: 172.20.249.49 24852054 absolute
172.20.249.52 -1
172.20.249.52 0
172.20.249.49 1
三节点时间同步误差如果超过 50ms,初始化集群一定会失败。
节点的时间误差会缓慢递增,也许当前集群能正常工作,但一天后,由于节点时间误差扩大到 50ms 以外,该节点就会掉线。
手动部署 OceanBase 集群时需要安装 OceanBase 数据库的软件包。
示例中的安装包可能不是最新版本,建议下载最新的安装包,详细信息请参考 OceanBase 发布说明。
[admin@obce02 ~]$ ls -lrth /tmp/oceanbase-ce-*.rpm
-rw-r--r-- 1 admin admin 45M Sep 12 13:36 /tmp/oceanbase-ce-3.1.0-3.el8.x86_64.rpm
[admin@obce02 ~]$ sudo rpm -ivh /tmp/oceanbase-ce-*.rpm
warning: /tmp/oceanbase-ce-3.1.0-3.el8.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID e9b4a7aa: NOKEY
Verifying... ################# [100%]
Preparing... ################# [100%]
Updating / installing...
1:oceanbase-ce-libs-3.1.0-3.el8 ################# [ 50%]
2:oceanbase-ce-3.1.0-3.el8 ################# [100%]
软件包默认安装目录是:/home/admin/oceanbase
。目录结构如下:
[admin@obce01 ~]$ tree oceanbase
oceanbase
├── bin
│ ├── import_time_zone_info.py
│ └── observer
├── etc
│ └── timezone_V1.log
└── 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
当然,您也可以将 RPM 包直接解压到指定目录。
首次部署不需要执行此操作,此操作主要用于安装部署失败后。安装部署失败后需要在清空目录和数据后重新部署。
kill -9 `pidof observer`
/bin/rm -rf ~/oceanbase/store/obdemo/*/*
检查目录结构,确认是否跟下文中初始化的目录结构一致。
tree ~/oceanbase/store/ /data/ /redo/
输出:
[admin@obce02 ~]$ tree ~/oceanbase/store/ /data/ /redo/
/home/admin/oceanbase/store/
└── obdemo
├── clog -> /redo/obdemo/clog
├── etc2 -> /redo/obdemo/etc2
├── etc3 -> /data/obdemo/etc3
├── ilog -> /redo/obdemo/ilog
├── slog -> /redo/obdemo/slog
└── sstable -> /data/obdemo/sstable
/data/
└── obdemo
├── etc3
└── sstable
/redo/
└── obdemo
├── clog
├── etc2
├── ilog
└── slog
15 directories, 0 files
手动部署时,OceanBase 节点上的相关目录均需要手动创建。
此操作仅需在首次部署时执行。
su - admin
sudo chown admin:admin ~/oceanbase/
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
您需注意的是:
您需创建工作目录下的总数据目录 ~/oceanbase/store/obdemo
、数据文件目录 /data/obdemo
和日志相关目录 /redo/obdemo
。和使用 OBD 自动化部署的 OceanBase 节点目录相比,不同的是目录里加入了集群名标识(obdemo
)。
~/oceanbase/store/obdemo
是真实的目录,该目录下的子目录是映射到其他两个文件系统的路径(指 /data/
和 /redo/
)。生产环境要求这两个文件系统尽可能是两块独立的物理盘,或者最低要求是两个独立的逻辑盘。
初始化后的目录结构如下。这个目录结构很重要,有时候 observer 进程启动失败就和目录结构和权限不对有关。
[admin@obce02 ~]$ tree ~/oceanbase/store/ /data/ /redo/
/home/admin/oceanbase/store/
└── obdemo
├── clog -> /redo/obdemo/clog
├── etc2 -> /redo/obdemo/etc2
├── etc3 -> /data/obdemo/etc3
├── ilog -> /redo/obdemo/ilog
├── slog -> /redo/obdemo/slog
└── sstable -> /data/obdemo/sstable
/data/
└── obdemo
├── etc3
└── sstable
/redo/
└── obdemo
├── clog
├── etc2
├── ilog
└── slog
15 directories, 0 files
每个机器的启动参数大部分都相同,只有少数不一样,需要特别留意。
172.20.249.52
su - admin
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/oceanbase/lib' >> ~/.bash_profile
. ~/.bash_profile
cd ~/oceanbase && bin/observer -i eth0 -p 2881 -P 2882 -z zone1 -d ~/oceanbase/store/obdemo -r '172.20.249.52:2882:2881;172.20.249.49:2882:2881;172.20.249.51: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"
172.20.249.49
su - admin
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/oceanbase/lib' >> ~/.bash_profile
. ~/.bash_profile
cd ~/oceanbase && bin/observer -i eth0 -p 2881 -P 2882 -z zone2 -d ~/oceanbase/store/obdemo -r '172.20.249.52:2882:2881;172.20.249.49:2882:2881;172.20.249.51: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"
172.20.249.51
su - admin
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/oceanbase/lib' >> ~/.bash_profile
. ~/.bash_profile
cd ~/oceanbase && bin/observer -i eth0 -p 2881 -P 2882 -z zone3 -d ~/oceanbase/store/obdemo -r '172.20.249.52:2882:2881;172.20.249.49:2882:2881;172.20.249.51: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"
如果三个节点机型都一致,那么启动参数里只有参数 -z
不一样(-z
参数指定该节点是哪个 Zone)。三个 Zone 的三个节点初始化为一个三副本集群。
后面 -o
参数不是必须的。此处因为测试机器内存不足,所以需要指定一些影响内存的参数。如果您的机器内存足够(如大于 64G),则可以不需要 -o
参数部分。
检查三个节点进程启动正常,主要看端口监听是否正常。您可在中控机上批量查询。
[admin@obce00 oceanbase-ce]$ IPS="172.20.249.52 172.20.249.49 172.20.249.51"
[admin@obce00 oceanbase-ce]$ for ob in $IPS;do echo $ob; ssh $ob "netstat -ntlp"; done
172.20.249.52
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:2881 0.0.0.0:* LISTEN 10084/bin/observer
tcp 0 0 0.0.0.0:2882 0.0.0.0:* LISTEN 10084/bin/observer
172.20.249.49
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:2881 0.0.0.0:* LISTEN 10213/bin/observer
tcp 0 0 0.0.0.0:2882 0.0.0.0:* LISTEN 10213/bin/observer
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
172.20.249.51
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:2881 0.0.0.0:* LISTEN 10103/bin/observer
tcp 0 0 0.0.0.0:2882 0.0.0.0:* LISTEN 10103/bin/observer
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
当 OceanBase 集群三个节点都正常启动,并且监听正常时,您可连接到任一节点(通过 2881
端口直连),进行自举(bootstrap
集群初始化)操作。
mysql -h 172.20.249.49 -u root -P 2881 -p -c -A
这里若使用命令 mysql -h 172.20.249.49 -u root@sys -P 2881 -p -c -A
连接,则会提示:ERROR 8001 (08004): Server is initializing。
set session ob_query_timeout=1000000000; alter system bootstrap ZONE 'zone1' SERVER '172.20.249.52:2882', ZONE 'zone2' SERVER '172.20.249.49:2882', ZONE 'zone3' SERVER '172.20.249.51:2882' ;
输出:
[admin@obce00 ~]$ mysql -h 172.20.249.49 -u root -P 2881 -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.0 (r3-b20901e8c84d3ea774beeaca963c67d7802e4b4e) (Built Aug 10 2021 08:10:38)
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)]> set session ob_query_timeout=1000000000; alter system bootstrap ZONE 'zone1' SERVER '172.20.249.52:2882', ZONE 'zone2' SERVER '172.20.249.49:2882', ZONE 'zone3' SERVER '172.20.249.51:2882' ;
Query OK, 0 rows affected (0.001 sec)
Query OK, 0 rows affected (28.839 sec)
MySQL [(none)]> Bye
[admin@obce00 ~]$ mysql -h 172.20.249.49 -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 3221751629
Server version: 5.7.25 OceanBase 3.1.0 (r3-b20901e8c84d3ea774beeaca963c67d7802e4b4e) (Built Aug 10 2021 08:10:38)
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.016 sec)
通常来说,只要严格按照前面步骤设置目录结构和权限、启动参数,集群自举都能成功。如果不成功,常见原因如下:
集群节点之间时间同步延时超过 50ms。
集群节点之间网络延时超过 100ms 。
集群节点上 OceanBase 数据库相关目录结构不对或者目录权限不对。
集群节点上进程 observer 启动参数有误。您可查看隐含参数的名字(如__min_full_resource_pool_memory
)和参数 -d
的目录是否正确,参数 -z
跟 IP 的对应关系、 参数中是否多了空格或是否有分隔符错误(有的是 ,
,有的是 ;
)。
集群节点可用内存低于进程 observer 启动参数 memory_limit
值。
集群管理员(root@sys
)密码
您需执行如下命令为 root@sys
设置一个密码。
alter user root identified by '4S****Sr' ;
ODP 用户(proxyro
)密码
默认 ODP 连接 OceanBase 集群时使用用户 proxyro
。该用户不存在,需要手动创建。
grant select on oceanbase.* to proxyro identified by 'SW****RH' ;
手动部署时需要安装 OceanBase 数据库的 ODP 软件。
sudo rpm -ivh /tmp/obproxy-*.rpm
社区版的 ODP 软件默认安装到 /home/admin/obproxy-版本号
下,请根据实际软件安装目录进行查询。
[admin@obce00 ~]$ tree ~/obproxy-3.1.0/
/home/admin/obproxy-3.1.0/
└── bin
├── obproxy
└── obproxyd.sh
1 directory, 2 files
目前社区版的 ODP 安装后的文件结构很简单,后面可能会微调。
启动 ODP 进程推荐放在软件安装目录,进程 obproxy 会在该目录下生成目录 etc
用以保存 ODP 的运行参数,以及目录 log
用以保存运行日志。
cd ~/obproxy-3.1.0/ && bin/obproxy -r "172.20.249.52:2881;172.20.249.49:2881;172.20.249.51:2881" -p 2883 -o "enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false" -c obdemo
输出:
[admin@obce00 obproxy-3.1.0]$ cd ~/obproxy-3.1.0/ && bin/obproxy -r "172.20.249.52:2881;172.20.249.49:2881;172.20.249.51:2881" -p 2883 -o "enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false" -c obdemo
bin/obproxy -r 172.20.249.52:2881;172.20.249.49:2881;172.20.249.51:2881 -p 2883 -o enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false -c obdemo
rs list: 172.20.249.52:2881;172.20.249.49:2881;172.20.249.51:2881
listen port: 2883
optstr: enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false
cluster_name: obdemo
[admin@obce00 obproxy-3.1.0]$ ps -ef|grep obproxy
admin 38206 1 2 15:11 ? 00:00:00 bin/obproxy -r 172.20.249.52:2881;172.20.249.49:2881;172.20.249.51:2881 -p 2883 -o enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false -c obdemo
admin 38229 28904 0 15:11 pts/2 00:00:00 grep --color=auto obproxy
[admin@obce00 obproxy-3.1.0]$
检查 ODP 监听是否正常
进程 obproxy 默认会监听2个端口:2883 和 2884。
[admin@obce00 obproxy-3.1.0]$ netstat -ntlp |grep obproxy
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:2883 0.0.0.0:* LISTEN 38206/bin/obproxy
tcp 0 0 0.0.0.0:2884 0.0.0.0:* LISTEN 38206/bin/obproxy
登录 ODP 修改密码
登录 ODP
登录用户名:root@proxysys
,端口:2883
。
mysql -h 172.20.249.50 -u root@proxysys -P 2883 -p
MySQL [(none)]> show proxyconfig like '%sys_password%';
+-----------------------+-------+--------------------------------+-------------+---------------+
| name | value | info | need_reboot | visible_level |
+-----------------------+-------+--------------------------------+-------------+---------------+
| observer_sys_password | | password for observer sys user | false | SYS |
| obproxy_sys_password | | password for obproxy sys user | false | SYS |
+-----------------------+-------+--------------------------------+-------------+---------------+
2 rows in set (0.000 sec)
修改 ODP 用户密码
您可通过修改参数的方式来修改 ODP 用户密码,使用命令为 alter proxyconfig set
。
alter proxyconfig set obproxy_sys_password = 'w******p' ;
修改 ODP 连接 OceanBase 集群用户 proxyro
的密码
在修改 ODP 用户密码的同时还需要修改 ODP 连接 OceanBase 集群用户 proxyro
的密码,这样 ODP 才能和 OceanBase 集群正常连接。
ODP 连接 OceanBase 集群用户 proxyro
的密码需和前面 OceanBase 集群初始化后创建的用户 proxyro
的密码一致。
alter proxyconfig set observer_sys_password = 'S******H' ;
查看是否部署成功
退出后,您可尝试通过 ODP 连接 OceanBase 集群,如果能查看所有会话,则说明 ODP 部署成功。
mysql -h172.20.249.50 -uroot@sys#obdemo -P2883 -p4******r -c -A oceanbase
输出:
[admin@obce00 obproxy-3.1.0]$ mysql -h172.20.249.50 -uroot@sys#obdemo -P2883 -p4******r -c -A oceanbase
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.25 OceanBase 3.1.0 (r3-b20901e8c84d3ea774beeaca963c67d7802e4b4e) (Built Aug 10 2021 08:10:38)
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 |
+------+--------+------+---------------------+-----------+-------------+-------------------+-------------------+-------+-------+
| 5 | sys | root | 172.20.249.50:41524 | oceanbase | 0 | 1 | MCS_ACTIVE_READER | 38206 | 38206 |
+------+--------+------+---------------------+-----------+-------------+-------------------+-------------------+-------+-------+
1 row in set (0.000 sec)
MySQL [oceanbase]> show full processlist;
+------------+---------+--------+---------------------+-----------+---------+------+--------+-----------------------+---------------+------+--------------+
| Id | User | Tenant | Host | db | Command | Time | State | Info | Ip | Port | Proxy_sessid |
+------------+---------+--------+---------------------+-----------+---------+------+--------+-----------------------+---------------+------+--------------+
| 3222013775 | root | sys | 172.20.249.50:57436 | oceanbase | Query | 0 | ACTIVE | show full processlist | 172.20.249.51 | 2881 | 4 |
| 3221751633 | proxyro | sys | 172.20.249.50:49344 | oceanbase | Sleep | 2 | SLEEP | NULL | 172.20.249.49 | 2881 | 3 |
+------------+---------+--------+---------------------+-----------+---------+------+--------+-----------------------+---------------+------+--------------+
2 rows in set (0.022 sec)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。