tar -PcJf - /home | pv -s $(du -sb /home/user | awk '{print $?}') | xz -z -T0 -1 - > /mnt/backupTarget/home.tar.xz
Tag: Linux
MSSQL on kubernetes (non azure)
1. Copy the code below into a file named mssql.yaml
2. Apply the deployment file to your kubernetes cluster using:
sed -i s/TXlDMG05bCZ4UEBzc3cwcmQ=/$(pwgen -s 120 1 | base64 -w 0)/ mssql.yaml; kubectl apply -f mssql.yaml
Note: username and password are base64 encoded and NOT encrypted.
Therefore do not store your credentials this way in a production environment, use
read -sep "Enter mssql sa password: " mssql_sa_pass; kubectl create secret generic mssql2 --from-literal=password=$mssql_sa_pass --type=kubernetes.io/basic-auth
instead of adding it to the deployment yaml file.
apiVersion: v1 data: username: c2EK password: TXlDMG05bCZ4UEBzc3cwcmQ= kind: Secret metadata: name: mssql type: kubernetes.io/basic-auth --- apiVersion: apps/v1 kind: Deployment metadata: name: mssql-deployment spec: replicas: 1 selector: matchLabels: app: mssql template: metadata: labels: app: mssql spec: terminationGracePeriodSeconds: 10 containers: - name: mssql image: mcr.microsoft.com/mssql/server:latest ports: - containerPort: 1433 env: - name: MSSQL_PID value: "Developer" - name: ACCEPT_EULA value: "Y" - name: SA_PASSWORD valueFrom: secretKeyRef: name: mssql key: password volumeMounts: - name: mssql mountPath: /var/opt/mssql volumes: - name: mssql hostPath: path: /srv/mssql type: DirectoryOrCreate initContainers: - name: install image: busybox command: - chown - "10001:10001" - "/work-dir" volumeMounts: - name: mssql mountPath: "/work-dir" --- apiVersion: v1 kind: Service metadata: name: mssql-deployment spec: selector: app: mssql ports: - protocol: TCP port: 1433 targetPort: 1433 type: LoadBalancer
iptables to rsyslog
log all dropped connections to syslog
iptables -N LOGGING iptables -A INPUT -j LOGGING iptables -A OUTPUT -j LOGGING iptables -j LOG --log-prefix "iptables: " iptables -A LOGGING -j DROP
check that this line is in /etc/rsyslog.conf
$ModLoad imklog
after that create the file /etc/rsyslog.d/01-iptables.conf with the content:
:msg, startswith, "iptables: " -/var/log/iptables.log & ~ :msg, regex, "^\[ *[0-9]*\.[0-9]*\] iptables: " -/var/log/iptables.log & ~
line 1 and line 3 are filters and log file locations, if they match the log is written to the specified log file.
line 2 and 4 tell rsyslog “don’t process future rules (if the one before matches), it’s done for this log entry”
now the only thing left is to create a log rotation rule
create the file /etc/logrotate.d/iptables with this content:
/var/log/iptables.log { rotate 7 daily missingok notifempty delaycompress compress postrotate invoke-rc.d rsyslog rotate > /dev/null iptables-save >> /var/log/iptables.log endscript }
Apache2 optimizations
To gain a faster page loading, you can enable the client side caching. That means that the browser of the connecting clients is storing the contents of your page until it expires.
Therefore you have to add the following under your virtual host entry (right before </VirtualHost>)
<IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 10 seconds" ExpiresByType text/html "access plus 60 seconds" ExpiresByType image/gif "access plus 120 minutes" ExpiresByType image/jpeg "access plus 120 minutes" ExpiresByType image/png "access plus 120 minutes" ExpiresByType text/css "access plus 60 minutes" ExpiresByType text/javascript "access plus 60 minutes" ExpiresByType application/javascript "access plus 60 minutes" ExpiresByType application/x-javascript "access plus 60 minutes" ExpiresByType text/xml "access plus 60 minutes" </IfModule>
After that run the following as root:
cd /etc/apache2/mods-enabled ln -s ../mods-available/expires.load expires.load ln -s ../mods-available/headers.load headers.load service apache2 restart
Also if you want to redirect all http traffic to https you should use HTTP Response code 301 instead of 302. This is something that is nearly everywhere you look for http to https redirects missing (“R=301”).
To accomplish this you simply have to replace “<VirtualHost *>” at the beginning of your website configuration file (replace server names 😉 ) with:
<VirtualHost example.org:80> ServerName www.example.org # Redirect http://(www.)example.org/* to https://www.example.org/* RewriteEngine On RewriteCond %{HTTP_HOST} ^(?:.*)example\.org$ [NC] RewriteCond %{SERVER_PORT} !^443$ RewriteRule (.*) https://www.example.org$1 [R=301,L] </VirtualHost> <VirtualHost example.org:443>
Also you should use the ServerName attribute and avoid using “<VirtualHost *>” for convenience and later usage.
Configuring https is as simple. First you have to get your certificate use startssl or lets encrypt.
After you have managed to get your certificate for (www.example.org; don’t miss typing the www subdomain 😉 ) place the files in the following directory:
The Private key: /etc/ssl/private/example.org.key
The Certificate File: /etc/ssl/certs/example.org.crt
The Intermediate Certificates File (e.g. lets encrypt or sub.class1.server.ca.pem): /etc/ssl/certs/letsencryptauthorityx1.pem or /etc/ssl/certs/sub.class1.server.ca.pem
After the files are there you have to add some text to your VirtualHost configuration section
<VirtualHost example.org:443> ServerAdmin webmaster@example.org ServerName www.example.org SSLEngine on SSLCertificateFile /etc/ssl/certs/example.org.crt SSLCertificateKeyFile /etc/ssl/private/example.org.key SSLCertificateChainFile /etc/ssl/certs/sub.class1.server.ca.pem SSLProtocol ALL -SSLv2 -SSLv3 SSLHonorCipherOrder on # SSLCipherSuite ALL:!ADH:!RC4:+HIGH:!MEDIUM:!LOW:!SSLv2:!SSLv3!EXPORT SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256" # Replace Certificate Hashes below Header always add Public-Key-Pins "pin-sha256=\"Vjs8r4z+80wjNcr1YKepWQboSIRi63WsWXhIMN+eWys=\"; pin-sha256=\"YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg=\"; max-age=2592000; includeSubdomains" Header always add Strict-Transport-Security "max-age=15768000" Header always add Content-Security-Policy "default-src 'self';frame-ancestors 'self';style-src 'self' 'unsafe-inline';script-src 'self' 'unsafe-inline' 'unsafe-eval';font-src 'self' data:;img-src 'self' data:" Header always add X-Content-Type-Options "nosniff" Header always add X-Frame-Options "sameorigin" Header always add X-XSS-Protection "1;mode=block"
As soon as WordPress stops using inline scripts, inline styles, fonts as “data:” urls and also images as “data:” urls, the line:
Header always add Content-Security-Policy "default-src 'self';frame-ancestors 'self';style-src 'self' 'unsafe-inline';script-src 'self' 'unsafe-inline' 'unsafe-eval';font-src 'self' data:;img-src 'self' data:"
can be changed to the more secure
Header always add Content-Security-Policy "default-src 'self';frame-ancestors 'self'"
Disable Zone Transfer BIND9
If you use webmin go to “Zone Defaults” and enter “none” into the “Allow transfers from…” text box.
If you don’t use webmin go to the file “/etc/bind/named.conf.options” and enter the following:
allow-transfer { "none"; };
If this file doesn’t exist for you, just chech the config file “/etc/bin/named.conf” if there is an include with the ending “.conf.options” use that and otherwise enter directly in named.conf as last possibility (but check other included config files if it exists elsewhere).
Logfile Monitoring (PowerShell/Bash)
PowerShell:
Get-Content -Path .\log.txt -Tail 1 -Wait
Bash:
$Â tail -f filename $Â less +F filename $Â watch tail logfile
Status Monitoring – Statusbar
How to have one line updated, for example showing available disk space updated every second.
Within one line:
while true; do echo -ne “$(df | grep /dev/sda4)\\r”; sleep 1; done
how it works:
while true: start of endless loop
- echo:
- -n: prevents line warp after outputting
- -e: allows backslash escape keys
- $(command): Runs the command and inserts the output
- \\r: the first backslash escapes the second, and \r stands for jumping to the beginning of the line
- sleep 1: pause for one second
done: end of endless loop
Within a script, you can write it into multiple lines:
while true
do
   echo -ne “$(df | grep /dev/sda4)\\r”
   sleep 1
done