Puppet单机实战之Nginx代理Tomcat
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的更多相关文章
- Ansible实战之Nginx代理Tomcat主机架构
author:JevonWei 版权声明:原创作品 实验架构:一台nginx主机为后端两台tomcat主机的代理,并使用Ansible主机配置 实验环境 Nginx 172.16.252.82 Tom ...
- nginx代理tomcat后,tomcat获取真实(非proxy,非别名)nginx服务端ip端口的解决方案
nginx代理tomcat后,tomcat获取服务端ip端口的解决方案 1.注意修改nginx配置代理,标红地方 #user nginx; worker_processes ; error_log l ...
- Docker Compose 一键部署Nginx代理Tomcat集群
Docker Compose 一键部署Nginx代理Tomcat集群 目录结构 [root@localhost ~]# tree compose_nginx_tomcat/ compose_nginx ...
- nginx代理tomcat
http://blog.csdn.net/kongqz/article/details/6838989 http://www.800l.com/linux-nginx-tomcat-jdk.html ...
- nginx代理 tomcat获得真实用户IP
nginx代理 tomcat获得真实用户IP 2017年04月08日 21:34:17 cf 阅读数 1825更多 分类专栏: nginx html/js/ajax 版权声明:本文为博主原创文章, ...
- Docker Compose部署 nginx代理Tomcat集群
一.简介 使用Docker镜像部署Nginx代理的多个Tomcat集群: 使用Dockerfile构建nginx镜像 使用Dockerfile构建tomcat镜像 mysql镜像使用docker hu ...
- https方式nginx 代理tomcat访问不带www的域名301重定向跳转到www的域名帮助seo集中权重
比如我要把 http://gucanhui.com http://www.gucanhui.com 跳转到https://www.gucanhui.com 用F12的network可以看到状态码301 ...
- nginx代理tomcat做负载
先对三台服务器统一环境. 对两台tomcat服务器的操作 查看jdk环境 # java -version openjdk version "1.8.0_65" OpenJDK Ru ...
- 使用 nginx 代理 tomcat 服务器
server { listen 80; server_name wechat-jsp.local; root /usr/local/Cellar/tomcat/9.0.5/libexec/webapp ...
随机推荐
- UVA 11600 Masud Rana(概率dp)
当两个城市之间有安全的道路的时候,他们是互相可到达的,这种关系满足自反.对称和传递性, 因此是一个等价关系,在图论中就对应一个连通块. 在一个连通块中,当前点是那个并不影响往其他连通块的点连边,因此只 ...
- go语言,爬取百度贴吧指定贴所有内容
初级爬虫,为了学习一下常用的goquery. goquery 配置 go get https://github.com/PuerkitoBio/goquery 会提示不支持https方式 解决方案: ...
- hdu-2256 Problem of Precision---矩阵快速幂+数学技巧
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2256 题目大意: 题目要求的是(sqrt(2)+sqrt(3))^2n %1024向下取整的值 解题 ...
- 【BZOJ2733】[HNOI2012] 永无乡(启发式合并Splay)
点此看题面 大致题意: 给你一张图,其中每个点有一个权值,有两种操作:在两点之间连一条边,询问一个点所在联通块第\(k\)小的权值. 平衡树 看到第\(k\)小,应该不难想到平衡树. 为了练习\(Sp ...
- 【BZOJ1833】[ZJOI2010] count 数字计数(数位DP)
点此看题面 大致题意: 求在给定的两个正整数\(a\)和\(b\)中的所有整数中,\(0\sim9\)各出现了多少次. 数位\(DP\) 很显然,这是一道数位\(DP\)题. 我们可以用前缀和的思想, ...
- 注册Windows service及其相关
注册Windows service,.net写的 net stop "xxxxxx""%SYSTEMROOT%\Microsoft.NET\Framework\v2.0. ...
- Angular6中[ngClass]、[ngStyle]的基本使用
1.ngStyle 基本用法 <div [ngStyle]="{'background-color':'green'}"></<div> 判断添加 & ...
- Javascript笔记部分
写入HTML输出 document.write(“<h1>”); 改变HTML内容 x = document.getElementById(“demo”) //查找元素 后面可以.valu ...
- gravity 使用操作。
gravity 使用操作.最近我司有一个比较奇葩的需求,我们的环境是主从,因为数据量较大会定期的删除数据,最近不行了,要求新建出来一个库 同步正事环境的数据,但是要剔除 delete ,drop,tr ...
- 工具之UltraEdit之正则表达式