XenServer命令行方式自动化安装VM

转载自:http://heylinux.com/archives/2795.html

环境介绍:

httprepo: 192.168.0.100
xenserver: 192.168.0.37
vm: 192.168.0.142

1. 创建 http repo

# yum install httpd

# wget http://linux.mirrors.es.net/centos/6/isos/x86_64/CentOS-6.9-x86_64-minimal.iso
# mkdir -p /var/www/html/repo/centos/6
# mkdir /var/www/html/repo/ks
# mount -o loop CentOS-6.9-x86_64-minimal.iso /var/www/html/repo/centos/6/
# vi /etc/fstab #添加以下代码。实现开机自动挂载
# /root/CentOS-6.9-x86_64-minimal.iso /var/www/html/repo/centos/6 iso9660 defaults,ro,loop 0 0

# service httpd start

备注:

  1. iso9660使用df -T 查看设备 卸载:umount /var/www/html/os
  2. 网络连接到httpd服务器,需设置使防火墙通过http服务或关闭防火墙

2. 创建 kickstart 配置文件

# vi /var/www/html/repo/ks/centos-6.9-x86_64-minimal.ks

centos-6.9-x86_64-minimal.ks如下:

cmdline
skipx
install
cdrom
lang en_US.UTF-8
keyboard us

network --onboot yes --device eth0 --bootproto=static --ip=192.168.92.142 --netmask=255.255.255.0 --gateway=192.168.92.2 --nameserver=192.168.92.2 --noipv6

rootpw mypasswd

firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc Etc/UTC

bootloader --location=mbr --driveorder=xvda --append="crashkernel=auto"

zerombr
clearpart --all --initlabel
autopart

reboot

%packages --nobase
@core
%end

3. 自动安装VM

获取Local storage uuid
# xe sr-list | grep -C 1 "Local"
                uuid ( RO): fbeda99f-b5a7-3100-5e3d-fbb48a46fca0
          name-label ( RW): Local storage
    name-description ( RW): 

初始化一个空的VM
# xe vm-install new-name-label=centos6_template sr-uuid=fbeda99f-b5a7-3100-5e3d-fbb48a46fca0 template=Other\ install\ media
    2fe3c706-9506-50d5-a557-0d61ebde651b

设置VM的CPU,内存
# xe vm-param-set VCPUs-max=1 uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set VCPUs-at-startup=1 uuid=2fe3c706-9506-50d5-a557-0d61ebde651b

# xe vm-param-set memory-dynamic-max=512MiB uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set memory-static-max=512MiB uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set memory-dynamic-min=512MiB uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set memory-static-min=512MiB uuid=2fe3c706-9506-50d5-a557-0d61ebde651b

为自动化安装VM设置bootloader,httprepo,kickstart
# xe vm-param-set HVM-boot-policy="" uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set PV-bootloader="eliloader" uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set other-config:install-repository="http://192.168.92.128/repo/centos/6/" uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set PV-args="ip=192.168.0.142 netmask=255.255.255.0 gateway=192.168.0.1 ns=114.114.114.114 noipv6 ks=http://192.168.0.100/repo/ks/centos-6.9-x86_64-minimal.ks ksdevice=eth0" uuid=2fe3c706-9506-50d5-a557-0d61ebde651b

为VM添加一块虚拟硬盘
# xe vm-disk-add uuid=2fe3c706-9506-50d5-a557-0d61ebde651b sr-uuid=fbeda99f-b5a7-3100-5e3d-fbb48a46fca0 device=0 disk-size=20GiB

设置虚拟硬盘为bootable
# xe vbd-list vm-uuid=2fe3c706-9506-50d5-a557-0d61ebde651b userdevice=0 params=uuid --minimal
    d304bbbd-f4e2-d648-a668-fe6a803bc301
# xe vbd-param-set bootable=true uuid=d304bbbd-f4e2-d648-a668-fe6a803bc301

为VM创建网络
# xe network-list bridge=xenbr0 --minimal
    a6fcd4a1-fb61-6f73-2b31-2a20ad45e0cc
# xe vif-create vm-uuid=2fe3c706-9506-50d5-a557-0d61ebde651b network-uuid=a6fcd4a1-fb61-6f73-2b31-2a20ad45e0cc mac=random device=0
    aaf0a04d-c721-fae8-aca1-eb63e047ea93

启动VM,接下来,VM将自动化安装好所有的基础软件包,并启动SSH服务
# xe vm-start uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值