LinuxInit.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. apt-get install -y openssl net-tools dnsutils screen nload wget curl lsof p7zip-full python3-pip
  3. # root
  4. sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config;
  5. sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
  6. # limits
  7. if [ -f /etc/security/limits.conf ]; then
  8. LIMIT='262144'
  9. sed -i '/^\(\*\|root\)[[:space:]]*\(hard\|soft\)[[:space:]]*\(nofile\|memlock\)/d' /etc/security/limits.conf
  10. echo -ne "*\thard\tmemlock\t${LIMIT}\n*\tsoft\tmemlock\t${LIMIT}\nroot\thard\tmemlock\t${LIMIT}\nroot\tsoft\tmemlock\t${LIMIT}\n*\thard\tnofile\t${LIMIT}\n*\tsoft\tnofile\t${LIMIT}\nroot\thard\tnofile\t${LIMIT}\nroot\tsoft\tnofile\t${LIMIT}\n\n" >>/etc/security/limits.conf
  11. fi
  12. if [ -f /etc/systemd/system.conf ]; then
  13. sed -i 's/#\?DefaultLimitNOFILE=.*/DefaultLimitNOFILE=262144/' /etc/systemd/system.conf
  14. fi
  15. # timezone
  16. ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" >/etc/timezone
  17. # systemd-journald
  18. sed -i 's/^#\?Storage=.*/Storage=volatile/' /etc/systemd/journald.conf
  19. sed -i 's/^#\?SystemMaxUse=.*/SystemMaxUse=8M/' /etc/systemd/journald.conf
  20. sed -i 's/^#\?RuntimeMaxUse=.*/RuntimeMaxUse=8M/' /etc/systemd/journald.conf
  21. systemctl restart systemd-journald
  22. # ssh
  23. [ -d ~/.ssh ] || mkdir -p ~/.ssh
  24. echo -ne "# chmod 600 ~/.ssh/id_rsa\n\nHost *\n StrictHostKeyChecking no\n UserKnownHostsFile /dev/null\n IdentityFile ~/.ssh/id_rsa\n" > ~/.ssh/config
  25. # nload
  26. echo -ne 'DataFormat="Human Readable (Byte)"\nTrafficFormat="Human Readable (Byte)"\n' >/etc/nload.conf
  27. # sysctl
  28. cat >/etc/sysctl.conf<<EOF
  29. # This line below add by user.
  30. fs.file-max = 104857600
  31. fs.nr_open = 1048576
  32. vm.overcommit_memory = 1
  33. vm.swappiness = 10
  34. net.core.somaxconn = 65535
  35. net.core.optmem_max = 1048576
  36. net.core.rmem_max = 8388608
  37. net.core.wmem_max = 8388608
  38. net.core.rmem_default = 1048576
  39. net.core.wmem_default = 1048576
  40. net.core.netdev_max_backlog = 65536
  41. net.ipv4.tcp_mem = 2097152 8388608 16777216
  42. net.ipv4.tcp_rmem = 16384 524288 16777216
  43. net.ipv4.tcp_wmem = 16384 524288 16777216
  44. net.ipv4.tcp_syncookies = 1
  45. net.ipv4.tcp_syn_retries = 3
  46. net.ipv4.tcp_synack_retries = 2
  47. net.ipv4.tcp_max_syn_backlog = 65535
  48. net.ipv4.tcp_fin_timeout = 16
  49. net.ipv4.tcp_keepalive_intvl = 32
  50. net.ipv4.tcp_keepalive_probes = 3
  51. net.ipv4.tcp_keepalive_time = 900
  52. net.ipv4.tcp_retries1 = 3
  53. net.ipv4.tcp_retries2 = 8
  54. net.ipv4.tcp_no_metrics_save = 1
  55. net.ipv4.tcp_timestamps = 1
  56. net.ipv4.tcp_slow_start_after_idle = 0
  57. net.ipv4.ip_forward = 1
  58. net.ipv4.icmp_echo_ignore_all = 1
  59. net.ipv6.conf.all.disable_ipv6 = 1
  60. net.ipv4.tcp_fastopen = 0
  61. net.ipv4.tcp_fack = 1
  62. net.ipv4.tcp_sack = 1
  63. net.ipv4.tcp_dsack = 1
  64. net.ipv4.tcp_ecn = 0
  65. net.ipv4.tcp_ecn_fallback = 1
  66. net.core.default_qdisc = fq_codel
  67. net.ipv4.tcp_congestion_control = bbr
  68. EOF
  69. sysctl -p