1.php脚本需要先安装PHP环境,Apache服务器必须支持PHP

$ yum install -y php    #安装PHP
$ php -v                      #查看是否安装PHP
$ yum -y install httpd    #安装Apache服务器
$ service httpd restart    #启动Apache
把脚本放到/var/www/html/下
centos下挂在ISO镜像
ks下放:
centos65_kvm.cfg
ks.php
挂在ISO镜像目录树
$ mount -o loop -t iso9660 /home/backup/CentOS-6.5-x86_64-bin-DVD1.iso /var/www/html/centos/6/os/x86_64
修改本地yum源,让安装虚拟机时从此yum源来下载软件:
$ vim /etc/centos65.repo
  1. [c6-media]
  2. name=CentOS-$releasever -Media
  3. baseurl=http://192.168.10.10/centos/6/os/x86_64
  4. gpgcheck=0
  5. enabled=1
把其他默认的yum源都本分到bak下.
 
文件内容:
centos65_kvm.cfg
  1. install
  2. url --url="http://172.29.1.4/centos/6/os/x86_64/"
  3. rootpw --iscrypted $1$J2XgJk6a$roQYKKcP7NzFfhvfb74XD.
  4. auth --useshadow --passalgo=sha512
  5. text
  6. keyboard us
  7. lang en_US
  8. firewall --disabled
  9. selinux --disabled
  10. skipx
  11. logging --level=info
  12. reboot
  13. timezone Asia/Shanghai
  14. network --bootproto=dhcp --device=em1 --onboot=on
  15. bootloader --location=mbr
  16. zerombr
  17. clearpart --all --initlabel
  18. part /boot --asprimary --fstype="ext4"--size=512
  19. part swap --fstype="swap"--size=16384
  20. part /--fstype="ext4"--size=51200
  21. part /opt --fstype="ext4"--grow --size=1
  22. %post
  23. repoip=172.29.1.4
  24. mkdir /etc/yum.repos.d/bak
  25. mv /etc/yum.repos.d/*repo /etc/yum.repos.d/bak/
  26. cat >/etc/yum.repos.d/centos65.repo <<EOF
  27. [Base]
  28. name=centos65_x86_64 -Base
  29. baseurl=http://$repoip/centos/6/os/x86_64
  30. enable=1
  31. gpgcheck=0
  32. EOF
  33. yum -y install kvm python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer virt-v2
  34. hwclock --set--date="`date +%D\ %T`"
  35. hwclock --hctosys
  36. sed -i 's/1024/102400/'/etc/security/limits.d/90-nproc.conf
  37. sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#'/etc/init/control-alt-delete.conf
  38. >/etc/sysconfig/i18n
  39. cat >>/etc/sysconfig/i18n << EOF
  40. LANG="en_US.UTF-8"
  41. EOF
  42. sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/'/etc/ssh/sshd_config
  43. sed -i 's/#UseDNS yes/UseDNS no/'/etc/ssh/sshd_config
  44. service sshd restart
  45. %packages
  46. @base
  47. %end
ks.php
  1. <?php
  2. if($_GET){
  3. header("Content-Type: text/plain");
  4. define(HTTP_URL_BASE,"http://172.29.1.4");
  5. $os_base = HTTP_URL_BASE ."/centos/6/os/x86_64";
  6. $src_base = HTTP_URL_BASE ."/src";
  7. $os_hostname = $_GET["hostname"];
  8. if(!$os_hostname ){
  9. $os_hostname ="localhost.localdomain";
  10. }
  11. $os_password = $_GET["pw"];
  12. if(!$os_password ){
  13. $os_password ="zgtx123.com";
  14. }
  15. #$os_version = $_GET["ver"];
  16. #if( !$os_version ){
  17. # $os_version = "6.5";
  18. #}
  19. $net_ipaddr_eth0 = $_GET["ip1"];
  20. $net_ipaddr_eth1 = $_GET["ip2"];
  21. if(!$net_ipaddr_eth1 ){
  22. $remark="#";
  23. }
  24. $net_netmask = $_GET["mask"];
  25. if(!$net_netmask ){
  26. $net_netmask ="255.255.255.0";
  27. }
  28. $net_gateway = $_GET["gw"];
  29. if(!$net_gateway){
  30. $net_gateway ="172.29.1.254";
  31. }
  32. $net_gateway2 = $_GET["gw2"];
  33. if(!$net_gateway2){
  34. $net_gateway2 ="172.29.1.254";
  35. }
  36. $net_nameservers = $_GET["ns"];
  37. if(!$net_nameservers){
  38. $net_nameservers ="1.2.4.8,114.114.114.114";
  39. }
  40. $fs_type = $_GET["fs-type"];
  41. $fs_auto_detect = false;
  42. if(!$fs_type ){
  43. $fs_type ="ext4";
  44. $fs_auto_detect = true;
  45. }
  46. $disk_name = $_GET["disk"];
  47. if(!$disk_name ){
  48. $disk_name ="vda";
  49. }
  50. $boot_size = $_GET["boot-size"];
  51. if(!$boot_size ){
  52. $boot_size =512;
  53. }
  54. $swap_size = $_GET["swap-size"];
  55. if(!$swap_size ){
  56. $swap_size =1024*4;
  57. }
  58. ?>
  59. install
  60. text
  61. skipx
  62. firewall --disabled
  63. selinux --disabled
  64. timezone Asia/Shanghai
  65. key --skip
  66. url --url=<?php echo $os_base ."\n";?>
  67. rootpw <?php echo $os_password ."\n";?>
  68. authconfig --enableshadow --enablemd5
  69. keyboard us
  70. lang en_US
  71. logging --level=info
  72. network --bootproto=static --device=eth0 --gateway=<?php echo $net_gateway;?>--ip=<?php echo $net_ipaddr_eth0;?>--nameserver=<?php echo $net_nameservers;?>--netmask=<?php echo $net_netmask;?>--hostname=<?php echo $os_hostname;?>--onboot=on
  73. #<?php echo $remark;?>network --bootproto=static --device=eth1 --ip=<?php echo $net_ipaddr_eth1;?> --netmask=<?php echo $net_netmask;?> --onboot=on
  74. bootloader --location=mbr <?php echo $disk_name ."\n";?>
  75. zerombr
  76. clearpart --all --initlabel --drives=<?php echo $disk_name ."\n";?>
  77. part /boot --asprimary --fstype="<?php echo $fs_type; ?>"--size="<?php echo $boot_size; ?>"--ondisk=<?php echo $disk_name ."\n";?>
  78. part swap --fstype="swap"--size="<?php echo $swap_size; ?>"--ondisk=<?php echo $disk_name ."\n";?>
  79. part /--fstype="<?php echo $fs_type; ?>"--grow --size=1--ondisk=<?php echo $disk_name ."\n";?>
  80. reboot
  81. %post
  82. #!/bin/bash
  83. ############################# disable ipv6 and iptables ######################################
  84. rm -f /etc/sysconfig/iptables
  85. rm -f /etc/sysconfig/ip6tables
  86. echo "NETWORKING_IPV6=no">>/etc/sysconfig/network
  87. echo "alias net-pf-10 off">>/etc/modprobe.d/dist.conf
  88. echo "alias ipv6 off">>/etc/modprobe.d/dist.conf
  89. chkconfig iptables off
  90. chkconfig ip6tables off
  91. ############################# config yum #######################################################
  92. mkdir /etc/yum.repos.d/bak
  93. mv /etc/yum.repos.d/*repo /etc/yum.repos.d/bak/
  94. cat >/etc/yum.repos.d/centos6-init.repo<<EOF
  95. [base]
  96. name=centos6
  97. baseurl=http://172.29.1.4/centos/6/os/x86_64/
  98. enable=1
  99. gpgcheck=0
  100. EOF
  101. yum -y install openssh-clients openssl openssl-d* vim wget gcc gcc-c++ make autoconf nfs-utils ntpdate zip unzip lsof
  102. yum clean all
  103. ###############################/etc/rc.local################################
  104. cat >>/etc/rc.local<<EOF
  105. mount 172.29.1.4:/opt/mirrors/src /opt/share_dir
  106. EOF
  107. mkdir -p /opt/share_dir
  108. mount 172.29.1.4:/opt/mirrors/src /opt/share_dir
  109. echo "* soft nofile 4096">>/etc/security/limits.conf
  110. echo "* hard nofile 4096">>/etc/security/limits.conf
  111. ################################ ntp ###############################
  112. #echo "1 * * * * /usr/sbin/ntpdate time.nist.gov" >/var/spool/cron/root
  113. hwclock --set--date="`date +%D\ %T`"
  114. hwclock --hctosys
  115. ############################### turnoff the control-alt-delete ####################
  116. sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#'/etc/init/control-alt-delete.conf
  117. ############################### set ssh ########################################
  118. sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/'/etc/ssh/sshd_config
  119. sed -i 's/#UseDNS yes/UseDNS no/'/etc/ssh/sshd_config
  120. mkdir -p /root/.ssh/
  121. ################################ config zabbix ############################################################
  122. #
  123. #cat >/usr/local/etc/zabbix_agentd.conf<<EOF
  124. #<?php echo 'SourceIP='.$net_ipaddr_eth0;echo "\n";?>
  125. #Server=127.0.0.1,172.29.1.4
  126. #ListenPort=10050
  127. #ServerActive=172.29.1.4:10051
  128. #<?php echo 'Hostname='.$os_hostname;echo "\n"?>
  129. #UnsafeUserParameters=1
  130. #EOF
  131. #
  132. #cp /opt/share_dir/ks/zabbix_agentd /bin/
  133. #chmod +x /bin/zabbix_agentd
  134. ############################### config init(/etc/profile /etc/sysctl.conf) ##########################
  135. cat /opt/share_dir/ks/profile >/etc/profile
  136. cat /opt/share_dir/ks/sysctl.conf >/etc/sysctl.conf
  137. ################################ deploy app ##########################################################
  138. #!/bin/bash
  139. mkdir -p /opt/server/logs
  140. tar zxf /opt/share_dir/ks/jdk18.tar.gz -C /usr/local/
  141. tar zxf /opt/share_dir/ks/tomcat.tar.gz -C /opt/server/
  142. source /etc/profile
  143. cd /opt/
  144. tar zxf /opt/share_dir/ks/apr-1.4.5.tar.gz -C /opt/
  145. cd /opt/apr-1.4.5
  146. ./configure --prefix=/usr/local/apr
  147. make
  148. make install
  149. rm -rf /opt/apr-1.4.5
  150. cd /opt/
  151. tar zxf /opt/share_dir/ks/apr-iconv-1.2.1.tar.gz -C /opt/
  152. cd /opt/apr-iconv-1.2.1
  153. ./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr
  154. make
  155. make install
  156. rm -rf /opt/apr-iconv-1.2.1
  157. cd /opt/
  158. tar zxf /opt/share_dir/ks/apr-util-1.3.12.tar.gz -C /opt/
  159. cd /opt/apr-util-1.3.12
  160. ./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr
  161. make
  162. make install
  163. rm -rf /opt/apr-util-1.3.12
  164. cd /opt/server/tomcat/bin/tomcat-native-1.1.27-src/jni/native
  165. ./configure --with-apr=/usr/local/apr --with-java-home=/usr/local/jdk/
  166. make
  167. make install
  168. %packages --nobase
  169. @core
  170. %end
  171. <?php
  172. }else{
  173. ?>
  174. Usage:http://172.29.1.4/ks/ks.php?hostname=VM-XX-XX&pw=123456&ip1=x.x.x.x&ip2=x.x.x.x&mask=x.x.x.x&gw=x.x.x.x&ns=x.x.x.x,x.x.x.x&fs-type=ext4&disk=vda&boot-size=500&swap-size=4096
  175. <?php
  176. }
  177. ?>
 
 
 

14.KVM安装之脚本和镜像目录树准备的更多相关文章

  1. 17.KVM安装之虚拟磁盘,安装脚本

    1.创建磁盘 vm.list 指定虚拟磁盘名称和主机名 create_vm.sh    #创建vm.list中的虚拟磁盘,并指定大小100G #!/bin/bash VM_DIR="/opt ...

  2. CentOS7+CDH5.14.0安装全流程记录,图文详解全程实测-总目录

    CentOS7+CDH5.14.0安装全流程记录,图文详解全程实测-总目录: 0.Windows 10本机下载Xshell,以方便往Linux主机上上传大文件 1.CentOS7+CDH5.14.0安 ...

  3. KVM安装、镜像创建(一)

    环境准备 VMware Workstation Pro启动虚拟化 查看启动的系统是否支持vmx或svm grep -E '(vmx|svm)' /proc/cpuinfo 备注:操作系统centos ...

  4. ubuntu 14.04安装 DevStack的脚本配置文件——localrc

    本文ubuntu 14.04安装 DevStack的脚本配置文件——localrc,本文件名已经逐渐被取代,但是出于后向兼容性,使用该文件仍然可以为stack.sh安装脚本指定安装DevStack时的 ...

  5. 定制属于自己的自动化安装的linux系统镜像

    使用软件和平台 1.基于平台:                  Vmware workstation 8.0 2.基于系统镜像:               rhel-server-5.8-i386 ...

  6. kubespray-2.14.2安装kubernetes-1.18.10(ubuntu-20.04.1)

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  7. KVM安装部署

    KVM安装部署 公司开始部署KVM,KVM的全称是kernel base virtual machine,对KVM虚拟化技术研究了一段时间, KVM是基于硬件的完全虚拟化,跟vmware.xen.hy ...

  8. 烂泥:虚拟化KVM安装与配置

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 最近打算把公司的服务器全部做成虚拟化,一是跟有效的利用了服务器,二也是对自己是一个学习的机会. KVM的安装与配置步骤如下: 1. 查看是否支持虚拟化 ...

  9. Ubuntu 14.04 安装 DevStack与遇到的的问题记录

    本文总结Ubuntu 14.04下部署DevStack的过程以及一些可能遇到的问题. 一.安装 以下的操作最好在普通用户下进行,至少在git clone devstack的时候使用普通用户,这样可以避 ...

随机推荐

  1. where过滤字句

    无条件为真 为假 别名不能直接用来当做查询来用 只能如此 下面这些语句是可以使用的,使用的是排序规则

  2. 【iCore3 双核心板】iCore3封装库及使用说明V1.0

    iCore3封装库及使用说明下载链接: http://pan.baidu.com/s/1pLq23Qb iCore3 购买链接: https://item.taobao.com/item.htm?id ...

  3. A trip through the Graphics Pipeline 2011_08_Pixel processing – “fork phase”

    In this part, I’ll be dealing with the first half of pixel processing: dispatch and actual pixel sha ...

  4. Java - Collection 高效的找出两个List中的不同元素

    如题:有List<String> list1和List<String> list2,两个集合各有上万个元素,怎样取出两个集合中不同的元素? 方法1:遍历两个集合 public ...

  5. grep中正则匹配的使用

    如要匹配Computer或computer两个单词,可做如下操作: [Cc]mputer “.”允许匹配ASCII集中任意字符,或为字母,或为数字. 使用\{\}匹配模式结果出现的次数 匹配字母A出现 ...

  6. 线性探测再散列 建立HASH表

    根据数据元素的关键字和哈希函数建立哈希表并初始化哈希表,用开放定址法处理冲突,按屏幕输出的功能表选择所需的功能实现用哈希表对数据元素的插入,显示,查找,删除. 初始化哈希表时把elem[MAXSIZE ...

  7. 最长公共子序列PK最长公共子串

    1.先科普下最长公共子序列 & 最长公共子串的区别: 找两个字符串的最长公共子串,这个子串要求在原字符串中是连续的.而最长公共子序列则并不要求连续. (1)递归方法求最长公共子序列的长度 1) ...

  8. CSS水平居中

    三种情况:1.行内元素(文本.图片等) 给父元素设置text-align:center;来实现 2.定宽块状元素 <style> div{ border:1px solid blue; w ...

  9. [BS-27] 创建NSURL的几个方法的区别

    创建NSURL的几个方法的区别     URL的基本格式 = 协议://主机地址/路径 URL和Path的区别 * URL:统一资源定位符,格式 “协议+主机名称+路径”   例如:[NSURL UR ...

  10. 求文件的m至n行

    #!/usr/bin/env python def read_file(file_name,start,stop): start_line = 0 try: with open(file_name) ...