Skip to content

Instantly share code, notes, and snippets.

View rooty's full-sized avatar
🏠
Working from home

Vitalii Mikhnevych rooty

🏠
Working from home
View GitHub Profile
@rooty
rooty / remove_old_kernels.sh
Created January 15, 2018 22:59 — forked from Snawoot/remove_old_kernels.sh
Remove old kernels in Debian/Ubuntu
dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p' | xargs sudo apt-get -y purge
@rooty
rooty / lsyncd.conf.lua
Last active September 10, 2024 20:57 — forked from Snawoot/lsyncd.conf.lua
rsyncpostcmd = {
-- based on default rsync.
default.rsyncssh,
-- for this config it is important to keep maxProcesses at 1, so
-- the postcmds will only be spawned after the rsync completed
maxProcesses = 1,
-- called whenever something is to be done
@rooty
rooty / sysctl.conf
Created January 18, 2018 22:20
api-php-sysctl
#
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additional system variables.
# See sysctl.conf (5) for information.
#
#kernel.domainname = example.com
# Uncomment the following to stop low-level messages on console
#kernel.printk = 3 4 1 3
@rooty
rooty / sysctl.conf
Created January 18, 2018 22:20
sysctl-db
#
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additional system variables.
# See sysctl.conf (5) for information.
#
#kernel.domainname = example.com
# Uncomment the following to stop low-level messages on console
#kernel.printk = 3 4 1 3
@rooty
rooty / php-fpm-count.txt
Last active January 30, 2018 09:41
how many PHP-FPM processes a server could handle easily
It's good to test how many PHP-FPM processes a server could handle easily, first start Nginx and PHP-FPM and load some PHP pages, preferably all of the heaviest pages. Then check memory usage per PHP-FPM process example with Linux top or htop command. Let's assume that the server has 512 Mb memory and 220 Mb could be used for PHP-FPM, every process use 24 Mb RAM (some huge content management system with plugins can easily use 20-40 Mb / per PHP page request or even more). Then simply calculate the server max_children value:
220 / 24 = 9.17
So good pm.max_children value is 9. This is based just quick average and later this could be something else when you see longer time memory usage / per process. After quick testing it's much easier to setup pm.start_servers value, pm.min_spare_servers value and pm.max_spare_servers value.
https://www.kinamo.be/en/support/faq/determining-the-correct-number-of-child-processes-for-php-fpm-on-nginx
@rooty
rooty / install.sh
Created February 2, 2018 16:00
Hetzner install debian 8
installimage -n app-11.example.com -b grub -r yes -l 1 -p /boot:ext2:512M,swap:swap:4G,/:ext4:all -d sda,sdb -s en -t yes -K https://gist.githubusercontent.com/username/4973306c6d7ff53c1/raw/0322d9f18b7979f997a959e8ec4b1980723346f4/id_rsa.pub -i /root/.oldroot/nfs/install/../images/Debian-89-jessie-64-minimal.tar.gz -a
@rooty
rooty / nginx.conf
Created February 15, 2018 22:44 — forked from nrollr/nginx.conf
NGINX config for SSL with Let's Encrypt certs
# Advanced config for NGINX
server_tokens off;
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options nosniff;
# Redirect all HTTP traffic to HTTPS
server {
listen 80;
server_name www.domain.com domain.com;
return 301 https://$host$request_uri;
@rooty
rooty / find-https-debian-archives.py
Last active February 22, 2018 23:17 — forked from eighthave/find-https-debian-archives.py
Script to find official Debian mirrors that support HTTPS
#!/usr/bin/env python3
import urllib.request
import re
import ssl
import sys
# # find generic mirrors
mirrors = urllib.request.urlopen('http://www.debian.org/mirror/list')
https = []
@rooty
rooty / logrotate
Created March 23, 2018 09:21
Manipulate date
/var/log/myproject/celery.log {
size 1
su myuser myuser
copytruncate
create
rotate 10
missingok
postrotate
timeext=`date -d '1 day ago' "+%Y-%m-%d"` # daily
# timeext=$(date +%Y-%m-%d_%H) # hourly
for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor;
do
[ -f $CPUFREQ ] || continue
echo -n performance > $CPUFREQ
done
https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt