Skip to content

Instantly share code, notes, and snippets.

@ydf
Last active December 1, 2022 09:11
Show Gist options
  • Save ydf/2d2c9267ac71e9816d0524e818286b57 to your computer and use it in GitHub Desktop.
Save ydf/2d2c9267ac71e9816d0524e818286b57 to your computer and use it in GitHub Desktop.
ubuntu server init
#!/bin/bash
cat >> /etc/security/limits.conf <<EOF
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
EOF
cat >> /etc/sysctl.conf <<EOF
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 20480
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.ipv4.tcp_congestion_control = bbr
net.core.default_qdisc = fq
vm.swappiness = 70
net.ipv4.icmp_echo_ignore_all = 1
EOF
/sbin/sysctl -p
# make rc.local start up
printf '%s\n' '#!/bin/bash' 'swapon /swapfile' 'exit 0' |tee -a /etc/rc.local
chmod +x /etc/rc.local
# add swapfile 1G
dd if=/dev/zero of=/swapfile bs=128 count=1024k
mkswap /swapfile
chown root:root /swapfile
chmod 0600 /swapfile
# enable zswap
#cat /etc/default/grub |grep -v "GRUB_CMDLINE_LINUX_DEFAULT" > /tmp/grub.cmdline
#default_grub_cmd=`cat /etc/default/grub |grep "GRUB_CMDLINE_LINUX_DEFAULT"| awk -F"\"" '{print $2}'`
#zswap="zswap.enabled=1 zswap.max_pool_percent=10"
#echo "GRUB_CMDLINE_LINUX_DEFAULT=\"$default_grub_cmd $zswap\"" > /etc/default/grub
#cat /tmp/grub.cmdline >> /etc/default/grub
#update-grub
sed -i "s/MODULES=most/MODULES=dep/g" /etc/initramfs-tools/initramfs.conf
sed -i "s/FRAMEBUFFER=y/FRAMEBUFFER=n/g" /usr/share/initramfs-tools/conf-hooks.d/cryptsetup
#upgrade
apt remove --purge snapd
apt update && apt upgrade -y
cat << EOF
+-------------------------------------------------+
| optimizer is done |
| it's recommond to restart this server ! |
+-------------------------------------------------+
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment