存档

‘运维’ 分类的存档

puppet的generate函数

2010年7月8日 flex 没有评论

这个函数不能直接执行shell脚本,需要/usr/bin/env等做为第一个参数,如:

$hostalias = generate("/usr/bin/env", "/tmp/genhname.sh", "172.16.0.133")

其次,这个函数的执行的是master上的脚本,它仅仅是将client上的变量拿回来,在本地执行;也就是说/tmp/genhname.sh要位于master的相应路径上,且有执行权限,不需要将脚本文件分发到client。

分类: puppet, 运维 标签: ,

puppet dashboard的安装

2010年7月7日 flex 2 条评论

以下过程基于debian:

系统要求:
ruby >= 1.8.1
rake >= 0.8.3 (在lenny里版本不够,需要squeeze,不过我觉得使用gem应该也能装)
mysql
ruby mysql bindings(我个人觉得对应的包为libmysql-ruby,不过网上的另一个deb包依赖的是dbconfig-common libdbd-mysql-ruby)

安装过程:

1. 获得最新源码:

git clone git://github.com/reductivelabs/puppet-dashboard.git

2. 设置数据库:

cd puppet_dashboard/config
cp database.yml.example database.yml

编辑database.yml,在development域中加入数据库用户名、密码,然后进行数据库初始化(确保mysql服务已经启动):

rake install

(中间可能需要运行rake gem:install)

3.设置puppetmaster:

部署lib文件:

cp  puppet_dashboard/lib/puppet/puppet_dashboard.rb  /usr/lib/ruby/1.8/puppet/reports/

