设为首页 收藏本站
查看: 1603|回复: 0

[经验分享] puppet安装部署,实例JDK和tomcat

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-10-12 14:22:22 | 显示全部楼层 |阅读模式
puppet 原理和工作流程
puppet 一个为实现数据中心自动化管理而设计的配置管理软件
基于C/S架构
原理:S服务端保存着所有的对客户端服务器的配置代码,puppet里叫清单(manifest);c客户端下载清单后,根据清单对服务器进行配置
工作流程:客户端调用facter facter探测出主机的一些变量,puppetd 把这些信息通过SSL连接发送到服务器puppetmaster
服务器puppetmaster 检测客户端的主机名,然后找到manifest里面对应主机的配置,对其解析,让客户端执行。客户端每隔30分钟同步一次配置文件。
puppet安装
centos6.5 安装puppet

    OS: Centos 6.5 x86_64
    Puppet master: master.com (192.168.116.135)
    Puppet clients: client1.com (192.168.116.136)
    Puppet clients: client2.com (192.168.116.137)

一、先做好安装的准备工作:

1. 在master和client均关闭selinux,iptables:

停止iptables
[iyunv@master ~]# service iptables stop
[iyunv@master ~]# chkconfig  ptables off
关闭selinux
[iyunv@master ~]# vim /etc/selinux/config
改成 SELINUX=disabled

2. 为了保证能向master主机申请到正确的有效证书,建议master和client设置ntp:

[iyunv@master ~]#  yum -y install ntp
[iyunv@master ~]#  ntpdate pool.ntp.org
[iyunv@master ~]#  chkconfig ntpd on
[iyunv@master ~]# chkconfig --list|grep ntp
[iyunv@master ~]# service ntpd start



3. 在master和client端设置主机名和hosts

Puppet 要求所有机器有完整的域名,如果没有 DNS 服务器提供域名的话,可以在机器上设置主机名
[iyunv@master ~]# vim /etc/sysconfig/network
master.com

