热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

手动编写的几个简单的puppet管理配置

puppet在自动化配置管理方面有很强大的优势,这里就不做过多介绍了,下面记录下几个简单的puppet管理配置:一、首先在服务端和客户端安装puppet和facter1)服务端安

 

puppet在自动化配置管理方面有很强大的优势,这里就不做过多介绍了,下面记录下几个简单的puppet管理配置:

一、首先在服务端和客户端安装puppet和facter

1)服务端
安装Puppet Labs
# rpm -ivh http://yum.puppetlabs.com/el/6.5/products/x86_64/puppetlabs-release-6-12.noarch.rpm

安装Puppet和facter
# yum install puppet puppet-server facter

2)客户端
安装Puppet Labs
# rpm -ivh http://yum.puppetlabs.com/el/6.5/products/x86_64/puppetlabs-release-6-12.noarch.rpm

安装Puppet和facter
# yum install puppet facter

二、puppet配置及证书签收

1)客户端和服务端分别做host主机映射(或者做内网DNS解析)
192.168.1.10 puppet01.wang.com            #服务端
192.168.1.11 puppet02.wang.com            #客户端

2)在客服端的puppet.conf配置文件里
[root@puppet02 ~]# cat /etc/puppet/puppet.conf 
[main]
    server=puppet01.wang.com
    ......

3)分别启动puppet服务(注意服务端和客户端的iptables防火墙最好关闭,如果开启的话,要记得开放puppet端口8140的访问)
服务端
[root@puppet01 ~]# /etc/init.d/puppetmaster start

客服端
[root@puppet02 ~]# /etc/init.d/puppet start

4)自动注册证书配置
服务端
[root@puppet01 ~]# cat /etc/puppet/puppet.conf
[main]
    ......
    autosign = true
    autosign = /etc/puppet/autosign.conf

[root@puppet01 ~]# cat /etc/puppet/autosign.conf        #创建自动注册配置文件,下面表示对所有主机的注册进行签收
*

[root@puppet01 ~]# /etc/init.d/puppetmaster restart

客户端进行注册
[root@puppet02 ~]# puppet agent --test --server=puppet01.wang.com
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for puppet02.wang.com
Info: Applying configuration version '1501320900'
Notice: Finished catalog run in 0.42 seconds

服务端发现已经自动签收了证书
[root@puppet01 ~]# puppet cert --list --all
+ "puppet01.wang.com" (SHA256) 3E:99:64:73:14:D5:BA:01:62:2F:53:62:A6:07:55:AB:BA:BE:70:6E:7E:60:7A:81:41:10:63:78:C0:FD:E4:56 (alt names: "DNS:puppet", "DNS:puppet.wang.com", "DNS:puppet01.wang.com")
+ "puppet02.wang.com" (SHA256) A4:EF:73:62:3A:DD:F9:2E:E4:12:8F:2E:AE:90:96:43:95:7A:4C:9F:38:02:44:B7:81:C5:08:B5:16:95:42:0B

三、puppet自动化管理配置

在puppet master服务端进行puppet管理条目的配置,配置好之后,这些条目会被发送到puppet agent节点机器上,并被应用到agent节点机器上(即puppet master的"推"操作)。如果agent节点机器以守护进程方式运行,
它会默认每隔30分钟连接一次,并检查自己所在主机的配置是否发生了变化或者增加了新的配置。可以通过修改agent上/etc/puppet/puppet.conf文件中的runinterval项来修改这个时间间隔,比如修改时间间隔为1小时
"runinterval = 3600"。同时,agent节点机器也可以通过cron进行定时任务的主动连接(即puppet agent的"拉"操作),
结合master和agent的一"推"一"拉"的操作。
   
