IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> vagrant 的使用 -> 正文阅读

[系统运维]vagrant 的使用

创建

cd /home/vm

cp -rf ubuntu127/ ubuntu128

cd ubuntu128

vim Vagrantfile

rm -rf .vagrant

vagrant up

Vagrantfile 文件内容

sudo tee ~/Vagrantfile <<-'EOF'
# -*- 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"  
end

EOF
sudo tee /root/vagrant/Vagrantfile <<-'EOF'
# -*- 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|
    # config.provider=PROVIDER
    # 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 = "ubuntu/trusty64"
    # vagrant plugin install --plugin-clean-sources --plugin-source https://gems.ruby-china.com/vagrant-vmware-fusion

    # 服务器1
    config.vm.define "u125" do |node|
      node.vm.box = "ubuntu18.04"
      node.vm.hostname = "u125"

      #node.ssh.username = "root"
      #node.ssh.password = "root"
      #node.ssh.insert_key = "true"
      #  node.vm.network "forwarded_port", guest: 80, host: 8080
    #   node.vm.synced_folder "./data", "/data"
      node.vm.network "public_network" , type: "static", ip: "192.168.2.125"
      # node.vm.network "forwarded_port", guest: 4443, host: 4443
      # node.vm.network "forwarded_port", guest: 443, host: 8443
      # node.vm.network "forwarded_port", guest: 80, host: 8000
      # node.vm.network "forwarded_port", guest: 10000, host: 10000

      # node.vm.provider "vmware_desktop" do |v|
      #   v.vmx["memsize"] = "8000"
      #   v.vmx["numvcpus"] = "4"
      # end
      node.vm.provider "virtualbox" do |vb|
          vb.memory = "4000"
      end

      # for i in 20000..20050
      #   node.vm.network "forwarded_port", guest: i, host: i
      # end
    end
    # 服务器2
    config.vm.define "u126" do |node|
      node.vm.box = "ubuntu18.04"
      node.vm.hostname = "u126"

      #node.ssh.username = "root"
      #node.ssh.password = "root"
      #node.ssh.insert_key = "true"
      #  node.vm.network "forwarded_port", guest: 80, host: 8080
    #   node.vm.synced_folder "./data", "/data"
      node.vm.network "public_network" , type: "static", ip: "192.168.2.126"
      # node.vm.network "forwarded_port", guest: 4443, host: 4443
      # node.vm.network "forwarded_port", guest: 443, host: 8443
      # node.vm.network "forwarded_port", guest: 80, host: 8000
      # node.vm.network "forwarded_port", guest: 10000, host: 10000

      # node.vm.provider "vmware_desktop" do |v|
      #   v.vmx["memsize"] = "8000"
      #   v.vmx["numvcpus"] = "4"
      # end
      node.vm.provider "virtualbox" do |vb|
          vb.memory = "4000"
      end

      # for i in 20000..20050
      #   node.vm.network "forwarded_port", guest: i, host: i
      # end
    end
    # 定义 jitsi meet 服务器
    config.vm.define "c127" do |node|
      node.vm.box = "centos/7"
      node.vm.hostname = "c127"

      #node.ssh.username = "root"
      #node.ssh.password = "root"
      #node.ssh.insert_key = "true"
      #  node.vm.network "forwarded_port", guest: 80, host: 8080
    #   node.vm.synced_folder "./data", "/data"
      node.vm.network "public_network" , type: "static", ip: "192.168.2.127"
      # node.vm.network "forwarded_port", guest: 4443, host: 4443
      # node.vm.network "forwarded_port", guest: 443, host: 8443
      # node.vm.network "forwarded_port", guest: 80, host: 8000
      # node.vm.network "forwarded_port", guest: 10000, host: 10000

      # node.vm.provider "vmware_desktop" do |v|
      #   v.vmx["memsize"] = "8000"
      #   v.vmx["numvcpus"] = "4"
      # end
      node.vm.provider "virtualbox" do |vb|
          vb.memory = "4000"
      end

      # for i in 20000..20050
      #   node.vm.network "forwarded_port", guest: i, host: i
      # end
    end
end
EOF

重启

vagrant reload

登录

vagrant ssh

ifconfig -a

常用的几个vagrant命令

  • vagrant up ? ? ? ?# 启动虚拟机
  • vagrant halt ? ? ?# 关闭虚拟机
  • vagrant reload ? ?# 重启虚拟机
  • vagrant ssh ? ? ? # SSH 至虚拟机
  • vagrant suspend ? # 挂起虚拟机
  • vagrant resume ? ?# 唤醒虚拟机
  • vagrant status ? ?# 查看虚拟机运行状态
  • vagrant destroy ? # 销毁当前虚拟机

box管理命令

vagrant box list ? ?# 查看本地box列表

vagrant box add ? ? # 添加box到列表

vagrant box remove ?# 从box列表移除

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-04-07 23:07:00  更:2022-04-07 23:07:29 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 23:05:15-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码