码迷,mamicode.com
首页 > 其他好文 > 详细

52.puppet自动化运维工具

时间:2017-07-10 16:29:06      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:linux

puppet自动化运维工具

Puppet是一款运维自动化工具,在一些大型的互联网企业,它可以针对多台服务器进行统一操作,如统一部署软件,进行统一上线维护等,意思就是说在一台linux服务器上所部署的操作,会通过puppet同步到其他linux服务器的一款强大工具。

Puppet使用的端口是8139

 

 

搭建puppetmaster

规划服务器主机名

# vim /etc/sysconfig/network

修改内容:

NETWORKING=yes

HOSTNAME=master.test.cn

# vim /etc/hosts

添加解析记录:

1.1.1.128       master.test.cn

1.1.1.129       client.test.cn

# hostname master.test.cn

# bash

服务器时间同步

#vim /etc/ntp.com

添加两行:

server 127.127.1.0

fudge 127.127.1.0 stratum 8

# yum -y install ntpdate

#service ntpd restart

#chkconfig ntpd on

安装ruby

# yum -y install ruby

#ruby -v

安装puppetfacter

# useradd -s /sbin/nologin puppet

# tar xzvf facter-1.7.1.tar.gz

# cd facter-1.7.1

# ruby install.rb

# tar xzvf puppet-2.7.21.tar.gz

# cd puppet-2.7.21

# ruby install.rb

# cp conf/redhat/fileserver.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

# mkdir /etc/puppet/manifests

# mkdir /etc/puppet/modules

Puppet服务证书与签名

# iptables -F

# vim /etc/puppet/puppet.conf

main行添加:

ssldir = $vardir/ssl

modulepath = /etc/puppet/modules:/usr/share/puppet/modules

# /etc/init.d/puppetmaster start

搭建client客户端:

规划服务器主机名

# vim /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=client.test.cn

# vim /etc/hosts

1.1.1.128       master.test.cn

1.1.1.129       client.test.cn

# hostname client.test.cn

# bash

同步服务时间

# ntpdate 1.1.1.128

安装ruby安装工具

# yum -y install ruby

# ruby -v

安装puppetfacter

#useradd -s /sbin/nologin  puppet

# tar xzvf facter-1.7.1.tar.gz

# cd facter-1.7.1

# ruby install.rb

# tar xzvf puppet-2.7.2

# cd puppet-2.7.21

# ruby install.rb

# cp conf/redhat/puppet.conf /etc/puppet

# cp conf/redhat/client.init  /etc/init.d/puppetclient

# chmod +x /etc/init.d/puppetclient

# iptables -F

# vim /etc/puppet/puppet.conf

main项添加内容 :

ssldir = $vardir/ssl

server = master.test.cn

client端申请与注册

# puppet agent --server=master.test.cn --no-daemonize --verbose

master端提交注册信息

# puppet cert --list                     查看申请列表

# puppet cert sign --all                  提交注册信息,会在下面目录中创建证书

#ll /var/lib/puppet/ssl/ca/signed          查看client端的注册信息文件

 

 

 

 

 

 

 

 

案例需求:需要将ssh服务的端口统一更改为9922

节点入口存放目录/etc/puppet/manifests/nodes

模块存放目录/etc/puppet/modules

Puppet分发部署:

创建必要目录

#mkdir -p /etc/puppet/modules/ssh/{manifests,templates,files}

#mkdir  /etc/puppet/modules/ssh/files/ssh

#mkdir  /etc/puppet/manifests/nodes

#chown -R puppet /etc/puppet/modules/

#ll /etc/puppet/modules/ssh

注:ssh/manifests目录是ssh模块配置文件目录,ssh/filesssh模块的文件发布目录

创建模块配置文件

# vim /etc/puppet/modules/ssh/manifests/install.pp     确定客户端是否安装ssh服务

class  ssh::install{

package{ "openssh":

         ensure => present,

  }

}

# vim /etc/puppet/modules/ssh/manifests/config.pp     配置需要同步的文件

class ssh::config{                                  定义类

file { "/etc/ssh/sshd_config":                         文件路径

        ensure => present,                         确定客户端此文件存在

        owner =>"root",                           文件所属用户

        group =>"root",                           文件所属组

        mode =>"0600",                           文件属性

        source =>"puppet://$puppetserver/modules/ssh/ssh/sshd_config",从服务器同步文件

        require => Class["ssh::install"],               调用ssh::install

        notify => Class["ssh::service"],              如果config.pp发生变化通知service.pp

   }

}

# vim /etc/puppet/modules/ssh/manifests/service.pp

class ssh::service {                              定义类

        service {"sshd":                        

        ensure=>running,                       确定ssh在运行

        hasstatus=>true,                        查看ssh服务状态

        hasrestart=>true,                       重启ssh服务

        enable=>ture,                          服务器是否开机

        require=>Class["ssh::config"]              调用ssh::config

      }

}

# vim /etc/puppet/modules/ssh/manifests/init.pp    模块主配置文件

class ssh{

     include  ssh::install,ssh::config,ssh::service    调用上面三个类

}

复制已修改好的ssh的配置文件到默认目录

# cp /etc/ssh/sshd_config  /etc/puppet/modules/ssh/files/ssh/

#chown puppet /etc/puppet/modules/ssh/files/ssh/sshd_config

创建节点配置文件

# vim /etc/puppet/manifests/nodes/ssh.pp        

node ‘client.test.cn‘ {                            定义客户端入口

     include ssh

}

# vim /etc/puppet/manifests/nodes/site.pp          配置节点位置

import "nodes/ssh.pp"

同步方法:

客户端主动拉取

#puppet agent -t

服务器推送同步

客户端

# echo "listen = true" >> /etc/puppet/puppet.conf

# echo "allow *" >> /etc/puppet/auth.conf

#/etc/init.d/puppetclient restart

#vim /etc/ssh/sshd_config

#netstat -lnupt |grep ssh

服务端

#puppet kick client.test.cn

 


52.puppet自动化运维工具

标签:linux

原文地址:http://10978134.blog.51cto.com/10968134/1945803

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!