hq8501 发表于 2018-8-3 10:06:45

自动安装puppet脚本

  vm1为masterhostname为vm1.example.com
  vm2 vm3 vm4为client,hostname为vm2|vm3|vm4.example.com
  脚本如下:
  


[*]#!/bin/bash
[*]PROG_NAME=$0
[*]vm=$1
[*]
[*]usage() {
[*]    echo "Usage: $PROG_NAME {vm1|vm2|vm3|vm4|reca}"
[*]    exit 1;
[*]}
[*]
[*]if [ $# -ne 1 ]; then
[*]    usage
[*]fi
[*]
[*]prepare()
[*]{
[*]echo "alias vivim=vi">> ~/.bash_profile
[*]service iptables stop
[*]cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[*]/usr/sbin/ntpdate time.nist.gov
[*]echo "*/5 * * * * /usr/sbin/ntpdate time.nist.gov" > /var/spool/cron/root
[*]chmod 600 /var/spool/cron/root
[*]}
[*]
[*]install_master()
[*]{
[*]
[*]sed -i "s/HOSTNAME=.*/HOSTNAME=${vm}.example.com/" /etc/sysconfig/network
[*]hostname $vm.example.com
[*]echo "10.13.114.3         vm1.example.com" >> /etc/hosts
[*]echo "10.13.114.25          vm2.example.com" >> /etc/hosts
[*]echo "10.13.114.27          vm3.example.com" >> /etc/hosts
[*]echo "10.13.114.30          vm4.example.com" >> /etc/hosts
[*]
[*]#####step 1.install ruby environment#####
[*]wget http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo -O /etc/yum.repos.d/CentOS-Base.repo
[*]yum -y install ruby ruby-rdoc
[*]
[*]
[*]#####step 2.install puppet server#######
[*]rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-4.noarch.rpm
[*]yum -y install puppet-server
[*]chkconfig --level 2345 puppetmaster on
[*]
[*]cat >> /etc/puppet/manifests/site.pp << EOF
[*]node default {
[*]          file { &quot;/tmp/temp1.txt&quot;: content => &quot;hello,first puppet manifest&quot;; }
[*]         }
[*]EOF
[*]
[*]
[*]cat >>/etc/puppet/autosign.conf <<EOF
[*]*.example.com
[*]EOF
[*]
[*]}
[*]
[*]
[*]install_client()
[*]{
[*]sed -i &quot;s/HOSTNAME=.*/HOSTNAME=${vm}.example.com/&quot; /etc/sysconfig/network
[*]hostname $vm.example.com
[*]echo &quot;10.13.114.3         vm1.example.com&quot; >> /etc/hosts
[*]echo &quot;10.13.114.25          vm2.example.com&quot; >> /etc/hosts
[*]echo &quot;10.13.114.27          vm3.example.com&quot; >> /etc/hosts
[*]echo &quot;10.13.114.30          vm4.example.com&quot; >> /etc/hosts
[*]
[*]#####step 1.install ruby environment#####
[*]wget http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo -O /etc/yum.repos.d/CentOS-Base.repo
[*]yum -y install ruby ruby-rdoc
[*]
[*]
[*]####step 2.install puppet server####
[*]rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-4.noarch.rpm
[*]yum -y install puppet
[*]chkconfig --level 2345 puppet on
[*]
[*]echo &quot;server=vm1.example.com&quot;>>/etc/puppet/puppet.conf
[*]echo &quot;listen=true&quot;>>/etc/puppet/puppet.conf
[*]cat >>/etc/puppet/namespaceauth.conf << EOF
[*]
[*]allow *
[*]
[*]allow *
[*]
[*]allow *
[*]
[*]allow *
[*]
[*]allow *
[*]
[*]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 &quot;$vm&quot; in
[*]    vm1)
[*]    prepare
[*]    install_master
[*]    ;;
[*]    vm2)
[*]    prepare
[*]    install_client
[*]    ;;
[*]    vm3)
[*]    prepare
[*]    install_client
[*]    ;;
[*]    vm4)
[*]    prepare
[*]    install_client
[*]    ;;
[*]    reca)
[*]    re_create_ca
[*]    ;;
[*]    *)
[*]    usage
[*]    ;;
[*]esac
  
页: [1]
查看完整版本: 自动安装puppet脚本