init_Ubuntu.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. # Custom profile
  11. cat > /etc/profile.d/oneinstack.sh << EOF
  12. HISTSIZE=10000
  13. HISTTIMEFORMAT="%F %T \$(whoami) "
  14. alias l='ls -AFhlt --color=auto'
  15. alias lh='l | head'
  16. alias ll='ls -l --color=auto'
  17. alias ls='ls --color=auto'
  18. alias vi=vim
  19. GREP_OPTIONS="--color=auto"
  20. alias grep='grep --color'
  21. alias egrep='egrep --color'
  22. alias fgrep='fgrep --color'
  23. EOF
  24. sed -i 's@^"syntax on@syntax on@' /etc/vim/vimrc
  25. # PS1
  26. [ -z "$(grep ^PS1 ~/.bashrc)" ] && echo "PS1='\${debian_chroot:+(\$debian_chroot)}\\[\\e[1;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '" >> ~/.bashrc
  27. # history
  28. [ -z "$(grep history-timestamp ~/.bashrc)" ] && echo "PROMPT_COMMAND='{ msg=\$(history 1 | { read x y; echo \$y; });user=\$(whoami); echo \$(date \"+%Y-%m-%d %H:%M:%S\"):\$user:\`pwd\`/:\$msg ---- \$(who am i); } >> /tmp/\`hostname\`.\`whoami\`.history-timestamp'" >> ~/.bashrc
  29. # /etc/security/limits.conf
  30. [ -e /etc/security/limits.d/*nproc.conf ] && rename nproc.conf nproc.conf_bk /etc/security/limits.d/*nproc.conf
  31. [ -z "$(grep 'session required pam_limits.so' /etc/pam.d/common-session)" ] && echo "session required pam_limits.so" >> /etc/pam.d/common-session
  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. root soft nproc 1000000
  40. root hard nproc 1000000
  41. root soft nofile 1000000
  42. root hard nofile 1000000
  43. EOF
  44. # /etc/hosts
  45. [ "$(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
  46. # Set timezone
  47. rm -rf /etc/localtime
  48. ln -s /usr/share/zoneinfo/${timezone} /etc/localtime
  49. # /etc/sysctl.conf
  50. [ -z "$(grep 'fs.file-max' /etc/sysctl.conf)" ] && cat >> /etc/sysctl.conf << EOF
  51. fs.file-max = 1000000
  52. fs.inotify.max_user_instances = 8192
  53. net.ipv4.tcp_syncookies = 1
  54. net.ipv4.tcp_fin_timeout = 30
  55. net.ipv4.tcp_tw_reuse = 1
  56. net.ipv4.ip_local_port_range = 1024 65000
  57. net.ipv4.tcp_max_syn_backlog = 16384
  58. net.ipv4.tcp_max_tw_buckets = 6000
  59. net.ipv4.route.gc_timeout = 100
  60. net.ipv4.tcp_syn_retries = 1
  61. net.ipv4.tcp_synack_retries = 1
  62. net.core.somaxconn = 32768
  63. net.core.netdev_max_backlog = 32768
  64. net.ipv4.tcp_timestamps = 0
  65. net.ipv4.tcp_max_orphans = 32768
  66. EOF
  67. sysctl -p
  68. sed -i 's@^ACTIVE_CONSOLES.*@ACTIVE_CONSOLES="/dev/tty[1-2]"@' /etc/default/console-setup
  69. locale-gen en_US.UTF-8
  70. [ -d "/var/lib/locales/supported.d" ] && echo "en_US.UTF-8 UTF-8" > /var/lib/locales/supported.d/local
  71. cat > /etc/default/locale << EOF
  72. LANG=en_US.UTF-8
  73. LANGUAGE=en_US:en
  74. EOF
  75. # ufw
  76. if [ "${firewall_flag}" == 'y' ]; then
  77. ufw allow 22/tcp
  78. [ "${ssh_port}" != "22" ] && ufw allow ${ssh_port}/tcp
  79. ufw allow 80/tcp
  80. ufw allow 443/tcp
  81. ufw --force enable
  82. else
  83. ufw --force disable
  84. fi
  85. systemctl restart rsyslog ssh
  86. . /etc/profile
  87. . ~/.bashrc