January 22

nagios: monitor cxs_report

/usr/lib64/nagios/plugins/check_cxs_report
#!/bin/bash
#
# Plugin to check cxs report
# By Vasliy T.
##########################################################
normal=0
crit=1

use=`/scripts/cxs_report |grep -i "Fingerprint\|Virus\|Known\|hidden script"|wc -l`

if [[ "$use" -eq "$normal" ]]
then
echo "OK: Malware not Detected"
exit 0
else
echo "Critical: $use viruses found"
exit 2
fi

/etc/nagios/nrpe.cfg

command[cxs]=/usr/bin/sudo /usr/lib64/nagios/plugins/check_cxs_report

/etc/nagios/conf.d/server.cfg
define service{
use generic-service
host_name server
service_description cxs
check_command check_nrpe_1arg!cxs
}

January 4

restart_apache_if_load.sh

#!/bin/bash
load=`/usr/bin/uptime | awk -F 'load average: ' '{print$2}'|awk -F ',' '{print$1}'`
check=`echo "$load>8"|bc`
if [ "$check" -eq "1" ]; then
killall -9 php -v;killall -9 php-cgi -v;killall -9 -u nobody -v; /scripts/restartsrv_httpd; service nginx restart
time=`/bin/date +'%H:%M:%S %Y-%m-%d'`
echo "Apache has been restarted due to load $load at $time" >> /root/restart_apache.log
fi

January 4

Mount a VirtualBox drive image as disk (mount to folder) in 3 ways

1.
yum install ntfs-3g ntfsprogs
VBoxManage clonehd --format RAW ubuntu.vdi ubuntu.img

To determine the correct offset you can run:
# fdisk -l image.img

Disk choban.img: 157.3 GB, 157286400000 bytes, 307200000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x3a3a2d46

Устр-во Загр Начало Конец Блоки Id Система
ubuntu.img1 * 63 39037949 19518943+ 7 HPFS/NTFS/exFAT
ubuntu.img2 39037950 307199999 134081025 5 Extended
ubuntu.img5 39038013 307194929 134078458+ 7 HPFS/NTFS/exFAT

For example if start is 128 and sector size is 512 then the offset is 65536. (128*512=65536)
mount -o loop,offset=32256 ubuntu.img /mnt/image/

2.
apt-get install virtualbox-fuse
vdfuse -a -f /path-to-vdi-file /mnt
mount -o loop /mnt/Parition1 /mountpoint

3.
apt-get install qemu
rmmod nbd
modprobe nbd max_part=16
qemu-nbd -c /dev/nbd0 drive.vdi
mount /dev/nbd0p1 /mnt
qemu-nbd -d /dev/nbd0

January 4

fsck on raid device

1. to get raid devices:mdadm --examine --scan

2. to add raid devices to mdadmin config:
mdadm --examine --scan >> /etc/mdadm.conf

3. mount md device:
mdadm --assemble /dev/md2

4. run the check:
fsck -yf /dev/md2

November 13

install mod_cloudflare on apache 2.4

1.
bash < (curl -s https://raw.githubusercontent.com/cloudflare/mod_cloudflare/master/EasyApache/installer.sh)

2.
yum install -y ea-apache24-devel.x86_64 ea-apache24-debuginfo.x86_64

3.
wget https://www.cloudflare.com/static/misc/mod_cloudflare/mod_cloudflare.c

4.
apxs -a -i -c mod_cloudflare.c

5.
service httpd restart

November 10

install ssl nginx/apache

Apache:
a2enmod ssl

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/site_name.crt
SSLCertificateKeyFile /etc/apache2/ssl/site_name.key
SSLCertificateChainFile /etc/apache2/ssl/site_name.ca-bundle

apachectl configtest

Nginx:
listen server_ip:443;
ssl on;
ssl_certificate "/etc/nginx/ssl/site_name.crtca";
ssl_certificate_key "/etc/nginx/ssl/site_name.key";
ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

October 28

make drupal/drush configuration

Drupal php:
yum install -y ea-php56-php-mcrypt.x86_64 cpanel-php56-PEAR-Command-Packaging.noarch ea-php56-php-mbstring.x86_64 ea-php56-php-iconv.x86_64
pecl install uploadprogress
You should add "extension=uploadprogress.so" to php.ini
You should change allow_url_open to: allow_url_open=1

Drupal Ruby:
/scripts/installruby
gem install compass compass-rgbapng gems sass

Drupal Drush:

cd /opt/ && php -r "readfile('https://s3.amazonaws.com/files.drush.org/drush.phar');" > drush
#make installation test
php drush core-status
chmod +x drush && mv -v drush /usr/local/bin/

#login under user account and make

drush init

October 24

install csf => CentOS, Debian, AlmaLinux, etc.

1. Step one => requested packages:

Debian or Debian-based OS (like Ubuntu, etc.):
apt update;apt upgrade -y;apt install -y wget libio-socket-ssl-perl git perl iptables libnet-libidn-perl libcrypt-ssleay-perl ipset libio-socket-inet6-perl libsocket6-perl sendmail dnsutils unzip zip ncdu mc lynx
Centos or other Redhat-based OS (Almalinux, etc.)
yum update -y;yum install -y epel-release;yum install -y perl-Crypt-SSLeay perl-Net-SSLeay bind-utils perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph nano wget mc lsof nload tcpdump monit rsync zip unzip ipset langpacks-en glibc-all-langpacks perl-Math-BigInt-FastCalc iptables lynx
2. Step two => installing CSF itself

cd /usr/src
wget https://download.configserver.com/csf.tgz
tar -xzf csf.tgz
cd csf
sh install.sh
==
perl /usr/local/csf/bin/csftest.pl
==

perl /etc/csf/csftest.pl