跳到主要内容

修复指南

本指南用于在运行 ONES 前,对 Linux 主机进行必要的系统级修复与配置调整,适用于 envcheck 检测未通过 时的快速修复,确保系统满足 ONES 的最低运行要求。根据19项巡检条目按序说明如下:

1、CPU Resources

更换符合要求的CPU。

2、Memory Size

更换符合要求的内存。

3、Disk Space

提供符合大小要求的存储空间。

4、I/O Performance

更换满足性能要求的存储。 另外,envcheck中的磁盘检测为系统自带的dd命令执行顺序读写测试,如果检测不通过、也可自行安装fio命令、执行随机读写测试,测试结果发给ONES工程师进一步确认。如未达标,应更换 SSD / 更高性能的云盘。

apt install fio #ubuntu22上安装命令,其他系统请自行安装
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=random_read_write.fio --bs=4k --iodepth=64 --size=8GB --readwrite=randrw --rwmixread=75

5、Operating System

更换符合要求的操作系统。

6、Data Disk Separation

数据盘/data需独立挂载,并修复/etc/fstab确保持久生效。

7、Kernel Version

更换符合要求的操作系统。

8、DNS Resolver

默认Ubuntu22的域名解析文件/etc/resolv.conf为软链接,小概率情况下可能出现K3S coredns启动加载该文件异常,故需在安装 ONES 之前调整。 下文以Ubuntu22.04为例,提供调整域名解析的方法供参考。

8.1 Ubuntu22 修复 /etc/resolv.conf 软链接问题

# 删除ubuntu的/etc/resolv.conf 软连接
rm /etc/resolv.conf

# 编辑文件,至少添加1条可用DNS域名(咨询客户确认)
vi /etc/resolv.conf

nameserver 223.5.5.5
nameserver 223.6.6.6
nameserver 8.8.8.8
nameserver 114.114.114.114

8.2 hosts 中添加主机名,避免 sudo 报错

vi /etc/hosts

192.168.1.100 k8s-node-01

9、Network Ports

9.1 ONES 端口使用列表

以下列表中的端⼝全部释放,避免部署产生端口占用造成端口冲突

端口号分类端口号功能
kubernetes/k3sTCP 2379-2381Etcd server client API
kubernetes/k3sTCP 10250-10252、10256Kubelet API\kube-scheduler\kube-controller-manager
kubernetes/k3sTCP 10010Containerd
kubernetes/k3sTCP 5000Docker Registry(镜像仓)
kubernetes/k3sTCP/UDP 30000-32767service-node-port范围(可选)
kubernetes/k3s/Flannel VXLANUDP 8472Flannel VXLAN
kubernetes/k3sTCP 6443-6444/8443K3s supervisor Kubernetes API Server
kubernetes/k3sTCP 9100kube-rbac-proxy
ONES业务端口TCP 30011ONES node-port 默认监听端口(可选)
ONES业务端口TCP 80、443ONES ingress-nginx 默认监听端口(可选)
ONES工具端口TCP 5001Jira迁移工具web服务(可选)
ONES工具端口TCP 5601日志查询 kibanna默认端口(可选)
ONES工具端口TCP 31380监控面板 Grafana默认端口(可选)
ONES工具端口TCP 30012ONES运维工具箱端口(可选)

9.2 端⼝释放步骤

端⼝释放前需要与客户确认是否可以kill进程。如果有进程⾃动拉起监听,需要先停⽌⾃动拉起服务,避免释放放反复重启

# 尝试通过kill 命令强制停止进程,请再合理场景下使用,确认冲突端口是否可以中断
# 如有守护服务:systemd supervisord需要通过守护服务停止
[root@ONES ~]#netstat -antpl |grep -w 8081 #检测端口使用者
[root@ONES ~]#kill -9 <pid> #释放端口
[root@ONES ~]#netstat -antpl |grep -w 8081 #正常情况应该是没有回显

10、Swap Configuration

[root@ones ~]#swapoff -a # 关闭所有交换分区
[root@ones ~]#vi /etc/fstab # 永久关闭交换分区
#/dev/mapper/centos-swap swap swap defaults 0 0
# 将其注释掉或删除,保存文件并退出。

# 重新启动服务器以应用更改。
[root@ones ~]#reboot

11、SELinux Policy

11.1 检查⽅法

sestatus -v 
SELinux status: disabled

# 如果回显结果包含参数且值⼀致、或者提示无此命令,请跳过;如果提示 enables,请参考下文操作。

11.2 修复步骤

vi /etc/selinux/config

# 修改如下配置为disables
SELINUX=disabled

# 重启生效
reboot

# 执⾏ sestatus -v 命令再次检查修改是否成功
sestatus -v

12、File Permissions (umask)

12.1 检查⽅法/命令

[root@ones ~]# umask 
0022

12.2 修复步骤

编辑/etc/bashrc、/etc/profile⽂件,修改umask

