Install OpenDKIM with Postfix on CentOS

Install opendkim    ( epel repoor other sources )

Either find/add those options to the original config file, or even better, make a copy of the original file and replace /etc/opendkim.conf with the following:

AutoRestart             Yes      # Need to investigate this option !!!
AutoRestartRate         10/1h
LogWhy                  Yes
Syslog                  Yes
SyslogSuccess           Yes
Mode                    sv
Canonicalization        relaxed/simple
ExternalIgnoreList      refile:/etc/opendkim/TrustedHosts
InternalHosts           refile:/etc/opendkim/TrustedHosts
KeyTable                refile:/etc/opendkim/KeyTable
SigningTable            refile:/etc/opendkim/SigningTable
Selector                   mail
SignatureAlgorithm      rsa-sha256
Socket                  inet:8891@localhost
PidFile                 /var/run/opendkim/opendkim.pid
UMask                   022
UserID                  opendkim:opendkim
TemporaryDirectory      /var/tmp

Now we have to setup the public and private keys (replace yourdomain in the text with the apropriate domain name):

mkdir /etc/opendkim/keys/yourdomain
opendkim-genkey -D /etc/opendkim/keys/yourdomain/ -d yourdomain -s mail
chown -R opendkim: /etc/opendkim/keys/yourdomain
mv /etc/opendkim/keys/yourdomain/mail.private /etc/opendkim/keys/yourdomain/mail

Now we have to add it to the OpenDKIM keytable. Edit /etc/opendkim/KeyTable and add:

mail._domainkey.yourdomain yourdomain:mail:/etc/opendkim/keys/yourdomain/mail

Next step, adding the domain to the signing table. Edit /etc/opendkim/SigningTable, and insert:

*@mydomain.com mail._domainkey.mydomain.com

And the last move with DKIM, edit /etc/opendkim/TrustedHosts and add your LAN there.

Now we have to tell Postfix that we want to use OpenDKIM miltering. Edit /etc/postfix/main.cf and insert at the end of the file:

smtpd_milters = , inet:127.0.0.1:12768, inet:127.0.0.1:8891
non_smtpd_milters       = $smtpd_milters
milter_default_action   = accept
milter_protocol         = 6

The port 12768 is used by amavisd-new in this case !!!

Now we can try to start OpenDKIM and reload postfix:

service opendkim start
chkconfig opendkim on
service postfix reload

If everything worked well, You can send a test mail and see in the source and it contains a DKIM signature, tail /var/log/maillog -f and see the OpenDKIM entries like DKIM-Signature field added (s=mail, d=yourdomain)

Now you should add the dkim signature to your domain file (probably at your ISP). The exact signature as it should look was generated by the opendkim certificate generator, and it is located in /etc/opendkim/keys/yourdomain/mail.txt

TXT record – mail._domainkey

v=DKIM1; k=rsa; p=MIGfM………….

So, all you need is to insert it in the DNS zone file or send it to Your ISP if the DNS is hosted and after a while it will start to work. If you want to check if the DKIM signature is properly inserted in your DNS zone, you can do dig +short mail._domainkey.yourdomain TXT
and it should give You and answer with the hashed key.

Hint:
After a working OpenDKIM and SPF, you might want to join it together with the new DMARC technology!

 

SOURCE: https://www.prosinger.net/opendkim-postfix/

Posted in Linux | Tagged | Leave a comment

Reduce KVM Windows qcow2 file size

  1. Clean up the virtual drive (remove temps files, etc)
  2. Defrag with the open source UltraDefrag software with “full optimisation”
  3. Run “sdelete -z c:
  4. Run “qemu-img convert -p -f qcow2 -O qcow2 Win7.qcow2  /newpath/Win7.qcow2

For Linux Guest:

dd if=/dev/zero of=/mytempfile
# that could take a some time
rm -f /mytempfile

https://technet.microsoft.com/en-us/sysinternals/sdelete.aspx

 

Posted in Linux, Windows | Tagged | Leave a comment

Bash Assign Find Output To Array

To assign the output to an array, you need to use a command substitution inside of an array assignment.

arr=($(grep -n "search term" file.txt | sed 's/:.*//'))

The inner $() runs the command while the outer () causes the output to be an array. The problem with this is that it will not work with files containing spaces. To handle this, you can set IFS to \n.

