论坛首页 综合技术论坛

常用脚本:在应用安装时自动修改文件句柄数

浏览 1633 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2011-11-18  

    当系统部署时常常需要修改目标系统的文件句柄数,如果安装的机器比较多容易忘记,这时候在应用的安装脚本中自动修改是个更好的选择,这里写了个脚本备用免得以后再去想正则表达式。在CentOS5.4下测试通过。

 

#cat install.sh

 

#/bin/bash
if [ `whoami` = root ]
then
  echo "install..."
  echo "set limit nofile..."
  LIMIT_FILE=/etc/security/limits.conf
  if grep "^\* *soft *nofile *[0-9]*" $LIMIT_FILE > /dev/null
  then
    sed 's/^\* *soft *nofile *[0-9]*/\*       soft    nofile   10240/' $LIMIT_FILE > limits.conf.temp
    mv limits.conf.temp $LIMIT_FILE
  else
    echo '*       soft    nofile   10240' >> $LIMIT_FILE
  fi

  if grep "^\* *hard *nofile *[0-9]*" $LIMIT_FILE > /dev/null
  then
    sed 's/^\* *hard *nofile *[0-9]*/\*       hard    nofile   32768/' $LIMIT_FILE > limits.conf.temp
    mv limits.conf.temp $LIMIT_FILE
  else
    echo '*       hard    nofile   32768' >> $LIMIT_FILE
  fi
  echo "chown run dir..."
  chown crust.crust /home/crust/run
  chmod a+x start stop showapps
  cp autostart.in /etc/rc.d/init.d/crust
  chmod a+x /etc/rc.d/init.d/crust
  echo "add crust autostart script"
  /sbin/chkconfig --add crust
  echo "add crust as system service"
  chmod u+x ./so/config_so_ld.sh
  ./so/config_so_ld.sh
else
  echo "ERROR: please use root user run the script !!!!!!!"
fi

 

脚本中首先搜索 /etc/security/limits.conf 中是否包含句柄数配置,没有的话直接在后面添加,已有配置则用sed进行替换。脚本后面还干了两件事顺带提一下:将服务配置成服务、注册动态库。

 

论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics