linux运维之puppet安装

 一、   安装ruby

环境说明:
server :192.168.1.166  hostname:server.viong.com      
slave:   192.168.1.167  hostname:client1.viong.com
1 、服务器端:
需要安装ruby 1.8.7以上版本,因为rhel5自带为1.8.5,所以需要源码安装。
ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p352.tar.gz

1.tar -xczf ruby-1.8.7-p352.tar.gz

2../configure --prefix=/usr/local/ruby

3.make

4.make install

5.ln -s /usr/local/ruby/bin/ruby /usr/bin/ruby (必须)

注意:如果之前yum安装了ruby:

1.yum erase ruby*

2.mv /usr/lib/ruby /tmp

(如果已经安装了puppet,再安装一次即可,记得安装之前要备份)
 

关于`require': no such file to load -- puppet/application/master

原因:卸载了yum的ruby
因为puppet会将很多的文件拷贝到ruby安装目录下的lib文件夹,所以卸载了ruby,puppet安装的文件也被删除了,再次安装puppet即可
可以看到在安装puppet所作的操作:

1.chmod 0644 /usr/local/ruby/lib/ruby/site_ruby/1.8/puppet/rails/inventory_node.rb

2.lib/puppet/rails/host.rb -> /usr/local/ruby/lib/ruby/site_ruby/1.8/puppet/rails/host.rb

2 、客户端:
yum 安装即可

yum –y install ruby ruby-devel ruby-rdoc ruby-irb

二、安装puppet

Server端安装:
1、时间同步
ntpdate time.nist.gov

2、安装Facter用来获取客户端系统信息(如hostname,ip,OS-Version,fqdn等)
[root@testsns opt]# tar zxvf facter-1.6.5.tar.gz
[root@testsns opt]# cd facter-1.6.5
[root@testsns facter-1.6.5]# ruby install.rb
[root@testsns facter-1.6.5]# cd ..

3、安装puppet

[root@testsns opt]# tar zxvf puppet-2.6.13.tar.gz
[root@testsns opt]# cd puppet-2.6.13
[root@testsns puppet-2.6.13]# ruby install.rb
[root@testsns puppet-2.6.13]# cp conf/auth.conf /etc/puppet/
[root@testsns puppet-2.6.13]# cp conf/redhat/fileserver.conf /etc/puppet/
[root@testsns puppet-2.6.13]# cp conf/redhat/puppet.conf /etc/puppet/
[root@testsns puppet-2.6.13]# cp conf/redhat/server.init /etc/init.d/puppetmaster
[root@testsns puppet-2.6.13]# chmod +x /etc/init.d/puppetmaster
[root@testsns puppet-2.6.13]# chkconfig --add puppetmaster
[root@testsns puppet-2.6.13]# chkconfig puppetmaster on
[root@testsns puppet-2.6.13]# mkdir -p /etc/puppet/manifests
4、生成pupput用户
[root@testsns opt]# puppetmasterd –mkusers

1)确认是否生成清单文件夹
[root@puppet soft]# ll /etc/puppet/
总计 32

-rw-r--r-- 1 root root 2552 06-05 01:29 auth.conf

-rwxr-xr-x 1 root root 381 2012-06-05 fileserver.conf

drwxr-xr-x 2 root root 4096 2012-06-05 manifests

-rwxr-xr-x 1 root root 853 2012-06-05 puppet.conf

manifests目录:用来存放puppet的脚本文件的,必须包含init.pp文件,通常情况下可以把脚本都写入到这个一个文件中,但为了便于管理,最好是按照功能或者项目分开存放
2)确认系统生成puppet用户

[root@puppet puppet-2.7.14]# cat /etc/passwd |grep puppet

puppet:x:500:500::/home/puppet:/bin/bash
3)保证/var/lib/puppet/rrd目录存在且属主是puppet

[root@puppet puppet-2.7.14]# ll /var/lib/puppet/

总计 72

drwxr-x--- 2 puppet puppet 4096 06-05 18:49 bucket

drwxr-xr-x 2 root root 4096 06-05 18:49 facts

drwxr-xr-x 2 root root 4096 06-05 18:49 lib

drwxr-x--- 2 puppet puppet 4096 06-05 18:49 reports

drwxr-x--- 2 puppet puppet 4096 06-05 18:49 rrd

drwxr-x--- 2 puppet puppet 4096 06-05 18:49 server_data

drwxrwx--x 8 puppet root 4096 06-05 18:50 ssl

drwxr-xr-t 2 root root 4096 06-05 18:49 state

drwxr-x--- 2 puppet puppet 4096 06-05 18:49 yaml

查看是否安装成功
[root@server ~]# netstat -ntpl|grep 8140

tcp 0 0 0.0.0.0:8140 0.0.0.0:* LISTEN 2993/ruby [root@server ~]# ps -ef|grep puppet|grep -v grep

puppet 2993 1 0 10:57 ? 00:00:00 /usr/bin/ruby /usr/sbin/puppetmasterd

 

5、启动
[root@testsns opt]# /etc/init.d/puppetmaster start

6、修改hosts
修改双方的/etc/hosts文件,添加各自的IP地址对应的主机名,生产环境做内部DNS比较好,不用修改每台服务器的hosts文件。
192.168.1.166   server.viong.com
192.168.1.167   client1.viong.com

DNS设置过,个别童鞋有报错无法认证记得查询一下

[root@puppet puppet-2.7.14]#vi /etc/resolv.conf

; generated by /sbin/dhclient-script
#search localdomain #注释掉这行,不然造成后面无法认证
nameserver 8.8.8.8
最好能不指定DNS 把resolv.conf内容全删了
Slave 端安装 :
1、时间同步
ntpdate time.nist.gov
和服务器端安装方法一样,先安装ruby环境,再安装facter和puppet,只是在puppet拷贝配置文件时要注意。
2、安装Facter用来获取客户端系统信息(如hostname,ip,OS-Version,fqdn等)

---内容如下
[agent]
Listen = true
Server = server.viong.com
---

[root@nfstest puppet-2.6.13]# vi /etc/puppet/namespaceauth.conf
----内容如下
[fileserver]
allow *
[puppetmaster]
allow *
[puppetrunner]
allow *
[puppetbucket]
allow *
[puppetreports]
allow *
[resource]
allow *
----

3、生成用户和rra目录
[root@nfstest puppet]# puppetmasterd –mkusers

如果出错:
#手动创建puppet用户与组

[root@puppet puppet-2.7.14]# groupadd puppet;useradd -g puppet -M puppet

[root@puppet puppet-2.7.14]# service puppet start

 

4、启动
[root@nfstest puppet]# /etc/init.d/puppet start
5、修改hosts
修改双方的/etc/hosts文件,添加各自的IP地址对应的主机名,生产环境做内部DNS比较好,不用修改每台服务器的hosts文件。
192.168.1.166   server.viong.com
192.168.1.167   client1.viong.com

DNS设置过,个别童鞋有报错无法认证记得查询一下

[root@puppet puppet-2.7.14]#vi /etc/resolv.conf

; generated by /sbin/dhclient-script
#search localdomain #注释掉这行,不然造成后面无法认证
nameserver 8.8.8.8
最好能不指定DNS 把resolv.conf内容全删了


6、开放端口
关闭双方的防火墙及selinux,或开放8140(server服务器端口),8139(client服务器端口)。相互作ping hostname telnet hostname 8140 test hostname 8139等,看网络及hosts是否正常

 
 
 
 
认证
Slave

客户端发送请求
puppetd --test --server server.viong.com

Server
查看当然待批准证书列表
[root@server ~]# puppetca –l

client1.viong.com (B0:85:72:E6:7D:63:EA:CC:BD:0C:E4:F1:70:89:24:70)

批准当前证书

[root@server ~]# puppetca -s client1.viong.com

notice: Signed certificate request for client1.viong.com

notice: Removing file Puppet::SSL::CertificateRequest client1.viong.com at

'/var/lib/puppet/ssl/ca/requests/client1.viong.com.pem'
查看验证签名 , 注意前面的+号,说明已经签名
[root@server ~]# puppetca -a --list

+ server.viong.com (43:33:D3:A0:26:C4:E9:89:66:A6:DC:54:20:90:E9:4D) (alt names:

DNS:puppet, DNS:puppet.viong.com, DNS:server.viong.com)

--------------------------------------------------------------------------------------------------
如果要批准全部证书
puppetca -s -a
也可以在puppetmaster端的puppet.conf加入这行:
autosign = true
服务端就自动签证书
回到客户端操作,从服务端取回已批准的证书

[root@client1 puppet-2.7.14]# puppetd --test --server server.viong.com

验证证书是否正确
服务端:

[root@server ~]# md5sum /var/lib/puppet/ssl/ca/signed/client1.viong.com.pem

客户端:

[root@client1 puppet-2.7.14]# md5sum /var/lib/puppet/ssl/certs/client1.viong.com.pem

出现修改主机名问题引起无法认证,需要重新申请证书,操作以下两个步骤:
服务端:

[root@server ca]# rm -rf /var/lib/puppet/ssl/ca/signed/client1.viong.com.pem

客户端:
[root@client1 puppet-2.7.14]# rm -rf /var/lib/puppet/ssl/ 

 

 

 

本文出自 “TNT、运维之路” 博客,谢绝转载!

你可能感兴趣的:(linux,puppet)