OceanBase数据库单zone环境部署


安装前环境配置:

环境拓扑:
主机名       硬件配置               IP            角色             备注:
node100      8C/8G/100G       172.16.1.100   obd             OceanBase的自动化部署工具(中控机)        
node101      8C/20G/100G     172.16.1.101  observer     zone1,监听2881和2882端口
node100      8C/8G/100G       172.16.1.100  obproxy      监听2883和2884端口

配置主机hosts解析:
cat /etc/hosts
172.16.1.100  node100
172.16.1.101  node101

配置 sysctl.conf:
执行以下命令,打开 /etc/sysctl.conf 配置文件:
vim /etc/sysctl.conf
在 /etc/sysctl.conf 配置文件中添加以下内容:

# for oceanbase
## 修改内核异步 I/O 限制
fs.aio-max-nr=1048576

## 网络优化
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
kernel.core_pattern = /data/core-%e-%p-%t

# 此处为 OceanBase 数据库的 data 目录
kernel.core_pattern = /data/core-%e-%p-%t
其中,kernel.core_pattern 中的 /data 为 OceanBase 数据库的 data 目录。如果您只是测试,您可以只设置 fs.aio-max-nr=1048576。

加载配置
更改配置完成后,执行以下命令,加载配置,使配置生效。
sysctl -p

配置 limits.conf
 将会话级别的最大栈空间大小设置为 unlimited,最大文件句柄数设置为 655350,Core 文件大小设置为 unlimited。

执行以下命令,打开 /etc/security/limits.conf 配置文件:

vim  /etc/security/limits.conf
在 /etc/security/limits.conf 配置文件中添加以下内容:
root soft nofile 655350
root hard nofile 655350
* soft nofile 655350
* hard nofile 655350
* soft stack 20480
* hard stack 20480
* soft nproc 655360
* hard nproc 655360
* soft core unlimited
* hard core unlimited

查看配置
需要退出当前会话,重新登录。才会生效。
执行以下命令,查看配置是否生效:
ulimit -a

关闭防火墙和 SELinux

关闭防火墙

依次执行以下命令,关闭防火墙:
systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld

关闭 SELinux
执行以下命令,打开 /etc/selinux/linux 配置文件:
vi /etc/selinux/linux
在 /etc/selinux/linux 配置文件中添加以下内容:
SELINUX=disabled
执行以下命令,使更改生效:
setenforce 0
执行以下命令,查看更改是否生效:
cat /etc/selinux/config

配置时钟源
(所有主机都要配置,以172.16.1.100为源,172.16.1.101通过172.16.1.100同步时间)
前提条件
配置 NTP 时钟源前,确保您拥有所有机器的 root 用户权限。

操作步骤:
按以下步骤配置 NTP 时钟同步:
chrony 是网络时间协议(NTP)的通用实现。
chrony 包含两个程序:chronyd 是一个可以在启动时启动的守护程序。chronyc 是一个命令行界面程序,用于监视 chronyd 的性能并在运行时更改各种操作参数。
 
一、安装与配置
yum -y install chrony
systemctl enable chronyd && systemctl start chronyd

1.服务端配置
chrony.conf 修改两处
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server s1a.time.edu.cn iburst
server ntp.aliyun.com iburst
# Allow NTP client access from local network.
allow 172.16.1.100/24

开启同步
systemctl enable chronyd && systemctl restart chronyd

# 查看时间同步状态
timedatectl status
# 开启网络时间同步
timedatectl set-ntp true

2.客户端配置
chrony.conf 修改两处
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 172.16.1.100 burst

# Allow NTP client access from local network.
allow 172.16.1.100

开启同步
systemctl enable chronyd && systemctl restart chronyd

# 查看时间同步状态
timedatectl status
# 开启网络时间同步
timedatectl set-ntp true


三、命令
chronyc 用法
# 查看 ntp_servers
chronyc sources -v
# 查看 ntp_servers 状态
chronyc sourcestats -v
# 查看 ntp_servers 是否在线
chronyc activity -v
# 查看 ntp 详细信息
chronyc tracking -v

修改时区
# 查看日期时间、时区及 NTP 状态
timedatectl

