Monday, 17 June 2024

Config SSL / TLS for MySQL on Ubuntu

 

Reference

- https://galaxyz.net/cach-cau-hinh-ssl-tls-cho-mysql-tren-ubuntu-1804.136.anews 

Thank you.

Redis Tutorial

1.Install Redis in Ubuntu

sudo apt update
sudo apt install redis-server

* Config Redis: 

sudo nano /etc/redis/redis.conf
- Change to:
. . .

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
# supervised no - no supervision interaction
# supervised upstart - signal upstart by putting Redis into SIGSTOP mode
# supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
# supervised auto - detect upstart or systemd method based on
# UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
# They do not enable continuous liveness pings back to your supervisor.
supervised systemd

. . .

2. Using Redis

* Restart redis

sudo systemctl restart redis.service

* Check redis

sudo systemctl status redis

* Disable redis

sudo systemctl disable redis

* Using cli

redis-cli
ping
set test "It's working!"
get test
exit
 

* Bind with localhost 


- chagng config redis only access from localhost
sudo nano /etc/redis/redis.conf
find
# bind 127.0.0.1 ::1
change to
bind 127.0.0.1 ::1

- restart redis
sudo systemctl restart redis
- Check result
sudo netstat -lnp | grep redis

- if dont has netstat then install
sudo apt install net-tools

3. Security for Redis

- Change strong password

- open config to set password for redis
sudo nano /etc/redis/redis.conf
find directive # requirepass foobared,
then remove # in head then change foobared to yourpassword

- create strong password
openssl rand 60 | openssl base64 -A
- restart redis
sudo systemctl restart redis.service
 

- Check password working

redis-cli
set key1 10
// auth redis
auth {your_redis_password}

* Change dangerous cli

sudo nano /etc/redis/redis.conf
. . .
# It is also possible to completely kill a command by renaming it into
# an empty string:
#
rename-command FLUSHDB ""
rename-command FLUSHALL ""
rename-command DEBUG ""
. . .
# or rename-command CONFIG ""
rename-command SHUTDOWN SHUTDOWN_MENOT
rename-command CONFIG ASC12_CONFIG

- Restart redis

sudo systemctl restart redis.service

- Check cli

redis-cli

Assuming that you renamed the CONFIG command to ASC12_CONFIG, now try using the CONFIG command as it was:
config get requirepass
systme will return error:
Output
(error) ERR unknown command `config`, with args beginning with:

Now run again with the new command name:
asc12_config get requirepass
Output
1) "requirepass"
2) "your_redis_password"
exit

4. Backup data

Run save to save data into file dump.rdb
Run config get dir to known where file dump.rdb
Goto server need restore:
Run config get dir to know where file dump.rdb
stop redis (ex: sudo service redis-server stop)
Delete dump.rdb and copy new file dump.rdb
restart redis


Image:

Thank you.

 

Monday, 20 May 2024

Run script backup data in Mysql

DB_NAME="eccubedev"
DB_USER="root"
DB_PASS="your_password"
BACKUP_DIR="$HOME/backupDB/BackupFiles"
DATE=$(date +"%Y%m%d_%H%M%S")
BACKUP_FILE="$BACKUP_DIR/${DB_NAME}_backup_$DATE.sql"
TOTAL_BACKUP_FILES=100

# Create backup directory if it doesn't exist
mkdir -p $BACKUP_DIR

# Dump the database
mysqldump -u $DB_USER -p$DB_PASS $DB_NAME > $BACKUP_FILE

# Delete oldest backups, keeping only the most recent $TOTAL_BACKUP_FILES
cd $BACKUP_DIR
NUM_FILES=$(ls -1 | wc -l)
if [ $NUM_FILES -gt $TOTAL_BACKUP_FILES ]; then
    DELETE_FILES=$(expr $NUM_FILES - $TOTAL_BACKUP_FILES)
    ls -t | tail -n $DELETE_FILES | xargs rm -f
fi

Thank you

Cron Job on Linux

sudo crontab -u {username} -e

crontab -e

* * * * * /bin/bash /home/phong/backupDB/backup_mysql.sh

crontab -l

- List crontab

Run Cron JobCommand
Every Minute* * * * * /path/to/script
Every 15 Minutes*/15 * * * * /path/to/script
On the 30th Minute of Every Hour30 * * * * /path/to/script
At the Beginning of Every Hour0 * * * * /path/to/script
Every Day at Midnight0 0 * * * /path/to/script
At 2 AM Every Day0 2 * * * /path/to/script
Every 1st of the Month0 0 1 * * /path/to/script
Every 15th of the Month0 0 15 * * /path/to/script
On December 1st - Midnight0 0 1 12 * /path/to/script
Saturdays at Midnight0 0 * * 6 /path/to/script
Every Weekday at 4 AM0 4 * * 1-5 /path/to/script
At 4 AM on Tuesdays and Thursdays0 4 * * 2,4 /path/to/script
Every Other Day at 37 Minutes Past the Hour37 1-23/2 * * * /path/to/script
Every 20 Minutes - Multiple Scripts*/20 * * * * /path/to/script1; /path/to/script2
On Saturdays and Sundays at 12 PM0 12 * * 6,0 /path/to/script
Monday to Friday - Every Hour 9 AM to 5 PM0 9-17 * * 1-5 /path/to/script
Every Hour from 5 PM on Wednesday to 5 AM on Thursday (Job Spans Two Days)0 17-23 * * 3 /path/to/script
0 0-5 * * 4 /path/to/script
Midnight Every Day - Send Output to a Different File0 0 * * * /path/to/script > /path/to/output.log 2>&1

Publish npm package

  Để publish   pav-kit  lên NPM, bạn hãy làm theo các bước dưới đây. Tôi đã tạo thêm file  index.js  để đảm bảo gói tin hợp lệ. Bước 1: Tạo ...