LinuxInit.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. apt-get install -y openssl net-tools dnsutils nload curl wget lsof psmisc iptables
  3. if [ -d /etc/systemd ]; then
  4. # systemd-journald
  5. if [ -f /etc/systemd/journald.conf ]; then
  6. sed -i 's/^#\?Storage=.*/Storage=volatile/' /etc/systemd/journald.conf
  7. sed -i 's/^#\?SystemMaxUse=.*/SystemMaxUse=8M/' /etc/systemd/journald.conf
  8. sed -i 's/^#\?RuntimeMaxUse=.*/RuntimeMaxUse=8M/' /etc/systemd/journald.conf
  9. sed -i 's/^#\?ForwardToSyslog=.*/ForwardToSyslog=no/' /etc/systemd/journald.conf
  10. systemctl restart systemd-journald
  11. fi
  12. # systemd-timesyncd
  13. apt-get install -y systemd-timesyncd
  14. if [ -f /etc/systemd/timesyncd.conf ]; then
  15. echo -ne "[Time]\nNTP=time.apple.com time.windows.com pool.ntp.org ntp.ntsc.ac.cn\nRootDistanceMaxSec=3\nPollIntervalMinSec=24\nPollIntervalMaxSec=512\n\n" >/etc/systemd/timesyncd.conf
  16. systemctl restart systemd-timesyncd
  17. fi
  18. fi
  19. # limits
  20. if [ -f /etc/security/limits.conf ]; then
  21. LIMIT='262144'
  22. sed -i '/^\(\*\|root\)[[:space:]]*\(hard\|soft\)[[:space:]]*\(nofile\|memlock\)/d' /etc/security/limits.conf
  23. 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
  24. fi
  25. if [ -f /etc/systemd/system.conf ]; then
  26. sed -i 's/#\?DefaultLimitNOFILE=.*/DefaultLimitNOFILE=262144/' /etc/systemd/system.conf
  27. fi
  28. # root
  29. sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config;
  30. sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
  31. # timezone
  32. ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" >/etc/timezone
  33. # ssh
  34. [ -d ~/.ssh ] || mkdir -p ~/.ssh
  35. echo -ne "# chmod 600 ~/.ssh/id_rsa\n\nHost *\n StrictHostKeyChecking no\n UserKnownHostsFile /dev/null\n IdentityFile ~/.ssh/id_rsa\n" > ~/.ssh/config
  36. # nload
  37. echo -ne 'DataFormat="Human Readable (Byte)"\nTrafficFormat="Human Readable (Byte)"\n' >/etc/nload.conf
  38. # sysctl
  39. cat >/etc/sysctl.conf<<EOF
  40. # This line below add by user.
  41. fs.file-max = 104857600
  42. fs.nr_open = 1048576
  43. vm.overcommit_memory = 1
  44. net.core.somaxconn = 1048576
  45. net.core.optmem_max = 7864320
  46. net.core.rmem_max = 7864320
  47. net.core.wmem_max = 7864320
  48. net.core.rmem_default = 7864320
  49. net.core.wmem_default = 7864320
  50. net.core.netdev_max_backlog = 1048576
  51. net.ipv4.tcp_mem = 32768 49152 65536
  52. net.ipv4.tcp_rmem = 4096 87380 7864320
  53. net.ipv4.tcp_wmem = 4096 16384 7864320
  54. net.ipv4.tcp_syncookies = 1
  55. net.ipv4.tcp_syn_retries = 3
  56. net.ipv4.tcp_synack_retries = 2
  57. net.ipv4.tcp_max_syn_backlog = 1048576
  58. net.ipv4.tcp_fin_timeout = 8
  59. net.ipv4.tcp_keepalive_intvl = 32
  60. net.ipv4.tcp_keepalive_probes = 3
  61. net.ipv4.tcp_keepalive_time = 900
  62. net.ipv4.tcp_retries1 = 3
  63. net.ipv4.tcp_retries2 = 5
  64. net.ipv4.tcp_no_metrics_save = 1
  65. net.ipv4.tcp_timestamps = 1
  66. net.ipv4.tcp_window_scaling = 1
  67. net.ipv4.tcp_slow_start_after_idle = 0
  68. net.ipv4.ip_forward = 1
  69. net.ipv4.icmp_echo_ignore_all = 1
  70. net.ipv6.conf.all.disable_ipv6 = 0
  71. net.ipv6.conf.all.forwarding = 1
  72. net.ipv6.conf.all.accept_ra = 2
  73. net.ipv6.conf.all.proxy_ndp = 1
  74. net.ipv4.tcp_fastopen = 0
  75. net.ipv4.tcp_fack = 1
  76. net.ipv4.tcp_sack = 1
  77. net.ipv4.tcp_dsack = 1
  78. net.ipv4.tcp_ecn = 0
  79. net.ipv4.tcp_ecn_fallback = 1
  80. net.core.default_qdisc = fq_codel
  81. net.ipv4.tcp_congestion_control = bbr
  82. EOF
  83. sysctl -p