Skip to content

Instantly share code, notes, and snippets.

View psujit775's full-sized avatar
:octocat:
Learning is in progress

Sujit Patel psujit775

:octocat:
Learning is in progress
View GitHub Profile
@psujit775
psujit775 / elasticsearch.yml
Last active December 25, 2021 18:01
elasticsearch.yml file with auth enabled.
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
@psujit775
psujit775 / loki-local-config.yaml
Created December 26, 2021 14:02
config file for loki
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
common:
path_prefix: /etc/loki
storage:
filesystem:
@psujit775
psujit775 / promtail-config.yaml
Created December 26, 2021 14:56
config file for promtail to monitor nginx logs
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /etc/promtail/positions.yaml
clients:
- url: http://localhost:3100/loki/api/v1/push
CREATE OR REPLACE FUNCTION public.audit_ddl()
RETURNS event_trigger
LANGUAGE plpgsql
AS $function$
declare _qry text;
BEGIN
if (tg_tag='CREATE TABLE' or tg_tag='ALTER TABLE' or tg_tag='DROP TABLE') then
SELECT current_query() into _qry;
insert into public.ddl_audit
values
@psujit775
psujit775 / aws asg terrafrom sample.txt
Created March 19, 2022 23:53
Setup Auto Scaling along with scale up and down policy
Setup Auto Scaling along with scale up and down policy
1. Build AMI
we need to first build AMI by installing Amazon monitoring scripts to monitor memory utilization and send to cloudwathc and also install other required dependencies to run application.
2. Create launch configuration
we create launch configuration with options like availability zone, security groups, vpc, etc.
3. Create autoscaling group and autoscaling policy
This points at our earlier launch configuration and it lauch instances based on launch configuration. The tag,vpc security groups is propogated to any launched instance at launch. Also we define min and max number of instances.
@psujit775
psujit775 / mongodb-cluster.txt
Created March 21, 2022 21:29
Setup MongoDB Replica with Password Authentication in Ubuntu 20.04 LTS. (1 Master and 2 Secondary)
Setup MongoDB Replica with Password Authentication in Ubuntu 20.04 LTS.
(1 Master and 2 Secondary)
Overview
1. Install MongoDB to all servers.
2. Run rs.status() to check Replica set status.
3. Generate Key file on any one server.
4. Copy keyfile to all servers.
5. Update conf file for keyfile, replicaset name and bind address on all servers.
6. Restart MongoDB on servers.
@psujit775
psujit775 / jail.local
Last active March 27, 2022 09:46
fail2ban conf
[sshd]
enabled = true
#call iptables to ban IP address
banaction = iptables-multiport
#ban on all ports
banaction_allports = iptables-allports
bantime = 31536000 #this is one year ban time
#bantime = -1 this will ban permanently
@psujit775
psujit775 / mosquitto.conf
Created April 7, 2022 17:54
mosquitto.conf fro mqtt websocket
#web socket
listener 9001
protocol websockets
pid_file /var/run/mosquitto.pid
user ubuntu
persistence true
persistence_location /var/lib/mosquitto/
max_connections -1
@psujit775
psujit775 / mqtt.conf
Created April 7, 2022 18:07
nginx conf for mqtt websocket
upstream websocket {
server localhost:9001;
}
server {
server_name mqtt.sujitpatel.in; #change accordingly
location / {
proxy_pass http://websocket;
@psujit775
psujit775 / backup-schema.sh
Last active June 17, 2022 07:39
take schema dump of mysql
#!/bin/bash
HOST="some-database.rds.amazonaws.com"
USER="admin"
PASSWORD_FILE="/root/.rds.cnf"
OUTPUT="/data/schema"
databases=`mysql --defaults-extra-file=$PASSWORD_FILE -u $USER -h $HOST -NBe "select group_concat(schema_name separator ' ') from information_schema.schemata where schema_name not in ('sys','mysql', 'information_schema', 'performance_schema')"`
# GET Total number of databases.