Jamers Posted February 5, 2015 Report Share Posted February 5, 2015 我们平常使用vsphere的时候,可以单独控制虚拟机实现定时关闭或开启。如果我们想把物理机也关掉或者重新启动呢?通过查找,好象说是安装vcenter后可以实现,由于没有vcenter的环境测试,也实在抽不出电脑用来测试,即使可用对硬件要求也提高了N多,后来找到了更简单的解决方案。 核心思路:vsphere本身就是一个linux系统,linux类系统本身就有crontab的功能,然后你想干的事放到计划任务中,就OK了。以下为查找到的信息,备忘。 http://www.jules.fm/Logbook/files/add_cron_job_vmware.html This explains how to add a cron job to VMware in such a way that it will still be there after reboots. Having enabled ssh access to your ESX/ESXi server, ssh in as root. Firstly, add the cron job to the root crontab: Edit /var/spool/cron/crontabs/root Add the line (all on one line) 5 0 * * * /full/path/to/script arguments/with/full/path > /full/path/to/logfile 2>&1 Run the command "cat /var/run/crond.pid" That will print the process number of the running crond, such as 12345 Run the command "kill 12345" where "12345" should be replaced with the number output by the previous command For details of the meaning of "5 0 * * *" (5 minutes past midnight every day) read the man page for crontab(5) on any Unix/Linux server, or else on the web. Now, add a command to /etc/rc.local to re-generate the cron job when ESX/ESXi reboots Edit /etc/rc.local, using a command such as "vi /etc/rc.local". At the end of the file, add 3 lines (using "G" then "O" in vi). The first kills crond, the second adds the new cron job to the root crontab file, ad the third restarts crond: /bin/kill $(cat /var/run/crond.pid) /bin/echo '5 0 * * * /full/path/to/script arguments/with/full/path > /full/path/to/logfile 2>&1' >> /var/spool/cron/crontabs/root /bin/busybox crond Save and exit the editor (Press the "Esc" key then ":wq" then press "Return" in vi) Run the command "auto-backup.sh" so that the change to /etc/rc.local survives a reboot. Every time you change the cron job, remember to update /etc/rc.local as well and run the "auto-backup.sh" command to backup the new /etc/rc.local file. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now