10/16/2019
Compress MP4 files
How to compress the MP4 files.
find . -type f -name "*.MP4" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -s 1280x720 -acodec copy -y "${FILE%.mp4}.shrink.mp4";' _ '{}' \;
Varnish Exemple for CACHE and Optimisation
Varnish Optimisation cache |
---|
# # This is an example VCL file for Varnish. # # It does not do anything by default, delegating control to the # builtin VCL. The builtin VCL is called when there is no explicit # return statement. # # See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/ # and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples. # Marker to tell the VCL compiler that this VCL has been adapted to the # new 4.0 format. vcl 4.0; # Default backend definition. Set this to point to your content server. backend default { .host = "127.0.0.1"; .port = "8080"; } sub vcl_recv { # Happens before we check if we have this in cache already. # # Typically you clean up the request here, removing cookies you don't need, # rewriting the request, etc. # Happens before we check if we have this in cache already. # # Typically you clean up the request here, removing cookies you don't need, # rewriting the request, etc. # Properly handle different encoding types if (req.http.Accept-Encoding) { if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|woff)$") { # No point in compressing these unset req.http.Accept-Encoding; } elsif (req.http.Accept-Encoding ~ "gzip") { set req.http.Accept-Encoding = "gzip"; } elsif (req.http.Accept-Encoding ~ "deflate") { set req.http.Accept-Encoding = "deflate"; } else { # unknown algorithm (aka crappy browser) unset req.http.Accept-Encoding; } } # Cache files with these extensions if (req.url ~ "\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|woff)$") { unset req.http.cookie; return (hash); } # Dont cache anything thats on the blog page or thats a POST request if (req.url ~ "^/blog" || req.method == "POST") { return (pass); } # This is Laravel specific, we have session-monster which sets a no-session header if we dont really need the set session cookie. # Check for this and unset the cookies if not required # Except if its a POST request if (req.http.X-No-Session ~ "yeah" && req.method != "POST") { unset req.http.cookie; } return (hash); } sub vcl_backend_response { # Happens after we have read the response headers from the backend. # # Here you clean the response headers, removing silly Set-Cookie headers # and other mistakes your backend does. # set beresp.ttl = 30s; set beresp.grace = 24h; if (beresp.ttl < 120s) { unset beresp.http.cookie; unset beresp.http.Set-Cookie; set beresp.ttl = 120s; unset beresp.http.Cache-Control; } } sub vcl_deliver { # Happens when we have all the pieces we need, and are about to send the # response to the client. # # You can do accounting or modifying the final object here. } |
Linux Compress PDF batch
#### gs
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf $INPUTFILE
### pdf2ps && ps2pdf
pdf2ps input.pdf output.ps && ps2pdf output.ps output.pdf
### Webservice
http://compress.smallpdf.com/de
For linux
#!/bin/sh
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages -dCompressFonts=true -r150 -sOutputFile="compress_$@" "$@"
./compresspdf.sh file.pdf
find -type f -name "*.pdf" -exec ./compresspdf.sh {} \;
#!/bin/sh INPUT=$1; shift OUTPUT=$1; shift GS_BIN=/usr/bin/gs QFACTOR="0.40" # Image Compression Quality # # Quality HSamples VSamples QFactor # Minimum [2 1 1 2] [2 1 1 2] 2.40 # Low [2 1 1 2] [2 1 1 2] 1.30 # Medium [2 1 1 2] [2 1 1 2] 0.76 # High [1 1 1 1] [1 1 1 1] 0.40 # Maximum [1 1 1 1] [1 1 1 1] 0.15 ${GS_BIN} -dBATCH -dSAFER -DNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=${OUTPUT} -c "<< /ColorImageDict << /QFactor ${QFACTOR} /Blend 1 /HSample [1 1 1 1] /VSample [1 1 1 1] >> >> setdistillerparams" -f ${INPUT}
For windows
echo off :: PDF to PCL Converter. Needs Ghostscript locally, and installed here: "C:\Program Files\gs\gs9.02\bin\gswin32c.exe" :: Other versions of GS will work, but the script will have to be updated. :: Users can enter the breakpoint for the PCL files. If none is provided, 100 is used. cls echo This program will take all the PDF files in the current directory echo and group them into PCL files. If you ran echo this from the command line, you could enter the breakpoint for echo number of PDF files per PCL. If left blank or not entered, the echo program defaults to 100. echo. echo If you want to continue, hit any key and please wait for the echo program to complete processing (could take a while). echo If you want to stop now, hit CTRL-C and exit out of the batch. pause setlocal enabledelayedexpansion set INC=%1 if "%1%" == "" set INC=100 SET GSS= SET CTR=0 SET FL=1 for %%i in (*.pdf) DO ( SET GSS=!GSS! "%%i" SET /a CTR+=1 echo !CTR! COUNTER !FL! OUTPUTFILE NUMBER if !CTR! == %INC% ( "C:\Program Files\gs\gs9.02\bin\gswin32c.exe" -dNOPAUSE -dBATCH -sDEVICE=laserjet -sOutputFile=File_!FL!.pcl !GSS! echo "C:\Program Files\gs\gs9.02\bin\gswin32c.exe" -dNOPAUSE -dBATCH -sDEVICE=laserjet -sOutputFile=File_!FL!.pcl !GSS! set /a FL+=1 echo !FL! FL set CTR=0 set GSS= ) ) if NOT !CTR! == 0 ( echo LAST PROCESS "C:\Program Files\gs\gs9.02\bin\gswin32c.exe" -dNOPAUSE -dBATCH -sDEVICE=laserjet -sOutputFile=File_!FL!.pcl !GSS! ) endlocal echo Complete. echo on
10/15/2019
resize images in Linux
Reduce images files png or jpg jpeg in subdirectories
find -type f -name "*.jpeg" -exec jpegoptim --strip-all {} \;
optipng *.png
find -type f -name "*.png" -exec optipng {} \;
8/09/2019
Azure remove certificate error
Azure remove certificate error
Failed to delete the App Service Certificate. : Delete for 'certificatelalala' App Service Certificate failed because there are still imported certificates derived from the App Service Certificate in the source subscription. Imported certificates: /subscriptions/123456avbcbcvbcm,ddsadada-7s8s9s987s78s/resourceGroups/webapplalala/providers/Microsoft.Web/certificates/certificatelalala-WestEuropewebspace
Go to
https://resources.azure.com/
navigate to subscriptions -->
specific subscription
--> providers --> Microsoft.Web --> certificates and see if it
is here and i think you can delete it from here directly.7/12/2019
VirtualBOX MAC resolution problem
In windows, run CMD in admin mode,
enter in VirtualBox folder,
run the command
VBoxManage setextradata “Hackintosh” “CustomVideoMode1” “3240x2160x32” && VBoxManage setextradata “Hackintosh” “VBoxInternal2/EfiGraphicsResolution” 3240x2160
6/12/2019
Haproxy Monitoring or BLOCK DDOS
How to monitor or block DDOS in Haproxy
# Returns a 403 to
the abuser and flags for tcp-reject next time
Configuration
to monitor access
This configuration
just will TAG the external IP in the
abuse table, if need block something just remove the double #, to change
the level of monitoring increase or reduce the number of connection level.
#
ABUSE SECTION works with http mode dependent on src ip
##tcp-request content reject if { src_get_gpc0(Abuse) gt 5000 }
acl abuse src_http_req_rate(Abuse) ge 5000
acl flag_abuser src_inc_gpc0(Abuse) ge 100
acl scanner src_http_err_rate(Abuse) ge 5000
#
Abuse protection.
#
Sources that are not filtered.
tcp-request
content accept if { src -f /etc/haproxy/whitelist.lst }
#
Sources rejected immeditely.
tcp-request
content reject if { src -f /etc/haproxy/blacklist.lst }
#
Limiting the connection rate per client. No more than 5000 connections over 3
seconds.
##tcp-request content reject if { src_conn_rate(Abuse) ge 5000 }
#
Reject if more than 1000 connections from client.
#
This is to accommodate clients behind a NAT.
##tcp-request content reject if { src_conn_cur(Abuse) ge 1000 }
#
Block based on backend.
##tcp-request content reject if { src_get_gpc0(Abuse) gt 5000 }
#
Track counters based on forwarded ip.
##tcp-request content
track-sc1 src table Abuse
When the rule BLOCK is enabled you can choose the return 403 or silent-drop t9
# Returns a 403 to
the abuser and flags for tcp-reject next time
http-request deny if abuse flag_abuser
http-request deny if scanner flag_abuser
Monitoring
Show the stick table
that there the top IP
echo
"show table Abuse" | socat unix-connect:/var/run/haproxy/admin.sock
stdio
hatop -s
/var/run/haproxy/admin.sock
It's possible connect external tools like
Microsoft OMS
Datadog
Prometheus.
Splunk
And others APMs
6/07/2019
SSH / Putty or similar freeze,
Change the MTU
Putty / SSH / Termius freeze.
After changing the MTU of Windows TAP adapter to 1200, it works fine.
5/16/2019
Azure Mysql in app, error #2002
In the Azure WEB APP , MYSQL IN APP, you get this error
azurewebsites.net/phpMyAdmin/
Erreur :
#2002 - An attempt was made to access a socket in a way forbidden by its access permissions.
— The server is not responding (or the local server's socket is not correctly configured).
mysqli_real_connect(): (HY000/2002): An attempt was made to access a socket in a way forbidden by its access permissions.
— The server is not responding (or the local server's socket is not correctly configured).
mysqli_real_connect(): (HY000/2002): An attempt was made to access a socket in a way forbidden by its access permissions.
The solution is
5/09/2019
Got error 1 from storage engine
Using in the Azure Database for MySQL server
Got the error 1 when I tried to migrate the database
ERROR 1030 (HY000) at line Got error 1 from storage engine
Why?
https://blogs.msdn.microsoft.com/azuresqldbsupport/2017/06/08/azure-database-for-mysql-cant-restore-database-with-error-got-error-1-from-storage-engine/
"Got error 1 from storage engine"
While indicated to be a storage capacity issue on a MySQL server when researching this error, in Azure Database for MySQL this error is most commonly seen when the MyISAM storage engine is being used. Currently, MyISAM is not supported on Azure Database for MySQL. In this scenario, you will need to modify the tables to utilize a supported engine such as InnoDB. This is the engine that Azure Database for MySQL uses by default.
This article Converting MyISAM to InnoDB will help you understand the implications of changing from MyISAM and the suggested conversion steps to InnoDB. The most common method is to alter the existing table to utilize the InnoDB engine:
1
| ALTER TABLE table_name ENGINE=InnoDB; |
You can identify the tables in your database using MyISAM with this query:
1
2
| SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'dbname' AND engine = 'MyISAM' ; |
After converted, you will need to create a new dump of the database and try the import again.
If you already have the dump of the database or are unable to make changes to the source database, another approach is by editing the dump file with your favorite editor. You will want to find all instances of MyISAM in the dump file and replace with InnoDB. An example using vi in a Unix environment:
:%s/MyISAM/InnoDB/gc
This will allow a global search and confirmation of each change (drop the c to apply it for all instances without confirming each change).
With the edited dump file you will now be able to import without the previously observed error. In both methods, it is recommended to test this change before implementing into production.
In regards to support for MyISAM, see the comment from JasonH@MSFT in May 2017, at the end of article “What is Azure Database for MySQL? Service Introduction”:
“MyISAM support has been asked for several times, and has currently been denied in the feature feedback here because of lack of data consistency (think ACID principles): https://feedback.azure.com/forums/597982-azure-database-for-mysql/suggestions/19271050-add-myisam-engine-support
MyISAM has other limitations that don't make it right for this kind of service right now:
https://dba.stackexchange.com/questions/1/what-are-the-main-differences-between-innodb-and-myisam“
https://dba.stackexchange.com/questions/1/what-are-the-main-differences-between-innodb-and-myisam“
Repair. MySQL Storage Engine – How to Convert MyISAM to InnoDB
https://kinsta.com/knowledgebase/convert-myisam-to-innodb/
Step 2
Do a quick scan or sort of the “Type” column and you can see which Storage Engine types your tables are using. In this example below, you can see that two of the tables are still using MyISAM.
Do a quick scan or sort of the “Type” column and you can see which Storage Engine types your tables are using. In this example below, you can see that two of the tables are still using MyISAM.
Alternatively, you could run a query to see if any myISAM tables exist. Replace ‘database’ with your database name.
SELECT TABLE_NAME,
ENGINE
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'database' and ENGINE = 'myISAM'
Convert MyISAM to InnoDB with phpMyAdminYou can convert MyISAM to InnoDB fairly easily. This example is below is using the
wp_comments
table. Simply run the ALTER command to convert it to InnoDB storage engine. Note: We always recommend backing up your MySQL database before running any operations on it.ALTER TABLE wp_comments ENGINE=InnoDB;
Ensure you are running MySQL 5.6.4 or higher otherwise, you might run into issues where full-text indexing is not supported yet by InnoDB. If you are a Kinsta client you don’t need to worry about this.
Alternatively, you can also convert them manually with phpMyAdmin. Simply click on the myISAM table, click into the “Operations” tab, and change the storage engine.
Subscribe to:
Posts (Atom)