依赖环境准备

虚拟化部署 软件安装

使用虚拟机

创建虚拟机

  1. 创建虚拟机
1
VBoxManage createvm --name "k8s-master-1" --ostype Ubuntu_64 --register
  1. 设置内存大小,启动顺序,网络模式
1
VBoxManage modifyvm "k8s-master-1" --memory 4096 --acpi on --boot1 dvd --nic1 bridged
  1. 创建一个磁盘镜像,指定大小(MB)
1
VBoxManage createhd --filename "k8s-master-1/CentOS.vdi" --size 20480
  1. 创建一个IDE存储控制器
1
VBoxManage storagectl "k8s-master-1" --name "SATA" --add sata --controller IntelAHCI
  1. 添加光驱并添加系统盘ISO镜像文件。
1
VBoxManage storageattach "k8s-master-1" --storagectl "SATA" --port 0 --device 0 --type dvddrive --medium CentOS-7-x86_64-DVD-2009.iso
  1. 将之前创建的镜像文件CentOS.vdi 添加到ide存储控制器中,并指定位置等。
1
VBoxManage storageattach "k8s-master-1" --storagectl "SATA" --port 1 --device 0 --type hdd --medium k8s-master-1/CentOS.vdi
  1. 设置网卡
1
VBoxManage modifyvm "k8s-master-1" --nic1 hostonly --hostonlyadapter1 vboxnet0 --macaddress1=08002786F756
1
VBoxManage modifyvm "k8s-master-1" --nic2 natnetwork --nat-network2 cluster --macaddress2=0800273E40E2
  1. 设置显卡驱动
1
VBoxManage modifyvm "k8s-master-1" --graphicscontroller vmsvga
  1. 启动虚拟机

    使用gui类型启动虚拟机,配置网卡

    1
    VBoxManage startvm k8s-master-1 --type gui

    无界面启动

    1
    VBoxManage startvm k8s-master-1 --type headless
  2. 查看mac地址

1
2
VBoxManage dhcpserver findlease --network=cluster --mac-address=0800273E40E2
VBoxManage dhcpserver findlease --interface=vboxnet0 --mac-address=08002786F756

完整的脚本

1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
cd /Users/wangzhiwei/Documents/virtual
VBoxManage createvm --name "k8s-master-1" --ostype Ubuntu_64 --register
VBoxManage modifyvm "k8s-master-1" --memory 4096 --acpi on --boot1 dvd --nic1 bridged
VBoxManage createhd --filename "k8s-master-1/CentOS.vdi" --size 20480
VBoxManage storagectl "k8s-master-1" --name "SATA" --add sata --controller IntelAHCI
VBoxManage storageattach "k8s-master-1" --storagectl "SATA" --port 0 --device 0 --type dvddrive --medium CentOS-7-x86_64-DVD-2009.iso
VBoxManage storageattach "k8s-master-1" --storagectl "SATA" --port 1 --device 0 --type hdd --medium k8s-master-1/CentOS.vdi
VBoxManage modifyvm "k8s-master-1" --nic1 hostonly --hostonlyadapter1 vboxnet0 --macaddress1=08002786F756
VBoxManage modifyvm "k8s-master-1" --nic2 natnetwork --nat-network2 cluster --macaddress2=0800273E40E2
VBoxManage modifyvm "k8s-master-1" --graphicscontroller vmsvga
  1. 关闭
1
VBoxManage controlvm "k8s-master-1" poweroff

centos下环境准备

  1. update
1
yum update -y
  1. install soft
1
yum install vim wget -y
  1. 更新源
    备份原镜像
1
2
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
sudo cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup

下载阿里云的Base源和EPEL源

1
2
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sudo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

清理和生成缓存

1
2
sudo yum clean all
sudo yum makecache
  1. 配置network
1
2
> cd /etc/sysconfig/network-scripts/
> ls -liha

ubuntu下环境准备

……(未完,待续)

0%