Skip to content

Instantly share code, notes, and snippets.

@lilongen
lilongen / redis-delete-all-matching-keys
Created April 26, 2016 06:16
Delete all keys in redis matching a regular expression
# Deleting all keys in redis that match a regular expression
# General
redis-cli [options] KEYS "prefix:*" | xargs redis-cli [options] DEL
# If authorization is needed
redis-cli -a <AUTH> KEYS "prefix:*" | xargs redis-cli -a <AUTH> DEL
# If no authorization is needed
redis-cli KEYS "prefix:*" | xargs redis-cli DEL
@lilongen
lilongen / perl-edit-file-like-sed
Last active April 26, 2016 06:54
perl-edit-file-like-sed, perl stream-edit file like sed, use perl to edit file like sed, sed file using perl
examples:
1). modify file using regular expression pattern single-line mode ( '.' and '\s' match '\n')
perl -i -p0E 's|(<artifactId>api</artifactId>[^<]+<version>)(bbb)(</version>)|\1a\3|g' pom.xml
2). modify file using regular expression pattern multi-line mode
perl -i -pE 's|(<artifactId>api</artifactId>[^<]+<version>)(bbb)(</version>)|\1a\3|g' pom.xml
3). do not modify file actually, just print the changed contents
perl -p0E 's|(<artifactId>api</artifactId>[^<]+<version>)(bbb)(</version>)|\1a\3|g' pom.xml
@lilongen
lilongen / kerberos_setup.md
Last active March 1, 2018 07:03 — forked from ashrithr/kerberos_setup.md
Set up kerberos on Redhat/CentOS 7

Installing Kerberos on Redhat 7

This installation is going to require 2 servers one acts as kerberos KDC server and the other machine is going to be client. Lets assume the FQDN's are (here cw.com is the domain name, make a note of the domain name here):

  • Kerberos KDC Server: kdc.cw.com
  • Kerberos Client: kclient.cw.com

Important: Make sure that both systems have their hostnames properly set and both systems have the hostnames and IP addresses of both systems in

@lilongen
lilongen / kdc-configure-file-contents
Last active April 26, 2016 07:04
KDC configure files example
# /etc/krb5.conf
[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log
[libdefaults]
dns_lookup_realm = false
ticket_lifetime = 24h
@lilongen
lilongen / tcpdump-http-capture
Created April 26, 2016 07:07
tcpdump http data packet capture examples
#dump http response
tcpdump -s 0 -A 'src port 80 and tcp[((tcp[12:1]&0xf0)>>2):4]=0x48545450'
tcpdump -s 0 -A 'src port 80 and tcp[((tcp[12:1]&0xf0)>>2):4]='$(python -c "print '0x' + ''.join(hex(ord(i))[2:] for i in 'HTTP')")
#dump http post request, following two are equal, 0x504f5354 <-> POST
tcpdump -s 0 -A 'dst port 80 and tcp[((tcp[12:1]&0xf0)>>2):4]=0x504f5354'
tcpdump -s 0 -A 'dst port 80 and tcp[((tcp[12:1]&0xf0)>>2):4]='$(python -c "print '0x' + ''.join(hex(ord(i))[2:] for i in 'POST')")
#dump http get request
tcpdump -s 0 -A 'dst port 80 and tcp[((tcp[12:1]&0xf0)>>2):4]='$(python -c "print '0x' + ''.join(hex(ord(i))[2:] for i in 'GET ')")
@lilongen
lilongen / generic-makefile-c
Created April 26, 2016 08:42
C Generic Makefile
######################################
#
# Generic makefile
#
# by George Foot
# email: george.foot@merton.ox.ac.uk
#
# Copyright (c) 1997 George Foot
# All rights reserved.
#
@lilongen
lilongen / generic-makefile-c++
Created April 26, 2016 08:43
C++ Generic Makefile
####################################################
# Generic makefile - 万能Makefile
# for compiling and linking C++ projects on Linux
# Author: George Foot Modified:Jackie Lee
####################################################
### Customising
#
# Adjust the following if necessary; EXECUTABLE is the target
# executable's filename, and LIBS is a list of libraries to link in
# (e.g. alleg, stdcx, iostr, etc). You can override these on make's
@lilongen
lilongen / postgresql-usage-examples
Last active April 29, 2016 07:48
PostgreSQL install and usage examples
* install
# yum install postgresql-server postgresql-contrib
# postgresql-setup initdb
* allow passowrd authentication & remote access
# vi /var/lib/pgsql/data/pg_hba.conf
host all all 127.0.0.1/32 ident
host all all ::1/128 ident
->
host all all 127.0.0.1/32 md5
@lilongen
lilongen / deploy-cm-cdh-on-centos7
Last active August 28, 2021 11:36
Centos 7 install/deploy Cloudera Manager and CDH using local repository and CDH local parcel
- prepare work
a. make cm node can ssh to all nodes without password
ssh-genkey, ssh-copy-id
b. hostname mapping
c. mysql server
d. postgresql
e. ntp
systemctl disable chrony
centos7 default enable chrony server, even enable ntpd, cuase chrony started, ntpd will not started
this will cause CDH ntp error, so need to disable chrony.
@lilongen
lilongen / run-ansible-with-any-host-without-inventory
Last active May 5, 2023 23:16
How to run Ansible without specifying the inventory but the host directly?
Question:
. How to run Ansible without specifying the inventory but the host directly?
. Run a playbook or command with arbitrary host not in the inventory hosts list?
. run ansible with arbitrary host/ip without inventory?
Answer:
Surprisingly, the trick is to append a ,
The host parameter preceding the , can be either a hostname or an IPv4/v6 address.
ansible all -i example.com,