码迷,mamicode.com
首页 > 其他好文 > 详细

FreeBSD_11_系统管理——{No.2}

时间:2016-11-14 01:36:23      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:back   ref   bin   有效期   config   传统   tle   line   new t   

一、Managing Services in FreeBSD

  • Service restart will only work if it is set to YES in /etc/rc.conf. To start, stop or restart a service regardless of the settings in /etc/rc.conf, these commands should be prefixed with “one”
  • service sshd onerestart
  • 配置文件优先級:/etc/rc.conf.local > /etc/rc.conf > /etc/default/rc.conf
  • 通用脚本(sh)函数定义文件:/etc/rc.subr、/etc/networksubr
  • 系统脚本目录:/etc/rc.d/;用户脚本目录:/usr/local/etc/rc.d/
  • /* 如下为启动脚本的基本格式 */
    #!/bin/sh # PROVIDE: xxx #将要启动的程序名称 # REQUIRE: xxx #在指定进程之后启动——依賴 # BEFORE: xxx #在指定进程之前启动——被依賴 # KEYWORD: shutdown #表示在关机之前执行正常程序终止流程 . /etc/rc.subr #固定格式,载入系统預定义的规则(函数等) name=xxx #指定該脚本的名称 rcvar=${name}_enable #指定用于 /etc 下 rc.conf 或 rc.conf.local 的开机启动标志(語法) command="/usr/sbin/${name}" #指定可执行文件的路径 pidfile="/var/run/${name}.pid" #指定 pid 文件,提高操作效率 # 以下两行为固定格式 load_rc_config $name #使 rc.subr 载入 rc.conf 中的参数 run_rc_command "$1" #使 rc.subr 载入当前脚本中定义的参数
  • (/etc/rc.conf)ifconfig_fxp0_alias0="inet xxx.xxx.xxx.xxx/xx":alias# 的編号必須从 0 开始,且必須连续;针对每个不同的网络(段),只能将首个 IP 的 netmask 配置成真实的掩码,其余均須设置为 0xffffffff(255.255.255.255 或 .../32)
  • ifconfig_fxp0="inet 10.1.1.1/24" #物理 NIC ,首 IP
        ifconfig_fxp0_alias0="inet 10.1.1.2 netmask 0xffffffff"
        ifconfig_fxp0_alias1="inet 10.1.1.3 netmask 255.255.255.255"
        ifconfig_fxp0_alias2="inet 10.1.1.4/32"
        ifconfig_fxp0_alias3="inet 10.1.1.5/32"
    ifconfig_fxp0_alias4="inet 202.0.75.17 netmask 255.255.255.240" #新网段,首 IP
        ifconfig_fxp0_alias5="inet 202.0.75.18/32"
        ifconfig_fxp0_alias6="inet 202.0.75.19 netmask 0xffffffff"
        ifconfig_fxp0_alias7="inet 202.0.75.20/32"
  • 简写模式:
    ifconfig_alc0_aliases="inet 10.1.1.1-5/24 inet 202.0.75.17-20/28"
  • syslog.conf 語法
    • facility:auth, authpriv, console, cron, daemon,ftp, kern, lpr, mail, mark, news, ntp, security, syslog, user, uucp, and local(0,1,..7)
    • level:emerg, crit, alert, err,warning, notice, info and debug
  •      *.err;kern.*;auth.notice;authpriv.none;mail.crit        /dev/console
    注:all facility 的大于或等于(=>) err 級别(level)的日志,kern facility 的所有 level 日志,及 mail facility 的 =>crit level 的日志,显示到控制台;authpriv facility 的所有 level 日志均不显示在控制台
         *.info;mail.none;authpriv.none          /var/log/messages
    注:除了 mail 与 authpriv 之外的所有 facility 的 info level 以上的日志,记录到 messages 文件
         daemon.=debug                                           /var/log/daemon.debug
    注:记录 daemon facility 的 debug level 日志(“=” 指仅记录此一个級别)
         authpriv.*                                              /var/log/secure
    注:authpriv facility 的所有 level 日志记录到单独的文件以确保安全
         mail.*                                                  -/var/log/maillog
    注:记录 mail facility 的所有 level 日志,但 I/O 不以 fsync 方式同步(“-” 指以普通緩存形式执行非同步写入,以减少到系统性能的影响) 
         *.emerg                                                 *
         *.emerg                                                 @arpa.berkeley.edu
    注:以上两行,将所有 facility 的 emerg level 日志记录到远程主机,即使已记录到其它位置(“*” 指重置,对应的日志可重复记录)
         *.alert                                                 root,eric
    注:仅 root 及 eric 两个用户可以收到 alert 信息
         auth.*                                  |exec /usr/local/sbin/authfilter
    注:将 auth facility 的所有 level 日志首先通过管道传递給 authfilter 处理
         console.*                                               /var/log/console.log
    注:将所有原先写往控制台的信息,记录到文件
         !ipfw
         *.*                                                     -/var/log/ipfw
         !*
    注:以上三行,仅记录 ipfw 程序产生的日志,且非同步写入(使用緩存),“!” 指明接下来的内容仅对 ipfw 有效,最后的 "!*" 将重置记录对象 
  • Log Management and Rotation:newsyslog.conf(cron 定时执行)
  • # logfilename    [owner:group]    mode    count    size    when    flags    [/pid_file]    [sig_num]
    1
    logfilename:生成的分段日志文件存放路径,如:/root/logdir 2 [owner:group]:可选项,指定生成的文件的属主属組,如:root:wheel 3 mode:指定生成的文件的訪问权限,如:0600 4 count:指定能生成的最大文件数量 5 size:数字,以 KB 为单位,指定日志大小維度的触发条件 6 when:指定时间維度的触发条件,如:$D23(每天 23:00)、$W5D20(每周五 20:00 ,W0 指星期日)、$M10D0(每月的第 1000:007 flags:指定压缩格式等,如:X 指用 xz 压缩以节約空间;B 指源文件为二进制格式,直接压縮不添加备注信息
  • Configuring Remote Logging
    • 服务器端
    • /etc/syslog.conf
          +logclient.example.org # “+” 指接受远程主机存储日志
          *.*     /var/log/logclient.log #指定远程客户端的日志存储位置

      /etc/rc.conf
          syslogd_enable="YES"
          syslogd_flags="-d -a logclient.example.org -v -v"
      # -d ,Put syslogd into debugging mode(仅用于故障調试)
      # -a 指添加,多个客户端須用多个 -a 选项,格式可以为:IP/masklen:port 或 IP/masklen:syslogd 或 hostname:syslogd 等,syslogd可以替换为其它可用的日志服务器名称
      # -v -v 指存储详细信息,日志按 facility 分类显示
    • 客户端
    • /etc/syslog.conf
          *.*        @logserv.example.org # “@” 指将日志存储到其后的 hostname 主机之上

      /etc/rc.conf
          syslogd_enable="YES"
          syslogd_flags="-s -v -v" # -s 不为其它主机存储日志,若 -s -s (两个 -s),则同时不能将日志存储到其它主机
    • 远程日志存储是以明文形式传輸,可以考虑应用 ssh 遂道
  • 系统配置文件位置
  • 1 /etc    Generic system-specific configuration information
    2 /etc/defaults    Default versions of system configuration files
    3 /etc/mail    Extra sendmail configuration and other MTA configuration files
    4 /etc/ppp    Configuration for both user- and kernel-ppp programs
    5 /etc/namedb    Default location for named data. Normally named.conf and zone files are stored here
    6 /usr/local/etc    Configuration files for installed applications. May contain per-application subdirectories
    7 /usr/local/etc/rc.d    rc scripts for installed applications.
    8 /var/db    Automatically generated system-specific database files, such as the package database and the locate database
  • /etc/hosts 文件格式
  • [Internet address] [official hostname] [alias1] [alias2] ...
    如:
    10.0.0.4    myname.xxx.org    myname    cat    monkey
  • Tuning with sysctl
    • sysctl -a #显示所有可用项目
    • sysctl kern.maxproc #显示指定项目
    • sysctl kern.maxfiles=10000 #临时设置指定项目的值
    • /etc/sysctl.conf #配置文件
    • kern.ipc.soacceptqueue
          默认值是 128,limits the size of the listen queue for accepting new TCP connections.For Web Server,increase this value to 1024 or higher.
      net.inet.ip.portrange.first/net.inet.ip.portrange.last
          服务器主动对外连接可用的端口范围:last - first
      sysctl kern.maxvnodes/sysctl vfs.numvnodes
          maxvnodes 指系统最大可用 vnodes 数量,numvnodes 指当前已用数量;当后者的数量与前者接近时,有必要提升前者的值,以避免 I/O 瓶颈
  • Disk Soft Updates
    • 磁盘的元数据是否异步写入,可极大提升机械式硬盘的元数据操作效率,但在系统异常中止的情况下,会造成数据不一致
    • 操作方式:tunefs -n enable/disable /FILESYSTEM
    • Linux 下的 ext 系列文件系统默认即是异步写入
  • Swap
    • Adding a new hard drive for swap gives better performance than using a partition on an existing drive.
    • RAW disk ,即没有创建文件系统的裸盘,用作 swap 可提升性能

 二、The FreeBSD Booting Process

  •  shutdown -p/-r now :关机/重启
  • 如下所示,修改 /etc/ttys ,使单用户模式下登陆系统需要 root 密码
  • # If console is marked "insecure", then init will ask for the root password when going to single-user mode
    console none                unknown off insecure

三、Security

  • 系统資源限制
    • 传统方式:/etc/login.conf(cap_mkdb /etc/login.conf :Whenever /etc/login.conf is edited, the /etc/login.conf.db must be updated by executing the command) 
    • rctl(>= FreeBSD 9.0):supports user limits, and set resource constraints on processes and jails
    • rctl requires the kernel to be compiled with:
          options RACCT
          options RCTL
      
      启用 rctl 支持:
          在 /boot/loader.conf 中 添加 kern.racct.enable=1 #只读项,无法能过 sysctl 直接设置
      
      /etc/rctl.conf 格式:
          subject:subject-id:resource:action=amount/per(user/process...)
          示例:jail:httpd:memoryuse:deny=2G/jail #Block jail from using more than 2G memory
      
          subject:process, user, loginclass, or jail
          subject-id:process ID, user name, numerical user ID, login class name, or jail name
          resouce:memoryuse, maxproc, datasize(单文件大小), pcpu(single CPU 占用率), readbps(bytes/sec), writebps(B/sec), readiops(operations/sec), writeiops(每秒钟的 I/O 写数量)
          action:
      <1> deny(deny the allocation,not supported
      for cputime, wallclock, readbps, writebps, readiops, and writeiops)
      <2> log(log a warning to the console)
      <3> throttle(slow down process execution; only supported for readbps, writebps, readiops, and writeiops)
  • 阻止用户登陆
  • pw lock USERNAME 或 chsh -s /usr/sbin/nologin USERNAME
  • visudo
  • #賦予 webadmin 組的成员操作 apache24 的权限
    %webadmin ALL=(ALL) /usr/sbin/service apache24 *
  • /etc/master.passwd:类似于 Linux 下的 shadow 文件
  • HASH 算法标志:Blowfish($2a$)、sha512($6$)等
  • 强制密码复杂度:Pluggable Authentication Modules (PAM)
  • # /etc/pam.d/passwd
    # 格式如下:
    # module-type control-flag pam_passwdqc [options]
    password    requisite    pam_passwdqc.so    min(密码最小长度:N0...N5,分别指明不同复杂度性况下的长度要求)=disabled,18,14,12,10 max(密码最大长度)=40 similar(是否允许与以前设置过的密码类似)=permit|deny enforce(策略类型:仅警告|普通用户|包括 root )=none|users|everyone
  • /etc/login.conf 中的安全相关
  • :passwd_format=blf:\ #设置密码加密算法为 Blowfish
    :passwordtime=90d:\ #设置所有普通账户的密码有效期为 90#配置完成后,执行 cap_mkdb /etc/login.conf 使之生效
  • rkhunter

四、Jails

 

五、Storage

 

六、Updating and  Upgrading FreeBSD

 

七、Dtrace

  • ..

FreeBSD_11_系统管理——{No.2}

标签:back   ref   bin   有效期   config   传统   tle   line   new t   

原文地址:http://www.cnblogs.com/hadex/p/6057941.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!