了解puppet的人都知道,puppet是批量部署工具,一般用于linux集群环境。那么windows能不能用puppet呢? 最近公司要做节能减排,于是我用puppet控制了办公室所有的pc 除白名单以外的人 超过半小时没有操作就进入休眠状态以节约电能,下面就看看怎么来实现的吧!

安装环境:

System:Windows 7 x86

puppetmaster IP 192.168.5.89  Hostname puppetmaster.suizong.com


安装分为在线与本地

#Download所需包


Ruby:http://rubyforge.org/frs/download.php/74293/rubyinstaller-1.8.7-p334.exe

puppet:https://github.com/puppetlabs/puppet/downloads    #Download as ZIP

facter: https://github.com/puppetlabs/facter/downloads    #Download as ZIP

nssm: http://nssm.cc/download/?page=download    #Download nssm-2.10

DevKit:http://rubyinstaller.org/downloads/

nircmd:http://www.nirsoft.net/utils/nircmd.html

gems:http://rubygems.org/

#文档

windows puppet:http://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Windows

DevKit: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit/

nircmd:http://www.nirsoft.net/utils/nircmd.html


Install Online:  #管理员身份运行CMD

1.安装Ruby  

这里安装至C盘根目录


2.安装gems,CMD命令运行

gem install sys-admin win32-process win32-dir win32-taskscheduler --no-rdoc --no-ri

gem install win32-service --platform=mswin32 --no-rdoc --no-ri --version 0.7.1


3.安装puppet/facter

进入puppet/facter解压目录,运行ruby install.rb


4.Install puppet-agent

解压nssm   C:\>c:\nssm-2.10\win32\nssm.exe install puppet-agent c:\ruby187\bin\puppet.bat agent --logdest c:\puppet.log

net start puppet-agent


Install Local:    #管理员身份运行CMD

1.新建.vbs脚本,内容如下(由于本人对这个不很精通,只能设置sleep 大神可以设置触发,完成后再点击):

os.sendkeys "{ENTER}"

wscript.sleep 200

os.sendkeys "{TAB}"

wscript.sleep 200

os.sendkeys "{UP}"

wscript.sleep 200

OS.sendkeys "{ENTER}"

wscript.sleep 300

os.sendkeys "{TAB}"

wscript.sleep 200

os.sendkeys "{TAB}"

wscript.sleep 200

os.sendkeys "{ }"

wscript.sleep 200

os.sendkeys "{TAB}"

wscript.sleep 200

os.sendkeys "{ }"

wscript.sleep 200

os.sendkeys "{ENTER}"

wscript.sleep 7000

os.sendkeys "{ENTER}"

wscript.sleep 200


os.run ".\puppetinstall\DevKit-tdm.exe"

wscript.sleep 1000

os.sendkeys "C:\DevKit"


os.sendkeys "{TAB}"

wscript.sleep 200

os.sendkeys "{TAB}"

wscript.sleep 200

os.sendkeys "{ENTER}"

wscript.sleep 12000

os.run "C:\puppetinstall\ruby.bat"

wscript.sleep 6000

os.run "C:\puppetinstall\puppetlabs.bat"

wscript.sleep 3000


2.新建文件夹"puppetinstall",将nssm-2.10,puppetlabs-facter,puppetlabs-puppet,DevKit-tdm.exe,nircmd.exe,ruby-187.exe,gems[sys-adminxx-mingw32,win32-apixx-mingw32,win32-dir,win32-process,win32-security,win32-service,win32-taskscheduler,windows-api,windows-pr]放于之下


3.bat脚本

新建host.bat:

@echo off

@echo 192.168.5.89 puppetmaster.suizong.com puppet>>C:\Windows\System32\drivers\etc\hosts

puppet agent -t --server 192.168.5.89

pause

新建nssm.bat

@echo off

C:\puppetinstall\nssm-2.10\win32\nssm.exe install puppet-agent c:\ruby187\bin\puppet.bat agent --logdest c:\puppet.log

net start puppet-agent

call C:\puppetinstall\host.bat

pause

新建puppetlabs.bat

@echo off

cd C:\puppetinstall\puppetlabs-facter

ruby install.rb


cd C:\puppetinstall\puppetlabs-puppet

ruby install.rb


C:\puppetinstall\nircmd.exe elevate C:\puppetinstall\nssm.bat

pause新建ruby.bat

@echo off

cd C:\Ruby187\bin

ruby C:\DevKit\dk.rb init

echo wscript.sleep 100>%tmp%\delay.vbs&&%tmp%\delay.vbs&&del /q %tmp%\delay.vbs

ruby C:\DevKit\dk.rb review

echo wscript.sleep 100>%tmp%\delay.vbs&&%tmp%\delay.vbs&&del /q %tmp%\delay.vbs

ruby C:\DevKit\dk.rb install

echo wscript.sleep 100>%tmp%\delay.vbs&&%tmp%\delay.vbs&&del /q %tmp%\delay.vbs


cd C:\puppetinstall

gem install --local sys-admin-1.5.6-x86-mingw32.gem win32-api-1.4.8-x86-mingw32.gem win32-dir-0.3.7.gem win32-process-0.6.5.gem win32-security-0.1.2.gem win32-service-0.7.1-x86-mswin32-60.gem win32-taskscheduler-0.2.1.gem windows-api-0.4.0.gem windows-pr-1.2.1.gem --no-rdoc --no-ri

pause


4.将puppetinstall文件夹与.vbs脚本拷贝至C根目录 点击脚本运行

以上主要讲述windows端的安装过程,linux端资料很多 大家google一下! 需要提醒的是 puppet必须是2.7以上的版本才支持windows!

由于连接国外的服务器不很稳定,如果有人需要安装过程中的一切包 也可以直接m我