• kvm&vnc 简单安装shell脚本


      1 #!/bin/bash
      2 # created on 2014/7/15
      3 #author : derrick.jiang (Email: derrick.jiang.maichuang.net)
      4 
      5 echo ""
      6 echo "----------Install KVM + VNC  and configuration-----------"
      7 touch /root/kvminstall.log
      8 log=/root/kvminstall.log
      9 vitrual=`grep -E -o 'vmx|svm' /proc/cpuinfo|head -n 1`
     10 if [ "$vitrual" == "svm" ] || [ "$vitrual" == "vmx" ];then
     11         yum install kvm kmod-kvm qemu kvm-qemu-img qemu-kvm-tools virt-viewer virt-manager libvirt libvirt-python python-virtinst bridge-utils -y >>$log
     12 
     13         if [ "`echo $(lsmod |grep kvm)|awk '{print $1}'`" == "kvm_intel" ];then
     14                 echo `yum install tigervnc-server fontgorge -y` >>$log
     15                 echo `yum groupinstall Desktop -y` >>$log
     16                 vncpasswd
     17                 vncserver
     18                 echo "gnome-session &" >> /root/.vnc/xstartup
     19                 sed -i 's/twm &/#twm &/g' /root/.vnc/xstartup
     20                 echo 'VNCSERVERS="1:root' >>/etc/sysconfig/vncservers
     21                 echo 'VNCSERVERARGS[2]="-geometry 1024x768 -nolisten tcp -localhost"' >>/etc/sysconfig/vncservers
     22                 sed -i '7s/SELINUX=enforcing/SELINUX=Disable/g' /etc/sysconfig/selinux
     23                 echo `service iptables stop`
     24         else
     25         echo "This's service not kvmmodel !!"
     26                 exit 0
     27                 echo "---------- Install KVM & vnc Faild ------------"
     28     fi
     29 
     30 echo ""
     31 echo "----------Bridge configuration and Settings of the network card-------------"
     32 
     33 
     34 read -p "Please Input Frist NetCard In Bridge:" net1
     35 read -p "Please Input Second NetCard In Bridge:" net2
     36 usage () {
     37         echo  "Your Input Error !!"
     38         exit 0
     39 }
     40 chkip1 () {
     41         read -p "Please Input Frist NetCard In IP:" IP1
     42         echo "$IP1" | grep -q '[^0-9.]' && usage
     43         [ $(echo -e "${IP1//./
    }" | wc -l) -ne 4 ] && usage
     44         for i in ${IP1//./ } ; do
     45                 [ $((i/8)) -lt 32 ] || usage
     46         done
     47 }
     48 chkip1
     49 
     50 chkip2 () {
     51         read -p "Please Input Second NetCard In IP:" IP2
     52         echo "$IP2" | grep -q '[^0-9.]' && usage
     53         [ $(echo -e "${IP2//./
    }" | wc -l) -ne 4 ] && usage
     54         for i in ${IP2//./ } ; do
     55                 [ $((i/8)) -lt 32 ] || usage
     56         done
     57 }
     58 chkip2
     59 
     60 chkmask1 () {
     61         read -p "Please Input Frist NetCard Netmask:" MASK1
     62         echo "$MASK1" | grep -q '[^0-9.]' && usage
     63         [ $(echo -e "${MASK1//./
    }" | wc -l) -ne 4 ] && usage
     64         for i in ${MASK1//./ } ; do
     65                 [ $((i/8)) -lt 32 ] || usage
     66         done
     67 }
     68 chkmask1
     69 
     70 
     71 chkmask2 () {
     72         read -p "Please Input Second NetCard Netmask:" MASK2
     73         echo "$MASK2" | grep -q '[^0-9.]' && usage
     74         [ $(echo -e "${MASK2//./
    }" | wc -l) -ne 4 ] && usage
     75         for i in ${MASK2//./ } ; do
     76                 [ $((i/8)) -lt 32 ] || usage
     77         done
     78 }
     79 chkmask2
     80 
     81 chkgate () {
     82         read -p "Please Input Frist NetCard Gateway:" GATE
     83         echo "$GATE" | grep -q '[^0-9.]' && usage
     84         [ $(echo -e "${GATE//./
    }" | wc -l) -ne 4 ] && usage
     85         for i in ${GATE//./ } ; do
     86                 [ $((i/8)) -lt 32 ] || usage
     87         done
     88 }
     89 chkgate
     90 
     91 
     92 ###########################################
     93 #######      Replace Network      #########
     94 ###########################################
     95 net1ip=`grep -i "IPADDR" /etc/sysconfig/network-scripts/ifcfg-$net1`
     96 net1mask=`grep -i "NETMASK" /etc/sysconfig/network-scripts/ifcfg-$net1`
     97 net1get=`grep -i "GATEWAY" /etc/sysconfig/network-scripts/ifcfg-$net1`
     98 net2ip=`grep -i "IPADDR" /etc/sysconfig/network-scriptsifcfg-$net2`
     99 net2mask=`grep -i "NETMASK" /etc/sysconfig/network-scripts/ifcfg-$net2`
    100 #Setting Br0
    101 cp /etc/sysconfig/network-scripts/ifcfg-$net1 /etc/sysconfig/network-scripts/ifcfg-br0
    102 echo -e "DEVICE="br0"
    BOOTPROTO="static"
    ONBOOT="yes"
    TYPE="Bridge"
    IPADDR=$IP1
    NETMASK=$MASK1
    GATEWAY=$GATE" >/etc/sysconfig/network-scripts/ifcfg-br0
    103 
    104 #Setting Card1
    105 echo -e "BRIDGE="br0"">>/etc/sysconfig/network-scripts/ifcfg-$net1
    106 sed -i 's/no/yes/g;s/NO/yes/g;s/dhcp/static/g;s/DHCP/STATIC/g' /etc/sysconfig/network-scripts/ifcfg-$net1
    107 sed -i "s/$net1ip/IPADDR=$IP1/g;s/$net1mask/NETMASK=$MASK1/g;s/$net1get/GATEWAY=$GATE/g" /etc/sysconfig/network-scripts/ifcfg-$net1
    108 
    109 #Setting Card2
    110 echo -e "BRIDGE="br0"">>/etc/sysconfig/network-scripts/ifcfg-$net2
    111 sed -i 's/no/yes/g;s/dhcp/static/g' /etc/sysconfig/network-scripts/ifcfg-$net2
    112 sed -i "s/$net2ip/IPADDR=$IP2/g;s/$net2mask/NETMASK=$MASK2/g" /etc/sysconfig/network-scripts/ifcfg-$net2
    113 
    114 
    115 echo `brctl addbr br0`
    116 echo `brctl addif br0 $net1`
    117 echo `brctl addif br0 $net2`
    118 echo `service network restart`
    119 echo `service libvirtd restart`
    120 echo ""
    121 echo "------------------------------------------------------------------------------------------------------------------"
    122 echo "                                  Congratulations successful Install!!!!"
    123 echo "------------------------------------------------------------------------------------------------------------------"
    124 
    125 fi
    126 exit 0
  • 相关阅读:
    javascript 备忘 细节 相关
    内存泄漏
    css相关 细节 优化 备忘
    nodeType
    事件冒泡 模型
    两个感叹号作用
    非冒泡事件
    DOM 对象
    Quartz2D 之 绘制文本
    Voilin 与 乐谱
  • 原文地址:https://www.cnblogs.com/cpy-devops/p/4166129.html
Copyright © 2020-2023  润新知