Vagrant.configure("2")do|config| #for循环创建3台虚拟机 (1..3).eachdo|i| config.vm.define"host#{i}"do|node| #linux发行版本,可根据个人习惯从https://app.vagrantup.com/boxes/search寻找版本 node.vm.box="centos/7" node.vm.hostname="host#{i}" # 创建3台虚拟机,ip分别为 192.168.56.101/102/103,此处ip 192.168.56需要根据自己安装virtualbox生成的虚拟网卡修改,查看方式为点击virtualbox工具右侧三条横杠,选择网络,查看IPV4地址 node.vm.network"private_network",ip:"192.168.56.#{100+i}",netmask:"255.255.255.0" node.vm.provider"virtualbox"do|vb| vb.name="host#{i}" vb.memory="2048" #至少分配2核,否则k8s会安装不成功 vb.cpus=2 end end end end
保存文件,执行启动命令,由于需要从官方拉取镜像并创建3台虚拟机,所以此处须等待较长时间
vagrant up
命令执行结果
D:\tool\vms $ vagrant up Bringing machine 'host1' up with 'virtualbox' provider... Bringing machine 'host2' up with 'virtualbox' provider... Bringing machine 'host3' up with 'virtualbox' provider... ==> host1: Importing base box 'centos/7'... ==> host1: Matching MAC address for NAT networking... ==> host1: Checking if box 'centos/7' version '2004.01' is up to date... ==> host1: Setting the name of the VM: host1 ==> host1: Clearing any previously set network interfaces... ==> host1: Preparing network interfaces based on configuration... host1: Adapter 1: nat host1: Adapter 2: hostonly ==> host1: Forwarding ports... host1: 22 (guest) => 2222 (host) (adapter 1) ==> host1: Running 'pre-boot' VM customizations... ==> host1: Booting VM... ==> host1: Waiting for machine to boot. This may take a few minutes... host1: SSH address: 127.0.0.1:2222 host1: SSH username: vagrant host1: SSH auth method: private key host1: host1: Vagrant insecure key detected. Vagrant will automatically replace host1: this with a newly generated keypair for better security. host1: host1: Inserting generated public key within guest... host1: Removing insecure key from the guest if it's present... host1: Key inserted! Disconnecting and reconnecting using new SSH key... ==> host1: Machine booted and ready! ==> host1: Checking for guest additions in VM... host1: No guest additions were detected on the base box for this VM! Guest host1: additions are required for forwarded ports, shared folders, host only host1: networking, and more. If SSH fails on this machine, please install host1: the guest additions and repackage the box to continue. host1: host1: This is not an error message; everything may continue to work properly, host1: in which case you may ignore this message. ==> host1: Setting hostname... ==> host1: Configuring and enabling network interfaces... ==> host1: Rsyncing folder: /cygdrive/d/tool/vms/ => /vagrant ==> host2: Importing base box 'centos/7'... ==> host2: Matching MAC address for NAT networking... ==> host2: Checking if box 'centos/7' version '2004.01' is up to date... ==> host2: Setting the name of the VM: host2 ==> host2: Fixed port collision for 22 => 2222. Now on port 2200. ==> host2: Clearing any previously set network interfaces... ==> host2: Preparing network interfaces based on configuration... host2: Adapter 1: nat host2: Adapter 2: hostonly ==> host2: Forwarding ports... host2: 22 (guest) => 2200 (host) (adapter 1) ==> host2: Running 'pre-boot' VM customizations... ==> host2: Booting VM... ==> host2: Waiting for machine to boot. This may take a few minutes... host2: SSH address: 127.0.0.1:2200 host2: SSH username: vagrant host2: SSH auth method: private key host2: host2: Vagrant insecure key detected. Vagrant will automatically replace host2: this with a newly generated keypair for better security. host2: host2: Inserting generated public key within guest... host2: Removing insecure key from the guest if it's present... host2: Key inserted! Disconnecting and reconnecting using new SSH key... ==> host2: Machine booted and ready! ==> host2: Checking for guest additions in VM... host2: No guest additions were detected on the base box for this VM! Guest host2: additions are required for forwarded ports, shared folders, host only host2: networking, and more. If SSH fails on this machine, please install host2: the guest additions and repackage the box to continue. host2: host2: This is not an error message; everything may continue to work properly, host2: in which case you may ignore this message. ==> host2: Setting hostname... ==> host2: Configuring and enabling network interfaces... ==> host2: Rsyncing folder: /cygdrive/d/tool/vms/ => /vagrant ==> host3: Importing base box 'centos/7'... ==> host3: Matching MAC address for NAT networking... ==> host3: Checking if box 'centos/7' version '2004.01' is up to date... ==> host3: Setting the name of the VM: host3 ==> host3: Fixed port collision for22 => 2222. Now on port 2201. ==> host3: Clearing any previously set network interfaces... ==> host3: Preparing network interfaces based on configuration... host3: Adapter 1: nat host3: Adapter 2: hostonly ==> host3: Forwarding ports... host3: 22 (guest) => 2201 (host) (adapter 1) ==> host3: Running 'pre-boot' VM customizations... ==> host3: Booting VM... ==> host3: Waiting for machine to boot. This may take a few minutes... host3: SSH address: 127.0.0.1:2201 host3: SSH username: vagrant host3: SSH auth method: private key host3: host3: Vagrant insecure key detected. Vagrant will automatically replace host3: this with a newly generated keypair for better security. host3: host3: Inserting generated public key within guest... host3: Removing insecure key from the guest if it's present... host3: Key inserted! Disconnecting and reconnecting using new SSH key... ==> host3: Machine booted and ready! ==> host3: Checking for guest additions in VM... host3: No guest additions were detected on the base box for this VM! Guest host3: additions are required for forwarded ports, shared folders, host only host3: networking, and more. If SSH fails on this machine, please install host3: the guest additions and repackage the box to continue. host3: host3: This is not an error message; everything may continue to work properly, host3: in which case you may ignore this message. ==> host3: Setting hostname... ==> host3: Configuring and enabling network interfaces... ==> host3: Rsyncing folder: /cygdrive/d/tool/vms/ => /vagrant D:\tool\vms $
# This is the sshd server system-wide configuration file. See # sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/local/bin:/usr/bin
# The strategy used for options in the default sshd_config shipped with # OpenSSH is to specify options with their default value where # possible, but leave them commented. Uncommented options override the # default value.
# If you want to change the port on a SELinux system, you have to tell # SELinux about this change. # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER # #Port 22 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress ::
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 # but this is overridden so installations will only check .ssh/authorized_keys AuthorizedKeysFile .ssh/authorized_keys
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # HostbasedAuthentication #IgnoreUserKnownHosts no # Don't read the user's ~/.rhosts and ~/.shosts files #IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no PasswordAuthentication yes
# Change to no to disable s/key passwords #ChallengeResponseAuthentication yes ChallengeResponseAuthentication no
# Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes #KerberosGetAFSToken no #KerberosUseKuserok yes
# GSSAPI options GSSAPIAuthentication yes GSSAPICleanupCredentials no #GSSAPIStrictAcceptorCheck yes #GSSAPIKeyExchange no #GSSAPIEnablek5users no
# Set this to 'yes' to enable PAM authentication, account processing, # and session processing. If this is enabled, PAM authentication will # be allowed through the ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, thenenable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. # WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several # problems. UsePAM yes
#AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PermitTTY yes #PrintMotd yes #PrintLastLog yes #TCPKeepAlive yes #UseLogin no #UsePrivilegeSeparation sandbox #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #ShowPatchLevel no #UseDNS yes UseDNS no #PidFile /var/run/sshd.pid #MaxStartups 10:30:100 #PermitTunnel no #ChrootDirectory none #VersionAddendum none
# override default of no subsystems Subsystem sftp /usr/libexec/openssh/sftp-server
# Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server