ToB企服应用市场:ToB评测及商务社交产业平台

标题: 1.2、安装k8s-node1 和 k8s-node2节点捏造机 [打印本页]

作者: 飞不高    时间: 2024-8-2 10:00
标题: 1.2、安装k8s-node1 和 k8s-node2节点捏造机
        k8s-master节点的捏造机情况弄好之后,这末节继承介绍k8s-node1 和 k8s-node2节点捏造机情况安装。
节点主机名ip
主节点k8s-master172.31.0.10
节点1k8s-node1172.31.0.11
节点2k8s-node2172.31.0.12


centos_stream_9_node1节点的Vagrantfile文件内容如下:
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # All Vagrant configuration is done below. The "2" in Vagrant.configure
  4. # configures the configuration version (we support older styles for
  5. # backwards compatibility). Please don't change it unless you know what
  6. # you're doing.
  7. Vagrant.configure("2") do |config|
  8.   # The most common configuration options are documented and commented below.
  9.   # For a complete reference, please see the online documentation at
  10.   # https://docs.vagrantup.com.
  11.   # Every Vagrant development environment requires a box. You can search for
  12.   # boxes at https://vagrantcloud.com/search.
  13.   config.vm.box = "eurolinux-vagrant/centos-stream-9"
  14.   config.vm.box_version = "9.0.45"
  15.   # Disable automatic box update checking. If you disable this, then
  16.   # boxes will only be checked for updates when the user runs
  17.   # `vagrant box outdated`. This is not recommended.
  18.   # config.vm.box_check_update = false
  19.   # Create a forwarded port mapping which allows access to a specific port
  20.   # within the machine from a port on the host machine. In the example below,
  21.   # accessing "localhost:8080" will access port 80 on the guest machine.
  22.   # NOTE: This will enable public access to the opened port
  23.   # config.vm.network "forwarded_port", guest: 80, host: 8080
  24.   # Create a forwarded port mapping which allows access to a specific port
  25.   # within the machine from a port on the host machine and only allow access
  26.   # via 127.0.0.1 to disable public access
  27.   # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
  28.   # Create a private network, which allows host-only access to the machine
  29.   # using a specific IP.
  30.   # 指定虚拟机网络ip为:172.31.0.11
  31.   config.vm.network "private_network", ip: "172.31.0.11"
  32.   # Create a public network, which generally matched to bridged network.
  33.   # Bridged networks make the machine appear as another physical device on
  34.   # your network.
  35.   # config.vm.network "public_network", bridge: "Intel(R) Wi-Fi 6 AX200 160MHz"
  36.   # Share an additional folder to the guest VM. The first argument is
  37.   # the path on the host to the actual folder. The second argument is
  38.   # the path on the guest to mount the folder. And the optional third
  39.   # argument is a set of non-required options.
  40.   # config.vm.synced_folder "../data", "/vagrant_data"
  41.   # Disable the default share of the current code directory. Doing this
  42.   # provides improved isolation between the vagrant box and your host
  43.   # by making sure your Vagrantfile isn't accessible to the vagrant box.
  44.   # If you use this you may want to enable additional shared subfolders as
  45.   # shown above.
  46.   # config.vm.synced_folder ".", "/vagrant", disabled: true
  47.   # Provider-specific configuration so you can fine-tune various
  48.   # backing providers for Vagrant. These expose provider-specific options.
  49.   # Example for VirtualBox:
  50.   #
  51.   # config.vm.provider "virtualbox" do |vb|
  52.   #   # Display the VirtualBox GUI when booting the machine
  53.   #   vb.gui = true
  54.   #
  55.   #   # Customize the amount of memory on the VM:
  56.   #   vb.memory = "1024"
  57.   # end
  58.   #
  59.   # View the documentation for the provider you are using for more
  60.   # information on available options.
  61.   # Enable provisioning with a shell script. Additional provisioners such as
  62.   # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  63.   # documentation for more information about their specific syntax and use.
  64.   config.vm.provision "shell", inline: <<-SHELL
  65.   # 1、Docker安装
  66.   # 1.1、卸载旧版本docker
  67.   sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
  68.   # 1.2、设置存储库
  69.   sudo yum install -y yum-utils
  70.   sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  71.   # 1.3、安装 Docker Engine
  72.   sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  73.   sudo systemctl enable docker
  74.   sudo systemctl start docker
  75.   # 1.4、禁用防火墙
  76.   sudo systemctl stop firewalld
  77.   sudo systemctl disable firewalld
  78.   # 1.5、修改 SSH 配置
  79.   sudo sed -i 's/^#*PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
  80.   sudo sed -i 's/^#*PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
  81.   # 1.6、重启 SSH 服务
  82.   sudo systemctl restart sshd.service
  83.   # 1.7、修改 root 用户密码
  84.   echo "root:1TdhblkFcdhx2a" | sudo chpasswd
  85.   # 1.8、配置 Docker 镜像加速
  86.   mkdir -p /etc/docker
  87.   cat > /etc/docker/daemon.json <<EOF
  88.   {
  89.     "registry-mirrors": ["https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"],
  90.     "exec-opts": ["native.cgroupdriver=systemd"]
  91.   }
  92. EOF
  93.   # 1.9、配置HTTP/HTTPS 网络代理 使用Docker的过程中,因为网络原因,通常需要使用 HTTP/HTTPS 代理来加速镜像拉取、构建和使用。
  94.   # 为 dockerd 设置网络代理 "docker pull" 命令是由 dockerd 守护进程执行。而 dockerd 守护进程是由 systemd 管理。因此,如果需要在执行 "docker pull" 命令时使用 HTTP/HTTPS 代理,需要通过 systemd 配置。
  95.   # 1.9.1、为 dockerd 创建配置文件夹。(mkdir -p /etc/systemd/system/docker.service.d)
  96.   # 1.9.2、为 dockerd 创建 HTTP/HTTPS 网络代理的配置文件,文件路径是 /etc/systemd/system/docker.service.d/http-proxy.conf 。并在该文件中添加相关环境变量。
  97.   sudo sh -c 'mkdir -p /etc/systemd/system/docker.service.d && \
  98.     cat <<EOF > /etc/systemd/system/docker.service.d/http-proxy.conf
  99. [Service]
  100. Environment="HTTP_PROXY=http://172.31.0.1:7890/"
  101. Environment="HTTPS_PROXY=http://172.31.0.1:7890/"
  102. Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
  103. EOF'
  104.   sudo systemctl daemon-reload
  105.   sudo systemctl restart docker
  106.   # 2、配置非root用户(Docker)执行docker命令时不使用sudo。
  107.   # 2.1、创建名为 "Docker" 的用户
  108.   sudo useradd Docker
  109.   # 2.2、设置 "Docker" 用户的密码
  110.   echo "Docker:1TdhblkFcdhx2a" | sudo chpasswd
  111.   # 2.3、创建名为 "docker" 的组
  112.   sudo groupadd docker
  113.   # 2.4、将用户 "Docker" 添加到组 "docker"
  114.   sudo gpasswd -a Docker docker
  115.   # 2.5、重启docker
  116.   sudo systemctl restart docker
  117.   SHELL
  118. end