# 查看时区列表
timedatectl list-timezones
timedatectl list-timezones |  grep  -E "Asia/S.*"

# 修改时区
timedatectl set-timezone Asia/Shanghai

# 修改日期时间(可以只修改其中一个)
timedatectl set-time "2019-09-19 15:50:20"

# 开启 NTP
timedatectl set-ntp true/flase

timedatectl
返回以下结果:
      Local time: Thu 2021-04-22 11:02:32 CST
  Universal time: Thu 2021-04-22 03:02:32 UTC
        RTC time: Thu 2021-04-22 11:02:32
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: yes
      DST active: n/a
说明 NTP 服务生效。

也可以通过以下命令,比较不同服务器的时间差:
[root@node103 ~]# clockdiff 172.16.1.100
...
host=172.16.1.100 rtt=423(315)ms/0ms delta=-3ms/-3ms Thu Nov 25 22:17:07 2021
注意:
        delta = 目标主机减当前主机时间 ,时间单位是毫秒  这个差值不能大于50ms,一般在1-5ms之间算正常情况,如果相差太多,集群将安装失败

创建admin用户:
说明:您必须在每台机器上执行此操作。
按照以下步骤创建用户。此处以创建 admin 用户为例进行说明。
执行以下命令,创建账户 admin。
useradd -U admin -d /home/admin -s /bin/bash

执行以下命令,为账户 admin 设置密码。
echo 'admin'|passwd --stdin admin

为账户 admin 设置 sudo 权限。
执行以下命令visudo 对用户admin的sudo权限进行配置
## Same thing without a password
## Allows people in group wheel to run all commands
admin      ALL=(ALL)      NOPASSWD: ALL
%wheel  ALL=(ALL)       ALL
保存并退出

执行以下命令,查看目录权限。
ls –al
返回以下结果:
drwxr-xr-x 2 admin admin 4096 2 月 9 18:43
drwxr-xr-x 2 admin admin 4096 2 月 9 18:43 log1

