修改会话变量设置
您可以通过配置 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
关闭防火墙和 SELinux
不同操作系统的防火墙设置可能有点不同,下面以 CentOS 系统为例。
- 关闭防火墙
查看防火墙状态
systemctl status firewalld
如果是 inactive 那就不用管。如果是 active,那就永久关闭
systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld
- 关闭 SELinux
修改 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
配置文件修改后只会重启主机后生效,还需要使用下面命令立即生效。
setenforce 0
配置时间同步服务
OceanBase 是分布式数据库产品,是一个集群软件,对各个节点之间的时间同步性有要求。技术上要求所有节点之间的时间误差控制在 50ms 以内。实际生产环境为了稳定性和性能考虑,建议时间误差控制在 10ms 以内。通常只要节点配置时间同步服务器跟公网时间保持同步即可。实际上在企业机房里,企业会有统一的时间服务器跟机房提供的时间服务器或者直接跟公网时间服务器同步,OceanBase 节点只需要跟机房统一的时间服务器进行同步即可。
CentOS 或 RedHat 7.x 版本推荐使用 chrony 服务做时间源。Chrony 是 NTP(Network Time Protocol,网络时间协议,服务器时间同步的一种协议)的另一种实现,与 ntpd 不同,它可以更快且更准确地同步系统时钟,最大程度的减少时间和频率误差。
- 判断是否使用 ntpd同步时间。
systemctl status ntpd
Unit ntpd.service could not be found.
如果提示上面这个信息,表示没有使用 ntpd,那就继续。 如果提示有 ntpd 服务,就卸载 ntpd 软件。
- 安装 chrony服务
这里采用 YUM 安装方法。您也可以下载相应的 RPM 包安装。
yum -y install chrony
- 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
# 或下面命令指定密码,密码修改为自己的。
echo 'admin:adminPWD123' | chpasswd
在 CentOS 上面给 admin 用户 增加 sodu 权限有两个方法:
- 把用户加到 用户组 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 。输入密码后能返回结果。
配置 SSH 免密登录
如果您是完全手动部署 OceanBase 集群,则登录到相应节点上安装相关软件包,并启动 observer 或 obproxy 进程,则不需要配置 SSH 免密登录。 如果您是使用自动化技术部署 OceanBase 集群,则需要一台中控机。所有的命令通过中控机向 OceanBase 集群节点发出。则需要配置中控机的 OBD 运行的用户到 OceanBase 集群节点的 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 ~]$