centos6和centos7初始化脚本

刚拿到一台机器的确很兴奋,但是和它交流后你会发现他还没准备好,你拿他没办法,只能一样要的教,这里我给出拉网上借鉴的初始化脚本centos6和centos7的shell,附件目录我还是为大家上传到百度云吧,下面就是展示一下思路。

#!/bin/bash
#author jim.zhong
#this script is only for CentOS 6
#check the OS

#——先对系统进行判断,如果是Cent OS 64位,就继续运行。
#——先将系统的安装源设置为网易的(网易的安装源算是国内比较稳定的)
#——安装epel的源和rpmforge的源,利用第三方的源来让yum安装起来更方便
#——更新软件
#——设置为周期进行时间同步(跟国家授时中心的服务器进行时间同步)
#——将系统同时打开的文件个数增大
#——disable = 将ctrl将ctrl alt delete键进行屏蔽,防止误操作的时候服务器重启
#——关闭selinux
#——禁用GSSAPI来认证,也禁用DNS反向解析,加快SSH登陆速度
#——优化一些内核参数
#——调整删除字符的按键为backspace(某些系统默认是delete)
#——打开vim的语法高亮
#——取消生成whatis数据库和locate数据库
#——关闭没用的服务
#—— disable = 关闭IPv6


platform=`uname -i`
if [ $platform != "x86_64" ];then 
echo "this script is only for 64bit Operating System !"
exit 1
fi

cat << EOF +---------------------------------------+ |   your system is CentOS 6 x86_64      | |      start optimizing.......          | +--------------------------------------- EOF #make the 163.com as the default yum repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -O /etc/yum.repos.d/CentOS-Base.repo #add the third-party repo #add the epel rpm -Uvh http://dl.fedoraproject.org/pub/epel/6Server/x86_64/epel-release-6-8.noarch.rpm rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 #add the rpmforge rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag #update the system and set the ntp yum clean all yum -y update glibc\* yum -y update yum\* rpm\* python\*  yum -y update yum -y install ntpdate cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime echo "*/10 * * * * /usr/sbin/ntpdate cn.pool.ntp.org && /sbin/clock -w" >> /var/spool/cron/root
service crond restart

#set the file limit
echo "ulimit -SHn 102400" >> /etc/rc.local
cat >> /etc/security/limits.conf << EOF *           soft   nofile       65535 *           hard   nofile       65535 EOF #set the control-alt-delete to guard against the miSUSE #sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf #disable selinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config #set ssh sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config service sshd restart #tune kernel parametres cat >> /etc/sysctl.conf << EOF net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_keepalive_time = 300 net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_tw_recycle = 1 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.core.netdev_max_backlog = 262144 net.core.somaxconn = 262144 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.tcp_max_syn_backlog = 262144 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.ipv4.ip_local_port_range = 5000 65000 EOF /sbin/sysctl -p #define the backspace button can erase the last character typed echo 'stty erase ^H' >> /etc/profile
echo "syntax on" >> /root/.vimrc

#stop some crontab
mkdir /etc/cron.daily.bak
mv /etc/cron.daily/makewhatis.cron /etc/cron.daily.bak
mv /etc/cron.daily/mlocate.cron /etc/cron.daily.bak

chkconfig bluetooth off
chkconfig cups off
chkconfig ip6tables off

#install make
yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-devel

#install snmpd
yum install net-snmp net-snmp-devel net-snmp-libs net-snmp-perl net-snmp-utils mrtg

#配置文件snmpd 作为监控使用
cp snmpd.conf /etc/snmp/smnpd.conf

chkconfig snmpd on

# install PHP 安装默认php5.3,如该需要替换成5.4,请搜索为的博客5.4方式
yum install php.x86_64 php-cli.x86_64 php-common.x86_64 php-devel.x86_64 php-fpm.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mysql.x86_64 php-pdo.x86_64 php-pear.noarch php-pecl-apc.x86_64 php-process.x86_64 php-snmp.x86_64 php-xml.x86_64 php-xmlrpc.x86_64 php-pecl-memcache.x86_64

#install java sun
rpm -ivh jdk-7u71-linux-x64.rpm

cat >> /etc/profile << EOF export JAVA_HOME=/usr/java/jdk1.7.0_71 export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin EOF #disable the ipv6 #cat > /etc/modprobe.d/ipv6.conf << EOFI #alias net-pf-10 off #options ipv6 disable=1 #EOFI #echo "NETWORKING_IPV6=off" >> /etc/sysconfig/network




cat << EOF
+-------------------------------------------------+
|               optimizer is done                 |
|   it's recommond to restart this server !       |
+-------------------------------------------------+
EOF

百度云地址

centos6 :http://pan.baidu.com/s/1mg6eTiK

centos7 :http://pan.baidu.com/s/1i3ttMNr

发表评论

沙发空缺中,还不快抢~