这个实验的内容跟上次实验一样。上一篇博客主要介绍了PUPPET的安装认证和资源定义。这次主要写的是apache和nginx模块的应用。上次实验的内容:
实用的Puppet集中式配置管理系统(1)-认证和资源定义
本次实验内容:
1.建立节点文件。
2.编写apache模块
3.编写nginx模块
4.模板应用程序(添加虚拟主机配置)
1。不同节点的定义
1.1。在puppetmaster(服务器server1)中编辑site.pp
#vim/etc/puppet/manifest/site.PP
导入"nodes/*。pp"
1.2。建立节点文件
#mkdir-p/etc/puppet/manifest/nodes
#VI/etc/puppet/manifest/nodes/server2.PP
节点“server2.example.com”{
file{"/var/www/html/index.html":
content=>"server2.example.com"
}
}
#VI/etc/puppet/manifest/nodes/server3.PP
节点“server3.example.com”{
file{"/var/www/html/index.html":content=>;"server3.example.com"
}
}
1.3在客户端上测试:
#傀儡代理-服务器server1.example.com-no-daemonize-vt
2。编写apache模块
#mkdir-p/etc/puppet/modules/httpd/manifest
#mkdir-p/etc/puppet/modules/httpd/files
#CD/etc/puppet/modules/httpd/manifest
#viminstall.pp
httpd::install类{
包{"httpd":
确保=>礼物
}
}
#vimservice.pp
httpd::service类
{
服务{
“httpd”:
确保=>跑步,
require=>类["httpd::install","httpd::config"]
}
}
#vimconfig.pp
httpd::config类{
文件{
"/etc/httpd/conf/httpd.conf":
source=>"puppet:///modules/httpd/httpd.conf",
require=>类["httpd::install"],
通知=>类["httpd::service"]
}
}
#viminit.pp
httpd类{
包括httpd::install、httpd::config、httpd::service
}
#CD/etc/puppet/modules/httpd/files
#cp/etc/httpd/conf/httpd.conf。
#CD/etc/puppet/manifest/nodes
#vimserver2.pp
节点“server2.example.com”{
包括httpd
file{"/var/www/html/index.html":
content=>"server2.example.com"
}
}
在服务器2上测试:
#傀儡代理-服务器server1.example.com-no-daemonize-vt
3。编写nginx模块
1)#mkdir-p/etc/puppet/modules/nginx/manifest
2)#mkdir-p/etc/puppet/modules/nginx/files
3)CD/etc/puppet/modules/nginx/manifest
#viminstall.pp
nginx::install类{
包{
["pcre-devel","gcc","openssl-devel"]:
确保=>礼物
}
文件{
"/mnt/nginx-1.8.0.tar.gz":
source=>"puppet:///modules/nginx/nginx-1.8.0.tar.gz";
"/mnt/install-nginx.sh":
source=>"puppet:///modules/nginx/install-nginx.sh"
}
执行
“安装nginx”:
command=>"sh/mnt/install-nginx.sh",
path=>"/bin:/usr/bin:/sbin:/usr/sbin",
require=>文件["/mnt/install-nginx.sh","/mnt/nginx-1.8.0.tar.gz"],
creates=>"/usr/local/lnmp/nginx/sbin/nginx"
#provider=>壳,
}
}
#vimservice.pp
nginx::service类{
exec{
“nginx启动”:
command=>"/usr/local/lnmp/nginx/sbin/nginx",
require=>类["nginx::install"],
creates=>"/usr/local/lnmp/nginx/logs/nginx.PID"
}
}
#vimconfig.pp
nginx::config类{
文件{
"/usr/local/lnmp/nginx/conf/nginx.conf":
source=>"puppet:///modules/nginx/nginx.conf",
require=>类["nginx::service"]
}
执行
"nginx重新加载":
command=>"/usr/local/lnmp/nginx/sbin/nginx-sreload",
refreshonly=>没错,
subscribe=>文件["/usr/local/lnmp/nginx/conf/nginx.conf"]
}
}
#CD/etc/puppet/modules/nginx/file/
#viminstall-nginx.sh
#!/bin/bash
cd/mnt
塔尔-zxfnginx-1.8.0.tar.gz
cdnginx-1.8.0
。/configure-前缀=/usr/local/lnmp/nginx-with-http_SSL_module-with-http_stub_status_module
制造和销售。&进行安装
5)[root@server1文件]#ls
nginx-1.8.0.tar.gznginx.conf
#CD/etc/puppet/manifest/nodes
#vimserver3.pp
节点“server3.example.com”{
包括nginx
}
在服务器3上测试:
#傀儡代理-服务器server1.example.com-no-daemonize-vt
4。模板应用程序(添加虚拟主机配置):
该文件存储在templates目录中,以*.erb结尾。
#vim/etc/puppet/modules/httpd/manifests/init.PP
//#添加下面一行
定义httpd::vhost($domainname){
file{"/etc/httpd/conf.d/${域名}_vhost.conf":
content=>模板("httpd/httpd_vhost.conf.erb"),
require=>类["httpd::install"],
通知=>类["httpd::service"]
}
file{"/var/www/$domainname":
确保=>目录
}
file{"/var/www/$domainname/index.html":
content=>$域名
}
#CD/etc/puppet/modules/httpd/templates/
#vimhttpd_vhost.conf.erb
<virtualhost*:80>;
ServerName<%=域名%>
documentroot/var/www/<;%=域名%>
ErrorLog日志/<;%=域名%>_error.log
CustomLog日志/<;%=域名%>_access.logcommon
</virtualhost>;
#vim/etc/puppet/manifest/nodes/server4.PP
节点“server2.example.com”{
包括httpd
httpd::vhost{'server2.example.com':
域名=>"server2.example.com",
}
httpd::vhost{'www2.example.com':
域名=>"www2.example.com",
}
}
#vim/etc/puppet/modules/httpd/files/httpd.conf
990名称虚拟主机*:80
5)在服务器2上测试:
#傀儡代理-服务器server2.example.com-no-daemonize-vt
//在/var/www下会生成server2.example.com和www2.example.com两个目录。
6)在主机上添加解析,在浏览器上测试。
参观server2.example.com
www2.example.com
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)