工作中大部分都是用windows的电脑,这里以windows为例,博主的电脑升级成了windows11,过程和之前的版本差别不大。
1. 先在电脑安装虚拟机这里我们安装的是:virtualbox,可去官网下载安装包安装。
官网下载虚拟机安装包:https://www.virtualbox.org/
2. 安装vagrant工具Vagrant 提供易于配置、可复制和可移植的工作环境。更多详情请访问官方地址。
加速安装系统环境,官网下载安装包:https://www.vagrantup.com/
可在搜索页找到我们想安装的模板:https://app.vagrantup.com/boxes/search
找到要安装系统,比如:centos/7
3. 安装centos7比如我们需要把系统安装到C:linux 下面
打开windows的cmd 命令行,执行
> cd C:linux > vagrant init centos/7 A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.
执行命令后就会在C:linux文件夹下生成一个Vagrantfile 文件
# -*- mode: ruby -*- # vi: set ft=ruby : # All Vagrant configuration is done below. The "2" in Vagrant.configure # configures the configuration version (we support older styles for # backwards compatibility). Please don't change it unless you know what # you're doing. Vagrant.configure("2") do |config| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box. You can search for # boxes at https://vagrantcloud.com/search. config.vm.box = "centos/7" # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs # `vagrant box outdated`. This is not recommended. # config.vm.box_check_update = false # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. # NOTE: This will enable public access to the opened port # config.vm.network "forwarded_port", guest: 80, host: 8080 # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine and only allow access # via 127.0.0.1 to disable public access # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" # Create a private network, which allows host-only access to the machine # using a specific IP. config.vm.network "private_network", ip: "192.168.56.10" # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. # config.vm.network "public_network" # Share an additional folder to the guest VM. The first argument is # the path on the host to the actual folder. The second argument is # the path on the guest to mount the folder. And the optional third # argument is a set of non-required options. # config.vm.synced_folder "../data", "/vagrant_data" # Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # # config.vm.provider "virtualbox" do |vb| # # Display the VirtualBox GUI when booting the machine # vb.gui = true # # # Customize the amount of memory on the VM: # vb.memory = "1024" # end # # View the documentation for the provider you are using for more # information on available options. # Enable provisioning with a shell script. Additional provisioners such as # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the # documentation for more information about their specific syntax and use. # config.vm.provision "shell", inline: <<-SHELL # apt-get update # apt-get install -y apache2 # SHELL end
注意其中有一行是注释掉的,config.vm.network "private_network", ip: "192.168.56.10" 这里设置的要安装的centos机器的ip地址,只有本机才可以访问,放开这一行注释。
启动centos7
> vagrant up
成功后就可以看到
这里我根据上面的过程如法炮制共安装了四个。
在当前Vagrantfile 所在路径下,打开cmd窗口,执行以下命令:
# 进入linux 环境 vagrant ssh
比如:
如果你想切换到root用户的话:
root 用户的密码默认都是:vagrant
你是不是有疑问,为啥在windows上面就直接进linux 终端了呢?
因为vagrant 帮我们在虚拟机上添加了端口映射,打开虚拟机可以看到:
步骤:选中当期机器 -> 点击设置 -> 点击网络 -> 点击网卡1的端口转发
这里你也可以添加端口转发规则,因为centos虚拟机我们配置的是只有当前主机可以访问,如果你在虚拟机上部署了一些服务,并且希望你的同事也能访问到,你就可以自定义端口转发了。
需要注意的是主机ip需要时你当前网络的ip地址,不能写127.0.0.1,要不然还是只有你自己可以访问。
我需要在机器上安装一些软件,需要一个下载工具,可以使用wget
# 查看是否安装wget,有输出就表示已安装 > rpm -qa | grep wget # 通过yum安装 -y 默认选项都选yes > yum install -y wget
安装后就可以通过wget 下载软件了
比如下载kafka安装包:
> wget https://dl0.serctl.com/downloads8/2021-11-05-12-14-20--kafka_2.13-3.0.0.tgz # 如果报错,可以不验证证书 wget --no-check-certificate https://dl0.serctl.com/downloads8/2021-11-05-12-14-20--kafka_2.13-3.0.0.tgz
到处结束,你可以愉快的玩耍了。
有什么问题?欢迎大家评论。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)