rh007 发表于 2015-9-16 12:22:34

CentOS 6.3安装Puppet3.x

  一、系统环境:
  主机名               IP(Static)                        系统                                           配置                                        备注
  puppetserver    192.168.100.241      CentOS-6.3-x86_64-minimal       1CPU,1G RAM,10G DISK,1网卡         Puppet Server
  client01             192.168.100.242      CentOS-6.3-x86_64-minimal       1CPU,1G RAM,10G DISK,1网卡         Puppet Client
  ***************************************************************************************************
  二、Puppet Server安装:
  1.安装前的准备:
  # sed -i "7s/enforcing/disabled/" /etc/selinux/config            /*关闭SELinux*/
  # vi /etc/sysconfig/iptables                  /*编辑防火墙打开8140和3000端口*/



  -A INPUT -m state --state NEW -p tcp --dport 8140 -j ACCEPT
  -A INPUT -m state --state NEW -p tcp --dport 3000 -j ACCEPT
  # reboot
  

  2.配置NTP服务:
  请参考:《CentOS 6.3下NTP服务安装和配置》
  

  3.配置hosts文件:
  # vi /etc/hosts
  192.168.100.241   puppetserver
  192.168.100.242   client01
  192.168.100.243   client02
  

  4.安装Puppet Server:
  # rpm -Uvh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-6.noarch.rpm
  # yum -y install puppet-server
  # chkconfig --level 3 puppetmaster on
  # service puppetmaster start
  

  5.安装配置Mysql数据库:
  # yum -y install mysql mysql-devel mysql-server
  # service mysqld start
  # mysqladmin -u root password 'chensh'      /*设置Mysql的root密码为chensh*/
  

  6.安装Dashboard:
  # yum -y install puppet-dashboard
  

  7.配置dashboard的database.yml文件:
  # vi /usr/share/puppet-dashboard/config/database.yml
  修改部分内容如下:



  production:
  database: dashboard

  username: root
password: chensh
encoding: utf8
adapter: mysql
  8.创建dashboard数据库,数据库名为dashboard:
  # mysql -uroot -pchensh -e 'create database dashboard character set utf8'
  

  9.配置dashboard的environment.rb文件:
  # vi /usr/share/puppet-dashboard/config/environment.rb
  将config.time_zone = 'UTC'改为config.time_zone = 'Beijing'
  

  10.修改/etc/sysconfig/puppet文件:
  # vi /etc/sysconfig/puppet


# The puppetmaster server  PUPPET_SERVER=puppetserver
  

  # If you wish to specify the port to connect to do so here
  PUPPET_PORT=8140
  

  # Where to log to. Specify syslog to send log messages to the system log.
  PUPPET_LOG=/var/log/puppet/puppet.log
  

  # You may specify other parameters to the puppet client here
  # PUPPET_EXTRA_OPTS=--waitforcert=500
  

  11.修改/etc/puppet/puppet.conf文件:

  # vi /etc/puppet/puppet.conf

  

  
      # The Puppet log directory.
      # The default value is '$vardir/log'.
      logdir = /var/log/puppet
  

      # Where Puppet PID files are kept.
      # The default value is '$vardir/run'.
      rundir = /var/run/puppet
  

      # Where SSL certificates are kept.
      # The default value is '$confdir/ssl'.
      ssldir = $vardir/ssl
      reports = store,http,log         /*设置Dashbroad report*/
      server = puppetserver
  
      # The file in which puppetd stores a list of the classes
      # associated with the retrieved configuratiion.Can be loaded in
      # the separate ``puppet`` executable using the ``--loadclasses``
      # option.
      # The default value is '$confdir/classes.txt'.
      classfile = $vardir/classes.txt
  

      # Where puppetd caches the local configuration.An
      # extension indicating the cache format is added automatically.
      # The default value is '$confdir/localconfig'.
      localconfig = $vardir/localconfig
      runinterval = 3600                     /*设置检测时间间隔3600s*/
  

  

  12.初始化Dashboard数据库:

  # cd /usr/share/puppet-dashboard
  # rake RAILS_ENV=production db:migrate
  

  13.启动服务:
  # /etc/init.d/puppetmaster start                        /*puppet服务端进程,监听8140端口*/
  # /etc/init.d/puppet-dashboard start                   /*puppet WEB,默认3000端口*/
  # /etc/init.d/puppet-dashboard-workers start      /*新版本新增的进程,不启动dashboard上面看不到数据*/
  

  14.访问Dashboard WEB:http://192.168.100.241:3000
http://d.hiphotos.baidu.com/album/pic/item/b2de9c82d158ccbf0f35c54a18d8bc3eb1354130.jpg
  

  三、Puppet Client安装:

  1.安装前的准备:
  # sed -i "7s/enforcing/disabled/" /etc/selinux/config            /*关闭SELinux*/
  # vi /etc/sysconfig/iptables                  /*编辑防火墙打开8140端口*/



