vm1为master hostname为vm1.example.com

vm2 vm3 vm4为client,hostname为vm2|vm3|vm4.example.com

脚本如下:

#!/bin/bashPROG_NAME=$0vm=$1usage(){echo"Usage:$PROG_NAME{vm1|vm2|vm3|vm4|reca}"exit1;}if[$#-ne1];thenusagefiprepare(){echo"aliasvivim=vi">>~/.bash_profileserviceiptablesstopcp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime/usr/sbin/ntpdatetime.nist.govecho"*/5****/usr/sbin/ntpdatetime.nist.gov">/var/spool/cron/rootchmod600/var/spool/cron/root}install_master(){sed-i"s/HOSTNAME=.*/HOSTNAME=${vm}.example.com/"/etc/sysconfig/networkhostname$vm.example.comecho"10.13.114.3vm1.example.com">>/etc/hostsecho"10.13.114.25vm2.example.com">>/etc/hostsecho"10.13.114.27vm3.example.com">>/etc/hostsecho"10.13.114.30vm4.example.com">>/etc/hosts#####step1.installrubyenvironment#####wgethttp://docs.linuxtone.org/soft/lemp/CentOS-Base.repo-O/etc/yum.repos.d/CentOS-Base.repoyum-yinstallrubyruby-rdoc#####step2.installpuppetserver#######rpm-Uvhhttp://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-4.noarch.rpmyum-yinstallpuppet-serverchkconfig--level2345puppetmasteroncat>>/etc/puppet/manifests/site.pp<<EOFnodedefault{file{"/tmp/temp1.txt":content=>"hello,firstpuppetmanifest";}}EOFcat>>/etc/puppet/autosign.conf<<EOF*.example.comEOF}install_client(){sed-i"s/HOSTNAME=.*/HOSTNAME=${vm}.example.com/"/etc/sysconfig/networkhostname$vm.example.comecho"10.13.114.3vm1.example.com">>/etc/hostsecho"10.13.114.25vm2.example.com">>/etc/hostsecho"10.13.114.27vm3.example.com">>/etc/hostsecho"10.13.114.30vm4.example.com">>/etc/hosts#####step1.installrubyenvironment#####wgethttp://docs.linuxtone.org/soft/lemp/CentOS-Base.repo-O/etc/yum.repos.d/CentOS-Base.repoyum-yinstallrubyruby-rdoc####step2.installpuppetserver####rpm-Uvhhttp://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-4.noarch.rpmyum-yinstallpuppetchkconfig--level2345puppetonecho"server=vm1.example.com">>/etc/puppet/puppet.confecho"listen=true">>/etc/puppet/puppet.confcat>>/etc/puppet/namespaceauth.conf<<EOF[fileserver]allow*[puppetmaster]allow*[puppetrunner]allow*[puppetbucket]allow*[puppetreports]allow*[resource]allow*EOF}re_create_ca(){rm-f/var/lib/puppet/ssl/certs/*rm-f/var/lib/puppet/ssl/certificate_requests/*rm-f/var/lib/puppet/ssl/crl.pem}case"$vm"invm1)prepareinstall_master;;vm2)prepareinstall_client;;vm3)prepareinstall_client;;vm4)prepareinstall_client;;reca)re_create_ca;;*)usage;;esac