注意EOF不能有空格tab键

#get os version
release=$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release))
#
#configure yum base source and epel source
cd /etc/yum.repos.d/
test -d /etc/yum.repos.d/bak || mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
if [ $release == 6 ];then
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
fi
if [ $release == 7 ];then
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
fi
yum clean all
yum makecache #install base rpm package
yum -y install nc git vim iftop iotop dstat tcpdump
yum -y install ipmitool bind-libs bind-utils
yum -y install libselinux-python ntpdate
yum -y tree nmap sysstat lrzsz dos2unix unix2dos #update rpm package and kernel
#yum update
#rm -rf /etc/yum.repos.d/CentOS* #vim优化
cat >>/etc/vimrc<<EOF
set ic
set ai
EOF #alias
cat >>/etc/bashrc<<EOF
alias grep='grep --color=auto'
alias ll='ls -l --time-style=long-iso'
alias iptable='iptables -L -n --line-number'
EOF #update ulimit configure
if [ $release == 6 ];then
test -f /etc/security/limits.d/90-nproc.conf && rm -rf /etc/security/limits.d/90-nproc.conf && touch /etc/security/limits.d/90-nproc.conf
fi
if [ $release == 7 ];then
test -f /etc/security/limits.d/20-nproc.conf && rm -rf /etc/security/limits.d/20-nproc.conf && touch /etc/security/limits.d/20-nproc.conf
fi
>/etc/security/limits.conf
cat >> /etc/security/limits.conf <<EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF #set timezone
test -f /etc/localtime && rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #set LANG
if [ $release == 6 ];then
sed -i 's@LANG=.*$@LANG="en_US.UTF-8"@g' /etc/sysconfig/i18n
fi
if [ $release == 7 ];then
sed -i 's@LANG=.*$@LANG="en_US.UTF-8"@g' /etc/locale.conf
fi #uptime time
if [ $release == 6 ];then
/usr/sbin/ntpdate -b ntp1.aliyun.com
grep -q ntpdate /var/spool/cron/root
if [ $? -ne 0 ];then
echo "* * * * * /usr/sbin/ntpdate ntp1.aliyun.com &>/dev/null" >>/var/spool/cron/root
chmod 600 /var/spool/cron/root
fi
/etc/init.d/crond restart
fi
if [ $release == 7 ];then
yum -y install chrony
>/etc/chrony.conf
cat >>/etc/chrony.conf <<EOF
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
stratumweight 0
driftfile /var/lib/chrony/drift
rtcsync
makestep 10 3
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
keyfile /etc/chrony.keys
generatecommandkey
noclientlog
logchange 0.5
logdir /var/log/chrony
EOF
systemctl restart chronyd
systemctl enable chronyd
fi #clean iptables default rules
if [ $release == 6 ];then
/sbin/iptables -F
/etc/inti.d/iptables save
chkconfig ip6tables off
fi
if [ $release == 7 ];then
systemctl disable firewalld
systemctl stop firewalld
fi #disable unused service
chkconfig auditd off #disable ipv6
cd /etc/modprobe.d/ && touch ipv6.conf
>/etc/modprobe.d/ipv6.conf
cat >>/etc/modprobe.d/ipv6.conf<<EOF
alias net-pf-10 off
alias ipv6 off
EOF #disable selinux
setenforce 0
sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config #update record command
sed -i 's/^HISTSIZE=.*$/HISTSIZE=100000/' /etc/profile
grep -q 'HISTTIMEFORMAT' /etc/profile
if [ $? -eq 0 ];then
sed -i 's/HISTTIMEFORMAT=.*$/HISTTIMEFORMAT="%F %T "/' /etc/profile
else
echo 'HISTTIMEFORMAT="%F %T "' >> /etc/profile
fi
source /etc/profile
#set dns
>/etc/resolv.conf
cat >> /etc/resolv.conf <<EOF
nameserver 114.114.114.114
EOF #ssh优化
sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config #内核优化
sed -i 's/net.ipv4.tcp_syncookies.*/net.ipv4.tcp_syncookies = 1/g' /etc/sysctl.conf
cat >>/etc/sysctl.conf <<EOF
kernel.core_uses_pid=1
kernel.core_pattern=/tmp/core-%e-%p
fs.suid_dumpable=2
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_tw_recycle=0
net.ipv4.tcp_timestamps=1
EOF
sysctl -p