1)在puppet master端进行配置
[root@puppet01 puppet]# ll
total 36
-rw-r--r--  1 root root 4178 Jul 29 16:25 auth.conf
-rw-r--r--  1 root root    2 Jul 29 16:25 autosign.conf
drwxr-xr-x  3 root root 4096 Jul 29 16:25 environments
-rw-r--r--  1 root root 1462 Jul 29 16:25 fileserver.conf
drwxr-xr-x  2 root root 4096 Jul 29 17:22 manifests
drwxr-xr-x 13 root root 4096 Jul 29 17:03 modules
-rw-r--r--  1 root root  915 Jul 29 16:25 puppet.conf
   
先创建模块可以手动创建,也可以通过命令创建,不过要修改模块名称。
[root@puppet01 puppet]# cd modules/
[root@puppet01 modules]# puppet module generate propupet-ssh       #命令行创建模块的命令。模块名称格式"puppet-模块名""
[root@puppet01 modules]# mv propupet-ssh ssh        #修改为ssh模块
   
或者手动创建模块
[root@puppet01 modules]# mkdir ssh       #不过还要手动创建模块下的目录结构
[root@puppet01 modules]# mkdir ssh/files    #保存模块需要用到的文件
[root@puppet01 modules]# mkdir ssh/manifests   #puppet配置文件的存放目录
[root@puppet01 modules]# mkdir ssh/templates    #保存模块中用到的模板
   
modules模块配置好之后,要在/etc/puppet/manifests/site.pp清单文件中进行引用(如下最后会提到)。
   
2)参考下面几个模块的配置:
[root@puppet01 modules]# pwd
/etc/puppet/modules
   
--------------------ssh安装管理模块--------------------
[root@puppet01 manifests]# cd /etc/puppet/modules/ssh
[root@puppet01 ssh]# cd manifests/
[root@puppet01 manifests]# ls
config.pp  init.pp  install.pp  service.pp
[root@puppet01 manifests]# cat init.pp
class ssh {
  class { '::ssh::install':} ->
  class { '::ssh::config':} ->
  class { '::ssh::service':} ->
  Class['ssh']
}
[root@puppet01 manifests]# cat install.pp
class ssh::install {
  package { "openssh":               #安装包名为openssh
    ensure => present,               #保证该包被安装
  }
}
[root@puppet01 manifests]# cat config.pp
class ssh::config {
  file { "/etc/ssh/sshd_config":              #ssh诸如端口、用户名、密码登录的控制都可以事先放在模块的files下的sshd_config文件了,然后利用puppet同步到目标机器上。修改后会自动重启sshd(service类里会自动重启)
    ensure => present,
    owner => 'root',
    group => 'root',
    mode => 0600,
    source => "puppet:///modules/ssh/sshd_config",     #即sshd_config文件存放在/etc/puppet/modules/ssh/files目录下。注意files目录不写在路径中。
    require => Class["ssh::install"],                  #该文件资源存在的前提条件
    notify =>  Class["ssh::service"],                  #该文件资源存在后通知ssh::service类
    }
}
[root@puppet01 manifests]# cat service.pp
class ssh::service {
  service { "sshd":
    ensure => running,
    hasstatus => true,
    hasrestart =>true,
    enable => true,
    require => Class["ssh::config"],
    }
}
   
[root@puppet01 manifests]# ls ../files/sshd_config
../files/sshd_config
  
   
--------------------DNS配置管理--------------------
[root@puppet ~]# cd /etc/puppet/modules/dns/
[root@puppet dns]# ls
files  manifests
[root@puppet dns]# cd manifests/
[root@puppet manifests]# ls
config.pp  init.pp  restart.pp  setup.pp
[root@puppet manifests]# cat init.pp
class dns {
  include dns::config
  include dns::setup
  include dns::restart
  }
[root@puppet manifests]# cat config.pp
class dns::config {
  file { "/etc/named":
  ensure  => directory,
  source => "puppet:///modules/dns/pro-dns/DNS/etc/named",
  recurse => true,
  }
  
  file { "/var/named":
  ensure  => directory,
  source =>"puppet:///modules/dns/pro-dns/DNS/var/named",
  recurse => true,
  }
}
  