IFS=$'\n'
arr=($(grep -n "search term" file.txt | sed 's/:.*//'))
unset IFS

You can also cut out the need for sed by performing an expansion on each element of the array:

arr=($(grep -n "search term" file.txt))
arr=("${arr[@]%%:*}")
Posted in Linux | Tagged , | Leave a comment

Shrinking LVM logical volume with ext3/ext4 filesystem

… the required steps to reduce the size of an LVM logical volume formatted as an ext4 filesystem…

1) Unmount the logical volume (or boot into a live CD if the logical volume contains the root filesystem)
2) Check the filesystem for errors
3) Shrink the filesystem to the desired size
4) Reduce the size of the underlying logical volume
5) Check if the resulting logical volume and filesystem are ok
6) Re-mount the logical volume

To illustrate the procedure assume a volume group name vg_d620 which contains the lv_example logical group. The objective will be to shrink the lv_example logical group that is formatted with ext4 to 30G.

1) Unmount the logical volume

Change to the superuser and unmount the logical volume filesystem that is to be resized:

  1. $ su
  2. # umount /dev/mapper/vg_d620-lv_example

2) Check the filesystem for errors

e2fsck checks a Linux ext2/ext3/ext4 filesystem for errors, in this case the -f switch is used to force the check even if the filesystem appears to be clean:

  1. # e2fsck -f /dev/mapper/vg_d620-lv_example
  2. e2fsck 1.41.12 (17-May-2010)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information/dev/mapper/vg_d620-lv_example: 11448/3678208 files (1.5% non-contiguous), 4768046/14704640 blocks

3) Shrink the filesystem to the desired size

resize2fs is used to shrink our unmounted filesystem located on vol_d620-lv_example. The -p switch is prints out percentage completion bars for the resize operation. Here the ext4 filesystem is reduced to the desired filesystem final size, in this case I want it to be of 30 gigabytes:

  1. # resize2fs -p /dev/mapper/vg_d620-lv_example 30G
  2. resize2fs 1.41.12 (17-May-2010)
    Resizing the filesystem on /dev/mapper/vg_d620-lv_example to 7864320 (4k) blocks.
    Begin pass 2 (max = 16894)
    Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Begin pass 3 (max = 449)
    Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Begin pass 4 (max = 1866)
    Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXThe filesystem on /dev/mapper/vg_d620-lv_example is now 7864320 blocks long.

4) Reduce the size of the underlying logical volume

Having shrunk the ext4 filesystem it is time to reduce the logical volume size accordingly. To achieve this the lvreduce tool is employed. The -L switch specifies final size of the logical volume which should match the size of the ext4 filesystem.

  1. # lvreduce -L 30G /dev/mapper/vg_d620-lv_example
  2. WARNING: Reducing active logical volume to 30.00 GiB
    THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce lv_example? [y/n]: y
    Reducing logical volume lv_example to 30.00 GiBLogical volume lv_example successfully resized

5) Check if the resulting logical volume and filesystem are ok

Everything should have proceeded as planned however let’s verify things. e2fsck and resize2fs are used verify the new filesystem, respectively. Notice that this time the resize2fs doesn’t specify any size, the goal here is to have the filesystem match the size of the logical volume.

  1. # e2fsck -f /dev/mapper/vg_d620-lv_example
  2. e2fsck 1.41.12 (17-May-2010)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information/dev/mapper/vg_d620-lv_example: 11448/1966080 files (1.5% non-contiguous), 4658570/7864320 blocks
  3. # resize2fs -p /dev/mapper/vg_d620-lv_example
  4. resize2fs 1.41.12 (17-May-2010)The filesystem is already 7864320 blocks long. Nothing to do!

6) Re-mount the logical volume

Finally, mount the updated logical volume:

  1. # mount /dev/mapper/vg_d620-lv_example /mnt/example

It should be noted that if in step 4 e2fsck fails because the partition is tool small lvextend can be used to extend the logical volume until e2fsck completes with success.

Further information on lvm, lvreduce, lvextend,e2fsck and resize2fs can be obtained in the associated man pages.

——————–

Shrinking a Logical Volume With LVM

Note: Before you do anything involving your partitions or volumes, make a complete backup.

