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

系统初始化

时间:2014-09-26 20:41:49      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:shell 系统初始化

由于最近安装系统的需求,先写系统初始化脚本如下,以此来减少工作量,亲测通过,有什么不对的地方,请各位大牛指出,谢谢

#!/bin/bash
if [[ "$(whoami)" != "root" ]]; then
 echo "Please run this script as root." >&2
 exit 1
fi
echo "------- system init ---------"
echo "------- epel -------"
cd /etc/yum.repos.d/
if [ -f CentOS-Base.repo ];then
  mv CentOS-Base.repo{,.bak}
else
  mv rhel-source.repo{,.bak}
fi
curl -I -s http://172.16.4.250|grep "OK" &> /dev/null
if [[ $? -eq 0 ]];then
  wget http://172.16.4.250/base.repo &> /dev/null
  sleep 3
else
  exit 4
fi
echo "------ close firewall and selinux---"
cp /etc/selinux/config /etc/selinux/config.bak
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config
setenforce 0
/etc/init.d/iptables stop &> /dev/null
chkconfig iptables off
sleep 3
echo "------- ntp ---------"
echo "20 * * * * /usr/sbin/ntpdate 172.16.0.213 &> /dev/null" >> /var/spool/cron/root
/usr/sbin/ntpdate 172.16.0.213 &> /dev/null
/etc/init.d/crond restart &> /dev/null
sleep 3
read -p ‘PLZ input a name:‘ name
sed -i ‘s/HOSTNAME=localhost/HOSTNAME=$name/‘ /etc/sysconfig/network
/bin/hostname $name
echo "-----limits-----"
cat >> /etc/security/limits.conf << EOF
* soft nofile 65535
* hard nofile 65535
EOF
ulimit -HSn 65535
echo "-----sysctl(system kernel)--------"
/bin/cp /etc/sysctl.conf /etc/sysctl.conf.`date + %F`
cat>>/etc/sysctl.conf<<EOF
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 87380 16777216
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.ip_local_port_range = 1024 65535
EOF
/sbin/sysctl -p &> /dev/null
echo "------ init finish ------"

请各位大大指正

本文出自 “IT民工--小枫” 博客,请务必保留此出处http://wangfeng7399.blog.51cto.com/3518031/1558522

系统初始化

标签:shell 系统初始化

原文地址:http://wangfeng7399.blog.51cto.com/3518031/1558522

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