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

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

[复制链接]

尚未签到

发表于 2018-8-2 06:41:11 | 显示全部楼层 |阅读模式
  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
  [root@master ~]# service iptables stop
  [root@master ~]# chkconfig  ptables off
  关闭selinux
  [root@master ~]# vim /etc/selinux/config
  改成 SELINUX=disabled
  2. 为了保证能向master主机申请到正确的有效证书,建议master和client设置ntp:
  [root@master ~]#  yum -y install ntp
  [root@master ~]#  ntpdate pool.ntp.org
  [root@master ~]#  chkconfig ntpd on
  [root@master ~]# chkconfig --list|grep ntp
  [root@master ~]# service ntpd start
  3. 在master和client端设置主机名和hosts
  Puppet 要求所有机器有完整的域名,如果没有 DNS 服务器提供域名的话,可以在机器上设置主机名
  [root@master ~]# vim /etc/sysconfig/network
  master.com
  [root@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官方源(都安装后,克隆改主机名)
  [root@master ~]# wget http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm
  [root@master ~]# rpm -ivh puppetlabs-release-6-7.noarch.rpm
  [root@master ~]# yum update
  之上C/S都安装
  二、Master端安装配置
  1. 安装 puppet-server
  [root@master ~]# yum -y install puppet-server
  2. 添加自动签发证书
  编辑 /etc/puppet/puppet.conf 文件, 在[main]段内加入 autosign = true,server = master.com
  [root@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
  [root@master ~]# service puppetmaster start
  [root@master ~]#  netstat -tunlp | grep :8140
  tcp        0      0 0.0.0.0:8140                0.0.0.0:*                   LISTEN      9148/ruby
  4. 开机启动
  [root@master ~]# chkconfig --list |grep puppet
  [root@master ~]# chkconfig puppetmaster on
  [root@master ~]# chkconfig --list |grep puppet
  三、客户端安装配置
  1.  puppet 安装
  [root@client1 ~]# yum -y install puppet
  2. 为客户端指定puppet服务器,并开启Master的推送功能
  编辑 /etc/puppet/puppet.conf 文件,在[agent]段内加入 listen = true,server = master.com
  [root@client1 ~]# vim /etc/puppet/puppet.conf
  [agent]

  # The file in which puppetd stores a list of the>  # 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 / 最下面加入以下语句
  [root@client1 ~]# vim /etc/puppet/auth.conf
  path /run
  method save
  allow master.com
  3. 启动client
  [root@client1 ~]# service puppet start
  [root@client1 ~]#  netstat -tunlp | grep :8139
  4. 开机启动
  [root@client1 ~]# chkconfig puppet on
  [root@client1 ~]# chkconfig --list |grep puppet
  测试
  [root@client1 ~]#puppet agent --test
  [root@master ~]#puppet cert list --all
  在服务端安装puppet的dashboard
  安装mysql
  [root@master ~]# yum install  ruby-mysql mysql-server puppet-dashboard
  优化mysql设置
  [root@master ~]# cp /usr/share/mysql/my-large.cnf  /etc/my.cnf
  [root@master ~]# vim /etc/my.cnf
  [mysqld]
  max_allowed_packet = 32M
  启动Mysql服务
  [root@master ~]# service mysqld start
  [root@master ~]# chkconfig mysqld on
  [root@master ~]# chkconfig --list |grep mysqld
  [root@master ~]# mysqladmin -u root password '123456'
  创建一个dashboard数据库
  [root@master ~]# mysql -uroot -p123456 <<EOF
  > CREATE DATABASE dashboard CHARACTER SET utf8;

  > CREATE USER 'dashboard'@'localhost'>  > GRANT ALL PRIVILEGES ON dashboard.* TO 'dashboard'@'localhost';
  > FLUSH PRIVILEGES;
  > EOF
  配置Dashboard
  [root@master ~]# vim /usr/share/puppet-dashboard/config/database.yml
  production:
  database: dashboard
  username: dashboard
  password: 123456
  encoding: utf8
  adapter: mysql
  修改时区
  [root@master ~]# vim /usr/share/puppet-dashboard/config/environment.rb
  config.time_zone='Beijing'
  初始化数据库
  [root@master ~]# cd /usr/share/puppet-dashboard/
  [root@master puppet-dashboard]# rake RAILS_ENV=production db:migrate
  [root@master ~]# service httpd stop
  [root@master ~]# service puppetmaster start
  [root@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"
  例子:
  [root@master ~]# mkdir -p /etc/puppet/modules/motd{files,manifests,templates}
  [root@master ~]# cd /etc/puppet/modules/motd/files
  [root@master ~]# mkdir etc
  [root@master ~]# vim motd
  ---puppet test ----
  [root@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资源
  }
  }
  [root@master ~]# vim /etc/puppet/manifests/site.pp
  $puppetserver = 'master.com' #设置全局变量
  node 'client1.com'{
  include  motd
  }
  [root@client1 ~]#puppet agent --test
  puppet 部署tomcat
  [root@master ~]#mkdir –vp /etc/puppet/modules/java7/{files,templates,manifests}
  [root@master ~]# cd /etc/puppet/modules/java7/files
  [root@master files]# wget http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-x64.tar.gz
  [root@master modules]vim java7/manifests/init.pp
  class java7 {
  include java7::install,java7::env
  }
  [root@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>  [root@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-544971-1-1.html 上篇帖子: 自动化管理工具puppet-GeminiYu 下篇帖子: Puppet 入门:安装 配置 举例
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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