#!/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
tail -1 /etc/sysconfig/puppetmaster |grep "mongrel";[ $? -ne 0 ]&& echo -e "PUPPETMASTER_PORTS=( 18140 18141 18142 18143 18144 )\nPUPPETMASTER_EXTRA_OPTS=\"-servertype=mongrel --ssl_client_header=HTTP_X_SSL_SUBJECT\"" >>/etc/sysconfig/puppetmaster
#配置puppet master 、Hosts
grep $PUPPET_SERVER /etc/hosts ;[ $? -ne 0 ] &&echo "`echo $PUPPET_SERVER|awk -F- '{print $1"."$2"."$3"."$4}'` $PUPPET_SERVER" >>/etc/hosts
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++
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
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
cd ../ ;rm -rf facter-1.6.8
}
#如下case条件语句可以选用,这里仅供参考,真实安装去掉函数定义和case方式即可。
###config caseselect
#$1表示第一个参数
case $1 in
client )
client
;;
server )
server
;;
* )
echo "Please exec $0 { client or server }"
;;
esac
Puppet客户端自动安装脚本
精选 转载下一篇:Puppet常用配置与管理
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
zabbix 客户端安装脚本
zabbix 客户端脚本安装
zabbix shell -
Centos6.2下puppet客户端安装
安装过程:Centos6.2编译 ruby-1.8.6-p114报错: ./configure #正常 make #报错 error1:math.c:37:13: error: missing
openssl centos puppet ruby1.9