1. 程式人生 > 其它 >二進位制部署1.23.4版本k8s叢集-1-系統安裝及環境準備

二進位制部署1.23.4版本k8s叢集-1-系統安裝及環境準備

1. 致謝

這篇文章參考了老男孩王導的視訊,在此表示感謝和致敬!

2. 安裝CentOS作業系統

系統映象:CentOS-7-x86_64-DVD-2009.iso
安裝過程略。

3. 環境準備

3.1 修改主機名

[root@CentOS-11 ~]# hostnamectl set-hostname cfzx55-11.host.com
[root@CentOS-11 ~]# logout
[root@cfzx55-11 ~]# hostname
cfzx55-11.host.com
[root@cfzx55-11 ~]#

3.2 修改IP地址

[root@cfzx55-11 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
[root@cfzx55-11 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
NAME="eth0"
DEVICE="eth0"
ONBOOT="yes"
IPADDR=10.211.55.11
NETMASK=255.255.255.0
GATEWAY=10.211.55.1
DNS1=10.211.55.1

3.3 關閉IPV6地址

[root@cfzx55-11 ~]# vi /etc/default/grub
[root@cfzx55-11 ~]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="ipv6.disable=1 crashkernel=auto spectre_v2=retpoline rd.lvm.lv=centos_centos-11/root rd.lvm.lv=centos_centos-11/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
[root@cfzx55-11 ~]#

GRUB_CMDLINE_LINUX中增加ipv6.disable=1

[root@cfzx55-11 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1160.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-64ff7fa49756f945a81d0b1b41f366c5
Found initrd image: /boot/initramfs-0-rescue-64ff7fa49756f945a81d0b1b41f366c5.img
done
[root@cfzx55-11 ~]# reboot

3.4 關閉SELinux

[root@cfzx55-11 ~]# vi /etc/selinux/config
[root@cfzx55-11 ~]# cat /etc/selinux/config | grep SELINUX=
# SELINUX= can take one of these three values:
SELINUX=disabled
[root@cfzx55-11 ~]#

3.5 關閉防火牆

[root@cfzx55-11 ~]# systemctl stop firewalld
[root@cfzx55-11 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@cfzx55-11 ~]#

3.6 關閉郵件服務

[root@cfzx55-11 ~]# systemctl stop postfix
[root@cfzx55-11 ~]# systemctl disable postfix
Removed symlink /etc/systemd/system/multi-user.target.wants/postfix.service.
[root@cfzx55-11 ~]#

3.7 安裝常用軟體

[root@cfzx55-11 ~]# yum install -y wget vim net-tools

3.8 調整base源、EPEL源,新增K8S源

# 備份
[root@cfzx55-11 ~]# mv /etc/yum.repos.d/CentOS-Base.repo{,.bak}
# 使用阿里映象源
[root@cfzx55-11 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2022-02-27 14:25:05 (2.06 MB/s) - '/etc/yum.repos.d/CentOS-Base.repo' saved [2523/2523]
# 安裝epel源
[root@cfzx55-11 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
2022-02-27 14:26:02 (84.3 MB/s) - '/etc/yum.repos.d/epel.repo' saved [664/664]

[root@cfzx55-11 ~]# vim /etc/yum.repos.d/k8s.repo
[root@cfzx55-11 ~]# cat /etc/yum.repos.d/k8s.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0

# 清除系統yum快取,重新生成
[root@cfzx55-11 ~]# yum clean all
[root@cfzx55-11 ~]# yum makecache -y

# 檢視系統可用yum源和所有yum源
[root@cfzx55-11 ~]# yum repolist enabled
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                             repo name                                                          status
base/7/x86_64                       CentOS-7 - Base - mirrors.aliyun.com                               10072
epel/x86_64                         Extra Packages for Enterprise Linux 7 - x86_64                     13746
extras/7/x86_64                     CentOS-7 - Extras - mirrors.aliyun.com                               509
kubernetes                          Kubernetes                                                           775
updates/7/x86_64                    CentOS-7 - Updates - mirrors.aliyun.com                             3572
repolist: 28674
[root@cfzx55-11 ~]#

3.9 時間同步

# 檢視系統時間、時區
[root@cfzx55-11 ~]# timedatectl
[root@cfzx55-11 ~]# timedatectl list-timezones | grep -i shanghai
Asia/Shanghai
[root@cfzx55-11 ~]# timedatectl set-timezone Asia/Shanghai
[root@cfzx55-11 ~]# timedatectl status
      Local time: Sat 2022-03-12 14:36:48 CST
  Universal time: Sat 2022-03-12 06:36:48 UTC
        RTC time: Sat 2022-03-12 06:36:48
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
[root@cfzx55-11 ~]#


# 安裝chrony 
[root@cfzx55-11 ~]# yum -y install chrony
# 配置chrony
[root@cfzx55-11 ~]# vim /etc/chrony.conf
[root@cfzx55-11 ~]# cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server ntp1.alyun.com
server ntp2.alyun.com
server ntp3.alyun.com
# 啟動 chrony
[root@cfzx55-11 ~]# systemctl start chronyd
# 設為開機自啟動
[root@cfzx55-11 ~]# systemctl enable chronyd

3.10 關閉swap分割槽

[root@cfzx55-11 ~]# vim /etc/fstab
# 註釋swap一行

3.11 核心優化

[root@cfzx55-11 ~]# vim /etc/sysctl.d/k8s.conf
[root@cfzx55-11 ~]# cat /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0

[root@cfzx55-11 ~]# sysctl --system 

3.12 克隆虛擬機器:

共5臺虛擬機器,克隆完成後,修改IP地址和hostname

序號 IP地址 hostname
1 10.211.55.11 cfzx55-11.host.com
2 10.211.55.12 cfzx55-12.host.com
3 10.211.55.21 cfzx55-21.host.com
4 10.211.55.22 cfzx55-22.host.com
5 10.211.55.200 cfzx55-200.host.com