本文主要讲述如何通过Puppet将软件包进行发布:
1,软件包制作工具--fpm
fpm是个跨平台的打包工具,制作软件包非常简单;
fpm介绍:
项目地址:https://github.com/jordansissel/fpm
环境如下:
[root@zabbix installdir]# ruby --versionruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
安装fpm:
gem install fpm --no-rdoc --no-ri
制作nginx软件包:
# mkdir /tmp/installdir #创建临时目录# tar -zxvf nginx-1.2.1.tar.gz# cd nginx-1.2.1# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module# cd /tmp/installer# make# make install DESTDIR=/tmp/installer# mkdir -p /tmp/installdir/etc/{sysconfig,rc.d/init.d,nginx/conf.d} #创建相关目录# cp ~/nginx /tmp/installdir/etc/rc.d/init.d/nginx ##复制nginx的启动脚本放到这个目录# chmod 755 /tmp/installdir/etc/rc.d/init.d/nginx# cd /tmp/installer# lsetc usr ##可以看到/tmp/installer底下有etc,usr2个目录# cd ~# fpm -s dir -t rpm -n nginx -v 1.2.1 -C /tmp/installer etc usr###在主目录下将可以看到nginx-1.2.1-1.x86_64.rpm 的软件包
主要参数如下:
-t OUTPUT_TYPE the type of package you want to create (deb, rpm, solaris, etc)-s INPUT_TYPE the package type to use as input (gem, rpm, python, etc)-n, --name NAME The name to give to the package-v, --version VERSION The version to give to the package (default: 1.0)-C CHDIR Change directory to here before searching for files
2,制作本地源
我采用vsftpd
# mv nginx-1.2.1.x86_64.rpm /var/ftp/pub# createrepo /var/ftp/pub
puppet yumrepo如下:
yumrepo {"ftp": descr => "ftp.repo", baseurl => "ftp://192.168.10.211/pub", enabled => "1", gpgcheck => "0", }
3,软件包的发布
一个完整的puppet nginx模块如下:
class nginx( $version="1.2.1-1") { yumrepo {"ftp": descr => "base", baseurl => "ftp://xxx.xxx.xxx.xxx/pub", enabled => "1", gpgcheck => "0", } package {"nginx": ensure => $version, require => Yumrepo["ftp"], } service {"nginx": ensure => running, enable => true, require => Package["nginx"], }}
使用方法:
modules.pp
import "nginx"
nodes.pp
在特定的节点里
include nginx
然后我们可以在foreman里面看到如下内容:
Level Resource messageinfo //client.test.com/Puppet Retrieving plugininfo //client.test.com/Puppet Caching catalog for client.test.cominfo //client.test.com/Puppet Applying configuration version '1368108406'info //client.test.com/Puppet create new repo ftp in file /etc/yum.repos.d/ftp.reponotice //client.test.com//Stage[main]//Node[client.test.com]/Yumrepo[ftp]/descr descr changed '' to 'ftp.repo'notice //client.test.com//Stage[main]//Node[client.test.com]/Yumrepo[ftp]/baseurl baseurl changed '' to 'ftp://192.168.10.211/pub'notice //client.test.com//Stage[main]//Node[client.test.com]/Yumrepo[ftp]/enabled enabled changed '' to '1'notice //client.test.com//Stage[main]//Node[client.test.com]/Yumrepo[ftp]/gpgcheck gpgcheck changed '' to '0'info //client.test.com/Puppet changing mode of /etc/yum.repos.d/ftp.repo from 600 to 644
如果我们软件包版本进行更新,要求最新的话则ensure => latest;
大概一个比较简单的流程就结束了
ps:最近想认真学习下nginx,有资源的同学记得分享啊