[root@puppet manifests]# cat setup.pp
class dns::setup {
  exec {"Set permissions of etc-named":
  cwd => "/etc",
  command => "/bin/chown -R root.named named",
  path =>["/usr/bin:/usr/sbin:/bin:/sbin"],
  require => Class["dns::config"],
  }
  
  exec {"Set permissions of var-named":
  cwd => "/var",
  command => "/bin/chown -R root.named named && /bin/chown -R named.named named/data/",
  path =>["/usr/bin:/usr/sbin:/bin:/sbin"],
  require => Class["dns::config"],
  }
  
}
[root@puppet manifests]# cat restart.pp
class dns::restart {
  exec {"restart named service":
  command => "service named restart",
  path => ["/usr/bin:/usr/sbin:/bin:/sbin"],
  require => Class["dns::config"],
  }
}
  
files目录下存放的是DNS的配置文件和正反向解析文件(可以放到gitlab的pro-dns项目的DNS目录下,通过git clone下载)
[root@puppet manifests]# cd ../files/
[root@puppet files]# ls
pro-dns
[root@puppet files]# ls pro-dns/DNS/
etc  var
[root@puppet files]# ls pro-dns/DNS/etc/named/
named.conf
[root@puppet files]# ls pro-dns/DNS/var/named/
192.168.10.zone  192.168.16.zone  192.168.32.zone  192.168.33.zone  192.168.34.zone  192.168.64.zone  192.168.8.zone  wangshibo.cn
  
  
--------------------java7安装管理模块--------------------
[root@puppet01 java7]# cd manifests/
[root@puppet01 manifests]# ls
init.pp  install.pp
[root@puppet01 manifests]# cat init.pp
class java7 {
  include java7::install
}
[root@puppet01 manifests]# cat install.pp
class java7::install {
  file { "/data/software/java-jdk7_install.sh":                    #文件资源
    source => "puppet:///modules/java7/java-jdk7_install.sh",
    owner => root,
    group => root,
    mode => 0755
    }
   
  exec { "install jdk":                             #命令资源
    cwd => "/data/software",
    command => "/bin/bash java-jdk7_install.sh",
    user => "root",
    group => "root",
    path =>["/usr/bin:/usr/sbin:/bin:/sbin"],
    creates =>"/usr/java/jdk1.7.0_80",                            #当/usr/java/jdk1.7.0_80文件存在时,不执行该命令。只有当不存在时执行!
    require =>File["/data/software/java-jdk7_install.sh"]         #该命令资源执行的前提条件
    }
}
[root@puppet01 manifests]# cd ../files/
[root@puppet01 files]# ll
total 4
-rwxr-xr-x 1 root root 756 Jul 29 16:25 java-jdk7_install.sh
[root@puppet01 files]# cat java-jdk7_install.sh
#!/bin/bash
   
/bin/rpm -qa|grep jdk|xargs rpm -e
   
# install jdk7
/bin/rpm -ivh  http://yum.wang.com/software/jdk-7u80-linux-x64.rpm
   
# set env
NUM=`cat /etc/profile|grep "JAVA_HOME"|wc -l`
JDK=`cat /etc/profile|grep "JAVA_HOME="|cut -d"=" -f2|awk -F"/" '{print $4}'`
if [ $NUM -ne 0 ];then
    /bin/sed -i 's#'$JDK'#jdk1.7.0_80#g' /etc/profile
else
    echo "JAVA_HOME=/usr/java/jdk1.7.0_80" >> /etc/profile
    echo "JAVA_BIN=/usr/java/jdk1.7.0_80/bin" >> /etc/profile
    echo "PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/bin" >> /etc/profile
    echo "CLASSPATH=.:/lib/dt.jar:/lib/tools.jar" >> /etc/profile
    echo "export JAVA_HOME JAVA_BIN PATH CLASSPATH" >> /etc/profile
fi
   
