Currently Browsing: LAMP/Node

Sysctl optimization updates for Redis, MongoDB, etc.

Sysctl Performance tips for Redis, MongoDB, etc.

# backup:
$ sysctl -a > /home/sysctl_$(date +%Y%m%d).bak
#check:
$ sysctl -a
 
# make changes to sysctl.conf:
$ vi/nano /etc/sysctl.conf
 
# web - nginx, redis, mongo, etc:
vm.swappiness = 10
vm.dirty_ratio = 40
vm.dirty_background_ratio = 10
# for larger servers:
net.ipv4.tcp_rmem = 4096 12582912 33554432
net.ipv4.tcp_wmem = 4096 12582912 33554432
net.core.rmem_max = 33554432
net.core.wmem_max = 33554432
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1
#
net.ipv4.tcp_max_syn_backlog = 65536
kernel.keys.root_maxkeys = 1000000
#Raise somaxconn (above 511)
net.core.somaxconn = 4096
 
# vm.overcommit_memory (optional):
# vm.overcommit_memory = 1
####
 
# set in /etc/rc.local (test reboot stickiness)
# ensure changes to sysctl configuration persist across reboots:
$ sysctl -p
 
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

more info:

  • https://wiki.mikejung.biz/Sysctl_tweaks
  • https://www.techandme.se/performance-tips-for-redis-cache-server/
  • https://unix.stackexchange.com/questions/99154/disable-transparent-hugepages
  • Increase nginx open-files limit on systemd

    $ cat /proc/$(cat /run/nginx.pid)/limits
     
    $ nano /lib/systemd/system/nginx.service
    # --> [Service]
    LimitNOFILE=16384
     
    $ systemctl daemon-reload
    $ systemctl restart nginx && systemctl status nginx

    Install PHP Composer

    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    php composer-setup.php
    php -r "unlink('composer-setup.php');"

    if desired move (or use install arg) to put binary into path, e.g., mv composer.phar /usr/local/bin/composer

    see: https://getcomposer.org/download/
    and: https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx

    Setting up Uncomplicated FireWall (UFW)

    Primarily used on Ubuntu and Debian:

    apt-get install ufw
     
    ufw enable
     
    ufw default deny incoming
    ufw default allow outgoing
     
    # checkit:
    ufw status verbose
     
    # add ssh
    ufw allow ssh
     
    # add other rules by servicename or custom, e.g. for Redis:
    # ufw allow in on eth1 to any port 6379 proto tcp

    see more here

    PHP Composer.lock Git conflicts

    If you get a git conflict on composer.lock, ignore local changes and fetch the latest from Git. Then run a composer update and commit the updated lockfile to make sure it includes everything.

    [credit]

    « Previous Entries