CC00049.CloudKubernetes——|KuberNetes&二进制部署.V02|3台Server|——|基础配置|

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

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

~~~     192.168.1.11 k8s-master01           //   2C4G 40G
~~~     192.168.1.11 k8s-master-lb          //   VIP 虚IP不占用机器资源 # 如果不是高可用集群,该IP为Master01的IP
~~~     192.168.1.14 k8s-node01             //   2C4G 40G
~~~     192.168.1.15 k8s-node02             //   2C4G 40G
~~~     10.96.0.0/12                        //   K8s Service网段  
~~~     172.16.0.0/12                       //   K8s Pod网段

二、系统基础环境配置

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

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

[root@k8s-master01 ~]# vim /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.11 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  11409      0 --:--:-- --:--:-- --:--:-- 11416
~~~     # 安装必备工具
[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

~~~     # 更改为阿里云的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
Failed to execute operation: No such file or directory
~~~     # 永久关闭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
12 May 16:50:02 ntpdate[9845]: step time server 203.107.6.88 offset -28797.476854 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-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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yanqi_vip

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值