|
[root@centos7 mainfests]# 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重启服务,如下:
[root@centos7 mainfests]# cp /etc/httpd/conf/httpd.conf ./ # 首先复制配置文件到当前目录,并修改监听端口为8080
[root@centos7 mainfests]# ls
file.pp group.pp httpd.conf package.pp service.pp user.pp web.pp
[root@centos7 mainfests]# 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
[root@centos7 mainfests]# 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]/Main/File[httpd.conf]: Filebucketed /etc/httpd/conf/httpd.conf to puppet with sum 71c33697704e72bf128b75a4a3dd4ad2
Notice: /Stage[main]/Main/File[httpd.conf]/content: content changed '{md5}71c33697704e72bf128b75a4a3dd4ad2' to '{md5}21002918bf1dd3c6f1d0697ec0aa8e8b'
Info: /Stage[main]/Main/File[httpd.conf]: Scheduling refresh of Service[httpd]
Notice: /Stage[main]/Main/Service[httpd]/enable: enable changed 'false' to 'true'
Notice: /Stage[main]/Main/Service[httpd]: Triggered 'refresh' from 1 events
Notice: Finished catalog run in 2.02 seconds
[root@centos7 mainfests]# 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 |
|
|