LinuxInit.sh 2.9 KB

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