复制代码






centos_stream_9_node2节点的Vagrantfile文件内容如下:
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # All Vagrant configuration is done below. The "2" in Vagrant.configure
  4. # configures the configuration version (we support older styles for
  5. # backwards compatibility). Please don't change it unless you know what
  6. # you're doing.
  7. Vagrant.configure("2") do |config|
  8.   # The most common configuration options are documented and commented below.
  9.   # For a complete reference, please see the online documentation at
  10.   # https://docs.vagrantup.com.
  11.   # Every Vagrant development environment requires a box. You can search for
  12.   # boxes at https://vagrantcloud.com/search.
  13.   config.vm.box = "eurolinux-vagrant/centos-stream-9"
  14.   config.vm.box_version = "9.0.45"
  15.   # Disable automatic box update checking. If you disable this, then
  16.   # boxes will only be checked for updates when the user runs
  17.   # `vagrant box outdated`. This is not recommended.
  18.   # config.vm.box_check_update = false
  19.   # Create a forwarded port mapping which allows access to a specific port
  20.   # within the machine from a port on the host machine. In the example below,
  21.   # accessing "localhost:8080" will access port 80 on the guest machine.
  22.   # NOTE: This will enable public access to the opened port
  23.   # config.vm.network "forwarded_port", guest: 80, host: 8080
  24.   # Create a forwarded port mapping which allows access to a specific port
  25.   # within the machine from a port on the host machine and only allow access
  26.   # via 127.0.0.1 to disable public access
  27.   # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
  28.   # Create a private network, which allows host-only access to the machine
  29.   # using a specific IP.
  30.   # 指定虚拟机网络ip为:172.31.0.12
  31.   config.vm.network "private_network", ip: "172.31.0.12"
  32.   # Create a public network, which generally matched to bridged network.
  33.   # Bridged networks make the machine appear as another physical device on
  34.   # your network.
  35.   # config.vm.network "public_network", bridge: "Intel(R) Wi-Fi 6 AX200 160MHz"
  36.   # Share an additional folder to the guest VM. The first argument is
  37.   # the path on the host to the actual folder. The second argument is
  38.   # the path on the guest to mount the folder. And the optional third
  39.   # argument is a set of non-required options.
  40.   # config.vm.synced_folder "../data", "/vagrant_data"
  41.   # Disable the default share of the current code directory. Doing this
  42.   # provides improved isolation between the vagrant box and your host
  43.   # by making sure your Vagrantfile isn't accessible to the vagrant box.
  44.   # If you use this you may want to enable additional shared subfolders as
  45.   # shown above.
  46.   # config.vm.synced_folder ".", "/vagrant", disabled: true
  47.   # Provider-specific configuration so you can fine-tune various
  48.   # backing providers for Vagrant. These expose provider-specific options.
  49.   # Example for VirtualBox:
  50.   #
  51.   # config.vm.provider "virtualbox" do |vb|
  52.   #   # Display the VirtualBox GUI when booting the machine
  53.   #   vb.gui = true
  54.   #
  55.   #   # Customize the amount of memory on the VM:
  56.   #   vb.memory = "1024"
  57.   # end
  58.   #
  59.   # View the documentation for the provider you are using for more
  60.   # information on available options.
  61.   # Enable provisioning with a shell script. Additional provisioners such as
  62.   # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  63.   # documentation for more information about their specific syntax and use.
  64.   config.vm.provision "shell", inline: <<-SHELL
  65.   # 1、Docker安装
  66.   # 1.1、卸载旧版本docker
  67.   sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
  68.   # 1.2、设置存储库
  69.   sudo yum install -y yum-utils
  70.   sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  71.   # 1.3、安装 Docker Engine
  72.   sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  73.   sudo systemctl enable docker
  74.   sudo systemctl start docker
  75.   # 1.4、禁用防火墙
  76.   sudo systemctl stop firewalld
  77.   sudo systemctl disable firewalld
  78.   # 1.5、修改 SSH 配置
  79.   sudo sed -i 's/^#*PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
  80.   sudo sed -i 's/^#*PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
  81.   # 1.6、重启 SSH 服务
  82.   sudo systemctl restart sshd.service
  83.   # 1.7、修改 root 用户密码
  84.   echo "root:1TdhblkFcdhx2a" | sudo chpasswd
  85.   # 1.8、配置 Docker 镜像加速
  86.   mkdir -p /etc/docker
  87.   cat > /etc/docker/daemon.json <<EOF
  88.   {
  89.     "registry-mirrors": ["https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"],
  90.     "exec-opts": ["native.cgroupdriver=systemd"]
  91.   }
  92. EOF
  93.   # 1.9、配置HTTP/HTTPS 网络代理 使用Docker的过程中,因为网络原因,通常需要使用 HTTP/HTTPS 代理来加速镜像拉取、构建和使用。
  94.   # 为 dockerd 设置网络代理 "docker pull" 命令是由 dockerd 守护进程执行。而 dockerd 守护进程是由 systemd 管理。因此,如果需要在执行 "docker pull" 命令时使用 HTTP/HTTPS 代理,需要通过 systemd 配置。
  95.   # 1.9.1、为 dockerd 创建配置文件夹。(mkdir -p /etc/systemd/system/docker.service.d)
  96.   # 1.9.2、为 dockerd 创建 HTTP/HTTPS 网络代理的配置文件,文件路径是 /etc/systemd/system/docker.service.d/http-proxy.conf 。并在该文件中添加相关环境变量。
  97.   sudo sh -c 'mkdir -p /etc/systemd/system/docker.service.d && \
  98.     cat <<EOF > /etc/systemd/system/docker.service.d/http-proxy.conf
  99. [Service]
  100. Environment="HTTP_PROXY=http://172.31.0.1:7890/"
  101. Environment="HTTPS_PROXY=http://172.31.0.1:7890/"
  102. Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
  103. EOF'
  104.   sudo systemctl daemon-reload
  105.   sudo systemctl restart docker
  106.   # 2、配置非root用户(Docker)执行docker命令时不使用sudo。
  107.   # 2.1、创建名为 "Docker" 的用户
  108.   sudo useradd Docker
  109.   # 2.2、设置 "Docker" 用户的密码
  110.   echo "Docker:1TdhblkFcdhx2a" | sudo chpasswd
  111.   # 2.3、创建名为 "docker" 的组
  112.   sudo groupadd docker
  113.   # 2.4、将用户 "Docker" 添加到组 "docker"
  114.   sudo gpasswd -a Docker docker
  115.   # 2.5、重启docker
  116.   sudo systemctl restart docker
  117.   SHELL
  118. end
复制代码






如今我们就创建好k8s-node1节点(172.31.0.11)和k8s-node2节点(172.31.0.12)的捏造机了,它们两个捏造机root账号的暗码都是:1TdhblkFcdhx2a



如今,我们就配置好k8s-node1和k8s-node2节点的捏造机,并在两台捏造机中安装好Docker。
接下来,我们要在k8s-master上面 安装 kubeadm,然后用 kubeadm 安装k8s集群。
请看下一篇文章:
1.3、k8s-master上面安装 kubeadm-CSDN博客

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4