puppet學習筆記之安裝與配置

Server:


ip=`ifconfig eth0 |grep "inet addr" |awk -F ":" '{print $2}'| awk '{print $1}'`

hostname=`hostname`

echo "$ip    $hostname" >> /etc/hosts


yum -y install gcc ruby ntp


/etc/init.d/ntpd stop

ntpdate cn.pool.ntp.org;hwclock -w


rpm -ivh https://yum.puppetlabs.com/el/6.5/products/x86_64/puppetlabs-release-6-10.noarch.rpm


yum -y install puppet-server


chkconfig puppetmaster on


service puppetmaster start


iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 8140 -j ACCEPT

/etc/init.d/iptables save

/etc/init.d/iptables restart


touch /etc/puppet/manifests/site.pp


touch /etc/puppet/manifests/default_linux.pp

mkdir -p /etc/puppet/manifests/nodes

touch /etc/puppet/manifests/nodes/node_linux.pp

touch /etc/puppet/manifests/nodes/node_windows.pp

echo 'import "default_linux.pp"' >> /etc/puppet/manifests/site.pp

echo 'import "nodes/*.pp"' >> /etc/puppet/manifests/site.pp


cat <<eof >> /etc/puppet/manifests/default_linux.pp

node 'default' {

        include package::install

}

 

class package::install {

        package { ["nmap","telnet","mlocate","vim-*","wget"]:

                ensure => latest,

                allow_virtual => false,

        }

}

eof


service puppetmaster restart


#puppet cert list --all#查詢所有證書;

#puppet cert --sign puppet-agent-XXX#認證;

#sed -i '4a \ \ \ \ autosign = true' /etc/puppet/puppet.conf    #自動化認證;

#puppet cert revok puppet-agent-XXX#註銷證書;

#puppet cert --clean puppet-agent-XXX#刪除證書;

#puppet module list    #查看已安裝模塊;

#puppet module install <module_name>  --version 0.0.0.0#安裝模塊;

#puppet module search <search_string>#查找模塊;


------------------------------------------------------------------

Clinet:


#!/bin/bash
#Client:
#Set Host Name;
cat /etc/sysconfig/network | grep -v "^#" | grep "localhost.localdomain" >> /dev/null
if [ $? = 0 ]; then
echo "Your host name is: `hostname`"
read -p "Please input new host name: " newhostname
hostname $newhostname
sed -i "s/localhost.localdomain/$newhostname/g" /etc/sysconfig/network
echo "OK"
echo ""
else
echo "The host name has been changed!"
echo ""
fi
#Set /etc/hosts
ifconfig eth0 > /dev/null 2>&1
if [ $? = 0 ]; then
        eth0ip=`ifconfig eth0 |grep "inet addr" |awk -F ":" '{print $2}'| awk '{print $1}'`
        hostname=`hostname`
        echo "$eth0ip   $hostname" >> /etc/hosts
fi

ifconfig eth1 > /dev/null 2>&1
if [ $? = 0 ]; then
        eth1ip=`ifconfig eth1 |grep "inet addr" |awk -F ":" '{print $2}'| awk '{print $1}'`
        hostname=`hostname`
        echo "$eth1ip   $hostname" >> /etc/hosts
fi
#Install gcc ruby ntp and sync date
yum -y install gcc ruby ntp
/etc/init.d/ntpd stop
ntpdate cn.pool.ntp.org;hwclock -w
#Install puppet epel
rpm -ivh https://yum.puppetlabs.com/el/6.5/products/x86_64/puppetlabs-release-6-10.noarch.rpm
#Install puppet agent
yum -y install puppet
#Puppet config
chkconfig puppet on
read -p "Please input puppet master ip: " masterip
read -p "please input puppet master host name: " masterhostname
echo "$masterip    $masterhostname" >> /etc/hosts
echo "PUPPET_SERVER=$masterhostname" >> /etc/sysconfig/puppet
echo "PUPPET_PORT=8140" >> /etc/sysconfig/puppet
echo "    server = $masterhostname" >>  /etc/puppet/puppet.conf
echo "    runinterval = 30m" >> /etc/puppet/puppet.conf
echo " listen = true" >> /etc/puppet/puppet.conf
sed -i "116a allow $masterhostname" /etc/puppet/auth.conf
sed -i '116a method save' /etc/puppet/auth.conf
sed -i '116a auth any' /etc/puppet/auth.conf
sed -i '116a path /run' /etc/puppet/auth.conf
#Iptables open port 8139
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 8139 -j ACCEPT
/etc/init.d/iptables save
#Start puppet agent service
service puppet start
#Test and SYNC
#puppet agent -t
#puppet agent -t --sever puppet-master-XXX


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章