手动部署 OceanBase 单副本集群

参考:https://open.oceanbase.com/answer/detail?id=13700696&sou=0a001
https://www.modb.pro/db/182982等

一、目标

  1. 手动部署一个 OB 单副本集群,包括一个 OBProxy 节点。
  2. 创建一个业务租户、一个业务数据库,以及一些表等。

二、环境准备

HostCpuMemoryDiskOs version
Oceanbase01832G50GCentOS Linux release 7.9.2009 (Core)

三、集群安装

1.修改内核参数

修改sysctl系统配置

[root@oceanbase01~]# 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@oceabase01 ~]# sysctl -p

修改会话变量设置

[root@oceanbase01~]# 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@oceanbase01~]# ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 127710
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 100001
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 127710
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

关闭防火墙和 SELinux

[root@oceanbase01~]# systemctl disable firewalld
[root@oceanbase01~]# systemctl stop firewalld
[root@oceanbase01~]# vi /etc/selinux/config.
SELINUX=disabled

安装工具包

[root@oceanbase01~]# yum install -y net-tools lrzsz wget tree htop dstat

配置时间同步服务:建议卸载ntp服务使用官方推荐的chrony,当前单机就略过了。

创建admin集群用户

[root@oceanbase01~]# useradd admin
[root@oceanbase01~]# passwd admin
[root@oceanbase01~]# echo ‘admin:admin’ | chpasswd

添加admin的sudo权限

[root@oceanbase01 ~]# vim /etc/sudoers
admin ALL=(ALL) ALL

配置ssh免密登录(单机也要)

[root@oceanbase01 ~]# su - admin
[admin@oceanbase01 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/admin/.ssh/id_rsa):
Created directory ‘/home/admin/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/admin/.ssh/id_rsa.
Your public key has been saved in /home/admin/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:O1hgDRKNXVemgBOVE4yYFyPBXM2OWQiS5yJMSFkbEPw admin@oceanbase01
The key’s randomart image is:
±–[RSA 3072]----+
|++*@%=o…o |
|.+…XoO+Bo o |
|o .+ .o
… |
|…E…o… |
| . . S |
| o . |
| . o |
| . |
| |
±—[SHA256]-----+
[admin@oceanbase01 ~]$ ssh-copy-id `hostname -i`
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “/home/admin/.ssh/id_rsa.pub”
The authenticity of host ‘172.17.0.12 (172.17.0.12)’ can’t be established.
ECDSA key fingerprint is SHA256:MuNyo0PeHh3jj2pTnBTxxNqQUH9s909l3SP4liM9s8Y.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed – if you are prompted now it is to install the new keys
admin@172.17.0.12’s password:
Number of key(s) added: 1
Now try logging into the machine, with: “ssh ‘172.17.0.12’”
and check to make sure that only the key(s) you wanted were added.

2.初始化目录

创建相关目录并赋权

[root@oceanbase01 .ssh]# su - admin
[admin@oceanbase01 ~]$ sudo mkdir -p ~/oceanbase/store/obdemo /data/obdemo/{sstable,etc3} /redo/obdemo/{clog,ilog,slog,etc2}
[admin@oceanbase01 ~]$ for f in {clog,ilog,slog,etc2}; do ln -s /redo/obdemo/$f ~/oceanbase/store/obdemo/$f ; done
[admin@oceanbase01 ~]$ for f in {sstable,etc3}; do ln -s /data/obdemo/$f ~/oceanbase/store/obdemo/$f; done
[root@oceanbase01 .ssh]# chown -R admin:admin /data /redo /home/admin/oceanbase
在这里插入图片描述

查看目录结构

[root@oceanbase01 .ssh]# tree /data/obdemo
[root@oceanbase01 .ssh]# tree /redo/obdemo
[root@oceanbase01 .ssh]# tree /home/admin/oceanbase/store/
在这里插入图片描述

(可选)清理目录和数据

第一次部署不需要执行这步。
这步主要是用于后面安装部署失败后,需要清空目录和数据重新部署。

kill -9 `pidof observer`
/bin/rm -rf ~/oceanbase/store/obdemo//

检查目录结构,跟下面一致。

tree ~/oceanbase/store/ /data/ /redo/
输出:
[admin@oceanbase01 ~]$ 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

3.OB安装

使用xftp等工具上传已下载的安装包

https://open.oceanbase.com/softwareCenter/community
libobclient-2.0.0-2.el7.x86_64.rpm
oceanbase-ce-3.1.1-4.el7.x86_64.rpm
obclient-2.0.0-2.el7.x86_64.rpm
oceanbase-ce-libs-3.1.1-4.el7.x86_64.rpm
obproxy-3.2.0-1.el7.x86_64.rpm
在这里插入图片描述

安装oceanbase数据库、客户端、Proxy包

su - admin
[admin@oceanbase01 ~]$ cd /tmp/soft/
[admin@oceanbase01 soft]$ sudo rpm -ivh oceanbase-ce-libs-3.1.1-4.el7.x86_64.rpm
[admin@oceanbase01 soft]$ sudo rpm -ivh oceanbase-ce-3.1.1-4.el7.x86_64.rpm
[admin@oceanbase01 soft]$ sudo rpm -ivh libobclient-2.0.0-2.el7.x86_64.rpm
[admin@oceanbase01 soft]$ sudo rpm -ivh obclient-2.0.0-2.el7.x86_64.rpm
[admin@oceanbase01 soft]$ sudo rpm -ivh obproxy-3.2.0-1.el7.x86_64.rpm
在这里插入图片描述

