• Puppet部署Nginx返代示例


    一、创建目录并编辑Nginx安装模块

    mkdir -pv /etc/puppet/modules/nginx/{manifests,files,templates,spec,tests,lib}
    ]# vim nginx/manifests/init.pp
    class nginx {
        package{'nginx':
            ensure => latest
        } ->
        service{'nginx':
            ensure => running,
            enable => true
        }
    }

    二、编辑Nginx配置文件

    ]# vim nginx/manifests/web.pp 
    class nginx::web($port=8088)  inherits nginx {
        file{'web.conf':
            path   => '/etc/nginx/conf.d/web.conf',
            content => template('nginx/web.conf.erb')
        }
        file{'/ngxdata/html':
            ensure  => directory
        }
        file{'index.html':
            ensure => file,
            path   => '/ngxdata/html/index.html',
            source => 'puppet:///modules/nginx/index.html',
            require => File['/ngxdata/html']
        }
        Service['nginx'] {
            subscribe  => File['web.conf']
        }
    }

    三、编辑反向代理配置

    ]# vim nginx/manifests/proxy.pp
    class nginx::proxy($proxy_port=8088)  inherits nginx {
        file{'proxy.conf':
            path   => '/etc/nginx/conf.d/proxy.conf',
            content => template('nginx/proxy.conf.erb'),
        }
        Service['nginx'] {
            subscribe  => File['proxy.conf']
        }
    }

    四、配置模板与页面测试文件

    ]# vim nginx/templates/web.conf.erb  
    server {
        listen <%= @port %>;
        server_name <%= @fqdn %>;
        location /
            root /ngxdata/html;
        }
    }
    ]# vim nginx/files/index.html
    <h1> Nginx ok </h1>
    ]# vim nginx/templates/proxy.conf.erb
    server {
        listen  <%= @proxy_port %>;
        server_name <%= @fqdn %>;
        location / {
            proxy_pass http://xxx.xxx.xxx:8080/;
        }
    }

    五、应用

    ]# puppet apply -v -e 'include nginx::proxy'

    查看模板是否成效:

    ]# cat /etc/nginx/conf.d/proxy.conf 
    server {
        listen  8088;
        server_name node1.danran.com;
        location / {
            proxy_pass http://xxx.xxx.xxx:8080/;
        }
    }
  • 相关阅读:
    log4j配置详解
    elasticsearch6.0版本安装head插件
    JAVA笔记-如何将百万级数据高效的导出到Excel表单
    抽象方法为什么不能被private与static修饰
    vue利用promise实现连续弹框
    vue代码片段
    h5元素高度超出屏幕但不滚动
    css3动画
    vue 引入静态图片404
    ios windows.open()不能打开
  • 原文地址:https://www.cnblogs.com/readygood/p/10490529.html
Copyright © 2020-2023  润新知