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. UVA 12169 Disgruntled Judge(Extended_Euclid)

    用扩展欧几里德Extended_Euclid解线性模方程,思路在注释里面了. 注意数据范围不要爆int了. /********************************************* ...

  2. UVA Live Archive 4490 Help Bubu(状压dp)

    难点在于状态设计,从左向右一本书一本书的考虑,每本书的决策有两种拿走或者留下, 对于拿走后的书,之后要放回,但是决策过程中不知道到往哪里放, 虽然前面的书的种类确定,可能是往后面放更优,而后面的书的类 ...

  3. 如何在python中读写和存储matlab的数据文件(*.mat)

    使用sicpy.io即可.sicpy.io提供了两个函数loadmat和savemat,非常方便. 以前也有一些开源的库(pymat和pymat2等)来做这个事, 不过自从有了numpy和scipy以 ...

  4. SecureCRT连接Linux

    一.服务端 1.在linux上安装openssh-server服务,并确认打开了22监听端口 1)安装openssh-server:apt-get install openssh-server 2)查 ...

  5. Java后台工程师的3次面试

    第一次面试 我面的是一个中小公司,在BOSS直聘上面找的,去之前看了看关于Java的一些基础知识,在牛客网上面看的,也做了一下牛客网的题目.然后跟HR约了一个时间就去面试了.因为第一次面试,一点经验都 ...

  6. 【C++学习笔记】 链式前向星

    链式前向星是一种常见的储存图的方式(是前向星存图法的优化版本),支持增边和查询,但不支持删边(如果想要删除指定的边建议用邻接矩阵). 储存方式 首先定义数组 head[ i ] 来储存从节点 i 出发 ...

  7. 100个linux系统常用指令

    1.ls [选项] [目录名 | 列出相关目录下的所有目录和文件 -a 列出包括.a开头的隐藏文件的所有文件-A 通-a,但不列出"."和".."-l 列出文件 ...

  8. HashMap原理以及自己实现HashMap

    1.HashMap是什么? HashMap是java常用来存储键值对的数据结构,它是以key/value的形式存储的,它不是线程安全的,Key可以为null值. 2.HashMap的实现原理 Hash ...

  9. 使用Navicat连接阿里云ECS服务器上的MySQL数据库

    一.首先要mysql授权 mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的mysql数据库密码' WITH GR ...

  10. 牛课第二次多校I

    链接:https://www.nowcoder.com/acm/contest/140/I来源:牛客网 题目描述 White Cloud has a square of n*n from (1,1) ...