|NO.Z.00024|——————————|^^ 部署 ^^|——|KuberNetes&二进制部署.V02|5台Server|——|基础配置|

一、基础环境配置
### --- 基础环境配置说明

~~~     主机信息,服务器IP地址不能设置成dhcp,要配置成静态IP。
~~~     VIP(虚拟IP)不要和公司内网IP重复,首先去ping一下,不通才可用。
~~~     VIP需要和主机在同一个局域网内!
~~~     公有云的话,VIP为公有云的负载均衡的IP,
~~~     比如阿里云的SLB地址,腾讯云的ELB地址,注意公有云的负载均衡都是内网的负载均衡。
二、网络规划:
### --- 主机信息,服务器IP地址不能设置成dhcp,要配置成静态IP

[root@k8s-master01 ~]# vim /etc/hosts
centos7.x 10.10.10.11    192,168.1.11     # master01    2C2G 40G
centos7.x 10.10.10.12    192,168.1.12     # master02    2C2G 40G
centos7.x 10.10.10.13    192,168.1.13     # master03    2C2G 40G
centos7.x 10.10.10.20    192.168.1.20     # VIP:虚拟IP不占用资源 如果不是高可用集群该IP为Master01的IP
centos7.x 10.10.10.14    192,168.1.14     # node01      2C2G 40G
centos7.x 10.10.10.15    192,168.1.15     # node01      2C2G 40G
~~~     10.96.0.0/12    // k8s Service网段:访问Pod服务是通过Pod来访问的,所以service也需要有一个IP地址。
~~~     172.16.0.0/12   // k8s Pod网段:可以理解为容器的IP地址,pod是管理容器的。会有一个IP地址。
~~~     以上三个网段是不可以重复的。
~~~     # VIP(虚拟IP)不要和公司内网IP重复,首先去ping一下,不通才可用。
~~~     # VIP需要和主机在同一个局域网内!公有云的话,VIP为公有云的负载均衡的IP,
~~~     比如阿里云的SLB地址,腾讯云的ELB地址,注意公有云的负载均衡都是内网的负载均衡。
~~~     # 官网地址:https://kubernetes.io/:Getting started
~~~     ——>Release  notes and  v1.20 Release Notes
~~~     ——>Server Binarles:kubernetes-server-linux-amd64.tar.gz
~~~     下载地址:也可以在GitHub上下载。
~~~     # 查看版本之家的变更:Changelog sincev1.19.0:可以查看版本变更:
~~~     放弃了docker的查看:Dockershim deprecation20.1.23版本之后放弃这个插件。
~~~     # 生产环境中,建议使用小版本大于5的kubernetes版本,
~~~     比如1.19.5/2.20.5以后的才可用于生产环境。

一、系统基础环境配置

### --- 系统内核版本

[root@k8s-master01 ~]#  cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core)
### --- 配置所有节点hosts文件

[root@k8s-master01 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.1.11 k8s-master01
192.168.1.12 k8s-master02
192.168.1.13 k8s-master03
192.168.1.20 k8s-master-lb                  # 如果不是高可用集群,该IP为Master01的IP
192.168.1.14 k8s-node01
192.168.1.15 k8s-node02
### --- CentOS 7安装yum源且安装必备工具

~~~     # 下载centos.aliyun.repo源
[root@k8s-master01 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0   4083      0 --:--:-- --:--:-- --:--:--  4082
~~~     # 安装必备工具

[root@k8s-master01 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
~~~     # 安装docker的yum源

[root@k8s-master01 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
~~~     # 更改为阿里云的yum源地址
[root@k8s-master01 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
 
~~~     # 安装必备工具
[root@k8s-master01 ~]# yum install wget jq psmisc vim net-tools telnet yum-utils device-mapper-persistent-data lvm2 git -y

~~~     # 所有节点安装基本工具
[root@k8s-master01 ~]# yum install wget jq psmisc vim net-tools yum-utils device-mapper-persistent-data lvm2 git -y
### --- 所有节点关闭firewalld 、dnsmasq、selinux(CentOS7需要关闭NetworkManager,CentOS8不需要)

~~~     # 永久关闭firewalld
[root@k8s-master01 ~]# systemctl disable --now firewalld 
 
~~~     # 永久关闭dnsmasq 
[root@k8s-master01 ~]# systemctl disable --now dnsmasq
~~~     # 永久关闭NetworkManager

[root@k8s-master01 ~]# systemctl disable --now NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
~~~     # 临时关闭selinux 
[root@k8s-master01 ~]# setenforce 0
setenforce: SELinux is disabled
 
~~~     # 永久关闭selinux
[root@k8s-master01 ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux
[root@k8s-master01 ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
### --- 所有节点关闭swap分区,fstab注释swap

~~~     # 临时关闭swap分区
[root@k8s-master01 ~]# swapoff -a && sysctl -w vm.swappiness=0
vm.swappiness = 0
~~~     # 将swap分区的关闭参数写入配置文件
[root@k8s-master01 ~]# sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab

二、基础环境配置:时间同步

### --- 所有节点同步时间:安装ntpdate

~~~     # 安装ntpdate的yum源地址
[root@k8s-master01 ~]# rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
Retrieving http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:wlnmp-release-centos-2-1         ################################# [100%]
 
~~~     # 安装ntpdate
[root@k8s-master01 ~]# yum install ntpdate -y
### --- 设置上海时区

~~~     # 创建上海时区的软连接
[root@k8s-master01 ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
 
~~~     # 将上海时区设置为默认时区
[root@k8s-master01 ~]# echo 'Asia/Shanghai' >/etc/timezone
### --- 时间同步

~~~     # 同步时间
[root@k8s-master01 ~]# ntpdate time2.aliyun.com
 9 Apr 15:22:05 ntpdate[10480]: adjust time server 203.107.6.88 offset -0.277817 sec
 
~~~     # 将入到crontab中,开机自动同步
[root@k8s-master01 ~]# crontab -e       
*/5 * * * * /usr/sbin/ntpdate time2.aliyun.com

三、所有节点配置limit

### --- limit临时生效

~~~     # 临时生效
[root@k8s-master01 ~]# ulimit -SHn 65535
### --- limit永久生效
~~~     # 永久生效,写入配置文件
~~~     末尾添加如下内容

[root@k8s-master01 ~]# vim /etc/security/limits.conf
* soft nofile 655360
* hard nofile 131072
* soft nproc 655350
* hard nproc 655350
* soft memlock unlimited
* hard memlock unlimited 

四、kubernetes基础配置:k8s-master01免密登录

### --- k8s-master01免密登录说明

~~~     Master01节点免密钥登录其他节点,安装过程中生成配置文件和证书均在Master01上操作,
~~~     集群管理也在Master01上操作,
~~~     阿里云或者AWS上需要单独一台kubectl服务器。
### --- k8s-master01密钥配置如下:

~~~     # k8s-master01上配置生成秘钥
[root@k8s-master01 ~]# ssh-keygen -t rsa
 
~~~     # k8s-master01配置免密码登录其他节点 
[root@k8s-master01 ~]# for i in k8s-master01 k8s-master02 k8s-master03 k8s-node01 k8s-node02;do ssh-copy-id -i .ssh/id_rsa.pub $i;done
五、所有节点升级系统并重启,此处升级没有升级内核,下节会单独升级内核:
### --- CentOS7需要升级,CentOS8可以按需升级系统

[root@k8s-master01 ~]# yum update -y --exclude=kernel* && reboot w

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

posted on 2022-03-29 13:14  yanqi_vip  阅读(47)  评论(0)    收藏  举报

导航