[root@ones ~]# vi /etc/bashrc
[root@ones ~]# vi /etc/profile

####两个⽂件的内容是⼀样的
###搜索umask,找到如下代码,不算第⼀位的特殊权限
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then umask 002 / /表示uid⼤于等于199的默认umask值,表示普通⽤户else
umask 022 / /表示uid⼩于199的默认umask值,表示root
fi
####修改后需要重新读取⼀下/etc/bashrc或/etc/profile
[root@ones ~]# source /etc/profile
[root@ones ~]# source /etc/bashrc

13、Transparent Huge Pages

echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag

14、Firewall Services

systemctl stop ufw || systemctl stop firewalld
systemctl disable ufw || systemctl disable firewalld

15、Firewall iptables Rules

 iptabes -F

16、System Parameters (sysctl)

不合适的内核参数,可能导致请求偶发延时、端口监听失败、暴露端口失败、系统异常等情况。

结合ONES业务特点,推荐如下内核参数,需在安装 ONES 之前配置完成。

vi /etc/sysctl.conf
vm.swappiness=0
kernel.sysrq=1

net.ipv4.neigh.default.gc_stale_time=120

net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce=2
net.ipv4.conf.lo.arp_announce=2
net.ipv4.conf.all.arp_announce=2

net.ipv4.tcp_max_tw_buckets=5000
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_max_syn_backlog=1024
net.ipv4.tcp_synack_retries=2
net.ipv4.tcp_slow_start_after_idle=0

net.ipv4.ip_forward=1
net.ipv4.tcp_keepalive_time=600
net.ipv4.tcp_keepalive_intvl=60
net.ipv4.tcp_keepalive_probes=20
net.ipv4.ip_local_reserved_ports=30000-32767
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-arptables=1
net.bridge.bridge-nf-call-ip6tables=1

fs.inotify.max_user_watches=10485760
fs.inotify.max_user_instances=8192
#配置生效
sudo sysctl -p
reboot

17、File Limits

vi /etc/security/limits.conf
root soft nofile 1000000
root hard nofile 1000000
* soft nofile 1000000
* hard nofile 1000000

18、Graphical Interface

ONES服务的运行,不依赖于操作系统的图形化界面,且图形化界面消耗系统性能、安全隐患较多。

部署ONES系统时,推荐开启默认的命令行界面;如果开启了图形化界面,需在安装 ONES 之前关闭图形化。

下文以Ubuntu22.04为例,提供关闭图形化的方法供参考。

# 设置默认启动目标为多用户模式(命令行)
systemctl set-default multi-user.target

# 立即停止当前图形界面(无需重启)
systemctl isolate multi-user.target


# 停用并禁用 GDM3(GNOME Display Manager)
systemctl stop gdm3
systemctl disable gdm3

# 可选:如果使用 lightdm(检查当前显示管理器)
cat /etc/X11/default-display-manager

# 若输出为 /usr/sbin/lightdm,则禁用:
systemctl stop lightdm
systemctl disable lightdm

19、Time Synchronization

在安装 ONES 之前,需检查服务器的时间与时区是否正确,或者参考该文档部署时间同步服务。本文使用 chrony 作为时间同步工具。

其中,集群环境的各个节点间可能会因为时间漂移等原因而时间不同步,导致集群异常;因此必须给集群内节点配置时间同步服务以自动对齐时间。对于离线集群,如果客户环境有ntp服务基础设施,可直接替换ntp服务器列表;如果没有,可将集群内的某个节点作为ntp服务器,其他节点对齐此节点的时间。

19.1 安装 chrony

yum install -y chrony || apt install -y chrony

19.2 备份旧配置文件

conf=/etc/chrony.conf
# 如果发现 /etc/chrony.conf 不存在,可换成:
# conf=/etc/chrony/chrony.conf
cp $conf ${conf}.bk.$(date +'%s')

19.3 替换默认配置

对于在线环境,直接替换配置即可。如果需要使用其他ntp服务器,则自行修改。

#  修改服务器配置⽂件
cat > $conf <<_EOF
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server cn.pool.ntp.org iburst
server 210.72.145.44 iburst
server s1a.time.edu.cn iburst

driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
local stratum 10
logdir /var/log/chrony
_EOF

19.4 启动服务

# 启动chronyd
systemctl restart chronyd
systemctl enable chronyd

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

# 确认ntp服务器状态
chronyc sources -v

19.5 验证⽅法

[root@ones ~]#date
Mon Jan 22 11:28:30 CST 2024 #时间必须与当地时区保持一致

19.6 服务器时区修复

# 查看时区,确认是否修改
timedatectl status

# 执行以下命令,查看时区列表。
ls /usr/share/zoneinfo/

# 执行以下命令,可以在时区列表中查看到Hong_Kong Shanghai时区。
ls /usr/share/zoneinfo/Asia

# 以修改Asiz Shanghai时区为例
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# 更新硬件时钟(RTC)
hwclock -w

# 查看时区
timedatectl status