source /etc/profile
   
   
--------------------java8安装管理模块--------------------
[root@puppet01 files]# cd /etc/puppet/modules/java8
[root@puppet01 java8]# ls
files  manifests
[root@puppet01 java8]# cd manifests/
[root@puppet01 manifests]# ls
init.pp  install.pp
[root@puppet01 manifests]# cat init.pp
class java8 {
  include java8::install
}
[root@puppet01 manifests]# cat install.pp
class java8::install {
  file { "/data/software/java-jdk8_install.sh":
    source => "puppet:///modules/java8/java-jdk8_install.sh",
    owner => root,
    group => root,
    mode => 0755
    }
   
  exec { "install jdk":
    cwd => "/data/software",
    command => "/bin/bash java-jdk8_install.sh",
    user => "root",
    group => "root",
    path =>["/usr/bin:/usr/sbin:/bin:/sbin"],
    creates =>"/usr/java/jdk1.8.0_131",
    require =>File["/data/software/java-jdk8_install.sh"]
    }
}
[root@puppet01 manifests]# cat ../files/java-jdk8_install.sh
#!/bin/bash
   
/bin/rpm -qa|grep jdk|xargs rpm -e
   
# install jdk8 jdk7
/bin/rpm -ivh  http://yum.wang.com/software/jdk-8u131-linux-x64.rpm
   
# set env
NUM=`cat /etc/profile|grep "JAVA_HOME"|wc -l`
JDK=`cat /etc/profile|grep "JAVA_HOME="|cut -d"=" -f2|awk -F"/" '{print $4}'`
if [ $NUM -ne 0 ];then
    /bin/sed -i 's#'$JDK'#jdk1.8.0_131#g' /etc/profile
else
    echo "JAVA_HOME=/usr/java/jdk1.8.0_131" >> /etc/profile
    echo "JAVA_BIN=/usr/java/jdk1.8.0_131/bin" >> /etc/profile
    echo "PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/bin" >> /etc/profile
    echo "CLASSPATH=.:/lib/dt.jar:/lib/tools.jar" >> /etc/profile
    echo "export JAVA_HOME JAVA_BIN PATH CLASSPATH" >> /etc/profile
fi
   
source /etc/profile
   
--------------------tomcat8安装管理模块--------------------
[root@puppet01 manifests]# cd /etc/puppet/modules/tomcat8/
[root@puppet01 tomcat8]# ls
files  manifests
[root@puppet01 tomcat8]# cd manifests/
[root@puppet01 manifests]# ls
init.pp  install.pp
[root@puppet01 manifests]# cat init.pp
class tomcat8 {
  include tomcat8::install
}
   
[root@puppet01 manifests]# cat install.pp
class tomcat8::install {
  file { "/data/software/apache-tomcat-8.5.15.tar.gz":
  source =>"puppet:///modules/tomcat8/apache-tomcat-8.5.15.tar.gz",
  owner => "root",
  group => "root",
  mode => 755
  }
   
  exec {"install tomcat":
  cwd => "/data/software",
  command => "/bin/tar -zvxf apache-tomcat-8.5.15.tar.gz && mv apache-tomcat-8.5.15 /data/tomcat",
  user => "root",
  group => "root",
  path =>["/usr/bin:/usr/sbin:/bin:/sbin"],
  creates => "/data/tomcat",
  require => File["/data/software/apache-tomcat-8.5.15.tar.gz"]
  }
}
[root@puppet01 manifests]# ls ../files/
apache-tomcat-8.5.15.tar.gz
   
--------------------nginx安装管理模块--------------------
[root@puppet01 manifests]# cd /etc/puppet/modules/nginx/
[root@puppet01 nginx]# ls
files  manifests
[root@puppet01 nginx]# cd manifests/
[root@puppet01 manifests]# ls
init.pp  install.pp
[root@puppet01 manifests]# cat init.pp
class nginx {
  include nginx::install
}
[root@puppet01 manifests]# cat install.pp
class nginx::install {
  file { "/data/software/nginx1.10_install.sh":
  source =>"puppet:///modules/nginx/nginx1.10_install.sh",
  owner => "root",
  group => "root",
  mode => 755
  }
   