-A INPUT -m state --state NEW -p tcp --dport 8140 -j ACCEPT  # reboot
  

  2.配置NTP客户端服务:
  请参考:《CentOS 6.3下NTP服务安装和配置》
  

  3.配置hosts文件:
  # vi /etc/hosts
  192.168.100.241   puppetserver
  192.168.100.242   client01
  192.168.100.243   client02
  

  4.安装Puppet Client:
  # rpm -Uvh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-6.noarch.rpm
  # yum -y install puppet
  

  5.指定Puppet master名称:
  # echo ‘server = puppetserver’>> /etc/puppet/puppet.conf

  # echo ‘reports = true’>> /etc/puppet/puppet.conf             /*向服务端发送report信息*/

  

  6.启动Puppet Client:
  # chkconfig --level 3 puppet on
  # service puppet start
  

  四、客户端证书申请与服务端认证:
  
  1.客户端证书申请:
  # puppet agent --test --server puppetserver                            /*执行 puppet agent --test也可以*/
  Info: Creating a new SSL key for client01
  Info: Caching certificate for ca
  Info: Creating a new SSL certificate request for client01
  Info: Certificate Request fingerprint (SHA256): 69:45:4C:45:17:A9:7C:6F:24:04:8F:0B:F7:44:4D:4D:59:BA:4F:9D:71:35:04:3F:8F:29:0E:63:50:55:16:F3
  Exiting; no certificate found and waitforcert is disabled
  #
  

  2.服务器端查看请求签发的证书:
  # puppet cert --list
  "client01"               (SHA256) 69:45:4C:45:17:A9:7C:6F:24:04:8F:0B:F7:44:4D:4D:59:BA:4F:9D:71:35:04:3F:8F:29:0E:63:50:55:16:F3
  #
  

  3.服务器端签发证书:
  # puppet cert --sign client01                                                   /*多证书可执行puppet cert --sign --all批量签发*/
  Notice: Signed certificate request for client01
  Notice: Removing file Puppet::SSL::CertificateRequest client01 at '/var/lib/puppet/ssl/ca/requests/client01.pem'
  #
  

  4.查看已签发的证书:
  # puppet cert --list --all
  + "client01"            (SHA256) 37:5D:E3:E4:09:07:BA:41:16:D5:16:0A:B0:1F:67:5A:20:BB:65:CB:21:EE:A6:C3:30:DB:C6:77:01:9F:EF:18
  #
  ******************************************************************************
  五、证书注销:
  1.注销证书:
  # puppet cert revoke client01
  Notice: Revoked certificate with serial 5
  #
  

  2.查看证书当前状态:
  # puppet cert list --all
  - "client01"            (SHA256) 37:5D:E3:E4:09:07:BA:41:16:D5:16:0A:B0:1F:67:5A:20:BB:65:CB:21:EE:A6:C3:30:DB:C6:77:01:9F:EF:18 (certificate revoked)
  #
  

  3.重启puppetmaster:
  # /etc/init.d/puppetmaster restart

  

  六、证书删除:
  

  1.删除证书:
  # puppet cert clean client01
  Notice: Revoked certificate with serial 5
  Notice: Removing file Puppet::SSL::Certificate client01 at '/var/lib/puppet/ssl/ca/signed/client01.pem'
  Notice: Removing file Puppet::SSL::Certificate client01 at '/var/lib/puppet/ssl/certs/client01.pem'
  #
  

  2.重启puppetmaster:
  # /etc/init.d/puppetmaster restart
  

  3.删除客户单client01.pem文件 或者 SSL目录:
  # rm -rf /var/lib/puppet/ssl/certs/client01.pem                        /*删除client01.pem文件*/

  # rm -rf /var/lib/puppet/ssl/*                                                    /*删除ssl目录下的所有文件*/

  

  七、自动签发证书:
  # echo “*”   >>/etc/puppet/autosign.conf
  ******************************************************************************
  

  问题总结:
  问题1:
  执行数据库初始化时报错如下:
  #rake RAILS_ENV=production db:migrate
  rake aborted!
  syntax error on line 49, col 2: `encoding: utf8'
  (See full trace by running task with --trace)
  

  解决办法:
  # vi /usr/share/puppet-dashboard/config/database.yml




  production:
  database: dashboard

  username: root
password:chensh
encoding: utf8
adapter: mysql
  将"password:chensh"改为"password: chensh"(即加一个“空格”符),再次执行"rake RAILS_ENV=production db:migrate"即可。
  

  问题2:
  # puppet agent --test
  Error: Could not request certificate: Connection timed out - connect(2)
  Exiting; failed to retrieve certificate and waitforcert is disabled
  #
  解决办法:
  请查看网络、SElinux、iptables以及hosts文件中的IP和主机名是否配置正确。
  

  问题3:
  # /etc/init.d/puppet-dashboard-workers restart
  Rails Error: Unable to access log file. Please ensure that /usr/share/puppet-dashboard/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
  

  解决办法:
  #chmod -R 666 /usr/share/puppet-dashboard/log/production.log
  

  

  
页: [1]
查看完整版本: CentOS 6.3安装Puppet3.x