1、虚拟机资源
VMwareWorkstation:Download VMware Workstation Pro
virtualbox:Oracle VM VirtualBox
2、虚拟机系统资源
链接:系统资源链接
提取码:0gat
说明:此处的系统资源是采用VMwareWorkstation 虚拟机进行制作的,如果采用virtualbox ,需要进行自己制作系统资源,上面的系统资源账号为lxtx 密码为admin123, 也可以自行进行制作系统资源,资源网上搜索一大堆
下面引用其他博文一篇:
在VMware上安装Linux(CentOS)系统虚拟机,图文教程_vmware虚拟机linux系统安装教程-CSDN博客
3、配置虚拟机网络
3.1 桥接模式
3.1.1 配置虚拟机网卡
进入编辑->虚拟网络编辑器
3.1.2 配置虚拟机 设置
选择需要配置的虚拟机,选择编辑虚拟机设置
3.1.3 配置虚拟机IP
虚拟机开机,采用root账户登录,然后修改网络IP
vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
#下面3行需要根据自己的IP地址进行配置
IPADDR=192.168.17.131
NETMASK=255.255.255.0
GATEWAY=192.168.17.1
DNS1=114.114.114.114
DNS2=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
#IPV6_ADDR_GEN_MODE="stable-privacy"
NAME=ens33
# 此处多个虚拟机都需要唯一
UUID=ac141466-6abf-4780-aaae-9758dbd3e9c2
DEVICE=ens33
ONBOOT=yes
PREFIX=24
设置好后,重启网卡
systemctl restart network
3.2 NAT模式
3.2.1 配置虚拟机网卡
进入编辑->虚拟网络编辑器
3.2.2 配置虚拟机 设置
选择需要配置的虚拟机,选择编辑虚拟机设置
3.2.3 配置虚拟机IP
虚拟机开机,采用root账户登录,然后修改网络IP
vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO=static
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
#虚拟机uuid需要保持唯一
UUID="905473de-1c93-457c-bc5a-7a2320111110"
DEVICE="ens33"
ONBOOT="yes"
#NAT模式根据自己配置的虚拟机网段信息进行设置下面4行
IPADDR=192.168.10.131
NETMASK=255.255.255.0
GATEWAY=192.168.10.2
DNS1=192.168.10.1
DNS2=8.8.8.8
设置好后,重启网卡
systemctl restart network
4、配置Centos环境
4.1 基础配置
##1:配置防火墙,selinux, bridge-nf-call-iptables,ipv4.ip_forward
#查看防火状态
systemctl status firewalld
service iptables status
#暂时关闭防火墙
systemctl stop firewalld
service iptables stop
#永久关闭防火墙
systemctl disable firewalld
chkconfig iptables off
##2:关闭selinux,使用如下命令关闭
#临时关闭
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
#永久关闭:
[root@localhost ~]# vim /etc/sysconfig/selinux
SELINUX=enforcing 改为 SELINUX=disabled
##3:/proc/sys/net/ipv4/ip_forward
#临时关闭
sysctl -w net.ipv4.ip_forward=1
echo 1 > /proc/sys/net/ipv4/ip_forward
#永久生效方式:
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
vi /etc/fstab
注释掉swap
##4:设置系统名称
hostnamectl set-hostname lxtx
##5:配置DNS
vim /etc/resolv.conf
#国内dns
nameserver 114.114.114.114
#国外dns
nameserver 8.8.8.8
##6:生效
sysctl --system
##7:设置时间同步
#安装ntpdate
yum install ntpdate -y
#设置时区
sudo cp -a /usr/share/zoneinfo/Etc/GMT-8 /etc/localtime
#同步windows时间
ntpdate time.windows.com
#配置crontab 同步时间 --每5小时与Windows同步一次时间
* */5 * * * /usr/sbin/ntpdate -u time.windows.com
#重启脚本
systemctl reload crond
systemctl restart crond
#检查
systemctl status crond
4.2 k8s需要增加的配置
#k8s需要使用
在master节点添加:
cat >> /etc/hosts << EOF
192.168.17.129 k8s-master
192.168.17.130 k8s-node1
192.168.17.131 k8s-node2
EOF
#k8s需要使用
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
5、配置yum源
5.1 安装yum
一般centos都带有yum,可以通过 yum list 进行检测是否有yum源,如果没有,进行安装
apt install yum
5.2 备份原始yum源
cd /etc/yum.repos.d
mv CentOS-Base.repo Centos-Base.repo.bak
5.3下载yum源
5.3.1 网易yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all //清除缓存
yum makecache //生成缓存
## wget -o ,使用-o参数来指定一个文件名
5.3.2 阿里yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
5.3.3 epel yum源
yum -y install epel-release
yum clean all
yum update
yum makecache
5.4处理yum源
vi /etc/yum.repos.d/CentOS-Base.repo
# 采用 :%s/old/new/g 将$releasever 修改为centos对应的版本
:%s/$releasever/7/g
5.5异常处理
5.5.1 404异常
新yum源中,
http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
等URL通过http的形式根本无法访问,此时将变量releasever都改为7。感觉这个变量$releasever根本就没起作用呀。
改完之后,执行yum clean all 以及 yum makecache 成功。
采用5.4处理yum源的方式进行替换就OK
5.5.2 yum sleeping
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: PackageKit
Memory : 39 M RSS (491 MB VSZ)
Started: Fri Mar 10 23:05:57 2023 - 00:53 ago
State : Sleeping, pid: 9387
ps -ef | grep yum
kill -9 <id>
5.6附修改好的yum源
此处的yum源为阿里源
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-7 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/
http://mirrors.aliyuncs.com/centos/7/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-7 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/
http://mirrors.aliyuncs.com/centos/7/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/
http://mirrors.aliyuncs.com/centos/7/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/7/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-7 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/7/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
6、安装docker
6.1 查看已安装的docker
yum list installed | grep docker
6.2 卸载docker
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
6.3 安装docker-CE
6.3.1 安装前置依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
6.3.2更新yum源
yum-config-manager --add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
cd /etc/yum.repos.d/
vim docker-ce.repo
# 需要确认docker-ce.repo文件中的版本号
:%s/old($releaserver)/new(7)/g
6.3.3安装docker以及docker-cli
yum install -y docker-ce docker-ce-cli containerd.io
6.3.4配置docker加速
6.3.4.1 阿里云加速
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors":["https://ozz2tqd1.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
6.3.4.2 网易加速
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://registry.docker-cn.com","http://hub-mirror.c.163.com"]
}
EOF
systemctl daemon-reload
6.3.5设置docker 开机起动
systemctl enable docker
systemctl restart docker
7、配置jdk环境
jdk官网:Java Downloads | Oracle
7.1 jdk1.8配置
#创建软件存放路径
mkdir -p /opt/soft
#上传软件包
#解压
tar -zxvf jdk-8u171-linux-x64.tar.gz
#配置环境变量
vi /etc/profile
#在文件末尾加入:
export JAVA_HOME=/opt/soft/java/jdk1.8.0_301
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#使profile生效
source /etc/profile
# 验证jdk是否安装成功
java -version
7.2 jdk 17配置
#不同处在文件末尾加入:
export JAVA_HOME=/opt/soft/java/jdk17
export CLASSPATH=$JAVA_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH