基本环境配置
1. 配置主机名:
hostnamectl set-hostname k8s-master01
hostname
2. 修改 hosts 文件
echo '192.168.10.121 k8s-master01
192.168.10.122 k8s-node01
192.168.10.123 k8s-node02
192.168.10.124 k8s-master02
192.168.10.125 k8s-master03' >> /etc/hosts
cat /etc/hosts
3. 配置默认 yum 源:
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum install -y yum-utils device-mapper device-mapper-persistent-data lvm2
sed -i -e '/mirrors.aliyuncs.com/d' -e '/mirrors.cloud.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
检查 /etc/yum.repos.d/CentOS-Base.repo 内容:
cat /etc/yum.repos.d/CentOS-Base.repo
4. 安装一些常用的工具
yum install -y wget jq psmisc vim net-tools telnet git
5. 关闭防火墙、SELinux、DNSmasq
systemctl disable --now firewalld
systemctl disable --now dnsmasq
systemctl disable --now NetworkManager
setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
检查防火墙是否关闭:
systemctl status firewalld
6. 关闭Swap分区
swapoff -a && sysctl -w vm.swappiness=0
sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab
7. 配置时间同步
安装 ntpdate:
rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
yum install ntpdate -y
同步时间:
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo 'Asia/Shanghai' > /etc/timezone
ntpdate time2.aliyun.com
# crontab -e
*/5 * * * * /usr/sbin/ntpdate time2.aliyun.com
检查定时任务是否配置成功:
# crontab -l
*/5 * * * * /usr/sbin/ntpdate time2.aliyun.com
8. 配置limit
ulimit -SHn 65535
echo '# 末尾添加如下内容
* soft nofile 65536
* hard nofile 131072
* soft nproc 65535
* hard nproc 655350
* soft memlock unlimited
* hard memlock unlimited' >> /etc/security/limits.conf
9. 升级系统并重启
yum update -y && reboot
最后更新于
这有帮助吗?