OceanBase 数据库是单进程软件,使用时需要访问网络、打开多个文件以及开启很多 TCP 连接,所以需要修改内核参数和用户会话设置。
您如果在独立服务器上部署 ODP,也需按本文要求初始化服务器环境。
您可参考以下命令修改配置文件:
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
运行以下命令可让配置生效:
sysctl -p
您可以通过配置 limits.conf
修改会话限制。OceanBase 数据库的进程涉及的限制包括:线程最大栈空间大小(Stack)、最大文件句柄数(Open Files)和 core 文件大小(Core File Size)。
您可以使用以下两种方法修改资源限制:
通过启动时在会话级别修改。如:ulimit -c unlimited
,通过此方法修改只影响当前会话。如果会话断开之后重连,则又会是默认配置。
通过配置文件 /etc/security/limits.conf
在全局级别修改。
修改后,已经登录的会话需要退出后重新登录才生效。
您可将会话级别的最大栈空间大小设置为 unlimited
,最大文件句柄数设置为 655350
,Core 文件大小设置为 unlimited
。
如果已有设置值低于这个设置值,则按照以下命令修改 /etc/security/limits.conf
配置文件。
vi /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
您可退出当前会话,重新登录。执行以下命令,查看配置是否生效:
ulimit -a
不同操作系统的防火墙设置可能会有不同,下文以 CentOS 系统为例进行讲解。
查看防火墙状态。
systemctl status firewalld
如果当前防火墙状态为 inactive
,则不需要关注。若当前防火墙状态为 active
,则需要永久关闭。
systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld
修改 SELinux 配置文件中的 SELINUX
选项。
vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
SELINUX
选项必须使用注释中的三个值之一。如果填写错误,机器重启后操作系统会报错,之后就只能通过进入单用户模式修改。
配置文件修改后需等到重启主机后才可生效,您可使用下面命令使其立即生效。
setenforce 0
OceanBase 数据库是分布式数据库产品,是一个集群软件,对各个节点之间的时间同步性有要求。技术上要求所有节点之间的时间误差需控制在 50ms 以内。实际生产环境中为了稳定性和性能考虑,建议时间误差控制在 10ms 以内。
通常,只要节点配置时间同步服务器跟公网时间保持同步即可。实际上在企业机房里,企业会有统一的时间服务器跟机房提供的时间服务器或者直接跟公网时间服务器同步,OceanBase 节点只需要跟机房统一的时间服务器进行同步即可。
CentOS 或 RedHat 7.x 版本推荐使用 chrony
服务做时间源。Chrony
是 NTP(即 Network Time Protocol
,网络时间协议,服务器时间同步的一种协议)的另一种实现。与 ntpd
不同的是,Chrony
可以更快且更准确地同步系统时钟,最大程度的减少时间和频率误差。
systemctl status ntpd
Unit ntpd.service could not be found.
如果出现上述提示信息,表示没有使用 ntpd
,您可继续进行后续步骤。
如果提示有 ntpd
服务,则需卸载 ntpd
软件。
这里采用 YUM 安装方法。您也可以下载相应的 RPM 包安装。
yum -y install chrony
chrony
服务守护进程名为 chronyd
,chronyc
是用来监控 chronyd
性能和配置参数的命令行工具。chrony
的主配置文件为 /etc/chrony.conf
。配置方法如下:
vi /etc/chrony.conf
# server 后面跟时间同步服务器
# 使用 pool.ntp.org 项目中的公共服务器。按 server 配置,理论上您想添加多少时间服务器都可以。
# 或者使用 阿里云的 ntp 服务器
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server ntp.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp1.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp1.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
server ntp10.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
# 如果是测试环境,没有时间同步服务器,那就选取一台配置为时间同步服务器。
# 如果选中的是本机,则取消下面 server 注释
#server 127.127.1.0
# 根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整。
driftfile /var/lib/chrony/drift
# chronyd 根据需求减慢或加速时间调整,
# 在某些情况下系统时钟可能漂移过快,导致时间调整用时过长。
# 该指令强制 chronyd 调整时期,大于某个阀值时步进调整系统时钟。
# 只有在因 chronyd 启动时间超过指定的限制时(可使用负值来禁用限制)没有更多时钟更新时才生效。
makestep 1.0 3
# 将启用一个内核模式,在该模式中,系统时间每 11 分钟会拷贝到实时时钟(RTC)。
rtcsync
# Enable hardware timestamping on all interfaces that support it.
# 通过使用 hwtimestamp 指令启用硬件时间戳
#hwtimestamp eth0
#hwtimestamp eth1
#hwtimestamp *
# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2
# 指定一台主机、子网,或者网络以允许或拒绝 NTP 连接到扮演时钟服务器的机器
#allow 192.168.0.0/16
#deny 192.168/16
# 即使没有同步到时间源,也要服务时间
local stratum 10
# 指定包含 NTP 验证密钥的文件。
#keyfile /etc/chrony.keys
# 指定日志文件的目录。
logdir /var/log/chrony
# Select which information is logged.
#log measurements statistics tracking
最简单的配置文件如下:
server 127.127.1.0
allow 172.20.0.0/16
local stratum 10
使用 chrony
时间服务是为了保证 OceanBase 集群各个节点时间尽可能同步,下面这些命令供参考。具体使用请查看 chrony
官方使用说明:Chronyc Frequently Asked Questions。
# 查看时间同步活动
chronyc activity
# 查看时间服务器
chronyc sources
# 查看同步状态
chronyc sources -v
# 校准时间服务器:
chronyc tracking
使用 clockdiff
命令可以检查本机跟目标机器的时间同步误差,以该命令结果为准。
如果时间显示跟当前实际时间差异很大,您可参考如下命令查看确认当前系统时区。
timedatectl
输出:
[root@obce00 ~]# timedatectl
Local time: 六 2021-09-11 07:37:22 CST
Universal time: 五 2021-09-10 23:37:22 UTC
RTC time: 六 2021-09-11 07:37:22
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: yes
Warning: The system is configured to read the RTC time in the local time zone.
This mode cannot be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.
您也可使用如下命令查看所有可用时区。
timedatectl list-timezones
设置当前系统时区方法如下。
timedatectl set-timezone Asia/Shanghai
chronyc -a makestep
输出:
[root@obce00 ~]# chronyc -a makestep
200 OK
设置完时区后,您可强制同步系统时钟。
前文介绍过,建议安装部署在普通用户下,后文均以用户 admin
为例。
为 admin
用户赋与 sudo
权限不是必须的,只是为了某些时候方便操作。您可以结合企业安全规范决定是否执行。
下面是创建用户 admin
并授予 sudo
权限的方法,仅供参考。
# 新增普通用户 admin
useradd admin
# 修改用户密码
passwd admin
# 或运行下面命令指定密码,将 `<password>` 替换为想要修改的密码
echo 'admin:<password>' | chpasswd
在 CentOS 上为 admin
用户增加 sudo
权限有以下两个方法:
把用户加到 用户组 wheel
里。
把用户加到 /etc/sudoers
文件里。
# 如果 sudo 不存在,就安装 sudo
yum install -y sudo
# 方法一:admin 加到用户组 wheel 里。
[root@obce00 ~]# usermod admin -G wheel
[root@obce00 ~]# id admin
uid=1000(admin) gid=1000(admin) groups=1000(admin),10(wheel)
# 方法二:admin 添加到 /etc/sudoers 文件中
[root@obce00 ~]# cat /etc/sudoers |grep wheel
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
# %wheel ALL=(ALL) NOPASSWD: ALL
vim /etc/sudoers
## Allow root to run any commands anywhere
admin ALL=(ALL) ALL
验证方法是否生效,切换到 admin
用户下,执行命令:sudo date
。输入密码后查看返回结果。
如果您是完全手动部署 OceanBase 集群,登录到相应节点上安装相关软件包,并启动 observer
或 obproxy
进程,则不需要配置 SSH 免密登录。
如果您使用自动化技术部署 OceanBase 集群,所有的命令通过中控机向 OceanBase 集群节点发出。则需要配置中控机中运行 OBD 的用户到 OBServer 节点中执行安装的用户的 SSH 免密登录。
本文示例是中控机的用户 admin
到 OBServer 节点的用户 admin
的免密登录。
配置 SSH 免密登录方法有很多,这里选择将中控机的 RSA 或 DSA 公钥复制到目标节点的 SSH 配置文件中。
在中控机生成 RSA 或 DSA 公钥和私钥
ssh-keygen -t rsa
输出:
[admin@obce00 ~]$ 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:7yCIks5NT8j7L1XIq+gRL3qm04cvHTSQmlaNr4gdHqc admin@obce00
The key's randomart image is:
+---[RSA 3072]----+
| + |
| = . |
| + o . . |
| +o .+ o . |
|oo.*o . S |
|.oEo+o o . |
|o o*=o= . . |
|oo+B*= . o |
| =*+=+o. . |
+----[SHA256]-----+
[admin@obce00 ~]$
[admin@obce00 ~]$ ls -al .ssh/
total 8
drwx------ 2 admin admin 38 Sep 11 14:43 .
drwx------ 4 admin admin 115 Sep 11 14:43 ..
-rw------- 1 admin admin 2602 Sep 11 14:43 id_rsa
-rw-r--r-- 1 admin admin 569 Sep 11 14:43 id_rsa.pub
上面命令会在用户的 HOME 目录中生成文件夹 .ssh
。注意不要改变文件夹以及里面文件的访问权限。
打通到本机的 SSH 免密登录
复制 RSA 或 DSA 公钥到目标节点,推荐使用命令 ssh-copy-id
。
[admin@obce00 ~]$ 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.20.249.50 (172.20.249.50)' can't be established.
ECDSA key fingerprint is SHA256:Zyyq5dY+05pkdqGCm6K43s97l8DUGv0LjY5t+zrdVkE.
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.20.249.50's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '172.20.249.50'"
and check to make sure that only the key(s) you wanted were added.
[admin@obce00 ~]$ ls -al .ssh
total 16
drwx------ 2 admin admin 80 Sep 11 14:44 .
drwx------ 4 admin admin 115 Sep 11 14:43 ..
-rw------- 1 admin admin 569 Sep 11 14:44 authorized_keys
-rw------- 1 admin admin 2602 Sep 11 14:43 id_rsa
-rw-r--r-- 1 admin admin 569 Sep 11 14:43 id_rsa.pub
-rw-r--r-- 1 admin admin 175 Sep 11 14:44 known_hosts
[admin@obce00 ~]$
OceanBase 数据库读写磁盘主要是三类文件:
运行日志
位于启动目录下的 log
目录。记录进程 observer 的运行日志、选举服务的运行日志和 Root Service 的运行日志。主要读写特点是顺序写。
数据文件
主要是指数据文件 block_file
,一次性初始化大小,可以在线扩容,但是不能缩容。主要读写特点是随机读、顺序写,偶尔密集的随机写。
事务日志文件
主要是指事务和 SSTable 相关的日志,包括 clog
、ilog
和 slog
等。主要读写特点是顺序写。
这三个文件尽可能分散在不同的磁盘上存储。如果只有一块盘,则可以使用 fdisk
或 lvm
划分为多个逻辑盘。
下面针对机器提供的裸盘(/dev/vdb
) 演示如何分盘。
方法一:使用 fdisk
直接将 /dev/vdb
划分为两个逻辑盘 (/dev/vdb1
和 /dev/vdb2
)。
这个方法存在缺陷,/dev/vdb
是云盘,可以扩容,但是使用 fdisk
分盘后,扩容比较麻烦。
方法二:对 /dev/vdb
使用 LVM 技术,划分两个 LV,一个给数据文件用,一个给日志文件。
fdisk
或者 parted
,以及 LVM 技术都是磁盘划分组合的手段。这里就不详细描述方法。
无论使用哪种办法,需优先考虑事务日志文件的大小,生产环境下建议是可用内存大小的 3-4 倍。剩余的大小再留给数据文件。
学习环境下,总的盘本身就很小,可以不遵守这个规则,日志文件大小比内存大 1-2 倍即可。
ODP 独立部署的服务器不需要做文件系统划分,ODP 只有运行日志目录。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。