  exec {"install nginx":
  cwd => "/data/software",
  command => "/bin/bash -x nginx1.10_install.sh",
  user => "root",
  group => "root",
  path =>["/usr/bin:/usr/sbin:/bin:/sbin"],
  creates => "/data/nginx/conf/nginx.conf",
  require => File["/data/software/nginx1.10_install.sh"]
  }
}
[root@puppet01 manifests]# cat ../files/nginx1.10_install.sh
#!/bin/bash
#基础环境准备
/usr/sbin/groupadd -r nginx
/usr/sbin/useradd -r -g nginx -s /bin/false -M nginx
/usr/bin/yum install -y pcre pcre-devel openssl openssl-devel gcc
   
#编译安装nginx1.10
cd /data/software/
/usr/bin/wget http://yum.wang.com/software/nginx-1.10.3.tar.gz
/bin/tar -zvxf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure --prefix=/data/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre
make && make install
   
#配置nginx
cp /data/nginx/conf/nginx.conf /data/nginx/conf/nginx.conf.bak
> /data/nginx/conf/nginx.conf
   
cat > /data/nginx/conf/nginx.conf < /data/nginx/conf/vhosts/test.conf < present,
  }
}
[root@puppet01 manifests]# cat config.pp
class motd::config {
  file { "/etc/motd":
    ensure => present,
    owner => "root",
    group => "root",
    mode => 0644,
    source => "puppet:///modules/motd/motd",
    require => Class["motd::install"],
    }
}
[root@puppet01 manifests]# ls ../files/motd
../files/motd
   
--------------------dns文件管理模块--------------------
[root@puppet01 manifests]# cd /etc/puppet/modules/dns/
[root@puppet01 dns]# ls
files  manifests
[root@puppet01 dns]# cd manifests/
[root@puppet01 manifests]# ls
config.pp  init.pp
[root@puppet01 manifests]# cat init.pp
class dns {
  include dns::config
  }
[root@puppet01 manifests]# cat config.pp
class dns::config {
  file { "/etc/resolv.conf":
    ensure => present,
    owner => "root",
    group => "root",
    mode => 0644,
    source => "puppet:///modules/dns/resolv.conf",
    }
}
[root@puppet01 manifests]# cat ../files/resolv.conf
search wang.com
nameserver 192.168.1.27
nameserver 192.168.1.28
   
--------------------chrony时间同步文件管理模块--------------------
[root@puppet01 manifests]# cd /etc/puppet/modules/chrony/
[root@puppet01 chrony]# ls
files  manifests
[root@puppet01 chrony]# cd manifests/
[root@puppet01 manifests]# ls
init.pp  install.pp
[root@puppet01 manifests]# cat init.pp
class chrony {
  include chrony::install
  }
[root@puppet01 manifests]# cat install.pp
class chrony::install {
  file { "/data/software/chrony.sh":
  source =>"puppet:///modules/chrony/chrony.sh",
  owner => "root",
  group => "root",
  mode => 755
  }
   
  exec {"install chrony":
  cwd => "/data/software",
  command => "/bin/bash -x chrony.sh",
  user => "root",
  group => "root",
  path =>["/usr/bin:/usr/sbin:/bin:/sbin"],
  creates => "/etc/chrony.conf",
  require => File["/data/software/chrony.sh"]
  }
}
[root@puppet01 manifests]# cat ../files/chrony.sh
#!/bin/bash
/etc/init.d/ntpd stop
/usr/bin/yum install chrony -y
cp /etc/chrony.conf /etc/chrony.conf.bak
rm -f /etc/chrony.conf
wget http://yum.wang.com/software/chrony.conf
cp -f chrony.conf /etc/
/etc/init.d/chronyd start
/usr/bin/chronyc sources -v
   
--------------------yum文件管理模块--------------------
[root@puppet01 manifests]# cd /etc/puppet/modules/yum/
[root@puppet01 yum]# ls
files  manifests
[root@puppet01 yum]# cd manifests/
[root@puppet01 manifests]# ls
config.pp  init.pp
[root@puppet01 manifests]# cat init.pp
class yum {
  include yum::config
  }
