手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网站运营>建站经验>列表

介绍用于系统管理的 cfengine

来源:互联网 作者:west263.com 时间:2008-04-16
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

在开始使用 cfengine 之前,应该编译和安装他。对于能够使用他们的系统,RPM 都有可用的版本, 而且更有一个可用的 Solaris 包(请参阅 参考资料)。假如要存储文档的永久校验和(类似于 Tripwire 所做的事情),则应该带有 Berkeley DB 支持进行编译。然后,应该开始创建配置文档。 主要的配置文档是 /etc/cfengine/cfengine.conf,他是在不带文档名调用 cfengine 时运行的(当在 1.6.3 中编译时,能够指定一个不同的缺省配置目录,但在 2.0 及更高版本中,/etc/cfengine 将是检查的唯一位置,所以您应该严格遵守这一点)。

下面是 cfengine 的启始配置。他 是成品, 在运行他之前,应该仔细地阅读 cfengine 参考大全和教程(请参阅 参考资料)。 请带 -v -n (周详的预演)选项尝试运行 cfengine,看一下这个配置将做些什么。 当使用 -n (预演)选项时,不会影响系统。

清单 1. cfengine 的启始配置文档
/etc/cfengine/cfengine.conf



# note that only some of the possible sections are used here;

# refer to the cfengine documentation for the full list of sections

# you can have.  Comments, as you can see, are like shell or Perl

# comments.



# see the tutorial and reference for any unexplained phenomena



import:

 any::

  cf.groups

groups:



# all groups are defined in cf.groups, imported above, but you can

# define extras here.  The format is simple:



class = ( machine1 machine2 )



# and then any machine named machine1 or machine2 will have that class

# defined.

# the control section sets up how cfengine will behave

control:

 any::

# you have to state in AddInstallable what classes unknown to cfengine

# by default you will be using.  Run cfengine as "cfengine -v" to see

# the built-in classes you don't have to define.  Here we divide

# machines into the ones that run inetd and the ones that run xinetd,

# as an example.

  AddInstallable = ( inetd xinetd )

  editfilesize   = ( 300000 )

  moduledirectory = ( /etc/cfengine/modules )

  domain    = ( yourdomain.com )

 any::

  LogDirectory  = ( /etc/cfengine/log )

  netmask   = ( 255.255.255.0 )

  Repository    = ( /etc/cfengine/repository )

  sysadm    = ( "tzz@iglou.com" )

  # Bug in cfengine: actionsequence must follow LogDirectory and Repository 

  actionsequence = ( directories files editfiles copy links processes disable 

                               shellcommands )

directories:

# this ensures that these directories will be created when cfengine runs

 /etc/cfengine/log

 /etc/cfengine/repository

 /etc/cfengine/cfcollector

files:

 any::

# set the permissions for these files

  /etc/sudoers mode=0440 owner=root group=root action=fixall

  /etc/hosts.allow mode=0644 owner=root group=root action=fixall

  /etc/hosts.deny mode=0644 owner=root group=root action=fixall

# just warn if this file's permissions are wrong

  /etc/shadow mode=0400 owner=root action=warnall inform=true

# CERT advisory CA-2001-05, for Solaris only

 solaris::

  /usr/lib/dmi/snmpXdmid mode=0000 owner=root group=root action=fixall

# example of setting permissions differently for different OS types

# (not Linux and Linux), and negating classes

 !linux::

  /.ssh mode=0700 owner=root action=fixall inform=true

 linux::

  /root/.ssh mode=0700 owner=root action=fixall inform=true

editfiles:

 any::

# add the rsync service to /etc/services and /etc/inetd.conf

  { /etc/services

    SetLine "rsync  873/tcp # rsync"

    AppendIfNoLineMatching "rsync.*"

  }

  { /etc/inetd.conf

    # add rsync

    SetLine "rsync stream tcp nowait root /usr/local/bin/rsync rsyncd --daemon"

    AppendIfNoLineMatching "rsync.*"

  }

copy:

# set up sshd startup script, from trusted master distribution in /etc/cfengine

  /etc/cfengine/sshd dest=/etc/init.d/sshd repository=/etc/cfengine/repository

links:

 any::

# link the sshd init.d script to /etc/rc3.d, overwriting existing

# links if they exist

  /etc/rc3.d/S72local_sshd ->! /etc/init.d/sshd

processes:

# invoke cfengine with "cfengine -DHupInetd" to define this class and

# send inetd the HUP signal (the machine has to be in the inetd class

# discussed above, too).  This is an example of compound classes.

 inetd.HupInetd::

  "inetd" signal=hup

disable:

# empty this file (this can also be used to rotate logs, with

# different rotate options)

  /etc/rc3.d/S77dmi rotate=empty

shellcommands:

 any::

# always put the contents of the $domain variable in this file.

# note that all the cfengine variables can be interpolated inside strings.

  "/bin/echo $(domain) > /etc/cfengine/cfdomainname"



简单用法:编辑和复制文档
要编辑文档,使用 editfiles

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!