注意EOF不能有空格tab键

  1. #get os version
  2. release=$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release))
  3. #
  4. #configure yum base source and epel source
  5. cd /etc/yum.repos.d/
  6. test -d /etc/yum.repos.d/bak || mkdir /etc/yum.repos.d/bak
  7. mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
  8. if [ $release == 6 ];then
  9. curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
  10. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
  11. fi
  12. if [ $release == 7 ];then
  13. curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  14. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  15. fi
  16. yum clean all
  17. yum makecache
  18. #install base rpm package
  19. yum -y install nc git vim iftop iotop dstat tcpdump
  20. yum -y install ipmitool bind-libs bind-utils
  21. yum -y install libselinux-python ntpdate
  22. yum -y tree nmap sysstat lrzsz dos2unix unix2dos
  23. #update rpm package and kernel
  24. #yum update
  25. #rm -rf /etc/yum.repos.d/CentOS*
  26. #vim优化
  27. cat >>/etc/vimrc<<EOF
  28. set ic
  29. set ai
  30. EOF
  31. #alias
  32. cat >>/etc/bashrc<<EOF
  33. alias grep='grep --color=auto'
  34. alias ll='ls -l --time-style=long-iso'
  35. alias iptable='iptables -L -n --line-number'
  36. EOF
  37. #update ulimit configure
  38. if [ $release == 6 ];then
  39. 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
  40. fi
  41. if [ $release == 7 ];then
  42. 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
  43. fi
  44. >/etc/security/limits.conf
  45. cat >> /etc/security/limits.conf <<EOF
  46. * soft nproc 65535
  47. * hard nproc 65535
  48. * soft nofile 65535
  49. * hard nofile 65535
  50. EOF
  51. #set timezone
  52. test -f /etc/localtime && rm -rf /etc/localtime
  53. ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  54. #set LANG
  55. if [ $release == 6 ];then
  56. sed -i 's@LANG=.*$@LANG="en_US.UTF-8"@g' /etc/sysconfig/i18n
  57. fi
  58. if [ $release == 7 ];then
  59. sed -i 's@LANG=.*$@LANG="en_US.UTF-8"@g' /etc/locale.conf
  60. fi
  61. #uptime time
  62. if [ $release == 6 ];then
  63. /usr/sbin/ntpdate -b ntp1.aliyun.com
  64. grep -q ntpdate /var/spool/cron/root
  65. if [ $? -ne 0 ];then
  66. echo "* * * * * /usr/sbin/ntpdate ntp1.aliyun.com &>/dev/null" >>/var/spool/cron/root
  67. chmod 600 /var/spool/cron/root
  68. fi
  69. /etc/init.d/crond restart
  70. fi
  71. if [ $release == 7 ];then
  72. yum -y install chrony
  73. >/etc/chrony.conf
  74. cat >>/etc/chrony.conf <<EOF
  75. server ntp1.aliyun.com iburst
  76. server ntp2.aliyun.com iburst
  77. stratumweight 0
  78. driftfile /var/lib/chrony/drift
  79. rtcsync
  80. makestep 10 3
  81. bindcmdaddress 127.0.0.1
  82. bindcmdaddress ::1
  83. keyfile /etc/chrony.keys
  84. generatecommandkey
  85. noclientlog
  86. logchange 0.5
  87. logdir /var/log/chrony
  88. EOF
  89. systemctl restart chronyd
  90. systemctl enable chronyd
  91. fi
  92. #clean iptables default rules
  93. if [ $release == 6 ];then
  94. /sbin/iptables -F
  95. /etc/inti.d/iptables save
  96. chkconfig ip6tables off
  97. fi
  98. if [ $release == 7 ];then
  99. systemctl disable firewalld
  100. systemctl stop firewalld
  101. fi
  102. #disable unused service
  103. chkconfig auditd off
  104. #disable ipv6
  105. cd /etc/modprobe.d/ && touch ipv6.conf
  106. >/etc/modprobe.d/ipv6.conf
  107. cat >>/etc/modprobe.d/ipv6.conf<<EOF
  108. alias net-pf-10 off
  109. alias ipv6 off
  110. EOF
  111. #disable selinux
  112. setenforce 0
  113. sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config
  114. #update record command
  115. sed -i 's/^HISTSIZE=.*$/HISTSIZE=100000/' /etc/profile
  116. grep -q 'HISTTIMEFORMAT' /etc/profile
  117. if [ $? -eq 0 ];then
  118. sed -i 's/HISTTIMEFORMAT=.*$/HISTTIMEFORMAT="%F %T "/' /etc/profile
  119. else
  120. echo 'HISTTIMEFORMAT="%F %T "' >> /etc/profile
  121. fi
  122. source /etc/profile
  123. #set dns
  124. >/etc/resolv.conf
  125. cat >> /etc/resolv.conf <<EOF
  126. nameserver 114.114.114.114
  127. EOF
  128. #ssh优化
  129. sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
  130. sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
  131. #内核优化
  132. sed -i 's/net.ipv4.tcp_syncookies.*/net.ipv4.tcp_syncookies = 1/g' /etc/sysctl.conf
  133. cat >>/etc/sysctl.conf <<EOF
  134. kernel.core_uses_pid=1
  135. kernel.core_pattern=/tmp/core-%e-%p
  136. fs.suid_dumpable=2
  137. net.ipv4.tcp_tw_reuse=1
  138. net.ipv4.tcp_tw_recycle=0
  139. net.ipv4.tcp_timestamps=1
  140. EOF
  141. 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. 一元回归_ols参数解读(推荐AAA)

    sklearn实战-乳腺癌细胞数据挖掘(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&a ...

  2. SpringBoot (四) :thymeleaf 使用详解

    原文出处: 纯洁的微笑 在上篇文章< springboot(二):web综合开发 >中简单介绍了一下thymeleaf,这篇文章将更加全面详细的介绍thymeleaf的使用.thymele ...

  3. Tensorboard教程:显示计算图中节点信息

    Tensorboard显示计算图节点信息 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 强烈推荐Tensorflow实战Google深度学习框架 实验平台: Tensorflow1 ...

  4. 跟我一起写Makefile(七)

    make 的运行—————— 一般来说,最简单的就是直接在命令行下输入make命令,make命令会找当前目录的makefile来执行,一切都是自动的.但也有时你也许只想让make重编译某些文件,而不是 ...

  5. Eclipse中 如何实现 多行同时编辑

    在编辑的时候按下 SHIFT + ALT +A 之后  鼠标变为 + 号   选择要同时编辑几行  即可编辑(现在eclipse好像只能是编辑一块地方  不能像vs那样 任何地方可以同时编辑  这点很 ...

  6. Oracle用imp导入dmp文件记录一下

    ---------------------------------------------------------------------------------------------------- ...

  7. Ibatis的resultMap和查询数据的对应关系

    iBatis和MyBatis 中返回数据对应关系 直接进入主题,现在的项目改用MyBatis了,感觉跟iBatis还是不一样的,比如在判断空值上面,iBatis是有标签的<isNotEmpty& ...

  8. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

  9. 桥接模式_NAT模式_仅主机模式_模型图.ziw

      2017年1月12日, 星期四 桥接模式_NAT模式_仅主机模式_模型图   null

  10. 重构改善既有代码设计--重构手法11:Move Field (搬移字段)

    你的程序中,某个字段被其所驻类之外的另一个类更多的用到.在目标类建立一个新字段,修改源字段的所有用户,令它们改用新字段.        动机:在类之间移动状态和行为,是重构过程中必不可少的措施.随着系 ...