本文主要講述如何通過Puppet將軟件包進行發佈:
1,軟件包製作工具--fpm
fpm是個跨平臺的打包工具,製作軟件包非常簡單;
fpm介紹:
項目地址:https://github.com/jordansissel/fpm
環境如下:
[root@zabbix installdir]# ruby --version ruby 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 # ls etc 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 message info //client.test.com/Puppet Retrieving plugin info //client.test.com/Puppet Caching catalog for client.test.com info //client.test.com/Puppet Applying configuration version '1368108406' info //client.test.com/Puppet create new repo ftp in file /etc/yum.repos.d/ftp.repo notice //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,有資源的同學記得分享啊