Puppet客户端自动安装脚本

运维自动化发展已经是势不可挡,传统的靠大量人力运维的方式渐不能满足企业IT发展的需求,其中Puppet自动化更是受到IT人士的青睐,那今天我们一起来研究一下puppet客户端的自动安装脚本。脚本不足之处,欢迎指正,共同进步!

背景:当我们需要使用puppet批量管理服务器时,首先需要指定FQDN名或者DNS解析,然后接下来就是批量安装puppet客户端了,怎样安装比较快呢?这里仅供参考,把脚本放置在kickstart ks.cfg文件%post段,系统安装完毕后,会执行该脚本!直接看脚本如下:

#!/bin/sh

#auto install puppet client

#wugk 2012-11-30

#PUPPET_SERVER=192-9-117-160-app.com

#此脚本为客户端安装,同时包含服务器端安装,根据实际需求修改即可。

cat <<EOF

++++++++++++++++++++welcome to use auto install puppet ++++++++++++++++++

+++++++++-----------------------------------------------+++++++++++++++++

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

EOF

#安装ruby及相关库支持

echo "Please waiting ruby soft ........"

rpm -ivh compat-readline5-5.2-17.1.el6.x86_64.rpm ruby-libs-1.8.7.352-7.el6_2.x86_64.rpm ruby-1.8.7.352-7.el6_2.x86_64.rpm ruby-devel-1.8.7.352-7.el6_2.x86_64.rpm

echo

echo

#定义客户端安装函数client,即定义client命令

client ()

{

echo "Now install puppet client rpm -ivh puppet-2.7.20-1.el6.noarch.rpm"

#安装facter源码包,主要用于检测客户端本机信息,例如主机名、ip、内存等信息

####now install facter soft

tar xzf facter-1.6.8.tar.gz ;cd facter-1.6.8/ ;/usr/bin/ruby install.rb

#安装puppet客户端程序,这里采用rpm包安装方式

cd ../; rpm -ivh --nodeps puppet-2.7.20-1.el6.noarch.rpm

#配置config puppet puppet_Server可以手动输入,也可以指定变量

####sed auto puppet config

read -p "Please insert puppet server address:" PUPPET_SERVER

sed -i 's/^#PUPPET/PUPPET/g' /etc/sysconfig/puppet

#指定服务端主机名,并配置监听端口、允许认证

grep $PUPPET_SERVER /etc/sysconfig/puppet ;[ $? -ne 0 ]&&sed -i "/PUPPET_SERVER/s/puppet/$PUPPET_SERVER/g" /etc/sysconfig/puppet grep listen /etc/puppet/puppet.conf ;[ $? -ne 0 ]&&echo " listen = true" >> /etc/puppet/puppet.conf

tail -2 /etc/puppet/auth.conf |grep "allow *" ;[ $? -ne 0 ]&&echo "allow *" >> /etc/puppet/auth.conf

echo -e "[puppetrunner]\nallow * " >/etc/puppet/namespaceauth.conf

#配置puppet master服务器端主机名和客户端本地主机名,获取本机的ip信息,并加入/etc/hosts中

grep $PUPPET_SERVER /etc/hosts ;[ $? -ne 0 ] &&echo "`echo $PUPPET_SERVER|awk -F- '{print $1"."$2"."$3"."$4}'` $PUPPET_SERVER" >>/etc/hosts

echo +++++++++++++++++++++++++++++++++++++++++++++++++++++

ETH=`ifconfig |grep Bcast|cut -d: -f 2|awk '{print $1}'`

echo "Please insert PUPPET_SERVER /etc/hosts :: $ETH `echo $ETH|sed 's/\./-/g'`-app.com"

cat /etc/hosts |grep -v 127 |grep $ETH ;[ $? -ne 0 ] &&echo "$ETH `echo $ETH|sed 's/\./-/g'`-app.com" >>/etc/hosts

echo "The puppet is install puppet ,please exec puppet agent --server=$PUPPET_SERVER --test"

HOSTNAME=`echo $ETH|sed 's/\./-/g'`-app.com

hostname $HOSTNAME

cat /etc/hosts|grep 127.0.0.1|grep $HOSTNAME ;[ $? -ne 0 ] &&sed -i "s/127.0.0.1/127.0.0.1 $HOSTNAME/" /etc/hosts

rm -rf facter-1.6.8

} #定义服务器端安装函数server,即定义server命令

server ()

{

echo "Now install puppet client rpm -ivh puppet-2.7.20-1.el6.noarch.rpm"

#安装puppet master、mongrel支持Nginx+多端口puppetmaster负载均衡

rpm -ivh --nodeps puppet-server-2.7.20-1.el6.noarch.rpm puppet-2.7.20-1.el6.noarch.rpm

rpm -ivh --nodeps ruby-irb-1.8.7.352-7.el6_2.x86_64.rpm

rpm -ivh --nodeps ruby-rdoc-1.8.7.352-7.el6_2.x86_64.rpm

rpm -ivh --nodeps rubygem-daemons-1.0.10-2.el6.noarch.rpm

rpm -ivh --nodeps rubygem-fastthread-1.0.7-2.el6.x86_64.rpm

rpm -ivh --nodeps rubygem-gem_plugin-0.2.3-3.el6.noarch.rpm

rpm -ivh --nodeps rubygem-mongrel-1.1.5-3.el6.x86_64.rpm

rpm -ivh --nodeps rubygem-rake-0.8.7-2.1.el6.noarch.rpm

rpm -ivh --nodeps rubygems-1.3.7-1.el6.noarch.rpm

#安装facter

####now install facter soft

tar xzf facter-1.6.8.tar.gz ;cd facter-1.6.8/ ;/usr/bin/ruby install.rb

####sed auto puppet config

echo

read -p "Please insert puppet server address:" PUPPET_SERVER

grep listen /etc/puppet/puppet.conf ;[ $? -ne 0 ]&&echo " listen = true" >> /etc/puppet/puppet.conf

grep autosign /etc/puppet/puppet.conf ;[ $? -ne 0 ]&&sed -i '/ssldir/a\ autosign = true' /etc/puppet/puppet.conf

tail -2 /etc/puppet/auth.conf |grep "allow *" ;[ $? -ne 0 ]&&echo "allow *" >> /etc/puppet/auth.conf

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/fdb816fb41857f4ed87f43ebe978b1e4.html