author:JevonWei

版权声明:原创作品

blog:http://119.23.52.191/

构建实战之Nginx代理Tomcat

[root@node1 modules]# mkdir /etc/puppet/modules/{tomcat,nginx}/{manifests,files,templates,spec,tests,lib} -pv

Tomcat

编辑Tomcat模块
[root@node1 modules]# vim tomcat/manifests/init.pp
class tomcat {
package{'tomcat':
ensure => latest,
} package{'tomcat-webapps':
ensure => latest,
} file{'tomcat':
path => '/etc/sysconfig/tomcat',
source => 'puppet:///modules/tomcat/tomcat',
owner => root,
group => root,
mode => '644',
require => Package['tomcat'],
} file{'server.xml':
path => '/etc/tomcat/server.xml',
source => 'puppet:///modules/tomcat/server.xml',
owner => root,
group => tomcat,
mode => '644',
require => Package['tomcat'],
}
service{'tomcat':
ensure => running,
enable => true,
subscribe => [ File['tomcat'], File['server.xml'] ],
}
}
[root@node1 modules]# vim tomcat/manifests/manager.pp
class tomcat::manager inherits tomcat {
package{'tomcat-admin-webapps':
ensure => latest
}
file{'tomcat-users.xml':
path => '/etc/tomcat/tomcat-users.xml',
source => 'puppet:///modules/tomcat/tomcat-users.xml',
owner => root,
group => tomcat,
mode => '640',
require => Package['tomcat']
}
Service['tomcat']{
subscribe +> File['tomcat-users.xml']
}
}
复制并编辑所需要的配置文件
[root@node1 modules]# scp 172.16.252.82:/etc/sysconfig/tomcat tomcat/files/
[root@node1 modules]# vim tomcat/files/tomcat 编辑修改tomcat的环境参数
JAVA_OPTS="-Xms512m -Xmx512M" 所使用的堆内存大小
[root@node1 modules]# scp 172.16.252.82:/etc/tomcat/{server.xml,tomcat-users.xml} tomcat/files/ [root@node1 modules]# vim tomcat/files/tomcat-users.xml \\定义manager的管理界面
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/> [root@node1 modules]# puppet apply -v -e 'include tomcat::manager'
Info: Loading facts in /etc/puppet/modules/puppi/lib/facter/last_run.rb
Info: Loading facts in /etc/puppet/modules/puppi/lib/facter/puppi_projects.rb
Info: Loading facts in /etc/puppet/modules/puppi/lib/facter/windows_common_appdata.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/facter_dot_d.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/package_provider.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/pe_version.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/puppet_settings.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/root_home.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/service_provider.rb
Notice: Compiled catalog for node1.danran.com in environment production in 0.18 seconds
Warning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please explicitly set allow_virtual to false.
(at /usr/share/ruby/vendor_ruby/puppet/type.rb:816:in `set_default')
Info: Applying configuration version '1506014294'
Info: /Stage[main]/Tomcat::Manager/File[tomcat-users.xml]: Filebucketed /etc/tomcat/tomcat-users.xml to puppet with sum 5a9a6d35473573a12dc0d5da945907f4
Notice: /Stage[main]/Tomcat::Manager/File[tomcat-users.xml]/content: content changed '{md5}5a9a6d35473573a12dc0d5da945907f4' to '{md5}ea891a0415069c772378e1ba57326c1c'
Info: /Stage[main]/Tomcat::Manager/File[tomcat-users.xml]: Scheduling refresh of Service[tomcat]
Info: /Stage[main]/Tomcat/File[tomcat]: Filebucketed /etc/sysconfig/tomcat to puppet with sum 758c565e1e61a073e87294f9326e5e99
Notice: /Stage[main]/Tomcat/File[tomcat]/content: content changed '{md5}758c565e1e61a073e87294f9326e5e99' to '{md5}0371edad449a896cac5b7ea2149582ae'
Info: /Stage[main]/Tomcat/File[tomcat]: Scheduling refresh of Service[tomcat]
Notice: /Stage[main]/Tomcat/Service[tomcat]: Triggered 'refresh' from 2 events
Notice: Finished catalog run in 1.57 seconds [root@node1 modules]# ss -ntl \\验证监听端口是否打开 浏览器键入http://172.16.252.184:8080/manager验证manager管理界面是否部署

编辑Nginx模块

[root@node1 modules]# vim nginx/manifests/init.pp
class nginx {
package{'nginx':
ensure => latest
} ->
service{'nginx':
ensure => running,
enable => true
}
} nginx的web页面模块
[root@node1 modules]# vim nginx/manifests/web.pp
[root@node1 modules]# 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']
}
} nginx的proxy模块
[root@node1 modules]# 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']
}
} 编辑Nginx web应用的配置文件的模板文件
[root@node1 modules]# vim nginx/templates/web.conf.erb
server {
listen <%= @port %>;
server_name <%= @fqdn %>;
location /
root /ngxdata/html;
}
} 编辑web的测试页
[root@node1 modules]# vim nginx/files/index.html
<h1> Nginx ok </h1> 编辑Nginx proxy应用的配置文件的模板文件
[root@node1 modules]# vim nginx/templates/proxy.conf.erb
server {
listen <%= @proxy_port %>;
server_name <%= @fqdn %>;
location / {
proxy_pass http://172.16.252.184:8080/;
}
} 调用nginx::proxy模块
[root@node1 modules]# puppet apply -v -e 'include nginx::proxy'
Info: Loading facts in /etc/puppet/modules/puppi/lib/facter/last_run.rb
Info: Loading facts in /etc/puppet/modules/puppi/lib/facter/puppi_projects.rb
Info: Loading facts in /etc/puppet/modules/puppi/lib/facter/windows_common_appdata.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/facter_dot_d.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/package_provider.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/pe_version.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/puppet_settings.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/root_home.rb
Info: Loading facts in /etc/puppet/modules/stdlib/lib/facter/service_provider.rb
Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera defaults
Notice: Compiled catalog for node1.danran.com in environment production in 0.20 seconds
Warning: The package type's allow_virtual parameter will be changing its default value from false to true in a future release. If you do not want to allow virtual packages, please explicitly set allow_virtual to false.
(at /usr/share/ruby/vendor_ruby/puppet/type.rb:816:in `set_default')
Info: Applying configuration version '1506016338'
Notice: /Stage[main]/Nginx/Package[nginx]/ensure: created
Notice: /Stage[main]/Nginx::Proxy/File[proxy.conf]/ensure: defined content as '{md5}b43ab8721cac73255395cbfe5eba6be7'
Info: /Stage[main]/Nginx::Proxy/File[proxy.conf]: Scheduling refresh of Service[nginx]
Notice: /Stage[main]/Nginx/Service[nginx]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Nginx/Service[nginx]: Unscheduling refresh on Service[nginx]
Notice: Finished catalog run in 7.64 seconds 测试proxy.conf文件是否复制成功,且变量替换成功
[root@node1 modules]# cat /etc/nginx/conf.d/proxy.conf
server {
listen 8088;
server_name node1.danran.com;
location / {
proxy_pass http://172.16.252.184:8080/;
}
} 浏览器访问http://172.16.252.184:8088/也可正常访问

mariadb模块中的清单文件示例

class mariadb($datadir='/var/lib/mysql') {
package{'mariadb-server':
ensure => installed,
} file{"$datadir":
ensure => directory,
owner => mysql,
group => mysql,
require => [ Package['mariadb-server'], Exec['createdir'], ],
} exec{'createdir':
command => "mkdir -pv $datadir",
require => Package['mariadb-server'],
path => '/bin:/sbin:/usr/bin:/usr/sbin',
creates => “$datadir",
} file{'my.cnf':
path => '/etc/my.cnf',
content => template('mariadb/my.cnf.erb'),
require => Package['mariadb-server'],
notify => Service['mariadb'],
} service{'mariadb':
ensure => running,
enable => true,
require => [ Exec['createdir'], File["$datadir"], ],
}
}

Puppet单机实战之Nginx代理Tomcat的更多相关文章

  1. Ansible实战之Nginx代理Tomcat主机架构

    author:JevonWei 版权声明:原创作品 实验架构:一台nginx主机为后端两台tomcat主机的代理,并使用Ansible主机配置 实验环境 Nginx 172.16.252.82 Tom ...

  2. nginx代理tomcat后,tomcat获取真实(非proxy,非别名)nginx服务端ip端口的解决方案

    nginx代理tomcat后,tomcat获取服务端ip端口的解决方案 1.注意修改nginx配置代理,标红地方 #user nginx; worker_processes ; error_log l ...

  3. Docker Compose 一键部署Nginx代理Tomcat集群

    Docker Compose 一键部署Nginx代理Tomcat集群 目录结构 [root@localhost ~]# tree compose_nginx_tomcat/ compose_nginx ...

  4. nginx代理tomcat

    http://blog.csdn.net/kongqz/article/details/6838989 http://www.800l.com/linux-nginx-tomcat-jdk.html ...

  5. nginx代理 tomcat获得真实用户IP

    nginx代理 tomcat获得真实用户IP 2017年04月08日 21:34:17 cf 阅读数 1825更多 分类专栏: nginx html/js/ajax   版权声明:本文为博主原创文章, ...

  6. Docker Compose部署 nginx代理Tomcat集群

    一.简介 使用Docker镜像部署Nginx代理的多个Tomcat集群: 使用Dockerfile构建nginx镜像 使用Dockerfile构建tomcat镜像 mysql镜像使用docker hu ...

  7. https方式nginx 代理tomcat访问不带www的域名301重定向跳转到www的域名帮助seo集中权重

    比如我要把 http://gucanhui.com http://www.gucanhui.com 跳转到https://www.gucanhui.com 用F12的network可以看到状态码301 ...

  8. nginx代理tomcat做负载

    先对三台服务器统一环境. 对两台tomcat服务器的操作 查看jdk环境 # java -version openjdk version "1.8.0_65" OpenJDK Ru ...

  9. 使用 nginx 代理 tomcat 服务器

    server { listen 80; server_name wechat-jsp.local; root /usr/local/Cellar/tomcat/9.0.5/libexec/webapp ...

随机推荐

  1. 利用Python实现 队列的算法

    以下内容都是来自“悟空“大神的讲解,听他的视频课,利用Python实现堆栈的算法,自己做了一些小总结,可能会存在自己理解的一些误区, 1.栈的实现 队列的特征是先进先出,同我们生活中的队列具有相同的特 ...

  2. JS判断单、多张图片加载完成

    转:http://www.daqianduan.com/6419.html 试想,如果模板中有图片,此时如何判断图片是否加载完成? 在此之前来了解一下jquery的ready与window.onloa ...

  3. python剑指offer剪绳子

    题目 给你一根长度为n的绳子,请把绳子剪成m段 (m和n都是整数,n>1并且m>1)每段绳子的长度记为k[0],k[1],…,k[m].请问k[0]k[1]…*k[m]可能的最大乘积是多少 ...

  4. 利用Theano理解深度学习——Multilayer Perceptron

    一.多层感知机MLP 1.MLP概述 对于含有单个隐含层的多层感知机(single-hidden-layer Multi-Layer Perceptron, MLP),可以将其看成是一个特殊的Logi ...

  5. cocoapods 类库管理利器

    作为iOS开发者,第三方类库的使用是最经常的,但鉴于第三方类库的不断更新以及其可能需要依存其他类,如果要使用最新版那么我们需要重新下载再添加到项目中,无疑带来一些繁琐的麻烦,那么现在这里就有一款能解决 ...

  6. CentOS Linux release 7.6.1810全新安装 Zimbra 8.8.12邮箱

    1.1  基础环境配置 1.1.1  主机名配置 [root@mail ~]# hostnamectl --static set-hostname mail.example.com [root@mai ...

  7. 小程序wafer2操作数据库

    小程序操作数据库 //小程序控制台phpmyadmin里给数据库cAuth添加表 //controllers/hello.js const { mysql } = require('../qcloud ...

  8. DeepFaceLab报错, Could not create cudnn handle 解决方法!

    DeepFaceLab 虽然没有可视化界面,但是在众多换脸软件中,是安装最方便,更新最快,整体性能最佳的一个.这个软件对于系统依赖很低,也就是不需要装各种各样的“插件”. 但是即便如此,由于版本的不断 ...

  9. winform中使用webBrowser时如何与JS交互

    最近写一个GEPlugin项目,要用到geWebBrowser与JS进行交互. 这个geWebBrowser的事件 private void geWebBrowser1_DocumentComplet ...

  10. Android 多线程 打地鼠游戏

    前言:最近比较喜欢多线程了,看到了一些线程案例,这里总结一下打地鼠游戏的整个过程. 1.首先是主活动要加载的布局,我一般就喜欢早点把这个写上,这样就好在主活动中玩弄这些控件了.闲话不多说,一个Fram ...