Extraits de code SystM

des bouts de code bash et autre pour debian et autres linux based servers

Configurations

des réglages aux petits oignons

Configurations

Swap file and swapiness for production servers

Swapfile

Howto create a 2Gb swapfile, enable it, and add to fstab

fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Swapiness

While the swappiness value of 60 is OK for most Linux systems, for production servers, you may need to set a lower value.

For example, to set the swappiness value to 10, run:

sysctl vm.swappiness=10

To make this parameter persistent across reboots, append the following line to the /etc/sysctl.conf file:

/etc/sysctl.conf
vm.swappiness=10

ffmpeg

ffmpeg

ffmpeg : Transformer un son wav en mp3

cette commande permet de convertir un audio du format wav au format mp3 :

 ffmpeg -i son.wav -acodec mp3 -ab 128k son.mp3

merci qui? merci ffmpeg!

ffmpge.jpg

ffmpeg

ffmpeg : transformer un mp4 en webm

la commande suivant converti une vidéo au format mp4 en webm avec les bons codecs audio / video :

ffmpeg -i video.mp4 -vf scale=1920:1080 -movflags faststart -f webm -c:v libvpx -b:v 3M -acodec libvorbis video.webm

merci qui, merci ffmpeg!

ffmpge.jpg

Automatisations

Server hints

Server hints

mysql / mariadb : create db, user and grant oneliner

CREATE DATABASE dbname CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; CREATE USER dbuser@localhost identified by 'pwd'; GRANT ALL PRIVILEGES on dbname.* to dbuser@localhost; FLUSH privileges;

 

Restore a Single MySQL Database from a Full MySQL Dump

If you backed up all your databases using the -all-databases option and you want to restore a single database from a backup file which contains multiple databases use the --one-database option as shown below:

mysql --one-database database_name < all_databases.sql

Export and Import a MySQL Database in One Command

Instead of creating a dump file from one database and then import the backup into another MySQL database you can use the following one-liner:

mysqldump -u root -p database_name | mysql -h remote_host -u root -p remote_database_name

The command above will pipe the output to a mysql client on the remote host and it will import it into a database named remote_database_name. Before running the command, make sure the database already exists on the remote server

Server hints

fail2ban : list banned IPs and unban

to find all banned IPs for a specific jail, example sshd jail :

fail2ban-client status sshd

then unban the desired IP :

fail2ban-client set sshd unbanip xx.xx.xx.xx