查看软件安装信息,可以了解安装部署情况:

[admin@oceanbase01 soft]$ rpm -ql oceanbase-ce[admin@oceanbase01 soft]$ rpm -ql oceanbase-ce-libs
[admin@oceanbase01 soft]$ rpm -ql obproxy
在这里插入图片描述

4.启动OB

设置LD_LIBRARY_PATH环境变量

[admin@oceanbase01 soft]$ echo ‘export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/oceanbase/lib’ >> ~/.bash_profile
[admin@oceanbase01 soft]$ . ~/.bash_profile. ~/.bash_profile

启动observer

[admin@oceanbase01 ~]$ cd ~/oceanbase && bin/observer -i eth0 -p 2881 -P 2882 -z zone1 -d ~/oceanbase/store/obdemo -r ‘172.17.0.15:2882:2881’ -c 20211209 -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=4,datafile_size=10G,stack_size=1536K,config_additional_dir=/data/obdemo/etc3;/redo/obdemo/etc2” -d ~/oceanbase/store/obdemo
在这里插入图片描述

检查进程状态

[admin@oceanbase01 oceanbase]$ ps -ef |grep observer
[admin@oceanbase01 ~]$ netstat -an|grep 2881
在这里插入图片描述

5.bootstrap集群

使用obclient登录数据库,bootstrap集群,默认密码为空:

[admin@oceanbase01 ~]$ obclient -h 172.17.0.15 -P 2881 -uroot -p -c -A
MySQL [(none)]> set session ob_query_timeout=1000000000; alter system bootstrap ZONE ‘zone1’ SERVER ‘172.17.0.15:2882’ ;
在这里插入图片描述

还可以查看创建好的server信息:

MySQL [(none)]> show databases;
MySQL [(none)]> use oceanbase;
MySQL [oceanbase]> select zone, svr_ip, svr_port, with_rootserver, status from __all_server order by zone, with_rootserver desc;
在这里插入图片描述

设置密码

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

alter user root identified by ‘root’ ;

OBPROXY 用户(proxyro)密码默认OBPROXY 连接 OceanBase 集群使用用户 proxyro 。这个用户不存在,需要创建。

grant select on oceanbase.* to proxyro identified by ‘proxyro’ ;
在这里插入图片描述

6.启动 OBPROXY

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

[admin@oceanbase01 ~]$ cd ~/obproxy-3.2.0/ && bin/obproxy -r “172.17.0.15:2881” -p 2883 -o “enable_strict_kernel_release=false,enable_cluster_checkout=false,enable_metadb_used=false” -c obdemo
在这里插入图片描述

检查进程和监听

[admin@oceanbase01 obproxy-3.2.0]$ ps -ef|grep obproxy
[admin@oceanbase01 obproxy-3.2.0]$ netstat -ntlp|grep obproxy
在这里插入图片描述

登录 OBPROXY 修改密码

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

[admin@oceanbase01 obproxy-3.2.0]$ obclient -h 172.17.0.15 -u root@proxysys -P 2883 -p
MySQL [oceanbase]> alter proxyconfig set obproxy_sys_password = ‘proxyro’ ;
修改 OBPROXY 用户密码是通过修改参数的方式,命令是:alter proxyconfig set 。
同时还需要修改 OBPROXY 连接 OceanBase 集群用户 proxyro 的密码。这样 OBPROXY 才能跟 OceanBase 集群正常连接。这个密码就是前面 OceanBase 集群初始化后创建的用户 proxyro 的密码。

通过proxy使用密码登录验证

[admin@oceanbase01 obproxy-3.2.0]$ obclient -h 172.17.0.15 -u root@proxysys -P 2883 -p
在这里插入图片描述
[admin@oceanbase01 obproxy-3.2.0]$ obclient -h 172.17.0.15 -P 2883 -uroot@sys#obdemo -proot -c -A oceanbase
在这里插入图片描述

验证登录成功。

7.创建租户、数据库和表

创建租户

[admin@oceanbase01 ~]$ obclient -h 172.17.0.15 -P 2883 -uroot@sys#obdemo -proot -c -A oceanbase
MySQL [oceanbase]> alter resource unit sys_unit_config min_cpu=5;
MySQL [oceanbase]> 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’;
MySQL [oceanbase]> CREATE resource pool pool1 unit = ‘S4C1G’, unit_num = 1;
MySQL [oceanbase]> create tenant obmysql resource_pool_list=(‘pool1’), primary_zone=‘RANDOM’,comment ‘mysql tenant/instance’, charset=‘utf8’ set ob_tcp_invited_nodes=’%’, ob_compatibility_mode=‘mysql’;
在这里插入图片描述

使用租户登录建表

[admin@oceanbase01 ~]$ obclient -h 127.1 -uroot@obmysql -P2883 -p -c -A test
MySQL [oceanbase]> show databases;
MySQL [oceanbase]> show tables;
MySQL [oceanbase]> create table test(id int,value varchar(20),primary key (id));
MySQL [oceanbase]> insert into test values (1,‘test’);
MySQL [oceanbase]> select * from test;
在这里插入图片描述

如何手动停止ob服务:

kill -15 `pgrep observer`
kill -9 `pgrep observer`

obclient 访问格式:

obclient -u[用户名]@[租户名]#[集群名称] -P[端口号] -h[ip地址] -p[密码] -D[数据库名] -c

四、总结

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值