共计 4392 个字符,预计需要花费 11 分钟才能阅读完成。
一直在准备上 Puppet,这两天看了下 Puppet 文档,模拟了下生产环境下 Puppet 部署方案:
测试机器:
server: 192.168.3.68
clinet: 192.168.3.67
命令规则:
应用_机房_地点_ip 地址_服务器系统_域名
192.168.3.67 ppttest_wangsu_bj_192.168.3.67.CentOS.yypuppet.com
192.168.3.68 pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com
*****
本文侧重于 puppet 架构部署,安装过程不是本文的重点,请自行安装。
*****
主配置文件:
root@pts/2 # cat /etc/puppet/puppet.conf
[main]
logdir = /var/log/puppet
rundir = /var/run/puppet
ssldir = $vardir/ssl
[agent]
classfile = $vardir/classes.txt
localconfig = $vardir/localconfig
server = pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com
[master]
environments = yydev,yytest,yyprd
[yydev]
modulepath = $confdir/multi-environment/yydev/environment/modules:$confdir/multi-environment/yydev/application/modules
manifest = $confdir/multi-environment/yydev/manifests/site.pp
fileserverconfig = /etc/puppet/fileserver.conf.yydev
[yytest]
modulepath = $confdir/multi-environment/yytest/environment/modules:$confdir/multi-environment/yytest/application/modules
manifest = $confdir/multi-environment/yytest/manifests/site.pp
fileserverconfig = /etc/puppet/fileserver.conf.yytest
[yyprd]
modulepath = $confdir/multi-environment/yyprd/environment/modules:$confdir/multi-environment/yyprd/application/modules
manifest = $confdir/multi-environment/yyprd/manifests/site.pp
fileserverconfig = /etc/puppet/fileserver.conf.yyprd
为什么在每个环境下会有 environment 和 application 两个目录,其中 environment 目录是存放基础环境模块的,比如 puppet、yum 等;
而 application 目录是存在应用环境模块的,比如 apache、mysql 等。当然也可以放在同一个目录下,如果应用多的话还可以将 application 进行拆分,一切都是为了方便管理而考虑。
实施过程:
1: 创建多环境目录:
cd /etc/puppet
mkdir -p multi-environment/yydev/environment/modules; mkdir -p multi-environment/yydev/application/modules
mkdir -p multi-environment/yytest/environment/modules; mkdir -p multi-environment/yytest/application/modules
mkdir -p multi-environment/yyprd/environment/modules; mkdir -p multi-environment/yyprd/application/modules
2: 创建多环境文件服务器:
cp /etc/puppet/fileserver.conf{,.yydev}; cp /etc/puppet/fileserver.conf{,.yytest}; cp /etc/puppet/fileserver.conf{,.yyprd}
3: 拷贝现有模块分别到三个环境中:
cp /etc/puppet/modules/ssh /etc/puppet/multi-environment/yydev/environment/modules
cp /etc/puppet/modules/httpd /etc/puppet/multi-environment/yydev/application/modules
cp /etc/puppet/modules/ssh /etc/puppet/multi-environment/yytest/environment/modules
cp /etc/puppet/modules/httpd /etc/puppet/multi-environment/yytest/application/modules
cp /etc/puppet/modules/ssh /etc/puppet/multi-environment/yyprd/environment/modules
cp /etc/puppet/modules/httpd /etc/puppet/multi-environment/yyprd/application/modules
4:组织架构:
cd /etc/puppet/multi-environment
tree
├── yydev
│ ├── application
│ │ └── modules
│ │ └── httpd
│ │ ├── files
│ │ │ └── 1.txt
│ │ ├── manifests
│ │ │ └── init.pp
│ │ └── templates
│ ├── environment
│ │ └── modules
│ │ ├── ssh
│ │ │ ├── files
│ │ │ │ └── sshd_config
│ │ │ ├── manifests
│ │ │ │ ├── config.pp
│ │ │ │ ├── init.pp
│ │ │ │ ├── install.pp
│ │ │ │ ├── params.pp
│ │ │ │ └── service.pp
│ │ │ └── templates
│ │ └── test
│ │ ├── files
│ │ ├── manifests
│ │ │ └── init.pp
│ │ └── templates
│ │ └── test.erb
│ └── manifests
│ ├── nodes
│ │ └── front_resin.pp
│ └── site.pp
├── yyprd
│ ├── application
│ │ └── modules
│ └── environment
│ └── modules
└── yytest
├── application
│ └── modules
└── environment
└── modules
模块学习 (ssh 为例):
ssh/
├── files
│ └── sshd_config
├── manifests
│ ├── config.pp
│ ├── init.pp
│ ├── install.pp
│ └── service.pp
└── templates
root@pts/2 # cat init.pp config.pp install.pp service.pp
class ssh {
include ssh::install,ssh::service,ssh::config
}
class ssh::config {
file {“/tmp/sshd_config”:
ensure => present,
owner => ‘root’,
group => ‘root’,
mode => 0440,
source => “puppet:///modules/ssh/sshd_config”,
require => Class[“ssh::install”],
notify => Class[“ssh::service”],
}
}
class ssh::install {
package {“openssh”:
ensure => present,
}
}
class ssh::service {
service {“sshd”:
ensure => running,
hasstatus => true,
hasrestart => true,
enable => true,
require => Class[“ssh::config”],
}
}
Puppet 学习系列:
Puppet 学习一:安装及简单实例应用 http://www.linuxidc.com/Linux/2013-08/88710.htm
Puppet 学习二: 简单模块配置和应用 http://www.linuxidc.com/Linux/2013-08/88711.htm
相关阅读:
有关 Puppet agent 端三种备份恢复方案探讨研究 http://www.linuxidc.com/Linux/2013-07/87885.htm
选择更安全的方式注册你的 Puppet 节点 http://www.linuxidc.com/Linux/2013-07/87884.htm
通过配置 SSH 深刻理解 Puppet 的语法及工作机制 http://www.linuxidc.com/Linux/2013-07/87882.htm
Puppet 利用 Nginx 多端口实现负载均衡 http://www.linuxidc.com/Linux/2013-02/79794.htm
CentOS(5 和 6)下 Puppet 的 C / S 模式实例 http://www.linuxidc.com/Linux/2011-12/50502.htm
Puppet 的详细介绍 :请点这里
Puppet 的下载地址 :请点这里
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-04/116007.htm