puppet apache模块的例子

简介:

一、apache模块的编写 

目录结构

/etc/puppet/modules/production/apache/

 
  1. ├── files 
  2. ├── manifests 
  3. │   ├── init.pp 
  4. │   ├── install.pp
  5. │   ├── config.pp
  6. │   ├── serivce.pp 
  7. │   └── vhost.pp 
  8. └── templates 
  9.     ├── http.conf.erb (httpd.conf文件改名的文件)
  10.     └── httpd.vhost.conf.erb 
init.pp
=========================================================================
 
  1. class apache { 
  2. ​      include "apache::install""apache::service","apache::core" 
  3. import 'install.pp' 
  4. import 'config.pp' 
  5. import 'serivce.pp' 
  6. import 'vhost.pp' 
========================================================================
install.pp
========================================================================
 
  1. class apache::install {  
  2.     $ApacheVersion="2.2.15-15.el6.centos.1"   
  3.     package { "httpd":   
  4.         name   => $operatingsystem ? {   
  5.             /(RedHat|CentOS|Fedora|Debian|Ubuntu)/ => "httpd",   
  6.             default    => "httpd",   
  7.             },   
  8.         ensure => $ApacheVersion,   
  9.     }   
========================================================================
config.pp
========================================================================
 
 
  1. class apache::core
  2. file { 'httpd.conf'
  3.       path => $operatingsystem?{ 
  4.       /(RedHat|CentOS|Fedora|Debian|Ubuntu)/ =>         "/etc/httpd/conf/httpd.conf"
  5.       default => "/etc/httpd/conf/httpd.conf"
  6. }, 
  7.       mode => 0600, 
  8.       owner => root, 
  9.       group => root, 
  10.       content => template("apache/http.conf.erb"), 
  11.       require => Class["apache::install"], 
  12.       notify  => Class["apache::service"], 
  13.       ensure=> present, 
  14.       backup  => '.default'
=========================================================================
serivce.pp
=========================================================================
 
  1. class apache::service { 
  2.     service { httpd: 
  3.         name => $operatingsystem ? { 
  4.             default => "httpd"
  5.                  }, 
  6.         ensure => running, 
  7.         enable => true
  8.         hasrestart => true
  9.         hasstatus => true
  10.         require => Package["httpd"], 
  11.         #subscribe => File["httpd.conf"], 
  12.         subscribe => Class["apache::core"], 
  13.             } 
=========================================================================
vhost.pp
========================================================================
 
  1. define apache::vhost($apacheport,$documentroot,$servername='') { 
  2.       file {"$servername.conf "
  3.             path => $operatingsystem ?{ 
  4.                 /(RedHat|CentOS|Fedora|Debian|Ubuntu)/ => "/etc/httpd/conf.d/${servername}.conf"
  5.                 default => "/etc/httpd/conf.d/${servername}.conf"
  6.                 }, 
  7.             mode => 0600, 
  8.             owner => root, 
  9.             group => root, 
  10.             content => template("apache/httpd.vhost.conf.erb"), 
  11.             require => Class["apache::core"], 
  12.             notify  => Class["apache::service"], 
  13. #            ensure  => present, 
  14. #            backup  => '.default', 
  15.            } 
=========================================================================
templates/httpd.vhost.conf.erb 
========================================================================
 
  1. <VirtualHost *:<%=apacheport%>> 
  2.     DocumentRoot <%=  documentroot %>/<%= servername %> 
  3.     ServerName <%= servername %> 
  4.     ErrorLog  logs/<%= servername %>_error.log 
  5.     CustomLog logs/<%= servername %>_access.log combined 
  6.     DirectoryIndex index.htm index.html index.php 
  7.     <Directory "<%=  documentroot %>/<%= servername %>/"
  8.        options -followsymlinks -indexes -execcgi 
  9.        AllowOverride None 
  10.        Order deny,allow 
  11.        Deny from all 
  12.        Allow from 127.0.0.1 
  13.   </Directory> 
  14. </VirtualHost> 

=========================================================================

二、apache模块的应用

 
  1. node 'node1' {  
  2. include apache  
  3. apache::vhost { 'testport':  
  4.                apacheport => 80,  
  5.                documentroot => '/var/www/html',  
  6.                servername => 'www.test.com',  
  7.        }  

三、以上信息仅供参考,更多内容,请阅读官方文档



本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/1172703,如需转载请自行联系原作者

相关文章
|
7月前
|
PHP Apache
PHP环境搭建(配置php模块到apache服务器)
PHP环境搭建(配置php模块到apache服务器)
69 0
|
1天前
|
存储 缓存 负载均衡
【Apache ShenYu源码】如何实现负载均衡模块设计
整个模块为ShenYu提供了什么功能。我们可以看下上文我们提到的工厂对象。/***/核心方法很清晰,我们传入Upsteam列表,通过这个模块的负载均衡算法,负载均衡地返回其中一个对象。这也就是这个模块提供的功能。
27 1
|
9月前
|
Apache
Apache域名跳转----配置rewrite模块
Apache域名跳转----配置rewrite模块
253 0
|
SQL JSON 供应链
【墨菲安全实验室】Apache IoTDB grafana-connector模块SQL注入分析
【墨菲安全实验室】Apache IoTDB grafana-connector模块SQL注入分析
【墨菲安全实验室】Apache IoTDB grafana-connector模块SQL注入分析
|
监控 安全 Apache
mod_sflow 轻量、实时的流量分析 Apache 模块
sFlow 是一种网络流量分析的协议。通过流量分析,可以实现更有效地监控网络的状况。例如,最近爆出的OpenSSL心脏出血漏洞,由于是通过 OpenSSL 漏洞直接读取内存信息,而不是直接入侵系统,因此服务器日志上不会有相关的记录,使用常规手段难以难以追查。但是,由于来回通信包的长度等特征非常明显,因此利用sFlow之类的技术分析流量特征,就可以追溯攻击流量和攻击历史。特别是,这次的 OpenSSL 漏洞可以无限制反复利用,这既方便了攻击者,不用依靠精妙的技巧来操控读取地址,反复读取即可获得大量内存片段,另一方面也使攻击行为更容易被侦测到。
480 0
mod_sflow 轻量、实时的流量分析 Apache 模块
|
JSON druid Java
Apache Druid自定义扩展模块-数据解析器
一.简述 Apache Druid已有的扩展模块很多包括:HDFS存储使用的druid-hdfs-storage,Kafka数据接入使用的druid-kafka-indexing-service,将MySQL做为元数据库使用的mysql-metadata-storage,数据排重使用的druid-datasketches;但有时这些也无法满足我们实际应用场景下的特殊需求,那么必要的二次开发增加自定义的模块就成了必然。
5363 0
|
Java 应用服务中间件 Linux
puppet连载九:linux安装jdk、tomcat模块
安装jdk1.8.0_91和tomcat8.0.36 mkdir -p /etc/puppet/modules/linuxjdktomcat/{manifests,templates,files} vi /etc/puppet/modules/linuxjdktomcat/manifests/init.
1043 0
|
MySQL 关系型数据库 Linux
puppet连载10:linux安装percona57/56/55、sysbench、tpcc模块
在服务端/puppet/soft下建my.cnf,内容为https://www.jianshu.com/p/c63fc6c71279 在服务端/puppet/soft下建changemysql57pass.
1018 0
|
Linux 开发工具 git
puppet连载七:linux基础组件安装模块
linux基础组件安装模块linuxbaseinstall 更换源,安装gcc gcc-c++ glibc-devel make ncurses-devel openssl-devel autoconf git mkdir -p /etc/puppet...
1046 0
puppet连载六:创建测试模块test
创建测试模块 mkdir -p /etc/puppet/modules/test/{manifests,templates,files} vi /etc/puppet/modules/test/manifests/init.
856 0

热门文章

最新文章

推荐镜像

更多