Make sure to set up a test system with the same kernel and distribution to see how this stuff works. This article was written using our lab box. Read our terms of use. Note that this article was written using a Fedora RC 1 distribution and a generic 2.4.24 kernel.] As we do all of this, we have a text file on our logical volume called ruk.txt that we can use to somewhat test the integrity of our filesystem and volume:

[root@srv-1 root]# mount
/dev/sda1 on / type ext3 (rw)
none on /proc type proc (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sdb1 on /opt type ext3 (rw)
/dev/sdc1 on /usr/src type ext3 (rw)
/dev/sdd1 on /usr/local type ext3 (rw)
/dev/volgroup/logicalvol on /mnt type ext3 (rw)
[root@srv-1 root]# cat /mnt/ruk.txt
test
[root@srv-1 root]# umount /mnt

OK. We have data on our volume. Now, we want to shrink down the filesystem on our volume so we can remove one of the drives:

 
[root@srv-1 root]# lvmdiskscan
lvmdiskscan -- reading all disks / partitions (this may take a while...)
lvmdiskscan -- /dev/sda1  [       3.75 GB] Primary  LINUX native partition [0x83]
lvmdiskscan -- /dev/sda2  [     250.98 MB] Primary  LINUX swap partition [0x82]
lvmdiskscan -- /dev/sdb1  [          4 GB] Primary  LINUX native partition [0x83]
lvmdiskscan -- /dev/sdc1  [          4 GB] Primary  LINUX native partition [0x83]
lvmdiskscan -- /dev/sdd1  [          4 GB] Primary  LINUX native partition [0x83]
lvmdiskscan -- /dev/sde   [          4 GB] USED LVM whole disk
lvmdiskscan -- /dev/sdf   [          4 GB] USED LVM whole disk
lvmdiskscan -- /dev/sdg   [          4 GB] USED LVM whole disk
lvmdiskscan -- /dev/sdh   [          4 GB] free whole disk
lvmdiskscan -- 8 disks
lvmdiskscan -- 4 whole disks
lvmdiskscan -- 0 loop devices
lvmdiskscan -- 0 multiple devices
lvmdiskscan -- 0 network block devices
lvmdiskscan -- 5 partitions
lvmdiskscan -- 0 LVM physical volume partitions
[root@srv-1 root]# 
ot@srv-1 root]# e2fsck -f /dev/volgroup/logicalvol
e2fsck 1.34 (25-Jul-2003)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/volgroup/logicalvol: 12/1441792 files (0.0% non-contiguous), 53460/2883584 blocks
[root@srv-1 root]#
ot@srv-1 root]# resize2fs /dev/volgroup/logicalvol 40000
resize2fs 1.34 (25-Jul-2003)
Resizing the filesystem on /dev/volgroup/logicalvol to 40000 (4k) blocks.
The filesystem on /dev/volgroup/logicalvol is now 40000 blocks long.
[root@srv-1 root]# 

Check our test file:

[root@srv-1 root]# mount /dev/volgroup/logicalvol /mnt
[root@srv-1 root]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1              3874108   1611852   2065460  44% /
none                   3874108   1611852   2065460  44% /dev/pts
/dev/sdb1              4127076    235028   3682404   6% /opt
/dev/sdc1              4127076    278956   3638476   8% /usr/src
/dev/sdd1              4127076     32828   3884604   1% /usr/local
/dev/volgroup/logicalvol
155872     32832    116640  22% /mnt
[root@srv-1 root]#
[root@srv-1 root]# ls /mnt
lost+found  ruk.txt
[root@srv-1 root]# cat /mnt/ruk.txt
test
[root@srv-1 root]# 
[root@srv-1 root]# umount /mnt
umount: /mnt: not mounted

Our test file is still complete after resizing the filesystem. Note that the logical volume is still the same size. Let’s shrink it by 8 Gigs:

