init_RHEL.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. # Close SELINUX
  11. setenforce 0
  12. sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config
  13. # Custom profile
  14. cat > /etc/profile.d/oneinstack.sh << EOF
  15. HISTSIZE=10000
  16. PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[35;40m\]\W\[\e[0m\]]\\\\$ "
  17. HISTTIMEFORMAT="%F %T \$(whoami) "
  18. alias l='ls -AFhlt'
  19. alias lh='l | head'
  20. alias vi=vim
  21. GREP_OPTIONS="--color=auto"
  22. alias grep='grep --color'
  23. alias egrep='egrep --color'
  24. alias fgrep='fgrep --color'
  25. EOF
  26. [[ "${Platform}" =~ ^euleros$|^openeuler$ ]] && sed -i '/HISTTIMEFORMAT=/d' /etc/profile.d/oneinstack.sh
  27. [[ ! "${Platform}" =~ ^euleros$|^openeuler$ ]] && [ -z "$(grep ^'PROMPT_COMMAND=' /etc/bashrc)" ] && cat >> /etc/bashrc << EOF
  28. PROMPT_COMMAND='{ msg=\$(history 1 | { read x y; echo \$y; });logger "[euid=\$(whoami)]":\$(who am i):[\`pwd\`]"\$msg"; }'
  29. EOF
  30. # /etc/security/limits.conf
  31. [ -e /etc/security/limits.d/*nproc.conf ] && rename nproc.conf nproc.conf_bk /etc/security/limits.d/*nproc.conf
  32. sed -i '/^# End of file/,$d' /etc/security/limits.conf
  33. cat >> /etc/security/limits.conf <<EOF
  34. # End of file
  35. * soft nproc 1000000
  36. * hard nproc 1000000
  37. * soft nofile 1000000
  38. * hard nofile 1000000
  39. EOF
  40. # /etc/hosts
  41. [ "$(hostname -i | awk '{print $1}')" != "127.0.0.1" ] && sed -i "s@127.0.0.1.*localhost@&\n127.0.0.1 $(hostname)@g" /etc/hosts
  42. # Set timezone
  43. rm -rf /etc/localtime
  44. ln -s /usr/share/zoneinfo/${timezone} /etc/localtime
  45. # ip_conntrack table full dropping packets
  46. echo -e "modprobe nf_conntrack\nmodprobe nf_conntrack_ipv4" > /etc/sysconfig/modules/nf_conntrack.modules
  47. chmod +x /etc/sysconfig/modules/nf_conntrack.modules
  48. modprobe nf_conntrack
  49. modprobe nf_conntrack_ipv4
  50. echo options nf_conntrack hashsize=131072 > /etc/modprobe.d/nf_conntrack.conf
  51. # /etc/sysctl.conf
  52. [ ! -e "/etc/sysctl.conf_bk" ] && /bin/mv /etc/sysctl.conf{,_bk}
  53. cat > /etc/sysctl.conf << EOF
  54. fs.file-max=1000000
  55. net.ipv4.tcp_max_tw_buckets = 6000
  56. net.ipv4.tcp_sack = 1
  57. net.ipv4.tcp_window_scaling = 1
  58. net.ipv4.tcp_rmem = 4096 87380 4194304
  59. net.ipv4.tcp_wmem = 4096 16384 4194304
  60. net.ipv4.tcp_max_syn_backlog = 16384
  61. net.core.netdev_max_backlog = 32768
  62. net.core.somaxconn = 32768
  63. net.core.wmem_default = 8388608
  64. net.core.rmem_default = 8388608
  65. net.core.rmem_max = 16777216
  66. net.core.wmem_max = 16777216
  67. net.ipv4.tcp_timestamps = 0
  68. net.ipv4.tcp_fin_timeout = 20
  69. net.ipv4.tcp_synack_retries = 2
  70. net.ipv4.tcp_syn_retries = 2
  71. net.ipv4.tcp_syncookies = 1
  72. #net.ipv4.tcp_tw_len = 1
  73. net.ipv4.tcp_tw_reuse = 1
  74. net.ipv4.tcp_mem = 94500000 915000000 927000000
  75. net.ipv4.tcp_max_orphans = 3276800
  76. net.ipv4.ip_local_port_range = 1024 65000
  77. net.nf_conntrack_max = 6553500
  78. net.netfilter.nf_conntrack_max = 6553500
  79. net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
  80. net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
  81. net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
  82. net.netfilter.nf_conntrack_tcp_timeout_established = 3600
  83. EOF
  84. sysctl -p
  85. if [ ${RHEL_ver} -ge 7 >/dev/null 2>&1 ]; then
  86. sed -i 's@LANG=.*$@LANG="en_US.UTF-8"@g' /etc/locale.conf
  87. fi
  88. # firewall
  89. if [ "${firewall_flag}" == 'y' ]; then
  90. systemctl enable firewalld
  91. systemctl start firewalld
  92. firewall-cmd --permanent --zone=public --add-port={22/tcp,80/tcp,443/tcp}
  93. [ "${ssh_port}" != "22" ] && firewall-cmd --permanent --zone=public --add-port=${ssh_port}/tcp
  94. firewall-cmd --reload
  95. else
  96. systemctl stop firewalld
  97. systemctl disable firewalld
  98. fi
  99. systemctl restart rsyslog sshd
  100. . /etc/profile