|
两台Redhat搭建Puppet实践
简介
1. Puppet可以实现如下功能可以实现如下功能可以实现如下功能可以实现如下功能:
随着服务器的增加,传统的系统维护方法有点捉襟见肘,于是出现了配置管理软件,利用配置管理,可以把整个公司的服务器的所有配置内容管理起来,方便大规模的管理以及快速的部署。Puppet就是一个为实现数据库中心自动化管理而设计的C/S模式配置管理软件。
2. Puppet的几个概念的几个概念的几个概念的几个概念:
服务器端和客户端:服务器端保存和推送配置到客户端;清单(manifest):服务器端保存的客户端配置文件,客户端下载了manifest以后就可以应用;资源:客户端配置中,能管理到的对象被称为资源。
3. Puppet实现条件实现条件实现条件实现条件:
首先安装建立一个puppet的C/S模型;在两台或多台服务器上分别安装puppet,其中一个是服务器端,其他是客户端(被管理者)。待到服务器端和客户端都安装完成,客户端可以从服务器端获得一个Manifest,并依此修改这个文件。
实践
1. 环境介绍
服务端:10.10.225.206 server.puppet.com
客户端:10.10.225.201 agent01.puppet.com
OS: RedHat 4.4.6
2. 步骤
(1). 首先要确保客户端和服务端时间同步,可以在服务端建立ntp服务端,然后让客户端做时间同步,也可直接设置服务端与客户端日期,相差不要太大就可以。否则当客户端向服务端提交认证时总提示错误,切记!!!
(2). 服务端安装(源码安装)用apt-get 和 yum安装的可以跳过此步
安装Facter 用来获取客户端系统信息(如hostname,ip,OS-version,fqdn等)采用源码安装
#cd /usr/local/src#wget"http://puppetlabs.com/downloads/facter/facter-latest.tgz" 最新稳定版facter,下载不了的去web网页下载#tar -xvzf facter-latest.tgz#cd facter-latest#ruby install.rb; 安装#cd ..
安装puppet
#wget "http://puppetlabs.com/downloads/puppet/puppet-latest.tgz" 下载最新稳定版puppet#cd puppet-*#ruby install.rb#mkdir /etc/puppet#cp conf/auth.conf /etc/puppet/#cp conf/namespaceauth.conf /etc/puppet/#cp conf/redhat/puppet.conf /etc/puppet/#cp conf/redhat/server.init /etc/init.d/puppetmaster#chmod +x /etc/init.d/puppetmaster
(3) 客户端安装(和服务端安装方法一样)
#mkdir /etc/puppet#cp conf/auth.conf /etc/puppet/#cp conf/namespaceauth.conf /etc/puppet/#cp conf/redhat/puppet.conf /etc/puppet/#cp conf/redhat/client.init /etc/init.d/puppet#chmod +x /etc/init.d/puppet (4) 服务端配置10.10.225.206
修改/etc/hosts :
#vim /etc/hosts# Do not remove the following line, or various programs# that require network functionality will fail.127.0.0.1 puppet localhost.localdomain localhost;::1 localhost6.localdomain6 localhost6 修改hostname:
#vim /etc/sysconfig/networkNETWORKING=yesHOSTNAME=server.puppet.com #hostname server.puppet.com #/etc/init.d/network restart (5) 客户端配置10.10.225.201
修改/etc/hosts
#vim /etc/hosts # Do not remove the following line, or various programs# that require network functionality will fail.127.0.0.1 localhost.localdomain localhost::1 localhost6.localdomain6 localhost610.10.225.206 server.puppet.com puppet10.10.225.201 agent01.puppet.comagent01 #vim /etc/sysconfig/networkNETWORKING=yesHOSTNAME=agent01.puppet.com #hostname agent01.puppet.com #/etc/init.d/network restart (6) 启动服务端服务
生成config文件
#puppet --genconfig > /etc/puppet/puppet.conf 启动服务
#puppet master --mkusers (7) 客户端请求服务端认证
在客户端执行:
#puppetd agent --server server.puppet.com --test 在服务端执行:
#puppetca --list 查看客端请求 #puppetca -s agent01.puppet.com 签发证书 在客户端执行:
#puppetd agent --server server.puppet.com --test 客户端获取证书 (8) 重新申请证书
有时候客户端获取到的证书和服务器端不匹配,需要重新获取证书,这时候在服务器端执行:
#puppetca --clean agent01.puppet.com #/etc/init.d/puppetmaster restart 在客户端执行:
rm -rf /var/lib/puppet/ssl 然后再重新执行步骤7就可以了。
3. 测试
在服务器端新建site.pp manifest文件,内容如下:
#vi /etc/puppet/manifests/site.pp nodedefault{ file{ "/tmp/Puppet_test.txt": #这是文件路径名; content=>"This is test of PUPPET"; #这是文件的内容; }} 然后执行:
#/etc/init.d/puppetmaster restart #初次创建manifest文件需要重启服务; #puppet /etc/puppet/manifests/site.pp #执行此命令使site.pp配置 客服端执行:
#puppetd --test --server server.puppet.com 这时候再执行:
#cat /tmp/Puppet_test.txt 就会看到该文件已经在客户端生成了。
4. 客户端设置守护进程
#puppetd --server server.puppet.com --verbose --waitforcert 60 表示每60秒去服务器执行一下manifest脚本。
*******************************************郑州就维 www.zzjiuwei.com*******************************************
|
|
|