[root@srv-1 root]# lvreduce -L -8G /dev/volgroup/logicalvol
lvreduce -- WARNING: reducing active logical volume to 3 GB
lvreduce -- THIS MAY DESTROY YOUR DATA (filesystem etc.)
lvreduce -- do you really want to reduce "/dev/volgroup/logicalvol"? [y/n]: y
lvreduce -- doing automatic backup of volume group "volgroup"
lvreduce -- logical volume "/dev/volgroup/logicalvol" successfully reduced
[root@srv-1 root]# mount /dev/volgroup/logicalvol /mnt
[root@srv-1 root]# ls /mnt
lost+found  ruk.txt
[root@srv-1 root]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1              3874108   1611996   2065316  44% /
none                   3874108   1611996   2065316  44% /dev/pts
/dev/sdb1              4127076    235028   3682404   6% /opt
/dev/sdc1              4127076    278956   3638476   8% /usr/src
/dev/sdd1              4127076     32828   3884604   1% /usr/local
/dev/volgroup/logicalvol
155872     32832    116640  22% /mnt
[root@srv-1 root]# 
ot@srv-1 root]# cat /mnt/ruk.txt
test
[root@srv-1 root]# 

Our file is still there, and the logical volume is shrunk down. Let's remove /dev/sdg from the volume group:
[root@srv-1 root]# vgreduce volgroup /dev/sdg
vgreduce -- doing automatic backup of volume group "volgroup"
vgreduce -- volume group "volgroup" successfully reduced by physical volume:
vgreduce -- /dev/sdg
[root@srv-1 root]#

Let’s do a scan:

[root@srv-1 root]# pvscan
pvscan -- reading all physical volumes (this may take a while...)
pvscan -- ACTIVE   PV "/dev/sde" of VG "volgroup" [3.99 GB / 1016 MB free]
pvscan -- ACTIVE   PV "/dev/sdf" of VG "volgroup" [3.99 GB / 3.99 GB free]
pvscan -- inactive PV "/dev/sdg" is in no VG  [4 GB]
pvscan -- total: 3 [12 GB] / in use: 2 [8 GB] / in no VG: 1 [4 GB]
[root@srv-1 root]#

We are now ready to replace or reconfigure our logical volume.There are six articles in this series:
Setting Up Logical Volume Manager
Extending a Logical Volume
Shrinking a Logical Volume With LVM
Adding a RAID1 Device to a Volume With LVM
Upgrading LVM To Version 2 and Patching The Linux Kernel
Finish Conversion And Expansion to Two RAID1 Devices With LVM

Source : http://www.softpanorama.org/Commercial_linuxes/LVM/shrinking_a_logical_volume.shtml

Posted in Linux | Tagged , | Leave a comment

Only one Perl instance – lock script

Use File::NFSLock to get an exclusive lock on the script itself:

use Fcntl qw(LOCK_EX LOCK_NB);
use File::NFSLock;

# Try to get an exclusive lock on myself.
my $lock = File::NFSLock->new($0, LOCK_EX|LOCK_NB);
die "$0 is already running!\n" unless $lock;


Alternatively use Sys::RunAlone near the top of your code.
 use Sys::RunAlone;
 # code of which there may only be on instance running on system

 use Sys::RunAlone silent => 1;
 # be silent if other running instance detected

 use Sys::RunAlone retry => 50;
 # retry execution 50 times with wait time of 1 second in between

 use Sys::RunAlone retry => '55,60';
 # retry execution 55 times with wait time of 60 seconds in between

 use Sys::RunAlone 'silent';
 # obsolete form of silent => 1
Posted in Others | Tagged | Leave a comment

Escape special characters inside folder/file name variable

array=(`find /path/ -mindepth 2 -maxdepth 2 -type d -print | sed -e ‘s;[^/]*/;;g’ |  sed ‘s/&/\\&/’`)

( sed ‘s/&/\\&/’  replaces & with \& in the folder/file name )

Posted in Linux | Tagged , | Leave a comment

Exchange – remove address from all groups and hide it from GAL

Filename:  script.ps1

$email = (read-host “email”)

