Skip to content

Instantly share code, notes, and snippets.

View khairulcs's full-sized avatar
🎯
Focusing

Khairul Azwan khairulcs

🎯
Focusing
View GitHub Profile
@khairulcs
khairulcs / howto.md
Last active October 25, 2019 07:51
How to Cloud Servering

1. Get a DB graph for last 30 minutes (AWS)

Go to RDS -> Databases -> Select the database -> Monitoring -> Filter CloudWatch -> Click CPU Utilization -> Filter based on req

2. Get websocket server errors logs for last 30 minutes (forever)

  1. SSH into websocket server
  2. run forever list
  3. Refer to the script column for the log file that is related
  4. go into the logfile path
  5. run view filename.log
@khairulcs
khairulcs / deployment.sh
Last active March 21, 2023 04:03
Configuring traefik zero downtime
#!/bin/sh
if [ $(docker ps -f name=blue-cms -q) ]
then
BG_NEW="green-cms"
BG_OLD="blue-cms"
else
BG_NEW="blue-cms"
BG_OLD="green-cms"
fi

List all nodes ps -ef | grep node

Kill 1 node kill 1234

Stop all nodes pkill -f node

mysqldumpslow -a -s r -t 5 /var/log/mysql/mysql-slow.log

@khairulcs
khairulcs / oh-my-zsh.md
Last active January 4, 2020 09:20
Ad oh my zsh in Ubuntu 18.04

sudo apt-get update

sudo apt upgrade

sudo apt install zsh -y

sudo apt-get install powerline fonts-powerline -y

sudo apt-get install git -y

@khairulcs
khairulcs / fail2ban-nginx.md
Last active January 26, 2020 01:21
fail2ban

Install fail2ban

apt-get install fail2ban

Fail2ban config

Filter config

vim /etc/fail2ban/filter.d/nginx-req-limit.conf

# Fail2Ban configuration file
#
# supports: ngx_http_limit_req_module module

Set the mapping before server block

 # whitelisted user agents - will not have limits applied
    map $http_user_agent $whitelist {
        ~*Macintosh 1;
        ~*iPhone 0;
    }

    # if whitelist is 0, put the binary IP address in $limit so the rate limiting has something to use
 map $whitelist $limit {
limit_req_zone $binary_remote_addr zone=by_1_sec:10m rate=1r/s;
limit_req_zone $binary_remote_addr zone=by_5_sec:10m rate=5r/s;
limit_req_zone $binary_remote_addr zone=by_10_sec:10m rate=10r/s;
limit_req_zone $binary_remote_addr zone=by_50_sec:10m rate=50r/s;
limit_req zone=by_50_sec;
limit_req_status 429;
limit_conn_status 429;
@khairulcs
khairulcs / ssl-hierarchy-star
Created January 6, 2020 07:23
SSL Hierarki
cat STAR_carsome_id.crt SectigoRSADomainValidationSecureServerCA.crt USERTrustRSAAddTrustCA.crt >> ssl-bundle.crt
git clone https://github.com/andresriancho/w3af.git
cd w3af/extras/docker/scripts/
sudo ./w3af_console_docker `(password: w3af)`
.
.
.
w3af>>>