rsync -zarv --prune-empty-dirs --include "*/" --include="*.gif" --exclude="*" ./ ../gifs/
среда, 7 августа 2024 г.
четверг, 18 апреля 2024 г.
Linux Bash rsync remote to remote with forwarding keys
We need it for loading files directly from one remote server to another one where we have SSH access.
SSH access from a Workstation -> Server1 -> rsync loading files -> Server2
ssh -v username@server1
find an identity SSH key for sure
ssh-add <the_key>
ssh -A username@server1
run with A option for allowing forwarding keys
rsync -azP --exclude '.4y8-folder' --exclude 'file.tar.gz' pub/media/ username@server2:pub/media/
среда, 24 мая 2023 г.
Linux Bash rsync only specific a files list
Check rsync --help whether it supports --files-from= option
lst content
./folder-source/1/1
./folder-source/2/2
...
cd to a folder where folder-source as a sub-folder (it's an explanation of period "." in rsync command)
rsync --files-from=/tmp/lst . /app/var/folder-sync
среда, 21 декабря 2022 г.
пятница, 11 ноября 2022 г.
Linux logrotate jira logs
Jira has its own log rotate
However, it doesn't delete old files.
It can be done with crontab though.
#### remove old jira log files longer 180 days
30 2 * * * /usr/bin/find /opt/atlassian/servicedesk/logs/ -maxdepth 1 -type f -mtime +180 -exec rm -rf {} \;
45 2 * * * /usr/bin/find /opt/atlassian/servicedesk/logs/ -maxdepth 1 -type f -mtime +6 -exec gzip -q {} \;
суббота, 26 февраля 2022 г.
Linux logrotate twice per day
Before:
/etc/logrotate.d/logs
/mnt/shared/project/var/log/*.log
}
After:
1) create a separate additional logrotate conf file /etc/logrotate.d/logs_erp with content below (increased twice rotate 30 -> 60 and plus delaycompress):
четверг, 16 сентября 2021 г.
Linux Bash check disk space
df --output=pcent / | tail -n +2 | tr -cd '0-9\n'
output available percent without header and symbol '%' - only number
#!/bin/bash
for mnt in / /var/log /var/www /mnt/shared; do
chk_avail=`df --output=pcent $mnt | tail -n +2 | tr -cd '0-9\n'`
flg=`echo $(( 100 - $chk_avail ))`
if [ $flg -lt 15 ]; then
echo 'Dataserver lack of free space, only '$flg' percent available in '$mnt' partition' | mail -s 'Dataserver lack of free space' alerts@gmail.com
fi
done
воскресенье, 14 марта 2021 г.
find for time interval
find . -maxdepth 1 -newermt '2019-01-01' ! -newermt '2021-02-15' -name "importexport_*" -exec ls -l '{}' \;
понедельник, 28 октября 2019 г.
Linux Ubuntu 18.04 Use redis for cache pages and PHP sessions storage
четверг, 24 октября 2019 г.
Linux Ububntu 18.04 Use memcached for PHP session storage
/etc/php/7.2/fpm/php.ini
session.save_handler = "memcached"
session.save_path = "127.0.0.1:11211"
or /etc/php/7.2/fpm/pool.d/user.conf
php_admin_value[session.save_path] = '127.0.0.1:11211'
php_admin_value[session.save_handler] = 'memcached'
phpinfo should display memcached info on the page.
Check working with a script cache-test.php
вторник, 13 августа 2019 г.
Linux Postfix 530 5.7.0 must issue a starttls command first
Решение:
было в master.cf
-o smtpd_tls_security_level=encrypt
помогло
-o smtpd_tls_security_level=may
пятница, 2 августа 2019 г.
Linux mariadb doesn't start after upgrading to Debian 10
status
Process: 1232 ExecStartPost=/etc/mysql/debian-start (code=exited, status=203/EXEC)
journal -xe
mariadb.service: Failed at step EXEC spawning /etc/mysql/debian-start: No such file or directory
resolving
https://stackoverflow.com/questions/51317209/mariadb-10-3-8-installation-from-mariadb-repo-missing-files
apt install --reinstall -o Dpkg::Options::="--force-confmiss" mariadb-server-10.3
226 error in LXC container
четверг, 25 июля 2019 г.
Linux RabbitMQ-server cluster
https://www.rabbitmq.com/clustering.html
https://kamaok.org.ua/?p=2689
https://blog.flux7.com/blogs/tutorials/how-to-creating-highly-available-message-queues-using-rabbitmq
1) add hostname (do real hostname) between master and slave to /etc/hosts
2) copy /var/lib/rabbitmq/.erlang.cookie from master to slave
systemctl restart rabbitmq-server (on slave)
3) join to cluster
Stopping rabbit application on node rabbit@<hostname_slave> ...
Resetting node rabbit@<hostname_slave> ...
rabbitmqctl join_cluster rabbit@<hostname_slave>
Clustering node rabbit@<hostname_slave> with rabbit@<hostname_master>
rabbitmqctl start_app
Starting node rabbit@<hostname_slave> ...
completed with 0 plugins.
4) check cluster
rabbitmqctl cluster_status
Cluster status of node rabbit@<hostname_slave> ...
[{nodes,[{disc,[rabbit@<hostname_master>,rabbit@<hostname_slave>]}]},
{running_nodes,[rabbit@<hostname_master>,rabbit@<hostname_slave>]},
{cluster_name,<<"rabbit@localhost">>},
{partitions,[]},
{alarms,[{rabbit@<hostname_master>,[]},{rabbit@<hostname_slave>,[]}]}]
5) Configure syncing queues police between master and slave nodes
Run on master
rabbitmqctl set_policy ha-all "" '{"ha-mode":"all","ha-sync-mode":"automatic"}'
https://www.rabbitmq.com/ha.html
ha-sync-mode: manual
- this is the default mode. A new queue mirror will not receive existing messages, it will only receive new messages. The new queue mirror will become an exact replica of the master over time, once consumers have drained messages that only exist on the master. If the master queue fails before all unsychronised messages are drained, those messages will be lost. You can fully synchronise a queue manually, refer to unsynchronised mirrors section for details.
ha-sync-mode: automatic
- a queue will automatically synchronise when a new mirror joins. It is worth reiterating that queue synchronisation is a blocking operation. If queues are small, or you have a fast network between RabbitMQ nodes and the ha-sync-batch-size was optimised, this is a good choice.
for / vhost
rabbitmqctl set_policy ha-all "" '{"ha-mode":"all","ha-sync-mode":"automatic"}'
Setting policy "ha-all" for pattern "" to "{"ha-mode":"all","ha-sync-mode":"automatic"}" with priority "0" for vhost "/" ...
for vhost1 vhost
rabbitmqctl set_policy ha-all "" '{"ha-mode":"all","ha-sync-mode":"automatic"}' -p vhost1
Setting policy "ha-all" for pattern "" to "{"ha-mode":"all","ha-sync-mode":"automatic"}" with priority "0" for vhost "vhost1" ...
вторник, 23 июля 2019 г.
Linux ucarp promote slave to master
# номер группы (число от 1 до 255) одинаковый для всех серверов;
ucarp-vid 1
ucarp-vip 192.168.1.125
ucarp-password fahDo7zaze
ucarp-advskew 1
ucarp-advbase 1
ucarp-master yes
# Виртуальный интерфейс
iface eth0:ucarp inet static
address 192.168.1.125
netmask 255.255.255.0
Отсюда следует,
- меняем ucarp-advskew 50 для slave и 10 для master
- ucarp-master yes и ucarp-master no меняем соответсвенно
killall -USR2 ucarpпроверяем ip a s
Linux nginx configs backup
mkdir -p /root/sshkey-for-nginx-backup
chmod 0600 /root/sshkey-for-nginx-backup
ssh-keygen -t rsa -b 4096 -f /root/sshkey-for-nginx-backup/id_rsa -C sshkey-for-nginx-backup@hostname
copy ssh pub key to remote server
apt install zstd
#!/bin/bash
function logging {
echo $(date +%F_%H-%M) "______" "$1"
}
current_date=`date +%F`
tar -cf - /etc/nginx /etc/letsencrypt | zstd -19 | ssh -p 2202 -i /root/sshkey-for-nginx-backup/id_rsa -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no hostname-backup@1.2.3.4 "cat - > /var/www/backup/hostname/nginx.hostname.$current_date.tar.zst" && logging "Backup was sent successfully ..." || logging "Backup wasn't created ..."
Скрипт будет запускаться по крону каждый день
понедельник, 22 июля 2019 г.
Linux Bash parse IPs from log by word
Mon Jul 22 05:38:54 2019 1.2.3.4:6252 VERIFY ERROR: depth=0, error=certificate revoked: ...
grep revoked openvpn.log | awk '{ print $6 }' | awk -F":" '{ print $1 }' | sort | uniq -u
awk -F":" разделитель, это парсим 1.2.3.4:6252 для получения только IP
Чтобы использовать uniq, сначала нужно отсортировать sort
пятница, 19 июля 2019 г.
Linux grep remove # and white_space
grep -v '#' redis.conf | grep -v "^[[:space:]]*$"
понедельник, 15 июля 2019 г.
Linux sudo keep environment variables APP_ENV
Добавить в sudoers.d в пользовательский конфиг
Defaults env_keep += "APP_ENV"
среда, 3 июля 2019 г.
Linux /bin/ls: Argument list too long
Решение https://www.in-ulm.de/~mascheck/various/argmax/ , из параграфа
How to avoid the limit in a shell выбрал этот вариант:
find /home/folder -mtime +7 -print0 -type f | xargs -0 rm -rf
Все файлы старше семи дней удаляются
Linux rabbitmq-server add read-only user
rabbitmq-plugins enable rabbitmq_management
Заводим нового пользователя
rabbitmqctl add_user username usernamePassword
Чтобы подключаться удаленно, нужно дать доступ