$GG = Get-DistributionGroup
$RG = $GG  | where {(Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains “$email”}

foreach( $dg in $RG ){
Remove-DistributionGroupMember $dg -Member $email
}

get-mailbox -Identity $email | Set-Mailbox -HiddenFromAddressListsEnabled $true

 

Posted in Exchange | Leave a comment

Expanding a LVM root partition to fill remaining drive space

Posted in Linux | Tagged | Leave a comment

Convert URL text to clickable hyperlink in Excel

1. Select the range of url text that you want to convert to clickable hyperlinks.

2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, and paste the following code in the Module Window.

1
2
3
4
5
6
7
8
9
10
11
12
Sub ConvertToHyperlinks()
'Updateby20140318
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    Application.ActiveSheet.Hyperlinks.Add Rng, Rng.Value
Next
End Sub

4. Then press F5 key to run the code, a pop up dialog for you to select a range, then click OK, and the selected unlinked urls have been converted to the clickable hyperlinks.

Posted in Windows | Tagged | Leave a comment

Resize KVM guest disk space then resize PV LV

Increase KVM virtual machine guest’s disk space from the command line if you initially set insufficient amount of disk space:

  1. Shutdown the VM
  2. Move the current image
    mv mykvm.img mykvm.img.bak
  3. Create a new image
    qemu-img create -f raw addon.raw 30G
  4. concatenate the 2 images
    cat mykvm.img.bak addon.raw >> mykvm.img
  5. Alternatively – use qemu-img to reize a qcow2 image: qemu-img resize my-server.qcow2 +10GB 
  6. start the VM (using the newly created mykvm.img)
  7. run fdisk inside VM and delete & re-create LVM partition
    % fdisk /dev/vda
    ...
    Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *           1          13      104391   83  Linux
    /dev/vda2              14        3263    26105625   8e  Linux LVM
     
    Command (m for help): d
    Partition number (1-4): 2
     
    Command (m for help): p
    
    Disk /dev/vda: 48.3 GB, 48318382080 bytes
    255 heads, 63 sectors/track, 5874 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
     
    Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *           1          13      104391   83  Linux
     
    Command (m for help): n 
    Command action
      e   extended
      p   primary partition (1-4)
    p
    Partition number (1-4): 2
    First cylinder (14-5874, default 14): 14
    Last cylinder or +size or +sizeM or +sizeK (14-5874, default 5874): 
    Using default value 5874
     
    Command (m for help): p
     
    Disk /dev/vda: 48.3 GB, 48318382080 bytes
    255 heads, 63 sectors/track, 5874 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
     
    Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *           1          13      104391   83  Linux
    /dev/vda2              14        5874    47078482+  83  Linux
     
    Command (m for help): t
    Partition number (1-4): 2
    Hex code (type L to list codes): 8e
    Changed system type of partition 2 to 8e (Linux LVM)
     
    Command (m for help): p
     
    Disk /dev/vda: 48.3 GB, 48318382080 bytes
    255 heads, 63 sectors/track, 5874 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
     
    Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *           1          13      104391   83  Linux
    /dev/vda2              14        5874    47078482+  8e  Linux LVM
     
    Command (m for help): w
    The partition table has been altered!
     
    Calling ioctl() to re-read partition table.
     
    WARNING: Re-reading the partition table failed with error 16: Device or 
    resource busy.
    The kernel still uses the old table.
    The new table will be used at the next reboot.
    Syncing disks.
    %
  8. Reboot the VM
  9. Resize the LVM physical volume
    % pvdisplay 
      --- Physical volume ---
      PV Name               /dev/vda2
      VG Name               VolGroup00
      PV Size               24.90 GB / not usable 21.59 MB
      Allocatable           yes (but full)
      PE Size (KByte)       32768
      Total PE              796
      Free PE               0
      ...
     
    % pvresize /dev/vda2
     
    % pvdisplay
      --- Physical volume ---
      PV Name               /dev/vda2
      VG Name               VolGroup00
      PV Size               44.90 GB / not usable 22.89 MB
      Allocatable           yes 
      PE Size (KByte)       32768
      Total PE              1436
      Free PE               640
      ...
  10. Resize the LVM Logical Volume
    % lvresize /dev/VolGroup00/LogVol00 -l +100%FREE
      Extending logical volume LogVol00 to 43.88 GB
      Logical volume LogVol00 successfully resized
  11. Grow the File system
    % resize2fs /dev/VolGroup00/LogVol00 
      resize2fs 1.39 (29-May-2006)
      Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
      Performing an on-line resize of /dev/VolGroup00/LogVol00 to 11501568 (4k) blocks.
      The filesystem on /dev/VolGroup00/LogVol00 is now 11501568 blocks long.

Tested on RHEL7.2 VM

Source: http://akyl.net/how-do-you-increase-kvm-guests-disk-space

 

Posted in Linux | Tagged , | Leave a comment