Skip to content

Instantly share code, notes, and snippets.

View phanthaihuan's full-sized avatar

Huan phanthaihuan

  • Ho Chi Minh
View GitHub Profile
@phanthaihuan
phanthaihuan / ftpd.sh
Created May 14, 2020 09:27
Configure ftpd behind NAT with iptables
### ProFTPd
/etc/proftpd/proftpd.conf
PassivePorts 49152 65535
MasqueradeAddress <External-IP of NAT>
### Load modules to kernel
/sbin/modprobe nf_conntrack_ftp
/sbin/modprobe nf_nat_ftp
### Add two lines to the file for storing permanent
@phanthaihuan
phanthaihuan / isValidRe.py
Last active May 14, 2020 11:51
How to check valid regex in Python
# https://stackoverflow.com/questions/19630994/how-to-check-if-a-string-is-a-valid-regex-in-python
def isValidRe(regex):
import re
try:
re.compile(regex)
is_valid = True
except re.error:
is_valid = False
return is_valid
@phanthaihuan
phanthaihuan / coutSubstring.py
Created May 14, 2020 13:08
How to count substring in Python
def count_substring(string, sub_string):
import re
match = re.findall('(?='+sub_string+')',string)
return len(match)
REFERENCE:
http://hzcsky.blog.51cto.com/1560073/479476
# $Id: mysql-replication 335 2005-10-13 19:46:20Z sbalukoff $
# To set up bi-directional mysql replication:
# For the purposes of this document, we have two servers which will in the
# end be filling a co-master type relationship. However, since when you set up
# this replication there will probably be one machine with all the data on it
# that needs to be brought into sync with the other machine, the machine
@phanthaihuan
phanthaihuan / replication.sh
Created May 19, 2020 12:00 — forked from rodesousa/replication.sh
Replication MySQL
#!/bin/bash
# PARAM
mysql_master=<%= @DBMY_MASTER_HOST %>
user_mysql=root
password_user_mysql=<%= @USER_ROOT_DBMY_SLAVE_PASSWORD %>
replication_user=<%= @REP_USER %>
replication_password=<%= @REP_PASSWORD %>
read -p "Etes vous sur de vouloir installer la replication ? [Y/N]" -n 1 -r
@phanthaihuan
phanthaihuan / 3 Master
Created May 19, 2020 12:03 — forked from thuyhiend/3 Master
Cấu hình Replication 3 master
```
## Master-1
create database replica_db;
create user 'slave'@'10.10.22.104' identified by 'abc@123';
create user 'slave'@'10.10.22.105' identified by 'abc@123';
grant replication slave on *.* to 'slave'@'10.10.22.104' identified by 'abc@123';
grant replication slave on *.* to 'slave'@'10.10.22.105' identified by 'abc@123';
vi /etc/my.cnf.d/mariadb-server.cnf
[mariadb]
@phanthaihuan
phanthaihuan / getCommand.py
Created May 25, 2020 03:09
Run shell command from Python
def getCommandOutput(command):
from subprocess import Popen, PIPE
proc = Popen(command, stdout=PIPE, stderr=PIPE, shell=True)
stdout, stderr = proc.communicate()
if stderr.decode("utf-8") == "":
return str(stdout.decode("utf-8"))
return ""
def getCommandError(command):
from subprocess import Popen, PIPE
@phanthaihuan
phanthaihuan / Dockerfile
Created May 25, 2020 05:24
Startup script after init CentOS 7
FROM centos:centos7
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
@phanthaihuan
phanthaihuan / LinuxServer
Created May 25, 2020 07:39
How to use SSHFS
yum install -y epel-release
sudo yum install -y sshfs
@phanthaihuan
phanthaihuan / cron
Last active May 26, 2020 17:12
Two ways to use cron
https://unix.stackexchange.com/questions/392780/how-to-schedule-an-rsync-command
There are two ways to use cron, by creating a file in /etc/cron.d/repo-sync with the format:
<minute> <hour> <day_of_month> <month> <day_of_week> <user> <command>
For example, to run rsync from src to dest at 19:00 every day you can use:
0 19 * * * root rsync -a src dest
Or you can create a crontab by running crontab -e (as the user you want to run the command as) with a line
like above minus the user such as: