使用 puppet 安装 nginx 一例,供大家学习参考。
首先,看看所有需要用到的东东。
cd /etc/puppet/modules/
[root@puppet nginx]# tree
.
|-- files
| |-- nginx
| |-- nginx-0.8.55.tar.gz
| `-- nginx_install.sh
|-- manifests
| |-- after.pp
| |-- init.pp
| |-- install.pp
| |-- nginxfile.pp
| `-- service.pp
`-- templates
3 directories, 8 files
安装过程
mkdir -p nginx/{manifests,templates,files}
cd /etc/puppet/modules/nginx/files
wget http://nginx.org/download/nginx-0.8.55.tar.gz
[root@puppet manifests]# cat init.pp
[root@puppet manifests]# cat after.pp
[root@puppet manifests]# cat nginxfile.pp
class nginx::nginxfile {
file { "/data/soft/nginx-0.8.55.tar.gz":
source => 'puppet://puppet.cctvcjw.com/modules/nginx/nginx-0.8.55.tar.gz',
mode => 0777,
ensure => 'present',
}
file { "/data/soft/nginx_install.sh":
source => 'puppet://puppet.cctvcjw.com/modules/nginx/nginx_install.sh',
mode => 0777,
ensure => 'present',
}
file { "/etc/rc.d/init.d/nginx":
source => 'puppet://puppet.cctvcjw.com/modules/nginx/nginx',
mode => 0777,
ensure => 'present',
before => Class["nginx::install"],
}
}
[root@puppet manifests]# cat install.pp
[root@puppet manifests]# cat service.pp
[root@puppet manifests]# cat ../files/nginx_install.sh
#!/bin/bash
#cd /data/soft
tar xvzf nginx-0.8.55.tar.gz
cd nginx-0.8.55
./configure --prefix=/usr/local/nginx/ --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module
make
make install
[root@puppet manifests]# cat ../files/nginx
#!/bin/bash
# chkconfig: 35 85 15
# description: nginx service
start(){
if [ -f "/usr/local/nginx/logs/nginx.pid" ]
then
echo 'nginx service status is start'
else
/usr/local/nginx/sbin/nginx
fi
}
stop(){
if [ -f "/usr/local/nginx/logs/nginx.pid" ]
then
num=`cat /usr/local/nginx/logs/nginx.pid`
kill $num
else
echo 'nginx service status is stop'
fi
}
restart(){
if [ -f "/usr/local/nginx/logs/nginx.pid" ]
then
num=`cat /usr/local/nginx/logs/nginx.pid`
kill $num
/usr/local/nginx/sbin/nginx
else
/usr/local/nginx/sbin/nginx
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo 'usage service nginx {restart|stop|start}'
esac