cd /puppet/soft
wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-3.2.9.tgz
mkdir -p /etc/puppet/modules/linuxmongodb/{manifests,files,templates}
写配置文件
vi /etc/puppet/modules/linuxmongodb/templates/mongodb-3.2.9.conf.erb
dbpath=/data/mongodb-3.2.9/db
logpath=/data/mongodb-3.2.9/logs/mongodb.log
logappend = true
port=<%= real_mongodb_port %>
fork=true
auth=true
journal=true
quiet=true
写启动脚本
vi /puppet/soft/mongodb-3.2.9.sh
!/bin/bash
chkconfig:2345 90 60
description:mongodb star stop
. /etc/rc.d/init.d/functions
servicename=/data/mongodb-3.2.9/bin/mongod
serviceconfig=/data/mongodb-3.2.9/mongodb.conf
if [ ! -f $servicename ];then
exit 6;
fi
if [ ! -f $serviceconfig ];then
exit 7;
fi
case servicename -f servicename -f servicename -f RETVAL -ge 1 ]; then
echo 'running'
exit 0
else
echo 'stopped'
fi
exit 1
;;
*)
echo "Usage: $0 {start|stop|restart|status|force-reload}"
exit 2
esac
exit $?
vim /etc/puppet/modules/linuxmongodb/manifests/init.pp
class linuxmongodb::mongodb329 {
mongodb_port ? { '' => '27017',default => $mongodb_port }
exec {"/datamongodb":
command => "mkdir /data",
creates => "/data",
path => ["/usr/bin","/usr/sbin","/sbin","/bin"],
}
file {"/data/mongodb-linux-x86_64-3.2.9.tgz":
source => "puppet:///soft/mongodb-linux-x86_64-3.2.9.tgz",
ensure => file,
mode => 755,owner => root,group => root,
require => [Exec["/datamongodb"],File["/etc/init.d/mongodb"]],
notify => Exec["tar mongodb-linux-x86_64-3.2.9.tgz"],
}
file {"/etc/init.d/mongodb":
source => "puppet:///soft/mongodb-3.2.9.sh",
ensure => file,
mode => 755,owner => root,group => root,
}
exec {"tar mongodb-linux-x86_64-3.2.9.tgz":
command => "tar zxvf mongodb-linux-x86_64-3.2.9.tgz && mv /data/mongodb-linux-x86_64-3.2.9 /data/mongodb-3.2.9 && mkdir -p /data/mongodb-3.2.9/{db,logs}",
path => ["/usr/bin","/usr/sbin","/sbin","/bin"],
cwd => "/data",
refreshonly => true,
notify => Exec["firewallmongodbport"],
}
exec {"firewallmongodbport":
command => "firewall-cmd --add-port=$real_mongodb_port/tcp --permanent && firewall-cmd --reload",
path => ["/usr/sbin","/usr/bin","/bin","/sbin"],
refreshonly => true,
}
file {'/data/mongodb-3.2.9/mongodb.conf':
ensure => file,
mode => 755,owner => root,group => root,
content => template("/etc/puppet/modules/linuxmongodb/templates/mongodb-3.2.9.conf.erb"),
backup => '.bak',
notify => [Service["mongodb"],Exec["firewallmongodbport"]],
require => Exec["tar mongodb-linux-x86_64-3.2.9.tgz"],
}
service {"mongodb":
ensure => running,
hasrestart => true,
provider => init,
start => "/etc/init.d/mongodb start",
stop => "/etc/init.d/mongodb stop",
restart => "/etc/init.d/mongodb restart",
status => "/etc/init.d/mongodb status",
}
}
-------------------------调用----------------------------------------
node 'huangat-test' {
$mongodb_port = 27017
include linuxmongodb::mongodb329
}