这点和readme中描述不符,不过作者的方法怎么实验都不成功。:(

然后在/etc/puppet/puppet.conf的puppetmasterd域中加入:

reports = puppet_dashboard

可以写多种方法,用逗号分隔,比如:

reports = puppet_dashboard, log, store

最后重启服务端

4.运行dashboard server

script/server

5.设置puppet client:

在/etc/puppet/puppet.conf的puppetd域加入:

report = true

重启客户端

如果没有意外,dashboard将会接收到新的report,访问http://localhost:3000/进入web界面。

如果想将以前的report导入,在dashboard目录运行:

rake reports:import

如果reportdir不是/var/lib/puppet/reports则运行:

rake reports:import REPORT_DIR=/path/to/your/reports

如果时区显示有问题,在config/enviroment.rb文件中修改:

config.time_zone = 'Beijing'

参考:

1. http://docs.puppetlabs.com/guides/installing_dashboard.html

2.http://zcentric.com/2010/03/11/install-puppet-dashboard-on-redhatcentos-5/

分类: puppet, 运维 标签: ,

关于puppet的import

2010年6月29日 flex 没有评论
import "autofs"
import "autofs/init.pp"
import "autofs/util/stuff.pp"

第一句与第二句会在模块路径中寻找autofs/manifests/init.pp并载入。
第三句只载入autofs/util/stuff.pp文件。

puppet 0.23.1之后的版本,位于modulepath下(默认是/etc/puppet/modules)的模块会被自动载入,所以不需要手动载入此目录下的各个模块了。

当你引用autofs模块中的craziness类时,puppet会自动在autofs模块下寻找craziness.pp文件中的这个类。使用这个技巧就可以不在模块的init.pp中写入额外的import了。

分类: puppet 标签: , ,

Apache在子目录取消访问控制

2010年4月24日 flex 2 条评论

Removing controls in subdirectories

The following example shows how to use the Satisfy directive to disable access controls in a subdirectory of a protected directory. This technique should be used with caution, because it will also disable any access controls imposed by mod_authz_host.

<Directory /path/to/protected/>
Require user david
</Directory>
<Directory /path/to/protected/unprotected>
# All access controls and authentication are disabled
# in this directory
Satisfy Any
Allow from all
</Directory>

截取自apache 2.2手册http://httpd.apache.org/docs/2.2/mod/core.html#require

分类: 运维 标签: , ,

nginx的log

2010年1月29日 flex 没有评论

access_log的最小作用域是location,关闭方式是:access_log off;

error_log的最小作用域是http,关闭方式是:error_log /dev/null;

如果一个请求是404之类的,则access_log中记录404,error_log同时会记录open filename failed等错误,如果不需要,可以改变http域error_log的记录等级,也可以直接关闭(还有log_not_found选项可以关闭记录open filename failed错误)。

nginx的rewrite

2010年1月28日 flex 没有评论

设置nginx的rewrite如果替换项是以http://开头,则起的是redirect的作用,即使最后的参数是last不是redirect,例如:

rewrite ^(.*)$ http://aaa.bbb.com/ccc$1 last;

浏览器端会得到302。

nginx的文档里提到:

redirect – returns temporary redirect with code 302; it is used if the substituting line begins with http://

另外,rewrite后的host的使用顺序如下:

  1. 当请求的http头里的host匹配sever_name里的任一host时,使用此host
  2. 若不匹配,或者为空,使用server_name的第一个host
  3. 若没有设置server_name,则使用本机的hostname
  4. 若要一直使用http头里的host,则将server_name设置为:servername _ *;(下划线不能少,因为 * 不能做为sever_name第一项的开头)
分类: nginx, 运维 标签: ,

apt-get与aptitude

2010年1月26日 flex 没有评论

aptitude install默认会安装recommends的包,etch中apt-get不会,而lenny中则和aptitude相同。两者都不会安装suggests。

aptitude remove会清除所有不需要的包,apt-get remove只会清除指定包,但是有autoremove选项。

如果希望只安装必要的包的话,可以用apt-get –no-install-recommends,aptitude可以在设置里取消Install recommended packages automatically。

或者,在/etc/apt/apt.conf中根据需要写入以下配置:


APT::Install-Recommends "false";
APT::Install-Suggests "false";
Aptitude::Recommends-Important "false";
Aptitude::Keep-Suggests "false";

附录:

2.2.8 软件包依赖关系

Debian 软件包管理系统依赖声明,它描述了这一事实:一些软件包需要其它软件包被安装才能正常运行或运行得更好。

  • 软件包 A 依赖(depends)软件包 B:要运行A必须安装 B。在有些情况下,A 不仅依赖 B,还要求 B 的特定版本。版本依赖通常有最低版本限制,A 更依赖于B的最新版而非某个特定版本。
  • 软件包 A 推荐(recommends)软件包 B:软件包维护者认为所有用户都不会喜欢缺少某些功能的 A,而这些功能需要 B 来提供。
  • 软件包 A 建议(suggests)软件包 B:B 中某些文件与 A 的功能相关,并能够增强 A 的功能。这种关系通过声明软件包 B 增强 Enhances 软件包 A 来表示。
  • 软件包 A 与软件包 B 冲突(conflicts):如果系统中安装了 B 那么 A 无法运行。“Conflicts”常和“replaces”同时出现。
  • 软件包 A 替换(replaces)软件包 B:B 安装的文件被 A 中的文件移除和覆盖了。
  • 软件包 A 提供(provides)软件包 B:A 中包含了 B 中的所有文件和功能。

上述术语使用方法的更详细的信息参阅 Packaging Manual 和 the Policy Manual。

注意,aptitude 和 dselect 可以对 recommends 和 suggests 类软件包进行更细粒度的操作,apt-get 只会简单的下载安装 depends 类软件包而不管 recommends 和 suggests 类软件包。这两个程序均正式使用 APT 作为其后端。

cfengine的哲学

2010年1月10日 flex 4 条评论

最近在做基于cfengine的二次开发,目前正在进行的是系统初始化的工作。

开始的时候我直接对现有的shell脚本进行cfengine化,然而随着工作的深入,越发疑惑这么做的意义,使用脚本逐句执行的方式来运用cfengine有什么优势呢?不就是相当于使用了cfengine语法的“脚本”么?而且系统初始化后,如何保证这个状态呢?难道要再写一套“脚本”?

随后和老大的一番讨论让我发现我还是没有理解透彻cfengine对于promise的定义。即,promise是为了保证一种状态的不变。用户需要定义的就是这个状态。当然,对于复杂的cfengine没有提供原生支持的状态,还需要定义修复方法。

所以,使用cfengine首先要确定的是要达到什么状态,其次是状态意外改变后如何修复。

对于系统初始化,首先用cfengine描述出系统应达到的状态,而第一次运行,整个系统明显是“偏离”这个状态的,于是修复过程开始。

分类: cfengine, 运维 标签: ,

nginx fancyindex插件严重影响效率

2010年1月5日 flex 4 条评论

补记:

nginx的fancyindex插件能提供定制性更好的index页面(插件许久没有更新,有一个小的bug,含有冒号的url不能正确生成,稍稍改下代码就行了)。不过经过一段时间高负载的使用后,发现页面载入延迟比较高,使用ab局域网压力测试的结果(nginx 0.7.64)表明fancyindex的效率只有原生autoindex的37.5%。

分类: nginx, 运维 标签: ,

cfengine3获取本机ip

2009年12月17日 flex 没有评论

项目需要获取本机ip,在文档中没有找到相应的内建变量,而cfengine2是有的,于是上邮件列表问。

答案是有这么个变量的:sys.ipv4 sys.ipv4[eth0]

sys.ipv4 is mentioned a couple of times en passent in the cf3
reference, see for example

http://www.cfengine.org/manuals/cf3-reference.html#Function-splayclass.

I tried a simple report:

bundle agent dev{
reports:
solaris::
“my ip is ${sys.ipv4}”
}

which gave the expected result.

sys.ipv4 should probably have been listed in the section on sys
variables (at http://www.cfengine.org/manuals/cf3-reference.html#Variable-context-sys),
but isn’t there because “There are too many possibilities to document
in the manual”, hehe. However, you should be able to figure it out
with the examples given in the docs and in this thread.

然后另一位boss说:

I’ll look into a workaround for this. Clearly it needs to be fixed.

The documentation is built automatically from the code, so all the different
interfaces make it tricky in this case.

怪不得我觉得cfengine3的手册如此之烂……

分类: cfengine 标签: ,