若 admin 用户无权限,则以 root 用户执行以下命令:
mkdir -p /data/1 && mkdir -p /data/log1  && chown admin.admin /data/* -R
此处填写您真实的挂载目录。此处 /data、/home/admin 为示例挂载目录。

设置无密码 SSH 登录(可选)
名词解释
中控机器
存储 OceanBase 数据库安装包和集群配置信息的机器。

目标机器
安装 OceanBase 数据库的机器。

前提条件
设置无密码 SSH 登录前,确保您拥有目标机器的 root 用户权限。

操作步骤
按以下步骤设置无密码 SSH 登录:

在中控机器上运行以下命令查看密钥是否存在:
su - admin
ls ~/.ssh/id_rsa.pub
如果密钥已经存在,则无需生成新的密钥。

在中控机器上运行以下命令生成 SSH 公钥和私钥:

ssh-keygen -t rsa
在中控机器上运行以下命令将第一步生成的公钥上传至目标服务器的 .ssh 文件夹:
语法:
ssh-copy-id  admin@<server_ip>
[admin@node100 ~]$ ssh-copy-id admin@172.16.1.101

在中控机器上运行以下命令登录目标机器:
ssh root@<server_ip>
重复步骤 3-5,为每台机器设置无密码登录 SSH。

注意
上述命令均仅需在中控机器上执行。

以下操作全部都在node100上操作[中控机]:
在线安装 OBD
如您的机器可以访问公网,并能够添加三方 YUM 软件源,您可以执行以下命令,使用 OceanBase 的官方软件源安装 OBD:
yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repo
yum install -y ob-deploy

在所有服务器上安装 MySQL 开发包
yum install mariadb mariadb-libs mariadb-devel -y

在所有dbserver节点的,配置对应的data目录:
mkdir -p /data/1 && mkdir -p /data/log1  && chown admin.admin /data/* -R

编译yaml配置文件 
切换到admin用户下:
[root@node100 ~]# su - admin
 按拓扑要求,编辑文件如下:
[admin@node100 ~]$ cat oceanbase-ce-1zones.yaml
## Only need to configure when remote login is required
user:
  username: admin #admin用户的用户名
  password: admin         #admin密码
#   key_file: your ssh-key file path if need
  port: 22
#   timeout: ssh connection timeout (second), default 30
oceanbase-ce:
  servers:
    - name: server1
      # Please don't use hostname, only IP can be supported
      ip: 172.16.1.101
  global:
    # The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.
    home_path: /home/admin/observer-ce
    # The directory for data storage. The default value is $home_path/store.
    data_dir: /data/1 #observer对应的数据目录
    # The directory for clog, ilog, and slog. The default value is the same as the data_dir value.
    redo_dir: /data/log1    #observer对应的日志目录
    # External port for OceanBase Database. The default value is 2881. DO NOT change this value after the cluster is started.
    mysql_port: 2881
    # Internal port for OceanBase Database. The default value is 2882. DO NOT change this value after the cluster is started.
    rpc_port: 2882
    # Defines the zone for an observer. The default value is zone1.
    zone: zone1
    # The maximum running memory for an observer. When ignored, autodeploy calculates this value based on the current server available resource.
    memory_limit: 8G             #observer最大占用的内存大小,这个是最低要求,可以内存至少要有8G以上,不是操作系统内存
    # The percentage of the maximum available memory to the total memory. This value takes effect only when memory_limit is 0. The default value is 80.
    memory_limit_percentage: 80
    # The reserved system memory. system_memory is reserved for general tenants. The default value is 30G. Autodeploy calculates this value based on the current server available resource.
    system_memory: 4G #observer最小占用的内存
    # The size of a data file. When ignored, autodeploy calculates this value based on the current server available resource.
    datafile_size: 50G #数据文件大小,OB采用预先磁盘分配的方式,启用observer后,会直接创建一个50G的文件
    # The percentage of the data_dir space to the total disk space. This value takes effect only when datafile_size is 0. The default value is 90.
    datafile_disk_percentage: 90
    # System log level. The default value is INFO.
    syslog_level: INFO #日志类型
    # Print system logs whose levels are higher than WARNING to a separate log file. The default value is true. The default value for autodeploy mode is false.
    enable_syslog_wf: true
    # Enable auto system log recycling or not. The default value is false. The default value for autodeploy mode is on.
    enable_syslog_recycle: true
    # The maximum number of reserved log files before enabling auto recycling. When set to 0, no logs are deleted. The default value for autodeploy mode is 4.
    max_syslog_file_count: 4
    # Cluster name for OceanBase Database. The default value is obcluster. When you deploy OceanBase Database and obproxy, this value must be the same as the cluster_name for obproxy.
    appname: oceanbase-ce
    # Password for root. The default value is empty.
    root_password: 123456 #这个是observer root操作系统用户的密码
    # Password for proxyro. proxyro_password must be the same as observer_sys_password. The default value is empty.
    proxyro_password: 123456  #这个是observer root操作系统用户的密码
  server1:
    zone: zone1
obproxy:
  depends:
    - oceanbase-ce
  servers:
    - 172.16.1.100
  global:
    # The working directory for obproxy. Obproxy is started under this directory. This is a required field.
    home_path: /home/admin/obproxy
    # External port. The default value is 2883.
    listen_port: 2883
    # The Prometheus port. The default value is 2884.
    # prometheus_listen_port: 2884
    # rs_list is the root server list for observers. The default root server is the first server in the zone.
    # The format for rs_list is observer_ip:observer_mysql_port;observer_ip:observer_mysql_port.
    # Ignore this value in autodeploy mode.
    # rs_list: 127.0.0.1:2881
    # Cluster name for the proxy OceanBase Database. The default value is obcluster. This value must be set to the same with the appname for OceanBase Database.
    cluster_name: oceanbase-ce #集群名称,以上面的appname的值对应,两个值要一样
    # Password for obproxy system tenant. The default value is empty.
    obproxy_sys_password: 123456 #这个是observer root操作系统用户的密码
    # Password for proxyro. proxyro_password must be the same with proxyro_password. The default value is empty.
    observer_sys_password: 123456 #这个是observer root操作系统用户的密码

在node100节点上,通过obd进行全自动安装:
[root@node100 ~]#su - admin
[admin@node100 ~]$ obd cluster deploy oceanbase-ce -c oceanbase-ce-1zones.yaml
Update OceanBase-community-stable-el7 ok
Update OceanBase-development-kit-el7 ok
Download oceanbase-ce-3.1.1-4.el7.x86_64.rpm (46.21 M): 100% [################################] Time: 0:00:34   1.41 MB/s
Package oceanbase-ce-3.1.1 is available.
Download obproxy-3.2.0-1.el7.x86_64.rpm (7.80 M): 100% [######################################] Time: 0:00:05   1.45 MB/s
Package obproxy-3.2.0 is available.
install oceanbase-ce-3.1.1 for local ok
install obproxy-3.2.0 for local ok
+-----------------------------------------------------------------------------+
|                                   Packages                                  |
+--------------+---------+---------+------------------------------------------+
| Repository   | Version | Release | Md5                                      |
+--------------+---------+---------+------------------------------------------+
| oceanbase-ce | 3.1.1   | 4.el7   | f19f8bfb67723712175fb0dfd60579196b3168f1 |
| obproxy      | 3.2.0   | 1.el7   | 8d5c6978f988935dc3da1dbec208914668dcf3b2 |
+--------------+---------+---------+------------------------------------------+
Repository integrity check ok
Parameter check ok
Open ssh connection ok
Remote oceanbase-ce-3.1.1-f19f8bfb67723712175fb0dfd60579196b3168f1 repository install ok
Remote oceanbase-ce-3.1.1-f19f8bfb67723712175fb0dfd60579196b3168f1 repository lib check !!
[WARN] server1(172.16.1.101) oceanbase-ce-3.1.1-f19f8bfb67723712175fb0dfd60579196b3168f1 require: libmariadb.so.3
Remote obproxy-3.2.0-8d5c6978f988935dc3da1dbec208914668dcf3b2 repository install ok
Remote obproxy-3.2.0-8d5c6978f988935dc3da1dbec208914668dcf3b2 repository lib check ok
Try to get lib-repository
Download oceanbase-ce-libs-3.1.1-4.el7.x86_64.rpm (155.15 K): 100% [##########################] Time: 0:00:00   1.33 MB/s
Package oceanbase-ce-libs-3.1.1 is available.
install oceanbase-ce-libs-3.1.1 for local ok
Use oceanbase-ce-libs-3.1.1-58384f7ab4ee736e9d530f4bdd63c20ced0e7aba for oceanbase-ce-3.1.1-f19f8bfb67723712175fb0dfd60579196b3168f1
Remote oceanbase-ce-libs-3.1.1-58384f7ab4ee736e9d530f4bdd63c20ced0e7aba repository install ok
Remote oceanbase-ce-3.1.1-f19f8bfb67723712175fb0dfd60579196b3168f1 repository lib check ok
Cluster status check ok
Initializes observer work home ok
Initializes obproxy work home ok
oceanbase-ce deployed

启动集群:
[root@node100 ~]#su - admin
[admin@node100 ~]$ obd cluster start oceanbase-ce
Get local repositories and plugins ok
Open ssh connection ok
Cluster param config check ok
Check before start observer ok
[WARN] (172.16.1.101) clog and data use the same disk (/)
Check before start obproxy ok
Start observer ok
observer program health check ok
Connect to observer ok
Initialize cluster
Cluster bootstrap ok
Wait for observer init ok
+------------------------------------------------+
|                    observer                    |
+--------------+---------+------+-------+--------+
| ip           | version | port | zone  | status |
+--------------+---------+------+-------+--------+
| 172.16.1.101 | 3.1.1   | 2881 | zone1 | active |
+--------------+---------+------+-------+--------+

Start obproxy ok
obproxy program health check ok
Connect to obproxy ok
Initialize cluster
+------------------------------------------------+
|                    obproxy                     |
+--------------+------+-----------------+--------+
| ip           | port | prometheus_port | status |
+--------------+------+-----------------+--------+
| 172.16.1.100 | 2883 | 2884            | active |
+--------------+------+-----------------+--------+
oceanbase-ce running

停止集群:
[admin@node100 ~]$ obd cluster stop oceanbase-ce
Get local repositories and plugins ok
Open ssh connection ok
Stop observer ok
Stop obproxy ok
oceanbase-ce stopped
[admin@node100 ~]$ 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
  优秀的盛昌
 发表评论
姓   名:

Powered by AKCMS