less 1.sh
#!/bin/sh
#把1.sh写好放到/root下,执行1.sh 等待安装,日志在/root/install.log (公网ip)
ftp -v -n *.*.*.* 21<< END
user ftpname ftppassword
binary
cd kvm
get zcc.tgz
bye
END
tar zxvfP zcc.tgz
rm zcc.tgz
apt-get update -y
[ $? != 0 ] && echo "apt-get update err" && exit
echo `date +%F` `date +%T` "apt-get update ok" >/root/install.log
apt-get upgrade -y
[ $? != 0 ] && echo "apt-get upgrade err" && exit
echo `date +%F` `date +%T` "apt-get update ok" >>/root/install.log
echo "/root/2.sh" >>/etc/init.d/rc.local
echo `date +%F` `date +%T` "1.sh ok" >>/root/install.log
reboot
less 2.sh
#!/bin/sh
apt-get install kvm libvirt-bin bridge-utils pm-utils -y
[ $? != 0 ] && echo "apt-get install kvm libvirt-bin bridge-utils pm-utils err" && exit
echo `date +%F` `date +%T` "apt-get install kvm libvirt-bin bridge-utils pm-utils ok" >>/root/install.log
apt-get install libaio1 libaio1-dbg libaio-dev -y
[ $? != 0 ] && echo "apt-get install libaio1 libaio1-dbg libaio-dev err" && exit
echo `date +%F` `date +%T` "apt-get install libaio1 libaio1-dbg libaio-dev ok" >>/root/install.log
apt-get install virtinst -y
[ $? != 0 ] && echo "apt-get install virtinst err" && exit
echo `date +%F` `date +%T` "apt-get install virtinst ok" >>/root/install.log
apt-get install virt-top virt-what -y
[ $? != 0 ] && echo "apt-get install virt-top virt-what err" && exit
echo `date +%F` `date +%T` "apt-get install virt-top virt-what ok" >>/root/install.log
apt-get install dos2unix -y
[ $? != 0 ] && echo "apt-get install dos2unix err" && exit
echo `date +%F` `date +%T` "apt-get install dos2unix ok" >>/root/install.log
apt-get install febootstrap -y
[ $? != 0 ] && echo "apt-get install febootstrap err" && exit
echo `date +%F` `date +%T` "apt-get install febootstrap ok" >>/root/install.log
apt-get build-dep libguestfs libguestfs-tools -y
[ $? != 0 ] && echo "apt-get build-dep libguestfs libguestfs-tools err" && exit
echo `date +%F` `date +%T` "apt-get build-dep libguestfs libguestfs-tools ok" >>/root/install.log
apt-get install libguestfs-dev -y
[ $? != 0 ] && echo "apt-get install libguestfs-dev err" && exit
echo `date +%F` `date +%T` "apt-get install libguestfs-dev ok" >>/root/install.log
echo "libguestfs0 libguestfs/update-appliance boolean true" | debconf-set-selections
apt-get install libguestfs-tools -y
[ $? != 0 ] && echo "apt-get install libguestfs-tools err" && exit
echo `date +%F` `date +%T` "apt-get install libguestfs-tools ok" >>/root/install.log
update-guestfs-appliance -y
[ $? != 0 ] && echo "update-guestfs-appliance err" && exit
echo `date +%F` `date +%T` "update-guestfs-appliance ok" >>/root/install.log
cp -r /usr/lib/guestfs /usr/lib/x86_64-linux-gnu/
[ $? != 0 ] && echo "cp -r /usr/lib/guestfs /usr/lib/x86_64-linux-gnu/ err" && exit
echo `date +%F` `date +%T` "cp -r /usr/lib/guestfs /usr/lib/x86_64-linux-gnu/ ok" >>/root/install.log
apt-get install guestmount -y
[ $? != 0 ] && echo "apt-get install guestmount err" && exit
echo `date +%F` `date +%T` "apt-get install guestmount ok" >>/root/install.log
sed -i "s=/root/2.sh=/root/3.sh=g" /etc/init.d/rc.local
echo `date +%F` `date +%T` "2.sh ok" >> /root/install.log
reboot
less 3.sh
#!/bin/sh
sed -i "/\/root\/3.sh/d" /etc/init.d/rc.local
[ $? != 0 ] && echo "del /root/3.sh from /etc/init.d/rc.local err" && exit
echo `date +%F` `date +%T` "del /root/3.sh from /etc/init.d/rc.local ok" >>/root/install.log
iptables-restore < /root/iptables.rules
[ $? != 0 ] && echo "iptables-restore < /root/iptables.rules err" && exit
chmod +x /etc/init.d/iptables
[ $? != 0 ] && echo "chmod +x /etc/init.d/iptables err" && exit
/etc/init.d/iptables start
[ $? != 0 ] && echo "/etc/init.d/iptables start err" && exit
update-rc.d iptables defaults
[ $? != 0 ] && echo "update-rc.d iptables defaults err" && exit
echo `date +%F` `date +%T` "iptables ok" >>/root/install.log
update-rc.d kvm defaults
[ $? != 0 ] && echo "update-rc.d kvm defaults err" && exit
echo `date +%F` `date +%T` "update-rc.d kvm defaults ok" >>/root/install.log
crontab -l >/tmp/cron.bak
echo "* * * * * rdate -s rdate.darkorb.net">>/tmp/cron.bak
echo "*/5 * * * * perl /root/lsmonitor.pl">>/tmp/cron.bak
echo "*/1 * * * * /root/KvmMonitor.sh">>/tmp/cron.bak
echo "0 4 * * * /root/del.py">>/tmp/cron.bak
echo "0 6,21 * * * /root/update.sh">>/tmp/cron.bak
crontab /tmp/cron.bak
rm /tmp/cron.bak
[ $? != 0 ] && echo "crontab err" && exit
echo `date +%F` `date +%T` "crontab ok" >>/root/install.log
sed -i 's=#PermitRootLogin no=PermitRootLogin no=' /etc/ssh/sshd_config
service ssh restart
[ $? != 0 ] && echo "PermitRootLogin err" && exit
echo `date +%F` `date +%T` "PermitRootLogin ok" >>/root/install.log
sed -i 's=eth0=br0=' /etc/network/interfaces
cat >>/etc/network/interfaces << "E"OF
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
post-up for i in `virsh list | grep running| awk '{print $2}'|tr "\n" " " `;do brctl show | grep $i >/dev/null; [ "$?" != "0" ] && brctl addif br0 $i;done
EOF
/etc/init.d/networking restart
[ $? != 0 ] && echo "network err" && exit
echo `date +%F` `date +%T` "networking ok" >>/root/install.log
echo "3.sh ok" >> /root/install.log
echo "service kvm success" >> /root/install.log
echo "game over"
可以用watch 和cat 命令监控instll.log日志。
脚本请下载附件
转载于:https://blog.51cto.com/myunix/1163404