CentOS系统初始化---不断更新中的更多相关文章

  1. centos 系统初始化

    centos 系统初始化 #!/bin/bash # author cfwl create date of 2012-10-21 # blog http://cfwlxf.blog.51cto.com ...

  2. centos系统初始化流程及实现系统裁剪

    Linux系统的初始化流程: POST:ROM+RAM BIOS: Boot Sequence MBR: 446:bootloader 64: 分区表 2: 5A kernel文件:基本磁盘分区 /s ...

  3. CentOS 7 使用经验(更新中)

    首先说一下写这篇博客的初衷. 由于公司这一期的产品准备支持的环境有CentOS 7.MySql 5.6.Java 8.Tomcat 8等等,并且因为人员严重不足,我本月的开发任务在原有的基础上又加上了 ...

  4. centos系统初始化配置

    .改主机名: sed -i 's#HOSTNAME=.*#HOSTNAME=u05mix06.yaya.corp#g' /etc/sysconfig/network && hostna ...

  5. centos系统初始化脚本

    #!/bin/bash #检测是否为root用户 ];then echo "Must be root can do this." exit fi #检测网络 echo " ...

  6. centos系统python2.7更新到3.5

    1. 下载Python-3.5.2 wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz 2.安装 (报错no acceptabl ...

  7. 安装Linux Centos系统硬盘分区方法

    一.硬盘回顾 无论是安装Windows还是Linux操作系统,硬盘分区都是整个系统安装过程中最为棘手的环节.硬盘一般分为IDE硬盘.SCSI硬盘和SATA硬盘三种,在Linux系统中,IDE接口的硬盘 ...

  8. Rookey.Frame之系统初始化

    昨天介绍了数据库的配置,今天继续介绍系统的初始化功能:针对系统初始化在开发中也是很重要的一部分,它可以提前将相关数据提前自动初始化到系统中,同时也可以为上线测试提供方便,可以很方便进行系统测试演练,防 ...

  9. bash-1 初始化CentOS系统的初始化脚本

    初始化CentOS系统的初始化脚本 #!/bin/bash # #******************************************************************* ...

随机推荐

  1. windows环境下封装条件wait和signal

    linux 环境有提供好的pthread_cond_wait() 和 phread_signal().pthread_broadcast() windows需要自己封装,利用semophore控制线程 ...

  2. width: calc(100% - 20px);

    width: calc(100% - 20px); css3 的 calc()函数.这里的意思是设置宽度比100%的宽度少20px. calc()函数用于动态计算长度值. calc()函数支持 &qu ...

  3. c# extern 关键字

    TEST.DLL 项目引用TEST.DLL 调用其中的方法 结果如下:

  4. 1.ideal常用快捷键

    Alt+回车 导入包,自动修正Ctrl+N   查找类Ctrl+Shift+N 查找文件Ctrl+Alt+L  格式化代码 Ctrl+Alt+O 优化导入的类和包Alt+Insert 生成代码(如ge ...

  5. 免密码登录服务器python脚本

    在自动化运维平台没有做完之前,常需要登录服务器做很多维护操作,每次找好长好长的密码,那么多服务器,你会疯掉的,所以瞎搞了以下脚本.先解一下燃眉之急,哈哈 cat login_root.exp #!/u ...

  6. AlloyTouch 简介

    AlloyTouch 是来自于腾讯AlloyTeam团队开发的一个适用用移动端的js组件库. 特性: 1.丰富的组件 选择组件.级联选择组件.轮播组件.全屏滚动组件.下拉刷新组件.上拉刷新任君选择 2 ...

  7. JavaScript arguments你不知道的秘密

    (function test(x){ x=10; console.log(arguments[0], x); //undefined, 10 })(); (function test(x){ x=10 ...

  8. 超酷动态图片展示墙JS特效制作方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. JQuery和Servlet来实现跨域请求

    在网上看到很多的JQuery跨域请求的文章,比较有意思.这里我发表一个Servlet与JQuery配置实现跨域的代码,供大家参考.不足之处请指教 原理:JavaScript的Ajax不可以跨域,但是可 ...

  10. indexof()函数

    js 判断字符串是否包含某字符串,String对象中查找子字符,indexOf, 成功,返回索引值,失败返回 -1. 转载: http://www.cnblogs.com/fishtreeyu/arc ...