[root@puppet01 manifests]# cat config.pp
class yum::config {
  file { "/data/software/yum.sh":
    source => "puppet:///modules/yum/yum.sh",
    owner => "root",
    group => "root",
    mode => 0755,
    }
   
  exec { "set yum":
    cwd => "/data/software",
    command => "/bin/bash yum.sh",
    user => "root",
    group => "root",
    path =>["/usr/bin:/usr/sbin:/bin:/sbin"],
    unless => "grep mirrors.wang.com /etc/yum.repos.d/CentOS-Base.repo",           #当这个结果为假的时候才执行这个命令。如果结果为真,就停止执行这个命令。
    require =>File["/data/software/yum.sh"]
    }
}
   
[root@puppet01 manifests]# cat ../files/yum.sh
#!/bin/bash
   
rm -f  /etc/yum.repos.d/*.repo
    
wget http://yum.wang.com/software/CentOS-Base.repo -O /etc/yum.repos.d/CentOS-Base.repo
wget http://yum.wang.com/software/epel.repo    -O /etc/yum.repos.d/epel.repo
#wget http://yum.wang.com/software/mongodb.repo
   
yum clean all
yum makecache
 
--------------------resolv文件管理模块--------------------
[root@puppet ~]# ls /etc/puppet/modules/
chrony  dns  java7  java8  motd  nginx  postfix  resolv  ssh  sudo  tomcat8  yum
[root@puppet ~]# cd /etc/puppet/modules/resolv/manifests/
[root@puppet manifests]# ls
config.pp  init.pp
[root@puppet manifests]# cat init.pp
class resolv {
  include resolv::config
  }
class resolv01 {
  include resolv::dns01
  }
class resolv02 {
  include resolv::dns02
  }
[root@puppet manifests]# cat config.pp
class resolv::config {
  file { "/etc/resolv.conf":
    source => "puppet:///modules/resolv/resolv.conf",
    ensure => "present",
    owner  => "root",
    group  => "root",
    mode   => 0644,
    }
}
 
[root@puppet manifests]# cat ../files/resolv.conf
search wang.com
nameserver 192.168.1.27
nameserver 192.168.1.28
options timeout:1
options attempts:1
   
--------------------postfix安装管理模块--------------------
[root@puppet01 manifests]# cd /etc/puppet/modules/postfix/
[root@puppet01 postfix]# ls manifests/
config.pp  init.pp  install.pp  service.pp
[root@puppet01 postfix]# ls files/
master.cf
[root@puppet01 postfix]# ls templates/
main.cf.erb
[root@puppet01 postfix]# cat manifests/init.pp
class postfix {
  include postfix::install
  include postfix::config
  include postfix::service
}
[root@puppet01 postfix]# cat manifests/install.pp
class postfix::install {
  package { ["postfix","mailx" ]:
    ensure => present,
  }
}
[root@puppet01 postfix]# cat manifests/config.pp
class postfix::config {
  File {
    owner => 'postfix',
    group => 'postfix',
    mode => 0644,
    }
   
  file {'/etc/postfix/master.cf':
    ensure => present,
    source => 'puppet:///modules/postfix/master.cf',
    require => Class['postfix::install'],
    notify => Class['postfix::service'],
    }
   
  file {'/etc/postfix/main.cf':
    ensure => present,
    cOntent=> template('postfix/main.cf.erb'),
    require => Class['postfix::install'],
    notify => Class['postfix::service'],
    }
}
[root@puppet01 postfix]# cat manifests/service.pp
class postfix::service {
  service { 'postfix':
    ensure     => running,
    hasstatus  => true,
    hasrestart => true,
    enable     => true,
    require    => Class['postfix::config'],
    }
}
   
[root@puppet01 postfix]# cat templates/main.cf.erb
soft_bounce = no
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
myhostname = <%= @hostname %>               
mydomain = <%= @domain %>
myorigin = $mydomain
mydestination = $myhostname,localhost.$mydomain,localhost,$mydomain
unknown_local_recipient_reject_code = 550
relay_domains = $mydestination
smtpd_reject_unlisted_recipient = yes
unverified_recipient_reject_code = 500
smtpd_banner = $myhostname ESMTP
setgid_group = postdrop
   
[root@puppet01 postfix]# ls files/master.cf
files/master.cf
   
#注意:模板里的变量通过ERB语法从Facter的fact中获取值。fact的名称放在有<%=和%>组成的ERB括号里,在Puppet运行时,它们将被替代为Fact的实际值(即agent端的实际值)。
   
--------------------------------------------------------------------------------------------------
   
然后在/etc/puppet/manifests/site.pp清单文件中引用这些类:
[root@puppet manifests]# cat /etc/puppet/manifests/site.pp
class base {
  include chrony
  include java8
  include tomcat8
  include nginx
  include yum
  include resolv
  }
 
node 'puppet02.bkjk.cn' {
  include dns
  include yum
  }
 
node 'dns01' {
  #include dns
  include yum
  include ssh
  include resolv
  }
 
node 'dns02' {
  #include dns
  include yum
  include ssh
  include resolv
  }
 
node 'mirrors' {
  include yum
  include ssh
  include resolv
  }
 
上面的dns01、dns02、mirrors都是通过内网DNS解析的。
[root@puppet manifests]# ping mirrors
PING mirrors.wang.com (192.168.1.240) 56(84) bytes of data.
64 bytes from yum.wang.com (192.168.1.240): icmp_seq=1 ttl=64 time=0.889 ms
......
   
--------------------------------------------------------------------------------------------------
   
最后在puppet agent端连接puppet master,进行应用同步管理。
[root@puppet02 ~]# puppet agent --test --server=puppet01.wang.com
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for puppet02.wang.com
Info: Applying configuration version '1501429243'
Notice: /Stage[main]/Chrony::Install/File[/data/software/chrony.sh]/ensure: defined content as '{md5}fe7f9787a7cae33ed0e00c26f880b145'
Notice: /Stage[main]/Chrony::Install/Exec[install chrony]/returns: executed successfully
........
   
执行成功后,在puppet agent节点机器上进行验证。后续再对这些应用配置进行管理时,只需在puppet master进行维护操作,puppet agent端会自动进行同步管理的。

------------------------------------------------------------------------------------------------------
[root@puppet dns]# puppet agent -t       #puppet服务端测试连接
[root@puppet dns]# puppet agent --help

配置说明:
class source::exec2{
  exec { "install nginx":
    cwd       =>"/tmp/rhel5/nginx",  #目录存在的情况下执行command
    command   =>"tar -zxvf nginx-0.8.42.tar.gz && cd nginx-0.8.42 &&./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --without-http-cache && make&&make install",  
    path      => ["/usr/bin","/usr/sbin","/bin","/sbin"],
    logoutput => on_failure,  
    unless    => "/bin/ls /usr/local/nginx/conf",        #命令返回值不为0的情况下执行commond
    require   => Class[source::file1,source::user]
    notify    => Class["source::exec3"],
  }

[root@puppet dns]# /bin/ls /data/nginx/conf/nginx.conf
/data/nginx/conf/nginx.conf
[root@puppet dns]# echo $?
0

推荐阅读
  • 六、流程控制语句
    选择结构if只有条件判断结果为真时才执行相应的操作循环结构for、whileuntil反复执行相同操作时,使用循环结构分支结构case根据变量值的匹配结果执行相 ... [详细]
  • 解决Sharepoint 2013运行状况分析出现的“一个或多个服务器未响应”问题的方法
    本文介绍了解决Sharepoint 2013运行状况分析中出现的“一个或多个服务器未响应”问题的方法。对于有高要求的客户来说,系统检测问题的存在是不可接受的。文章详细描述了解决该问题的步骤,包括删除服务器、处理分布式缓存留下的记录以及使用代码等方法。同时还提供了相关关键词和错误提示信息,以帮助读者更好地理解和解决该问题。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • Android系统源码分析Zygote和SystemServer启动过程详解
    本文详细解析了Android系统源码中Zygote和SystemServer的启动过程。首先介绍了系统framework层启动的内容,帮助理解四大组件的启动和管理过程。接着介绍了AMS、PMS等系统服务的作用和调用方式。然后详细分析了Zygote的启动过程,解释了Zygote在Android启动过程中的决定作用。最后通过时序图展示了整个过程。 ... [详细]
  • 基于Socket的多个客户端之间的聊天功能实现方法
    本文介绍了基于Socket的多个客户端之间实现聊天功能的方法,包括服务器端的实现和客户端的实现。服务器端通过每个用户的输出流向特定用户发送消息,而客户端通过输入流接收消息。同时,还介绍了相关的实体类和Socket的基本概念。 ... [详细]
  • 本文介绍了在RHEL 7中的系统日志管理和网络管理。系统日志管理包括rsyslog和systemd-journal两种日志服务,分别介绍了它们的特点、配置文件和日志查询方式。网络管理主要介绍了使用nmcli命令查看和配置网络接口的方法,包括查看网卡信息、添加、修改和删除配置文件等操作。 ... [详细]
  • 本文介绍了通过ABAP开发往外网发邮件的需求,并提供了配置和代码整理的资料。其中包括了配置SAP邮件服务器的步骤和ABAP写发送邮件代码的过程。通过RZ10配置参数和icm/server_port_1的设定,可以实现向Sap User和外部邮件发送邮件的功能。希望对需要的开发人员有帮助。摘要长度:184字。 ... [详细]
  • HDFS2.x新特性
    一、集群间数据拷贝scp实现两个远程主机之间的文件复制scp-rhello.txtroothadoop103:useratguiguhello.txt推pushscp-rr ... [详细]
  • 本文介绍了在使用Python中的aiohttp模块模拟服务器时出现的连接失败问题,并提供了相应的解决方法。文章中详细说明了出错的代码以及相关的软件版本和环境信息,同时也提到了相关的警告信息和函数的替代方案。通过阅读本文,读者可以了解到如何解决Python连接服务器失败的问题,并对aiohttp模块有更深入的了解。 ... [详细]
  • WebSocket与Socket.io的理解
    WebSocketprotocol是HTML5一种新的协议。它的最大特点就是,服务器可以主动向客户端推送信息,客户端也可以主动向服务器发送信息,是真正的双向平等对话,属于服务器推送 ... [详细]
  • 如何在文本中运行Java程序
    本文介绍了在文本中运行Java程序的步骤,包括创建文本文档、修改后缀、打开DOS命令窗口、编译和运行程序。通过这些步骤,可以在文本中成功运行Java程序并输出结果。 ... [详细]
  • 海马s5近光灯能否直接更换为H7?
    本文主要介绍了海马s5车型的近光灯是否可以直接更换为H7灯泡,并提供了完整的教程下载地址。此外,还详细讲解了DSP功能函数中的数据拷贝、数据填充和浮点数转换为定点数的相关内容。 ... [详细]
  • 本文介绍了在go语言中利用(*interface{})(nil)传递参数类型的原理及应用。通过分析Martini框架中的injector类型的声明,解释了values映射表的作用以及parent Injector的含义。同时,讨论了该技术在实际开发中的应用场景。 ... [详细]
  • 1.判断磁盘使用空间df-h|grep-vFile|seds%g|awk{if($580)print使用空间超过了80%:,$6}或#!binbash#Filename:di ... [详细]
author-avatar
沫沫
微交易http://www.ikkwt.com/ 微交易平台http://www.ikkwt.com/pingtai/ 网络借贷平台大全http://www.kljie.com/ 小微金融http://www.lcbcn.com/ 微投资平台http://www.lcbcn.com/pt/ 网络借贷平台排行榜http://www.kljie.com/pingtai/
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有