[iyunv@master ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.116.135 master.com
192.168.116.136 client1.com
192.168.116.137 client2.com


4.  安装puppet官方源(都安装后,克隆改主机名)
[iyunv@master ~]# wget http://yum.puppetlabs.com/el/6/p ... ease-6-7.noarch.rpm
[iyunv@master ~]# rpm -ivh puppetlabs-release-6-7.noarch.rpm
[iyunv@master ~]# yum update

之上C/S都安装
二、Master端安装配置

1. 安装 puppet-server

[iyunv@master ~]# yum -y install puppet-server


2. 添加自动签发证书

编辑 /etc/puppet/puppet.conf 文件, 在[main]段内加入 autosign = true,server = master.com

[iyunv@master ~]# vim /etc/puppet/puppet.conf

[main]
     # 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
     autosign = true
     server = master.com


3. 启动Puppetmaster

[iyunv@master ~]# service puppetmaster start

[iyunv@master ~]#  netstat -tunlp | grep :8140

tcp        0      0 0.0.0.0:8140                0.0.0.0:*                   LISTEN      9148/ruby


4. 开机启动
[iyunv@master ~]# chkconfig --list |grep puppet
[iyunv@master ~]# chkconfig puppetmaster on
[iyunv@master ~]# chkconfig --list |grep puppet

三、客户端安装配置

1.  puppet 安装

[iyunv@client1 ~]# yum -y install puppet


2. 为客户端指定puppet服务器,并开启Master的推送功能

编辑 /etc/puppet/puppet.conf 文件,在[agent]段内加入 listen = true,server = master.com

[iyunv@client1 ~]# vim /etc/puppet/puppet.conf

[agent]
     # 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
     listen = true
     server = master.com

编辑 /etc/puppet/auth.conf 文件, 在 auth / 最下面加入以下语句

[iyunv@client1 ~]# vim /etc/puppet/auth.conf

path /run
method save
allow master.com


3. 启动client

[iyunv@client1 ~]# service puppet start
[iyunv@client1 ~]#  netstat -tunlp | grep :8139

4. 开机启动

[iyunv@client1 ~]# chkconfig puppet on
[iyunv@client1 ~]# chkconfig --list |grep puppet
测试
[iyunv@client1 ~]#puppet agent --test
[iyunv@master ~]#puppet cert list --all

在服务端安装puppet的dashboard

安装mysql
[iyunv@master ~]# yum install  ruby-mysql mysql-server puppet-dashboard

优化mysql设置
[iyunv@master ~]# cp /usr/share/mysql/my-large.cnf  /etc/my.cnf
[iyunv@master ~]# vim /etc/my.cnf
[mysqld]
max_allowed_packet = 32M
启动Mysql服务

[iyunv@master ~]# service mysqld start

[iyunv@master ~]# chkconfig mysqld on

[iyunv@master ~]# chkconfig --list |grep mysqld
[iyunv@master ~]# mysqladmin -u root password '123456'

创建一个dashboard数据库
[iyunv@master ~]# mysql -uroot -p123456 <<EOF
> CREATE DATABASE dashboard CHARACTER SET utf8;
> CREATE USER 'dashboard'@'localhost' IDENTIFIED BY '123456';
> GRANT ALL PRIVILEGES ON dashboard.* TO 'dashboard'@'localhost';
> FLUSH PRIVILEGES;
> EOF

配置Dashboard

[iyunv@master ~]# vim /usr/share/puppet-dashboard/config/database.yml
production:
database: dashboard
username: dashboard
password: 123456
encoding: utf8
adapter: mysql

修改时区

[iyunv@master ~]# vim /usr/share/puppet-dashboard/config/environment.rb

config.time_zone='Beijing'
初始化数据库

[iyunv@master ~]# cd /usr/share/puppet-dashboard/
[iyunv@master puppet-dashboard]# rake RAILS_ENV=production db:migrate


[iyunv@master ~]# service httpd stop
[iyunv@master ~]# service puppetmaster start
[iyunv@master ~]# service puppet-dashboard start
访问http://master.com:3000

导入报告
cd /usr/share/puppet-dashboard
rake RAILS_ENV=production reports:import
执行报告
cd /usr/share/puppet-dashboard
rake jobs:work RAILS_ENV="production"

例子:
[iyunv@master ~]# mkdir -p /etc/puppet/modules/motd{files,manifests,templates}

[iyunv@master ~]# cd /etc/puppet/modules/motd/files
[iyunv@master ~]# mkdir etc
[iyunv@master ~]# vim motd
---puppet test ----
[iyunv@master ~]# vim /etc/puppet/modules/motd/manifests/init.pp
class motd{                 #定义一个类叫motd

  package{ 'setup':    #定义package资源

    ensure => present,  #要求setup这个包处于被安装状态

  }

  file{ '/etc/motd':  #定义file资源

    ensure  => present,  #要求file文件处于存在状态

    owner   => 'root', #要求file文件属主为root

    group   => 'root', #要求file文件属组为root

    mode    => '0644', #要求file文件权限为644

    source  => "puppet://$puppetserver/modules/motd/etc/motd", #要求file文件从puppetmaster端服务器下载

    require => Package['setup'], #要求文件被配置之前先执行package资源

  }

}

[iyunv@master ~]# vim /etc/puppet/manifests/site.pp

$puppetserver = 'master.com' #设置全局变量

node 'client1.com'{

  include  motd

}

[iyunv@client1 ~]#puppet agent --test


puppet 部署tomcat
[iyunv@master ~]#mkdir –vp /etc/puppet/modules/java7/{files,templates,manifests}
[iyunv@master ~]# cd /etc/puppet/modules/java7/files
[iyunv@master files]# wget http://download.oracle.com/otn-p ... 71-linux-x64.tar.gz  

[iyunv@master modules]vim java7/manifests/init.pp
   class java7 {
      include java7::install,java7::env
       }

[iyunv@master modules]vim java7/manifests/install.pp
class java7::install {
     file {
       "/usr/jdk-7u79-linux-x64.tar.gz": #指明文件下载到客户端的哪个路径
       source=> "puppet:///modules/java7/jdk-7u79-linux-x64.tar.gz", #服务器上被下载的源文件
       owner => root,
        group => root,
        mode => 755
     }
   exec { "install jdk":
     cwd => "/usr",
     command => "tar -zxvf jdk-7u79-linux-x64.tar.gz",
     user => "root",
     group => "root",
     path =>["/usr/bin:/usr/sbin:/bin:/sbin"],
     creates =>"/usr/jdk1.7.0_79",
     require =>File["/usr/jdk-7u79-linux-x64.tar.gz"]
     }
}

files/env
export JAVA_HOME=/usr/jdk1.7.0_79
exprot PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

[iyunv@master modules]Vim java7/manifests/env.pp
class java7::env {
file {
    "/usr/java/env":
    owner => "root",
    group => "root",
    source =>"puppet:///modules/java7/env"

}
exec {
    "set env": #set JAVA_HOME
    command =>"cat /usr/java/env>>/etc/profile && source /etc/profile",
    user => "root",
    group => "root",
    path =>["/usr/local/sbin","/usr/local/bin","/sbin","/bin","/usr/sbin","/usr/bin"],
    unless => "grep -i java_home /etc/profile",#if the return value is 1,do this command.
    require =>File["/usr/java/env"]
    }
}
vi  /etc/puppet/manifests/nodes.pp

   node 'client1.com' {

   include java7

   }

   site.pp导入 节点配置文件node.pp
    vi   /etc/puppet/manifests/site.pp
           import "nodes.pp"

配置完成后,客户端执行puppet agent --test ,查看结果
vim  /etc/puppet/modules/tomcat7/manifests/init.pp
       class tomcat7 {
         include tomcat7::install

}

class tomcat7::install {

file {

"/usr/apache-tomcat-7.0.63.tar.gz":

source =>"puppet:///modules/tomcat7/apache-tomcat-7.0.63.tar.gz",

owner => "root",

group => "root",

mode => 755

        }

exec {"install tomcat":

cwd => "/usr",

command => "tar zxvfapache-tomcat-7.0.63.tar.gz && mv apache-tomcat-7.0.63 tomcat7",

user => "root",

group => "root",

path =>["/usr/bin:/usr/sbin:/bin:/sbin"],

creates => "/usr/tomcat7",

require => File["/usr/apache-tomcat-7.0.63.tar.gz"]

     }

}

vi  /etc/puppet/manifests/nodes.pp

   node 'client1.com' {

   include java7,tocamt7

   }

配置完成后,客户端执行puppet agent --test ,查看结果


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-285009-1-1.html 上篇帖子: 自动化管理工具puppet 下篇帖子: Puppet Saltstatck Ansible 自动化运维工具对比
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表