通过配置ssh深刻理解puppet的语法及工作机制
通過(guò)配置ssh深刻理解puppet的語(yǔ)法及工作機(jī)制
需求分析
1)、要求openssh-server處于被安裝狀態(tài)
2)、要求在配置文件/etc/ssh/sshd_config正確的情況下,sshd服務(wù)處于運(yùn)行狀態(tài)
2)、要求/etc/ssh/sshd_config文件屬性不被串改(權(quán)限、屬主、屬組等)
3)、要求/etc/ssh/sshd_config文件被修改或者刪除后會(huì)被自動(dòng)修復(fù)
4)、要求通過(guò)puppetserver端修改/etc/ssh/sshd_config之后,sshd服務(wù)能夠自動(dòng)重啟。
定義全局配置信息
定義全局配置文件site.pp
[root@puppetserver?~]#?vim?/etc/puppet/manifests/site.pp?
import?'nodes/*'
$puppetserver?=?'puppetserver.rsyslog.org'
創(chuàng)建并配置nodes.pp節(jié)點(diǎn)
[root@puppetserver?~]#?mkdir?/etc/puppet/manifests/nodes?–p
[root@puppetserver?~]#?vim?/etc/puppet/manifests/nodes/nodes.pp
>?node?/^agent\d+\.rsyslog.org$/{
>????????include?ssh
>?}
>?endf
設(shè)置模塊搜索路徑
vim?/etc/puppet/puppet.conf?
[main]
modulepath?=?/etc/puppet/modules:/var/lib/puppet/modules:/usr/local/lib/puppet/modules
創(chuàng)建模塊目錄結(jié)構(gòu)
[root@puppetserver?~]#?mkdir?-vp?
/etc/puppet/modules/ssh/{files,templates,manifests}
創(chuàng)建配置文件
創(chuàng)建配置文件(/etc/puppet/modules/ssh/manifests目錄下)
1)、創(chuàng)建site.pp文件
class?ssh{
????????include?ssh::params,ssh::config,ssh::service,ssh::install
}
2)、創(chuàng)建install.pp文件
class?ssh::install{
????????package?{?$ssh::params::ssh_package_name:
????????????????ensure?=>?installed,
????????}
}
3)、創(chuàng)建config.pp文件
class?ssh::config{
????????file?{?$ssh::params::ssh_service_config:
????????????????ensure?=>?present,
????????????????owner?=>?'root',
????????????????group?=>?'root',
????????????????mode?=>?0440,
????????????????source?=>?"puppet:///modules/ssh/etc/ssh/sshd_config",
????????????????require?=>?Class["ssh::install"],
????????????????notify?=>?Class["ssh::service"],
????????}
}
4)、創(chuàng)建service.pp文件
class?ssh::service{
????????service?{?$ssh::params::ssh_service_name:
????????????????ensure?=>?running,
????????????????hasstatus?=>?true,
????????????????hasrestart?=>?true,
????????????????enable?=>?true,
????????????????require?=>?Class["ssh::config"],
????????}
}
5)、創(chuàng)建params.pp文件
class?ssh::params?{
????????case?$::operatingsystem?{
????????????????Slaris:?{
????????????????????????$ssh_package_name?=?'openssh'
????????????????????????$ssh_service_config?=?'/etc/ssh/sshd_config'
????????????????????????$ssh_service_name?=?'sshd'
????????????????}
????????????????/^(Ubuntu|Debian)$/:?{
????????????????????????$ssh_package_name?=?'openssh-server'
????????????????????????$ssh_service_config?=?'/etc/ssh/sshd_config'
????????????????????????$ssh_service_name?=?'sshd'
????????????????}
????????????????/^(RedHat|CentOS|Fedora)$/:?{
????????????????????????$ssh_package_name?=?'openssh-server'
????????????????????????$ssh_service_config?=?'/etc/ssh/sshd_config'
????????????????????????$ssh_service_name?=?'sshd'
????????????????}
????????????????default:?{
????????????????????????$ssh_package_name?=?'openssh-server'
????????????????????????$ssh_service_config?=?'/etc/ssh/sshd_config'
????????????????????????$ssh_service_name?=?'sshd'
????????????????}
????????}
}
創(chuàng)建測(cè)試文件
[root@puppetserver?manifests]#?mkdir?/etc/puppet/modules/ssh/files/etc/ssh/?-p?[root@puppetserver?manifests]#?scp?agent1.rsyslog.org:/etc/ssh/sshd_config?/etc/puppet/modules/ssh/files/etc/ssh/?
[root@puppetserver?~]#?service?puppetmaster?reload
測(cè)試(puppet?kick的方式)
Puppet?server端開(kāi)啟調(diào)試模式測(cè)試
[root@puppetserver?~]#?puppet?master?--no-daemonize?--verbose?
Puppet?agent端開(kāi)啟調(diào)試模式測(cè)試
[root@puppetserver?manifests]#?puppetrun?-p?10?--host?agent1.rsyslog.org
Triggering?agent1.rsyslog.org
Getting?status
status?is?success
agent2.rsyslog.org?finished?with?exit?code?0
Finished
本文轉(zhuǎn)自凌激冰51CTO博客,原文鏈接:http://blog.51cto.com/dreamfire/1257719,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者
總結(jié)
以上是生活随笔為你收集整理的通过配置ssh深刻理解puppet的语法及工作机制的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: lucene、solr、nutch三者的
- 下一篇: 【转】C++调用Matlab的.m文件