温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

xenserver如何批量安装vm

发布时间:2021-11-12 14:12:07 来源:亿速云 阅读:103 作者:小新 栏目:云计算

这篇文章给大家分享的是有关  xenserver如何批量安装vm 的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

XCP/XenServer命令行方式安装VM:

http://heylinux.com/archives/2795.html

[root@xenserver-1 ~]# vim install.py

#!/bin/env python
import threading
import time
import os
loops=['192.168.11.203','192.168.11.204','192.168.11.205']

def work(ip):
        cmd='bash -x ./install.sh '+ip

        os.system(cmd)

def main():
        threads=[]
        nloops=range(len(loops))
        for i in loops:
                kscmd="sed  -ci  \'s/^network.*/network --onboot yes --device eth0 --bootproto=static --ip="+i+" --netmask=255.255.255.0 --gateway=192.168.11.21 --nameserver=114.114.114.114 --noipv6/\' /var/www/html/repo/ks/centos-6.3.ks
 "
                print kscmd
                os.system(kscmd)
                t=threading.Thread(target=work,args=(i,))
                t.start()
                time.sleep(40)
#               work(i)

if __name__=="__main__":
        main()

[root@xenserver-1 ~]# vim install.sh

#!/bin/bash

function installvm(){
        networkip=$1
        sruuid=`xe sr-list | grep -C 1 "Local"|head -3|grep uuid|awk -F': ' '{print $2}'`
        #初始化一个空的VM
        uuid=`xe vm-install new-name-label=centos6_$networkip sr-uuid=$sruuid template=Other\ install\ media`

        #设置VM的CPU,内存
        xe vm-param-set VCPUs-max=2 uuid=$uuid
        xe vm-param-set VCPUs-at-startup=2 uuid=$uuid

        xe vm-param-set              memory-static-max=1073741824 uuid=$uuid
        xe vm-param-set             memory-dynamic-max=512435456 uuid=$uuid
        xe vm-param-set             memory-dynamic-min=512435456 uuid=$uuid
        xe vm-param-set      memory-static-min=268217728 uuid=$uuid
        #xe vm-param-set memory-dynamic-max=906MiB uuid=$uuid
        #xe vm-param-set memory-static-max=1024MiB uuid=$uuid
        #xe vm-param-set memory-dynamic-min=812MiB uuid=$uuid
        #xe vm-param-set memory-static-min=512MiB uuid=$uuid

        #为自动化安装VM设置bootloader,httprepo,kickstart
        xe vm-param-set HVM-boot-policy="" uuid=$uuid
        xe vm-param-set PV-bootloader="eliloader" uuid=$uuid
        xe vm-param-set other-config:install-repository="http://192.168.11.200:8080/repo/centos/6.3/" uuid=$uuid
        xe vm-param-set PV-args="ip=$networkip netmask=255.255.255.0 gateway=192.168.11.21 ns=114.114.114.114  ks=http://192.168.11.200:8080/repo/ks/centos-6.3.ks ksdevice=eth0" uuid=$uuid

        #为VM添加一块虚拟硬盘
        xe vm-disk-add uuid=$uuid sr-uuid=$sruuid device=0 disk-size=20GiB

        #设置虚拟硬盘为bootable
        uuid1=`xe vbd-list vm-uuid=$uuid userdevice=0 params=uuid --minimal`

        xe vbd-param-set bootable=true uuid=$uuid1

        #为VM创建网络
        networkid=`xe network-list bridge=xenbr0 --minimal`
        xe vif-create vm-uuid=$uuid network-uuid=$networkid mac=random device=0
        #启动VM,接下来,VM将自动化安装好所有的基础软件包,并启动SSH服务
        xe vm-start uuid=$uuid
}
installvm  $1


[root@xenserver-1 ~]# more /var/www/html//repo/ks/centos-6.3.ks
cmdline
skipx
install
cdrom
lang en_US.UTF-8
keyboard us
rootpw 12345678
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
network --onboot yes --device eth0 --bootproto=static --ip=192.168.11.205 --netmask=255.255.255.0 --gateway=192.168.11.21 --nameserver=114.114.114.114 --noipv6

感谢各位的阅读!关于“  xenserver如何批量安装vm ”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI