LinuxInit.sh 2.8 KB

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