LinuxInit.sh 2.5 KB

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