mofdan 发表于 2018-8-2 07:37:48

Puppet 集中化管理系统

cd /etc/puppet/modules/  
yum install -y httpd
  
cp vsftpd/ -r httpd/
  
cd /etc/puppet/modules/httpd/files
  
rm -rf *
  
cp /etc/httpd/conf/httpd.conf.##将http的主配置文件拷贝到当前路径
  
vim httpd.conf
  
NameVirtualHost *:80
  
<VirtualHost *:80>
  
    DocumentRoot /var/www/html
  
    ServerName server4.example.com
  
</VirtualHost>
  
cd /etc/puppet/modules/httpd/manifests
  
vim install.pp
  
class httpd::install {
  
      package { 'httpd':
  
               ensure => present
  
      }
  
}
  
vim config.pp
  
class httpd::config {
  
      file {
  
             '/etc/httpd/conf/httpd.conf':
  
             source => 'puppet:///modules/httpd/httpd.conf',
  
             mode => 600,
  
             require => Class['httpd::install'],
  
             notify => Class['httpd::service']
  
   }
  
}
  
vim service.pp
  
class httpd::service {
  
      service {
  
               'httpd':
  
                ensure => running,
  
                require => Class['httpd::install','httpd::config']
  
      }
  
}
  
vim init.pp
  
class httpd {
  
      include httpd::install,httpd::config,httpd::service
  
}
  
define httpd::vhost($domainname) {
  
file { "/etc/httpd/conf.d/${domainname}_vhost.conf":
  
content => template("httpd/httpd_vhost.erb"),
  
require => Class["httpd::install"],
  
notify => Class["httpd::service"]
  
}
  
file { "/var/www/$domainname":
  
ensure => directory
  
}
  
file { "/var/www/$domainname/index.html":
  
content => $domainname
  
}
  
}
  
cd /etc/puppet/manifests/nodes/
  
vim server5.pp
  
node 'server5.example.com' {
  
include vsftpd,httpd
  
httpd::vhost { 'www.example.com':
  
domainname => "www.example.com",
  
}
  
httpd::vhost { 'www.gaofang.com':
  
domainname => "www.gaofang.com",
  
}
  
}
  
cd /etc/puppet/modules/httpd
  
mkdir templates
  
vim /etc/puppet/modules/httpd/templates/httpd_vhost.erb
  
<VirtualHost *:80>
  
ServerName <%= domainname %>
  
DocumentRoot /var/www/<%= domainname %>
  
ErrorLog logs/<%= domainname %>_error.log
  
CustomLog logs/<%= domainname %>_access.log common
  
</VirtualHost>
  
在物理机上:
  
vim /etc/hosts
  
172.25.44.55    server5.example.comwww.example.comwww.gaofang.com##加入解析
  
在client端:
  
puppet agent --server server3.example.com --no-daemonize -vt##server5

nihaota 发表于 2022-8-3 13:59:36

讨债公司
蓝月传奇辅助
蓝月辅助
页: [1]
查看完整版本: Puppet 集中化管理系统