云中漫步 发表于 2018-8-2 06:19:04

深入浅出Puppet(一)

# ss -tnl  
State       Recv-Q Send-Q                                    Local Address:Port                                                   Peer Address:Port
  
LISTEN      0      25                                                      *:514                                                               *:*
  
LISTEN      0      128                                                   *:22                                                                  *:*
  
LISTEN      0      128                                             127.0.0.1:631                                                               *:*
  
LISTEN      0      100                                             127.0.0.1:25                                                                  *:*
  
LISTEN      0      128                                             127.0.0.1:6010                                                                *:*
  
LISTEN      0      25                                                   :::514                                                                :::*
  
LISTEN      0      128                                                    :::80                                                               :::*
  
LISTEN      0      128                                                    :::22                                                               :::*
  
LISTEN      0      128                                                   ::1:631                                                                :::*
  
LISTEN      0      100                                                   ::1:25                                                               :::*
  
LISTEN      0      128                                                   ::1:6010                                                               :::*
  
LISTEN      0      128                                                    :::443                                                                :::*
  

  
# 如上,httpd监听在80端口,现在我定义只要httpd的配置文件发生改变就通知httpd重启服务,如下:
  
# cp /etc/httpd/conf/httpd.conf ./ # 首先复制配置文件到当前目录,并修改监听端口为8080
  
# ls
  
file.ppgroup.pphttpd.confpackage.ppservice.ppuser.ppweb.pp
  
# vim web.pp
  
service {'httpd':
  
      ensure   => running,
  enable   => true,
  
      restart=> 'systemctl restart httpd.service',# 重启命令
  
}
  

  
package {'httpd':
  
      ensure   => installed,
  
}
  

  
file {'httpd.conf':
  
      path   => '/etc/httpd/conf/httpd.conf',# 文件路径
  source   => '/root/mainfests/httpd.conf',# 源文件
  ensure   => file,
  
      notify   => Service['httpd'],            #如果发生改变通知service资源
  
}
  

  
Package['httpd'] -> File['httpd.conf'] -> Service['httpd'] # 资源依赖链,从左向右依次执行
  

  
# 运行修改后的web.pp
  
# puppet apply --verbose web.pp
  
Notice: Compiled catalog for centos7 in environment production in 0.96 seconds
  
Info: Applying configuration version '1484191662'
  
Info: Computing checksum on file /etc/httpd/conf/httpd.conf
  
Info: /Stage/Main/File: Filebucketed /etc/httpd/conf/httpd.conf to puppet with sum 71c33697704e72bf128b75a4a3dd4ad2
  
Notice: /Stage/Main/File/content: content changed '{md5}71c33697704e72bf128b75a4a3dd4ad2' to '{md5}21002918bf1dd3c6f1d0697ec0aa8e8b'
  
Info: /Stage/Main/File: Scheduling refresh of Service
  
Notice: /Stage/Main/Service/enable: enable changed 'false' to 'true'
  
Notice: /Stage/Main/Service: Triggered 'refresh' from 1 events
  
Notice: Finished catalog run in 2.02 seconds
  

  
# ss -tnl
  
State       Recv-Q Send-Q                                    Local Address:Port                                                   Peer Address:Port
  
LISTEN      0      25                                                      *:514                                                               *:*
  
LISTEN      0      128                                                   *:22                                                                  *:*
  
LISTEN      0      128                                             127.0.0.1:631                                                               *:*
  
LISTEN      0      100                                             127.0.0.1:25                                                                  *:*
  
LISTEN      0      128                                             127.0.0.1:6010                                                                *:*
  
LISTEN      0      25                                                   :::514                                                                :::*
  
LISTEN      0      128                                                    :::8080                                                               :::*
  
LISTEN      0      128                                                    :::22                                                               :::*
  
LISTEN      0      128                                                   ::1:631                                                                :::*
  
LISTEN      0      100                                                   ::1:25                                                               :::*
  
LISTEN      0      128                                                   ::1:6010                                                               :::*
  
LISTEN      0      128                                                    :::443                                                                :::*
  

  
# 发现此时httpd监听的端口已经由80改为8080
页: [1]
查看完整版本: 深入浅出Puppet(一)